Skip to content
Open
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
5 changes: 3 additions & 2 deletions ts/packages/dispatcher/dispatcher/src/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ export function createDispatcherFromContext(
// Use original requestId so display appends to same message group
context.currentRequestId = pending.requestId;
context.commandResult = undefined;
let commandResult: CommandResult | undefined;
try {
const appAgent = context.agents.getAppAgent(
pending.agentName,
Expand Down Expand Up @@ -611,11 +612,11 @@ export function createDispatcherFromContext(
}
}
} finally {
const result = context.commandResult;
commandResult = context.commandResult;
context.commandResult = undefined;
context.currentRequestId = undefined;
return result;
}
return commandResult;
});
},
async respondToInteraction(
Expand Down
22 changes: 22 additions & 0 deletions ts/packages/dispatcher/dispatcher/test/chainedChoice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ const handlers = {
),
),
},
fail: {
description: "Returns a choice whose callback fails",
run: async () =>
createYesNoChoiceResult(choiceManager, "fail?", async () => {
throw new Error("choice callback failed");
}),
},
},
} as const;

Expand Down Expand Up @@ -140,4 +147,19 @@ describe("Chained choice cards", () => {
expect(captured[1].message).toBe("second?");
expect(captured[1].choiceId).not.toBe(captured[0].choiceId);
}, 10_000);

it("propagates choice callback failures without blocking later choices", async () => {
await awaitCommand(dispatcher, "@choicechain fail");
const choice = captured.at(-1)!;

await expect(
dispatcher.respondToChoice(choice.choiceId, true),
).rejects.toThrow("choice callback failed");

await awaitCommand(dispatcher, "@choicechain chain");
const nextChoice = captured.at(-1)!;
await dispatcher.respondToChoice(nextChoice.choiceId, true);

expect(captured.at(-1)!.message).toBe("second?");
});
});
Loading