@devries-cameron20 / t3code Mirror · read-only / commits / 78d74598d4
Fork 0

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, 06:00 UTC

fix(client-runtime): hide Resume where the provider cannot continue a stopped run (#39229)

Julius Marminge committed Nov 19, 2026 at 09:36 UTC 78d74598d47fad98f449f9890d62c72b604d937c
15 files changed +83 -10
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+1
@@ -570,6 +570,7 @@ export const ClaudeProviderCapabilitiesV2 = {
570 emitsTurnStarted: true,
571 emitsTurnCompleted: true,
572 supportsInterrupt: true,
573 + supportsNativeResume: true,
574 supportsActiveSteering: true,
575 activeSteeringInterruptsTools: true,
576 supportsSteeringByInterruptRestart: false,
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+1
@@ -282,6 +282,7 @@ export const CodexProviderCapabilitiesV2 = {
282 emitsTurnStarted: true,
283 emitsTurnCompleted: true,
284 supportsInterrupt: true,
285 + supportsNativeResume: true,
286 supportsActiveSteering: true,
287 activeSteeringDuringCompaction: true,
288 supportsSteeringByInterruptRestart: true,
apps/server/src/orchestration-v2/ProjectionStore.ts
+1 -1
@@ -5,7 +5,7 @@ import { projectTurnItemForWire } from "./WireProjection.ts";
5 import * as Stream from "effect/Stream";
6 import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
7 import { makeThreadFind } from "./ThreadFind.ts";
8 -import { unsentManualContinuationSource } from "./manualContinuation.ts";
8 +import { unsentManualContinuationSource } from "@t3tools/shared/orchestrationV2ManualContinuation";
9 import type {
10 OrchestrationV2ThreadLinkMetadata,
11 OrchestrationV2SearchThreadInput,
apps/server/src/orchestration-v2/ProviderTurnStartService.ts
+1 -1
@@ -61,7 +61,7 @@ import { deliverContextHandoffs, withInlineContext } from "./ContextHandoffDeliv
61 import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
62 import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
63 import * as ProjectionStore from "./ProjectionStore.ts";
64 -import { unsentManualContinuationSource } from "./manualContinuation.ts";
64 +import { unsentManualContinuationSource } from "@t3tools/shared/orchestrationV2ManualContinuation";
65 import * as ProviderSessionManager from "./ProviderSessionManager.ts";
66 import {
67 ContextHandoffBackgroundWorkError,
packages/client-runtime/src/state/threadExecution.test.ts
+33
@@ -198,6 +198,39 @@ describe("thread execution presentation", () => {
198 ).toMatchObject({ status: "running", lastError: null, lastErrorClass: null });
199 });
200
201 + it.each([
202 + {
203 + name: "a provider without native resume",
204 + nativeResume: false,
205 + delivered: true,
206 + resumes: false,
207 + },
208 + { name: "an undelivered message", nativeResume: false, delivered: false, resumes: true },
209 + { name: "a provider with native resume", nativeResume: true, delivered: true, resumes: true },
210 + {
211 + name: "a session from an older server",
212 + nativeResume: undefined,
213 + delivered: true,
214 + resumes: true,
215 + },
216 + ])("offers to resume an interrupted run on $name", ({ nativeResume, delivered, resumes }) => {
217 + const providerThreadId = ProviderThreadId.make("stopped-thread");
218 + const sessionId = ProviderSessionId.make("stopped-session");
219 + const attemptId = RunAttemptId.make("stopped-attempt");
220 + const stopped = { ...run("stopped", 1, "interrupted"), providerThreadId };
221 + const projection = {
222 + ...v2Projection,
223 + runs: [stopped],
224 + attempts: [{ id: attemptId, runId: stopped.id, attemptOrdinal: 1, reason: "initial" }],
225 + providerTurns: delivered ? [{ runAttemptId: attemptId }] : [],
226 + providerThreads: [{ id: providerThreadId, providerSessionId: sessionId }],
227 + providerSessions: [
228 + { id: sessionId, capabilities: { turns: { supportsNativeResume: nativeResume } } },
229 + ],
230 + } as unknown as typeof v2Projection;
231 + expect(deriveResumableRunId(projection, null)).toBe(resumes ? stopped.id : null);
232 + });
233 +
234 // regression: #15029 working timers no longer reset on every background wake
235 it("counts a wake run's activity from the start of the work it continues", () => {
236 const workStartedAt = DateTime.makeUnsafe("2026-07-28T09:20:00.000Z");
packages/client-runtime/src/state/threadExecution.ts
+33 -7
@@ -35,6 +35,7 @@ import {
35 resolveSelectableModel,
36 withLegacyUltracodeEffort,
37 } from "@t3tools/shared/model";
38 +import { unsentManualContinuationSource } from "@t3tools/shared/orchestrationV2ManualContinuation";
39 import { formatDuration } from "@t3tools/shared/orchestrationTiming";
40 import * as DateTime from "effect/DateTime";
41
@@ -317,16 +318,41 @@ export function formatProviderSubagentStatus(
318
319 /** The run a manual continuation resumes; the server holds the queue until it does. */
320 export function deriveResumableRunId(
320 - projection: Pick<ThreadStructure, "runs" | "turnItems">,
321 + projection: Pick<
322 + ThreadStructure,
323 + "runs" | "turnItems" | "attempts" | "providerTurns" | "providerThreads" | "providerSessions"
324 + >,
325 runtime: Pick<ThreadStructureRuntime, "lastErrorClass"> | null,
326 ): RunId | null {
327 const run = latestExecutedRun(projection.runs);
324 - if (run?.status === "interrupted") return run.id;
325 - return run?.status === "failed" &&
326 - runtime?.lastErrorClass === "usage_limit" &&
327 - latestRootProviderFailure(run, projection.turnItems)?.class === "usage_limit"
328 - ? run.id
329 - : null;
328 + const resumable =
329 + run?.status === "interrupted" ||
330 + (run?.status === "failed" &&
331 + runtime?.lastErrorClass === "usage_limit" &&
332 + latestRootProviderFailure(run, projection.turnItems)?.class === "usage_limit");
333 + if (!resumable) return null;
334 + // Without native resume the server can only resend a message the provider never received.
335 + if (
336 + runProviderSession(projection, run)?.capabilities.turns.supportsNativeResume === false &&
337 + unsentManualContinuationSource({ manualContinuationOfRunId: run.id }, projection) === undefined
338 + ) {
339 + return null;
340 + }
341 + return run.id;
342 +}
343 +
344 +function runProviderSession(
345 + projection: Pick<ThreadStructure, "providerThreads" | "providerSessions">,
346 + run: ThreadStructure["runs"][number],
347 +) {
348 + const sessionId = projection.providerThreads.find(
349 + (thread) => thread.id === run.providerThreadId,
350 + )?.providerSessionId;
351 + return sessionId == null
352 + ? projection.providerSessions.findLast(
353 + (session) => session.providerInstanceId === run.providerInstanceId,
354 + )
355 + : projection.providerSessions.find((session) => session.id === sessionId);
356 }
357
358 /**
packages/contracts/src/orchestrationV2.ts
+2
@@ -300,6 +300,8 @@ export const OrchestrationV2TurnCapabilities = Schema.Struct({
300 emitsTurnStarted: Schema.Boolean,
301 emitsTurnCompleted: Schema.Boolean,
302 supportsInterrupt: Schema.Boolean,
303 + // Continues an interrupted turn without a new message; absent on sessions recorded before it existed.
304 + supportsNativeResume: Schema.optional(Schema.Boolean),
305 supportsActiveSteering: Schema.Boolean,
306 // Some native steering mechanisms cancel pending tools before consuming the message.
307 activeSteeringInterruptsTools: Schema.optional(Schema.Boolean),
packages/provider-acp/src/server/adapter.ts
+1
@@ -817,6 +817,7 @@ export const AcpProviderCapabilitiesV2 = {
817 emitsTurnStarted: true,
818 emitsTurnCompleted: true,
819 supportsInterrupt: true,
820 + supportsNativeResume: false,
821 supportsActiveSteering: false,
822 supportsSteeringByInterruptRestart: true,
823 supportsQueuedMessages: true,
packages/provider-cursor/src/server/adapter.ts
+1
@@ -101,6 +101,7 @@ export const CursorProviderCapabilitiesV2 = {
101 emitsTurnStarted: true,
102 emitsTurnCompleted: true,
103 supportsInterrupt: true,
104 + supportsNativeResume: true,
105 supportsActiveSteering: true,
106 // A steer can move a foreground subagent to the background. Mailbox wakes
107 // stay queued so a notification does not cut into the live turn.
packages/provider-muse/src/server/adapter.ts
+1
@@ -130,6 +130,7 @@ const MuseProviderCapabilitiesV2 = {
130 emitsTurnStarted: true,
131 emitsTurnCompleted: true,
132 supportsInterrupt: true,
133 + supportsNativeResume: false,
134 supportsActiveSteering: true,
135 supportsSteeringByInterruptRestart: false,
136 supportsQueuedMessages: true,
packages/provider-opencode/src/server/adapter.ts
+1
@@ -134,6 +134,7 @@ const OpenCodeProviderCapabilitiesV2 = {
134 emitsTurnStarted: true,
135 emitsTurnCompleted: true,
136 supportsInterrupt: true,
137 + supportsNativeResume: true,
138 supportsActiveSteering: true,
139 supportsSteeringByInterruptRestart: true,
140 supportsQueuedMessages: true,
packages/provider-opencode/src/server/v2/adapter.ts
+1
@@ -147,6 +147,7 @@ const OpenCode2ProviderCapabilities = {
147 emitsTurnStarted: true,
148 emitsTurnCompleted: true,
149 supportsInterrupt: true,
150 + supportsNativeResume: true,
151 supportsActiveSteering: true,
152 supportsSteeringByInterruptRestart: true,
153 supportsQueuedMessages: true,
packages/provider-pi/src/server/adapter.ts
+1
@@ -126,6 +126,7 @@ const PiProviderCapabilitiesV2 = {
126 emitsTurnStarted: true,
127 emitsTurnCompleted: true,
128 supportsInterrupt: true,
129 + supportsNativeResume: false,
130 supportsActiveSteering: true,
131 supportsSteeringByInterruptRestart: false,
132 supportsQueuedMessages: true,
packages/shared/package.json
+4
@@ -463,6 +463,10 @@
463 "types": "./src/orchestrationV2PendingBackgroundWork.ts",
464 "import": "./src/orchestrationV2PendingBackgroundWork.ts"
465 },
466 + "./orchestrationV2ManualContinuation": {
467 + "types": "./src/orchestrationV2ManualContinuation.ts",
468 + "import": "./src/orchestrationV2ManualContinuation.ts"
469 + },
470 "./hostClassification": {
471 "types": "./src/hostClassification.ts",
472 "import": "./src/hostClassification.ts"
packages/shared/src/orchestrationV2ManualContinuation.ts renamed
+1 -1
@@ -1,7 +1,7 @@
1 import type { OrchestrationV2Run, OrchestrationV2ThreadProjection } from "@t3tools/contracts";
2
3 export function unsentManualContinuationSource(
4 - run: OrchestrationV2Run | undefined,
4 + run: Pick<OrchestrationV2Run, "manualContinuationOfRunId"> | undefined,
5 projection: Pick<OrchestrationV2ThreadProjection, "runs" | "attempts" | "providerTurns">,
6 ) {
7 let sourceId = run?.manualContinuationOfRunId;