@devries-cameron20 / t3code-1 / commits / 97e7834f4b
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): a released provider session ends its tool call nodes too (#39734)

Jex committed Nov 20, 2026 at 22:36 UTC 97e7834f4ba61cea2e6e6f4938152b5b7c0262b3
2 files changed +69 -15
apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
+42 -1
@@ -3414,8 +3414,12 @@ const openSessionWithBackgroundCommand = (fixtureName: string) =>
3414 toolName: "mcp__t3-code__t3_worktree_handoff",
3415 input: {},
3416 }) satisfies OrchestrationV2TurnItem;
3417 + const cutOffNodeId = idAllocator.derive.nodeFromProviderItem({
3418 + driver: CODEX_DRIVER,
3419 + nativeItemId: "cut-off",
3420 + });
3421 const seededToolCalls = {
3418 - cutOff: toolCall("cut-off", providerThreads[0]!, "running", now),
3422 + cutOff: { ...toolCall("cut-off", providerThreads[0]!, "running", now), nodeId: cutOffNodeId },
3423 finished: toolCall("finished", providerThreads[0]!, "completed", now),
3424 otherSession: toolCall("other-session", providerThreads[1]!, "running", now),
3425 // Started by a replacement session after the release.
@@ -3441,7 +3445,41 @@ const openSessionWithBackgroundCommand = (fixtureName: string) =>
3445 ],
3446 });
3447 });
3448 + yield* eventSink.write({
3449 + events: [
3450 + {
3451 + id: yield* idAllocator.allocate.event({ threadId }),
3452 + type: "node.updated",
3453 + threadId,
3454 + nodeId: cutOffNodeId,
3455 + driver: CODEX_DRIVER,
3456 + occurredAt: now,
3457 + payload: {
3458 + id: cutOffNodeId,
3459 + threadId,
3460 + runId: null,
3461 + parentNodeId: null,
3462 + rootNodeId: cutOffNodeId,
3463 + kind: "tool_call",
3464 + status: "running",
3465 + countsForRun: true,
3466 + providerThreadId: providerThreads[0]!.id,
3467 + providerTurnId: null,
3468 + nativeItemRef: null,
3469 + runtimeRequestId: null,
3470 + checkpointScopeId: null,
3471 + startedAt: now,
3472 + completedAt: null,
3473 + },
3474 + },
3475 + ],
3476 + });
3477 yield* Effect.forEach(Object.values(seededToolCalls), writeToolCall);
3478 + const cutOffNodeStatus = Effect.gen(function* () {
3479 + const projectionStore = yield* ProjectionStore.ProjectionStoreV2;
3480 + const projection = yield* projectionStore.getThreadProjection(threadId);
3481 + return projection.nodes.find((node) => node.id === cutOffNodeId)?.status;
3482 + });
3483 // A background native subagent that outlived its completed run; Claude records no provider thread on it.
3484 const nativeSubagentRunId = idAllocator.derive.run({ threadId, ordinal: 1 });
3485 const nativeSubagentId = idAllocator.derive.nodeFromProviderItem({
@@ -3525,6 +3563,7 @@ const openSessionWithBackgroundCommand = (fixtureName: string) =>
3563 toolCalls,
3564 toolCallStatus,
3565 nativeSubagentStatus,
3566 + cutOffNodeStatus,
3567 };
3568 });
3569
@@ -3544,6 +3583,7 @@ it.effect.each(["detach", "stream failure", "provider stop", "early close"] as c
3583 seededToolCalls,
3584 writeToolCall,
3585 nativeSubagentStatus,
3586 + cutOffNodeStatus,
3587 } = yield* openSessionWithBackgroundCommand("provider-session-manager-detach-roster");
3588 const runtime = Option.getOrThrow(yield* manager.get(providerSessionId));
3589 const subscription = yield* runtime.subscribeEvents!;
@@ -3628,6 +3668,7 @@ it.effect.each(["detach", "stream failure", "provider stop", "early close"] as c
3668 otherSession: "running",
3669 replacement: "running",
3670 });
3671 + assert.equal(yield* cutOffNodeStatus, "interrupted");
3672 // regression: #36548 a native subagent the dead process ran stayed running after its run completed
3673 assert.notInclude(["pending", "running", "waiting"], yield* nativeSubagentStatus);
3674 });
apps/server/src/orchestration-v2/ProviderSessionManager.ts
+27 -14
@@ -1050,23 +1050,36 @@ export const layerWithOptions = (
1050 // after each pass: queued events can also store more cut-off items.
1051 let pending = yield* readCutOff;
1052 for (let pass = 0; pass < 3 && pending.length > 0; pass++) {
1053 + const { nodes } = yield* projectionStore.getThreadRecords(threadId, ["nodes"], {
1054 + nodeIds: pending.flatMap((item) => (item.nodeId === null ? [] : [item.nodeId])),
1055 + });
1056 for (const item of pending) {
1057 const now = yield* DateTime.now;
1055 - yield* eventSink.writeIfTurnItemUnchanged({
1056 - expected: item,
1057 - events: [
1058 - {
1059 - id: yield* idAllocator.allocate.event({ threadId, providerSessionId }),
1060 - type: "turn-item.updated",
1061 - threadId,
1062 - ...(item.runId === null ? {} : { runId: item.runId }),
1063 - ...(item.nodeId === null ? {} : { nodeId: item.nodeId }),
1064 - driver,
1065 - occurredAt: now,
1066 - payload: { ...item, status: "interrupted", completedAt: now, updatedAt: now },
1067 - },
1068 - ],
1058 + const node = nodes.find((candidate) => candidate.id === item.nodeId);
1059 + const events: Array<OrchestrationV2DomainEvent> = [];
1060 + if (node !== undefined && isOrchestrationV2WorkActive(node.status)) {
1061 + events.push({
1062 + id: yield* idAllocator.allocate.event({ threadId, providerSessionId }),
1063 + type: "node.updated",
1064 + threadId,
1065 + ...(node.runId === null ? {} : { runId: node.runId }),
1066 + nodeId: node.id,
1067 + driver,
1068 + occurredAt: now,
1069 + payload: { ...node, status: "interrupted", completedAt: now },
1070 + });
1071 + }
1072 + events.push({
1073 + id: yield* idAllocator.allocate.event({ threadId, providerSessionId }),
1074 + type: "turn-item.updated",
1075 + threadId,
1076 + ...(item.runId === null ? {} : { runId: item.runId }),
1077 + ...(item.nodeId === null ? {} : { nodeId: item.nodeId }),
1078 + driver,
1079 + occurredAt: now,
1080 + payload: { ...item, status: "interrupted", completedAt: now, updatedAt: now },
1081 });
1082 + yield* eventSink.writeIfTurnItemUnchanged({ expected: item, events });
1083 }
1084 pending = yield* readCutOff;
1085 }