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, 14:45 UTC
fix(server): Resume keeps unaccepted replacement images (#36677)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 14, 2026 at 12:47 UTC
0acca1de27f932a07344da2656cba7e58aa059c7
2 files changed
+42
-11
apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts
+26
-5
@@ -413,6 +413,7 @@ function makeLocalCommandHarness(input: {
413
readonly unsentResume?: boolean;
414
readonly repeatedResume?: boolean;
415
readonly acceptedResume?: boolean;
416
+ readonly restartedResume?: boolean;
417
readonly nativeForkFrom?: "idle" | "busy";
418
readonly switchedProvider?: boolean;
419
readonly threadRuntimeMode?: OrchestrationV2ThreadProjection["thread"]["runtimeMode"];
@@ -814,6 +815,18 @@ function makeLocalCommandHarness(input: {
815
providerThreadId: oldProviderThreadId,
816
status: "interrupted",
817
},
818
+ ...(input.sideChat.restartedResume
819
+ ? [
820
+ {
821
+ ...projection.attempts[0]!,
822
+ id: RunAttemptId.make("unaccepted-replacement"),
823
+ runId: RunId.make("stopped-run"),
824
+ attemptOrdinal: 2,
825
+ reason: "steering_restart" as const,
826
+ status: "interrupted" as const,
827
+ },
828
+ ]
829
+ : []),
830
],
831
providerTurns: [
832
...projection.providerTurns,
@@ -1583,6 +1596,14 @@ effectIt.effect.each([
1596
unsentResume: true,
1597
acceptedResume: true,
1598
},
1599
+ {
1600
+ contextRun: "delivered",
1601
+ runtimeMode: "full-access",
1602
+ context: "",
1603
+ unsentResume: true,
1604
+ acceptedResume: true,
1605
+ restartedResume: true,
1606
+ },
1607
{
1608
contextRun: "current",
1609
threadRuntimeMode: "approval-required",
@@ -1604,14 +1625,14 @@ effectIt.effect.each([
1625
expect(harness.open).toHaveBeenCalledWith(
1626
expect.objectContaining({ runtimePolicy: expect.objectContaining({ runtimeMode }) }),
1627
);
1628
+ const resendsOriginal =
1629
+ "unsentResume" in sideChat &&
1630
+ (!("acceptedResume" in sideChat) || "restartedResume" in sideChat);
1631
expect(harness.startTurn.mock.calls.map(([turn]) => turn.message.text)).toEqual([
1608
- withInlineContext(
1609
- context,
1610
- "unsentResume" in sideChat && !("acceptedResume" in sideChat) ? "Original request" : "",
1611
- ),
1632
+ withInlineContext(context, resendsOriginal ? "Original request" : ""),
1633
]);
1634
expect(harness.startTurn.mock.calls[0]?.[0].resume === true).toBe(
1614
- context === "" && (!("unsentResume" in sideChat) || "acceptedResume" in sideChat),
1635
+ context === "" && !resendsOriginal,
1636
);
1637
expect(harness.projection().contextHandoffs).toMatchObject([
1638
{
apps/server/src/orchestration-v2/manualContinuation.ts
+16
-6
@@ -8,16 +8,26 @@ export function unsentManualContinuationSource(
8
if (sourceId === undefined) return undefined;
9
const runs = new Map(projection.runs.map((source) => [source.id, source]));
10
const acceptedAttempts = new Set(projection.providerTurns.map((turn) => turn.runAttemptId));
11
- const acceptedRuns = new Set(
12
- projection.attempts
13
- .filter((attempt) => acceptedAttempts.has(attempt.id))
14
- .map((attempt) => attempt.runId),
15
- );
11
+ const latestAttempt = (
12
+ runId: OrchestrationV2Run["id"],
13
+ matches: (attempt: (typeof projection.attempts)[number]) => boolean,
14
+ ) =>
15
+ Math.max(
16
+ 0,
17
+ ...projection.attempts
18
+ .filter((attempt) => attempt.runId === runId && matches(attempt))
19
+ .map((attempt) => attempt.attemptOrdinal),
20
+ );
21
const visited = new Set<OrchestrationV2Run["id"]>();
22
while (sourceId !== undefined && !visited.has(sourceId)) {
23
visited.add(sourceId);
24
const source = runs.get(sourceId);
20
- if (source === undefined || acceptedRuns.has(sourceId)) return undefined;
25
+ if (source === undefined) return undefined;
26
+ const accepted = latestAttempt(sourceId, (attempt) => acceptedAttempts.has(attempt.id));
27
+ // An accepted attempt delivered everything before it; only a later steering restart's message is unsent.
28
+ const restarted = latestAttempt(sourceId, (attempt) => attempt.reason === "steering_restart");
29
+ if (restarted > accepted) return source;
30
+ if (accepted > 0) return undefined;
31
if (source.manualContinuationOfRunId === undefined) return source;
32
sourceId = source.manualContinuationOfRunId;
33
}