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, 23:30 UTC
fix(server): runs cancelled by a server restart say why in the thread (#27192)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 11, 2026 at 04:32 UTC
d806251188fed764490359bd22bd2d0111a8681f
3 files changed
+47
-4
apps/server/src/orchestration-v2/ProviderRuntimeRecoveryService.test.ts
+1
@@ -793,6 +793,7 @@ it.effect(
793
["turn-item.updated", "cancelled"],
794
["turn-item.updated", "cancelled"],
795
["turn-item.updated", "cancelled"],
796
+ ["turn-item.updated", "completed"],
797
["provider-thread.updated", "idle"],
798
["provider-session.updated", "stopped"],
799
],
apps/server/src/orchestration-v2/ProviderRuntimeRecoveryService.ts
+30
@@ -634,6 +634,36 @@ export const make = Effect.gen(function* () {
634
payload: cancelledItem(item, now),
635
});
636
}
637
+ // Queued runs and unsent resumes leave no visible turn behind, so there is nothing to explain.
638
+ if (run.status === "queued" || unsentResumeRunIds.includes(run.id)) continue;
639
+ events.push({
640
+ id: yield* allocateEventId(),
641
+ type: "turn-item.updated",
642
+ threadId: projection.thread.id,
643
+ runId: run.id,
644
+ ...(run.rootNodeId === null ? {} : { nodeId: run.rootNodeId }),
645
+ providerInstanceId: run.providerInstanceId,
646
+ occurredAt: now,
647
+ payload: {
648
+ id: ids.derive.runSignalTurnItem({ runId: run.id, signal: "server-recovery" }),
649
+ threadId: projection.thread.id,
650
+ runId: run.id,
651
+ nodeId: run.rootNodeId,
652
+ providerThreadId: run.providerThreadId,
653
+ providerTurnId: null,
654
+ nativeItemRef: null,
655
+ parentItemId: null,
656
+ // EventSink allocates the real position, after the run's existing items.
657
+ ordinal: 0,
658
+ status: "completed",
659
+ title: trigger === "startup" ? "Server restarted" : "Server shut down",
660
+ startedAt: now,
661
+ completedAt: now,
662
+ updatedAt: now,
663
+ type: "system_notice",
664
+ message: detail,
665
+ },
666
+ });
667
}
668
// Blocking waits die with their turn; let child results wake the parent continuation as async tasks.
669
const cutRunIds = new Set(runs.map((run) => run.id));
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+16
-4
@@ -1591,10 +1591,16 @@ it.layer(layerTest)("OrchestrationV2LayerLive", (it) => {
1591
assert.equal(native.runtimeRequests[0]?.responseCapability.type, "not_resumable");
1592
yield* recovery.reconcile("shutdown");
1593
yield* recovery.reconcile("startup");
1594
- assert.deepEqual(
1595
- (yield* orchestrator.getThreadProjection(threadId)).runtimeRequests,
1596
- recovered.runtimeRequests,
1597
- );
1594
+ const rerecovered = yield* orchestrator.getThreadProjection(threadId);
1595
+ assert.deepEqual(rerecovered.runtimeRequests, recovered.runtimeRequests);
1596
+ const runItems = rerecovered.turnItems.filter((item) => item.runId === runId);
1597
+ const notices = runItems.filter((item) => item.type === "system_notice");
1598
+ assert.lengthOf(notices, scope === "run" ? 1 : 0);
1599
+ if (scope === "run") {
1600
+ assert.equal(notices[0]?.title, "Server restarted");
1601
+ assert.equal(notices[0]?.nodeId, recovered.runs[0]?.rootNodeId);
1602
+ assert.equal(notices[0]?.ordinal, Math.max(...runItems.map((item) => item.ordinal)));
1603
+ }
1604
yield* orchestrator.dispatch({
1605
type: "runtime-request.respond",
1606
commandId: CommandId.make(`recovery-answer-${trigger}-${scope}`),
@@ -9416,6 +9422,12 @@ it.layer(layerTest)("usage-limit recovery", (it) => {
9422
),
9423
[run.id, resumed.runs.at(-1)!.id],
9424
);
9425
+ assert.deepEqual(
9426
+ resumed.turnItems.flatMap((item) =>
9427
+ item.type === "system_notice" && item.title === "Server restarted" ? [item.runId] : [],
9428
+ ),
9429
+ scenario === "resume" ? [] : [continuation.id],
9430
+ );
9431
assert.deepEqual(
9432
resumed.runs.map((row) => row.status),
9433
scenario === "resume" ? ["failed", "cancelled", "starting"] : ["failed", "cancelled"],