Skip to content

Commit d756fed

Browse files
fix(server): provider switches hand off started cancelled runs (#34016)
1 parent 871b009 commit d756fed

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,13 @@ function rootProviderThreadsForProvider(
11011101
}
11021102

11031103
function isHandoffSourceRun(run: OrchestrationV2Run): boolean {
1104-
return run.status === "completed" || run.status === "failed" || run.status === "interrupted";
1104+
return (
1105+
run.status === "completed" ||
1106+
run.status === "failed" ||
1107+
run.status === "interrupted" ||
1108+
// A queued request cancelled before it started never reached any provider.
1109+
(run.status === "cancelled" && run.startedAt !== null)
1110+
);
11051111
}
11061112

11071113
function lastDeliveredRunForProviderThread(

‎apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ function makeTestAdapter(input: {
114114
readonly failure?: ReturnType<typeof makeProviderFailure>;
115115
readonly failedRunOrdinals?: ReadonlySet<number>;
116116
readonly interruptedRunOrdinals?: ReadonlySet<number>;
117+
readonly cancelledRunOrdinals?: ReadonlySet<number>;
117118
readonly holdRunOrdinal?: number;
118119
readonly pendingBackgroundWork?: Ref.Ref<boolean>;
119120
readonly subagentOnlyBackgroundWork?: boolean;
@@ -295,7 +296,9 @@ function makeTestAdapter(input: {
295296
? "failed"
296297
: input.interruptedRunOrdinals?.has(turnInput.runOrdinal)
297298
? "interrupted"
298-
: "completed";
299+
: input.cancelledRunOrdinals?.has(turnInput.runOrdinal)
300+
? "cancelled"
301+
: "completed";
299302
const response =
300303
input.responseByThreadId?.[turnInput.threadId]?.[turnInput.runOrdinal] ??
301304
input.responseByRunOrdinal[turnInput.runOrdinal] ??
@@ -1587,6 +1590,8 @@ describe("orchestration v2 provider switching", () => {
15871590
["failed", true, true, true],
15881591
["interrupted", false, true, false],
15891592
["interrupted", true, false, true],
1593+
["cancelled", false, false, false],
1594+
["cancelled", true, true, false],
15901595
] as const
15911596
).map(
15921597
([status, queued, returning, native]) =>
@@ -1631,6 +1636,7 @@ describe("orchestration v2 provider switching", () => {
16311636
interruptedRunOrdinals: new Set(
16321637
status === "interrupted" ? [sourceOrdinal] : [],
16331638
),
1639+
cancelledRunOrdinals: new Set(status === "cancelled" ? [sourceOrdinal] : []),
16341640
holdRunOrdinal: sourceOrdinal,
16351641
holdFirstTurn: started,
16361642
releaseFirstTurn: release,
@@ -1644,7 +1650,7 @@ describe("orchestration v2 provider switching", () => {
16441650
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
16451651
const waitForRun = (
16461652
ordinal: number,
1647-
expectedStatus: "completed" | "failed" | "interrupted",
1653+
expectedStatus: "completed" | "failed" | "interrupted" | "cancelled",
16481654
) =>
16491655
orchestrator.streamStoredEvents.pipe(
16501656
Stream.filter(

0 commit comments

Comments
 (0)