Skip to content

Commit dccdab7

Browse files
fix(server): commit the recovery handoff item with the running transition
An interrupted start no longer leaves a Recovered context item on a run that never reached running. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b509eb5 commit dccdab7

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,7 @@ export const layer: Layer.Layer<
11181118
let resumedRetryHandoff: ReadonlyArray<OrchestrationV2ContextHandoff> | undefined;
11191119
let resumedHandoffContext: ReturnType<typeof handoffContextForThread> | undefined;
11201120
let portableForkFallback: OrchestrationV2ContextHandoff | undefined;
1121+
let recoveryTurnItem: OrchestrationV2TurnItem | undefined;
11211122
const loadedProviderThread = yield* Effect.gen(function* () {
11221123
if (nativeForkTransfer !== undefined) {
11231124
const sourceProjection = yield* projectionStore.getThreadRecords(
@@ -1453,17 +1454,9 @@ export const layer: Layer.Layer<
14531454
consumedAt: null,
14541455
},
14551456
},
1456-
{
1457-
id: yield* idAllocator.allocate.event({ threadId: projection.thread.id }),
1458-
type: "turn-item.updated",
1459-
threadId: projection.thread.id,
1460-
runId: run.id,
1461-
providerInstanceId: run.providerInstanceId,
1462-
occurredAt: createdAt,
1463-
payload: handoffTurnItem,
1464-
},
14651457
],
14661458
});
1459+
recoveryTurnItem = handoffTurnItem;
14671460
return replacement;
14681461
});
14691462
if (loadedProviderThread === undefined) return;
@@ -1570,6 +1563,20 @@ export const layer: Layer.Layer<
15701563
},
15711564
},
15721565
]),
1566+
// Shown only once the replacement session commits with the running transition.
1567+
...(recoveryTurnItem === undefined
1568+
? []
1569+
: [
1570+
{
1571+
id: yield* idAllocator.allocate.event({ threadId: projection.thread.id }),
1572+
type: "turn-item.updated" as const,
1573+
threadId: projection.thread.id,
1574+
runId: run.id,
1575+
providerInstanceId: run.providerInstanceId,
1576+
occurredAt: now,
1577+
payload: recoveryTurnItem,
1578+
},
1579+
]),
15731580
{
15741581
id: yield* idAllocator.allocate.event({ threadId: projection.thread.id }),
15751582
type: "run.updated",

0 commit comments

Comments
 (0)