Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ export class RuntimeOrchestrationContext extends OrchestrationContext {

getActions(): pb.OrchestratorAction[] {
if (this._completionStatus === pb.OrchestrationStatus.ORCHESTRATION_STATUS_CONTINUED_AS_NEW) {
// Only return the single completion actions when continuing-as-new
let carryoverEvents: pb.HistoryEvent[] | null = null;

if (this._saveEvents) {
Expand All @@ -266,7 +265,11 @@ export class RuntimeOrchestrationContext extends OrchestrationContext {
carryoverEvents,
);

return [action];
// Include fire-and-forget actions (sendEvent, signalEntity, etc.) that were
// scheduled before continueAsNew was called, consistent with setComplete/setFailed
const allActions = Object.values(this._pendingActions);
allActions.push(action);
return allActions;
}

return Object.values(this._pendingActions);
Expand Down
43 changes: 43 additions & 0 deletions packages/durabletask-js/test/in-memory-backend.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,49 @@ describe("In-Memory Backend", () => {
expect(state?.serializedOutput).toEqual(JSON.stringify(5));
});

it("should preserve sendEvent actions when continuing-as-new", async () => {
// Receiver orchestration that waits for an event
const receiver: TOrchestrator = async function* (ctx: OrchestrationContext): any {
const value = yield ctx.waitForExternalEvent("ping");
return value;
};

// Sender orchestration that sends an event then continues-as-new
const sender: TOrchestrator = async (ctx: OrchestrationContext, input: { receiverId: string; iteration: number }) => {
if (input.iteration === 1) {
// On first iteration, send event to receiver then continue-as-new
ctx.sendEvent(input.receiverId, "ping", "hello from sender");
ctx.continueAsNew({ receiverId: input.receiverId, iteration: 2 }, false);
} else {
return "sender done";
}
};

worker.addOrchestrator(receiver);
worker.addOrchestrator(sender);
await worker.start();

// Start receiver first, then sender
const receiverId = await client.scheduleNewOrchestration(receiver);
await client.waitForOrchestrationStart(receiverId, false, 5);

const senderId = await client.scheduleNewOrchestration(sender, { receiverId, iteration: 1 });

// Wait for both to complete
const senderState = await client.waitForOrchestrationCompletion(senderId, true, 10);
const receiverState = await client.waitForOrchestrationCompletion(receiverId, true, 10);

// Sender should complete after continuing-as-new
expect(senderState).toBeDefined();
expect(senderState?.runtimeStatus).toEqual(OrchestrationStatus.COMPLETED);
expect(senderState?.serializedOutput).toEqual(JSON.stringify("sender done"));

// Receiver should have received the event sent before continue-as-new
expect(receiverState).toBeDefined();
expect(receiverState?.runtimeStatus).toEqual(OrchestrationStatus.COMPLETED);
expect(receiverState?.serializedOutput).toEqual(JSON.stringify("hello from sender"));
});

it("should handle orchestration without activities", async () => {
const orchestrator: TOrchestrator = async (_: OrchestrationContext, input: number) => {
return input * 2;
Expand Down
Loading