@devries-cameron20 / t3code-1 / commits / 943de8fe9d
Fork 0

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

fix(server): a Claude request that gets no answer fails after 10 minutes instead of running forever (#37728)

Julius Marminge committed Nov 16, 2026 at 12:30 UTC 943de8fe9d5dc751a06f4985dfae59cbe1724359
2 files changed +212 -30
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+120
@@ -15224,6 +15224,126 @@ describe("ClaudeAdapterV2 background wake turns", () => {
15224 ),
15225 );
15226
15227 + // regression: #37708 a gateway that holds the request open leaves Claude silent after "requesting"
15228 + it.effect.each([
15229 + { case: "after the prompt starts", requesting: false, backgroundProgress: false },
15230 + { case: "after a request goes out", requesting: true, backgroundProgress: false },
15231 + { case: "while a skill it forked runs", requesting: false, forkedTask: true },
15232 + {
15233 + case: "while an earlier background agent starts a nested task",
15234 + requesting: false,
15235 + nestedTaskStarted: true,
15236 + },
15237 + {
15238 + case: "while an earlier background task reports progress",
15239 + requesting: false,
15240 + backgroundProgress: true,
15241 + },
15242 + ])(
15243 + "does not keep a turn silently running when Claude goes quiet $case",
15244 + ({ requesting, backgroundProgress = false, forkedTask = false, nestedTaskStarted = false }) =>
15245 + Effect.gen(function* () {
15246 + const harness = yield* makeWakeHarness;
15247 + const now = yield* DateTime.now;
15248 + yield* harness.runtime.startTurn(
15249 + makeClaudeTestTurnInput({
15250 + threadId: harness.threadId,
15251 + providerThread: harness.providerThread,
15252 + now,
15253 + attemptId: RunAttemptId.make("attempt-claude-silent-after-started"),
15254 + text: "start again",
15255 + attachments: [],
15256 + }),
15257 + );
15258 + // Captured from Claude Code 2.1.325 against a gateway that never answers /v1/messages.
15259 + for (const [index, state] of (["queued", "started"] as const).entries()) {
15260 + yield* harness.offerAndWait(
15261 + claudeSdkFrame({
15262 + type: "command_lifecycle",
15263 + command_uuid: harness.promptUuid(0),
15264 + state,
15265 + uuid: `00000000-0000-4000-8000-00000000079${index}`,
15266 + session_id: WAKE_NATIVE_SESSION,
15267 + }),
15268 + );
15269 + }
15270 + if (requesting) {
15271 + yield* harness.offerAndWait(
15272 + claudeSdkFrame({
15273 + type: "system",
15274 + subtype: "status",
15275 + status: "requesting",
15276 + uuid: "00000000-0000-4000-8000-000000000792",
15277 + session_id: WAKE_NATIVE_SESSION,
15278 + }),
15279 + );
15280 + }
15281 + if (backgroundProgress) {
15282 + yield* harness.offerAndWait(
15283 + claudeSdkFrame({
15284 + type: "system",
15285 + subtype: "task_progress",
15286 + task_id: "earlier-background-task",
15287 + description: "Earlier background task",
15288 + usage: { total_tokens: 1, tool_uses: 0, duration_ms: 1 },
15289 + uuid: "00000000-0000-4000-8000-000000000793",
15290 + session_id: WAKE_NATIVE_SESSION,
15291 + }),
15292 + );
15293 + }
15294 + if (nestedTaskStarted) {
15295 + yield* harness.offerAndWait(
15296 + claudeSdkFrame({
15297 + type: "system",
15298 + subtype: "task_started",
15299 + task_id: "earlier-nested-task",
15300 + description: "Nested task of an earlier background agent",
15301 + spawn_depth: 2,
15302 + uuid: "00000000-0000-4000-8000-000000000795",
15303 + session_id: WAKE_NATIVE_SESSION,
15304 + }),
15305 + );
15306 + }
15307 + if (forkedTask) {
15308 + yield* harness.offerAndWait(
15309 + claudeSdkFrame({
15310 + type: "system",
15311 + subtype: "task_started",
15312 + task_id: "forked-skill-task",
15313 + description: "Forked skill",
15314 + uuid: "00000000-0000-4000-8000-000000000794",
15315 + session_id: WAKE_NATIVE_SESSION,
15316 + }),
15317 + );
15318 + }
15319 + assert.lengthOf(harness.terminalEvents(), 0);
15320 +
15321 + yield* TestClock.adjust("1 hour");
15322 + yield* yieldTicks(50);
15323 + const surfaced =
15324 + harness.terminalEvents().length > 0 ||
15325 + harness.events.some(
15326 + (event) =>
15327 + event.type === "turn_item.updated" &&
15328 + (event.turnItem.type === "system_notice" || event.turnItem.type === "error"),
15329 + );
15330 + if (forkedTask) {
15331 + assert.lengthOf(harness.terminalEvents(), 0, "a long forked skill was failed as silence");
15332 + } else {
15333 + assert.isTrue(surfaced, "an hour of silence after the prompt started surfaced nothing");
15334 + }
15335 + }).pipe(
15336 + Effect.provide(
15337 + Layer.mergeAll(
15338 + IdAllocator.layer,
15339 + McpProviderSessions.layer,
15340 + NodeServices.layer,
15341 + NodeCrypto.layer,
15342 + ),
15343 + ),
15344 + ),
15345 + );
15346 +
15347 // regression: #17531 a mod that holds a tool behind a focused pane must fail the turn, not hang it
15348 it.effect.each([
15349 { case: "fails a turn whose mod requests focus for a pane T3 cannot show", focus: true },
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+92 -30
@@ -4949,6 +4949,8 @@ function formatClaudeUsageLimitWait(waitMs: number): string {
4949
4950 interface ActiveClaudeTurnContext {
4951 retryBudgetFailure?: OrchestrationV2ProviderFailure;
4952 + // Set when the prompt starts or a request goes out; cleared by the turn's next frame.
4953 + unansweredRequestSince?: DateTime.Utc | undefined;
4954 readonly queryPolicy: ClaudeRuntimeQueryPolicy;
4955 readonly input: ProviderAdapter.ProviderAdapterV2TurnInput;
4956 readonly autoCompactWindow: string;
@@ -6397,40 +6399,73 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
6399 : undefined;
6400 });
6401 const retry = yield* isCurrentRetry;
6400 - // A user Stop already in flight keeps its interrupted outcome.
6401 - if (
6402 - retry === undefined ||
6403 - (yield* Ref.get(interruptedTurns)).has(context.providerTurnId)
6404 - )
6405 - return;
6406 - context.retryBudgetFailure = { ...retry.failure, retryable: false };
6407 - const liveQuery = yield* Ref.get(queryContext);
6408 - yield* interruptTurn({
6409 - providerThread: context.input.providerThread,
6410 - providerTurnId: context.providerTurnId,
6411 - }).pipe(
6412 - Effect.timeoutOption(CLAUDE_STOP_CONFIRM_TIMEOUT_MS),
6413 - Effect.catch((cause) =>
6414 - Effect.logWarning("orchestration-v2.claude-retry-budget-stop-failed", { cause }),
6415 - ),
6416 - );
6417 - if (liveQuery === null || (yield* isCurrentRetry) === undefined) return;
6418 - // The CLI did not confirm the stop; settle the turn without it.
6419 - const ownedLiveQuery = yield* Ref.modify(queryContext, (current) =>
6420 - current?.query === liveQuery.query ? [true, null] : [false, current],
6421 - );
6422 - if (!ownedLiveQuery) return;
6423 - liveQuery.stopping = true;
6424 - yield* liveQuery.query.close.pipe(
6425 - Effect.timeoutOption(CLAUDE_STOP_CONFIRM_TIMEOUT_MS),
6426 - Effect.ignore,
6402 + if (retry === undefined) return;
6403 + yield* failStalledTurn(
6404 + context,
6405 + { ...retry.failure, retryable: false },
6406 + Effect.map(isCurrentRetry, (current) => current !== undefined),
6407 );
6428 - yield* finalizeActiveTurnAfterQueryExit(liveQuery);
6429 - yield* endSubagentCallsOfClosedQuery(liveQuery.nativeThreadId, "interrupted");
6430 - yield* Deferred.succeed(liveQuery.closed, undefined);
6408 },
6409 );
6410
6411 + // Partial messages are on, so a started prompt or a sent request streams within seconds.
6412 + // A gateway can hold the request open without ever letting the CLI time out and retry.
6413 + const failUnansweredRequest = Effect.fn("ClaudeAdapterV2.failUnansweredRequest")(function* (
6414 + context: ActiveClaudeTurnContext,
6415 + since: DateTime.Utc,
6416 + ) {
6417 + const isUnanswered = Effect.map(
6418 + Ref.get(activeTurn),
6419 + (active) => active === context && context.unansweredRequestSince === since,
6420 + );
6421 + if (!(yield* isUnanswered)) return;
6422 + yield* failStalledTurn(
6423 + context,
6424 + makeProviderFailure({
6425 + class: "transport_error",
6426 + code: "claude_request_unanswered",
6427 + message: `Claude sent nothing for ${PROVIDER_RETRY_BUDGET_MS / 60_000} minutes. The API or a gateway in front of it is not responding.`,
6428 + retryable: false,
6429 + }),
6430 + // Once the stop is sent, a frame clearing the silence must not skip forced settlement.
6431 + Effect.map(Ref.get(activeTurn), (active) => active === context),
6432 + );
6433 + });
6434 +
6435 + const failStalledTurn = Effect.fn("ClaudeAdapterV2.failStalledTurn")(function* (
6436 + context: ActiveClaudeTurnContext,
6437 + failure: OrchestrationV2ProviderFailure,
6438 + stillStalled: Effect.Effect<boolean>,
6439 + ) {
6440 + // A user Stop already in flight keeps its interrupted outcome.
6441 + if ((yield* Ref.get(interruptedTurns)).has(context.providerTurnId)) return;
6442 + context.retryBudgetFailure = failure;
6443 + const liveQuery = yield* Ref.get(queryContext);
6444 + yield* interruptTurn({
6445 + providerThread: context.input.providerThread,
6446 + providerTurnId: context.providerTurnId,
6447 + }).pipe(
6448 + Effect.timeoutOption(CLAUDE_STOP_CONFIRM_TIMEOUT_MS),
6449 + Effect.catch((cause) =>
6450 + Effect.logWarning("orchestration-v2.claude-retry-budget-stop-failed", { cause }),
6451 + ),
6452 + );
6453 + if (liveQuery === null || !(yield* stillStalled)) return;
6454 + // The CLI did not confirm the stop; settle the turn without it.
6455 + const ownedLiveQuery = yield* Ref.modify(queryContext, (current) =>
6456 + current?.query === liveQuery.query ? [true, null] : [false, current],
6457 + );
6458 + if (!ownedLiveQuery) return;
6459 + liveQuery.stopping = true;
6460 + yield* liveQuery.query.close.pipe(
6461 + Effect.timeoutOption(CLAUDE_STOP_CONFIRM_TIMEOUT_MS),
6462 + Effect.ignore,
6463 + );
6464 + yield* finalizeActiveTurnAfterQueryExit(liveQuery);
6465 + yield* endSubagentCallsOfClosedQuery(liveQuery.nativeThreadId, "interrupted");
6466 + yield* Deferred.succeed(liveQuery.closed, undefined);
6467 + });
6468 +
6469 const rememberProviderThread =
6470 /* Provider events include streaming deltas; avoid a span for each update. */
6471 Effect.fnUntraced(function* (providerThread: OrchestrationV2ProviderThread) {
@@ -10556,6 +10591,33 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
10591 }
10592 return;
10593 }
10594 + if (context === (yield* Ref.get(activeTurn))) {
10595 + const lifecycle = claudePromptLifecycle(message);
10596 + if (
10597 + (message.type === "system" &&
10598 + message.subtype === "status" &&
10599 + message.status === "requesting") ||
10600 + (lifecycle?.state === "started" && lifecycle.uuid === context.promptUuid)
10601 + ) {
10602 + const since = yield* DateTime.now;
10603 + context.unansweredRequestSince = since;
10604 + yield* failUnansweredRequest(context, since).pipe(
10605 + Effect.delay(PROVIDER_RETRY_BUDGET_MS),
10606 + Effect.forkIn(sessionScope),
10607 + );
10608 + } else if (
10609 + // Background tasks from earlier turns keep streaming while the root request hangs.
10610 + // Only the root starts depth-1 tasks, so such a start (a forked skill) is this turn's.
10611 + Reflect.get(message, "parent_tool_use_id") == null &&
10612 + !(
10613 + message.type === "system" &&
10614 + message.subtype.startsWith("task_") &&
10615 + !(message.subtype === "task_started" && (message.spawn_depth ?? 1) <= 1)
10616 + )
10617 + ) {
10618 + context.unansweredRequestSince = undefined;
10619 + }
10620 + }
10621 const focusedPlugin = claudeFocusRequestedPanePlugin(message);
10622 if (focusedPlugin !== null && context === (yield* Ref.get(activeTurn))) {
10623 yield* Effect.logWarning("orchestration-v2.claude-mod-pane-focus-unsupported", {