The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 12:15 UTC
fix(server): Stop on a stalled run closes its approval and question cards (#30695)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Southwell committed
Nov 15, 2026 at 15:38 UTC
85168744f7dd5208b83ec84abcd659c3e4b649a1
2 files changed
+97
-4
apps/server/src/orchestration-v2/BackgroundWorkStop.integration.test.ts
+84
@@ -11,6 +11,7 @@ import {
11
ProviderTurnId,
12
RunAttemptId,
13
RunId,
14
+ RuntimeRequestId,
15
ThreadId,
16
TurnItemId,
17
type OrchestrationV2DomainEvent,
@@ -385,6 +386,79 @@ const stopEarlierBackgroundWork = ({
386
},
387
],
388
});
389
+ // Shaped like CodexAdapterV2's buildApprovalRequestArtifacts output.
390
+ const approvalRequestId = RuntimeRequestId.make("request:stalled-approval");
391
+ const approvalNodeId = NodeId.make("node:stalled-approval");
392
+ const approvalItemId = TurnItemId.make("turn-item:stalled-approval");
393
+ if (stalledRun === "returned-interrupt") {
394
+ yield* sink.write({
395
+ events: [
396
+ {
397
+ id: EventId.make("stalled-approval-node"),
398
+ type: "node.updated",
399
+ threadId,
400
+ runId: run.id,
401
+ occurredAt: now,
402
+ payload: {
403
+ ...node,
404
+ id: approvalNodeId,
405
+ parentNodeId: node.id,
406
+ kind: "approval_request",
407
+ status: "waiting",
408
+ countsForRun: false,
409
+ runtimeRequestId: approvalRequestId,
410
+ },
411
+ },
412
+ {
413
+ id: EventId.make("stalled-approval-request"),
414
+ type: "runtime-request.updated",
415
+ threadId,
416
+ occurredAt: now,
417
+ payload: {
418
+ id: approvalRequestId,
419
+ nodeId: approvalNodeId,
420
+ providerTurnId: codexTurn.id,
421
+ nativeRequestRef: { driver, nativeId: "approval", strength: "strong" },
422
+ kind: "command",
423
+ status: "pending",
424
+ responseCapability: {
425
+ type: "live",
426
+ providerSessionId: first.providerThread.providerSessionId!,
427
+ },
428
+ createdAt: now,
429
+ resolvedAt: null,
430
+ },
431
+ },
432
+ {
433
+ id: EventId.make("stalled-approval-item"),
434
+ type: "turn-item.updated",
435
+ threadId,
436
+ runId: run.id,
437
+ occurredAt: now,
438
+ payload: {
439
+ id: approvalItemId,
440
+ threadId,
441
+ runId: run.id,
442
+ nodeId: approvalNodeId,
443
+ providerThreadId: codexTurn.providerThreadId,
444
+ providerTurnId: codexTurn.id,
445
+ nativeItemRef: null,
446
+ parentItemId: null,
447
+ ordinal: 101,
448
+ status: "waiting",
449
+ title: null,
450
+ startedAt: now,
451
+ completedAt: null,
452
+ updatedAt: now,
453
+ type: "approval_request",
454
+ requestId: approvalRequestId,
455
+ requestKind: "command",
456
+ prompt: "rm -rf build",
457
+ },
458
+ },
459
+ ],
460
+ });
461
+ }
462
if (stalledRun === "superseded-attempt") {
463
yield* sink.write({
464
events: [
@@ -446,6 +520,16 @@ const stopEarlierBackgroundWork = ({
520
interrupted ? 1 : 0,
521
);
522
assert.isEmpty(after.runs.filter((candidate) => candidate.status === "waiting"));
523
+ if (stalledRun === "returned-interrupt") {
524
+ assert.deepEqual(
525
+ [
526
+ after.runtimeRequests.find((candidate) => candidate.id === approvalRequestId)?.status,
527
+ after.nodes.find((candidate) => candidate.id === approvalNodeId)?.status,
528
+ after.turnItems.find((candidate) => candidate.id === approvalItemId)?.status,
529
+ ],
530
+ ["cancelled", "interrupted", "interrupted"],
531
+ );
532
+ }
533
return;
534
}
535
const settled = yield* watch(
apps/server/src/orchestration-v2/Orchestrator.ts
+13
-4
@@ -12442,6 +12442,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
12442
.filter((subagent) => subagent.origin === "app_owned")
12443
.map((subagent) => subagent.id),
12444
);
12445
+ // Callers load only tool and message items; the request cards close with the requests below.
12446
+ const requestCards = yield* projectionStore
12447
+ .getThreadRecords(run.threadId, ["turnItems"], {
12448
+ turnItemTypes: ["approval_request", "user_input_request"],
12449
+ turnItemRunIds: [run.id],
12450
+ turnItemStatuses: ["waiting"],
12451
+ })
12452
+ .pipe(mapDispatchError(input.command));
12453
const cascaded = yield* RunExecutionService.cascadeTerminalizeRunOwnedSubagents({
12454
run,
12455
status: "interrupted",
@@ -12464,13 +12472,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
12472
),
12473
turnItems: new Map(),
12474
childTurnItems: new Map(
12467
- input.projection.turnItems
12468
- .filter(
12475
+ [
12476
+ ...input.projection.turnItems.filter(
12477
(item) =>
12478
item.runId === run.id &&
12479
(item.type === "assistant_message" || item.type === "reasoning"),
12472
- )
12473
- .map((item) => [item.id, item]),
12480
+ ),
12481
+ ...requestCards.turnItems,
12482
+ ].map((item) => [item.id, item]),
12483
),
12484
linkedChildThreadIds: new Set([run.threadId]),
12485
},