fix(server): a Claude request that gets no answer fails after 10 minutes instead of running forever #37728
Mergedjuliusmarmingemerged 6 commits into
main fromrefs/pull/37728/headmerged by juliusmarminge View on GitHubtanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -15226,0 +15259,21 @@15259+ claudeSdkFrame({15260+ type: "system",15261+ subtype: "status",15262+ status: "requesting",15263+ uuid: "00000000-0000-4000-8000-000000000792",15264+ session_id: WAKE_NATIVE_SESSION,15265+ }),15266+ );15267+ }15268+ assert.lengthOf(harness.terminalEvents(), 0);15269+15270+ yield* TestClock.adjust("1 hour");15271+ yield* yieldTicks(50);15272+ const surfaced =15273+ harness.terminalEvents().length > 0 ||15274+ harness.events.some(15275+ (event) =>15276+ event.type === "turn_item.updated" &&15277+ (event.turnItem.type === "system_notice" || event.turnItem.type === "error"),15278+ );15279+ assert.isTrue(surfaced, "an hour of silence after the prompt started surfaced nothing");@@ -6433 +6410,21 @@643364106411+ // 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+ isUnanswered,@@ -10556,3 +10590,19 @@1055610590 }1055710591 return;1055810592 }10593+ if (context === (yield* Ref.get(activeTurn))) {10594+ const lifecycle = claudePromptLifecycle(message);10595+ if (10596+ (message.type === "system" &&10597+ message.subtype === "status" &&10598+ message.status === "requesting") ||10599+ (lifecycle?.state === "started" && lifecycle.uuid === context.promptUuid)10600+ ) {10601+ const since = yield* DateTime.now;10602+ context.unansweredRequestSince = since;10603+ yield* failUnansweredRequest(context, since).pipe(10604+ Effect.delay(PROVIDER_RETRY_BUDGET_MS),10605+ Effect.forkIn(sessionScope),10606+ );10607+ } else {10608+ context.unansweredRequestSince = undefined;
- @@ -15226,0 +15271,21 @@15271+ session_id: WAKE_NATIVE_SESSION,15272+ }),15273+ );15274+ }15275+ if (backgroundProgress) {15276+ yield* harness.offerAndWait(15277+ claudeSdkFrame({15278+ type: "system",15279+ subtype: "task_progress",15280+ task_id: "earlier-background-task",15281+ description: "Earlier background task",15282+ usage: { total_tokens: 1, tool_uses: 0, duration_ms: 1 },15283+ uuid: "00000000-0000-4000-8000-000000000793",15284+ session_id: WAKE_NATIVE_SESSION,15285+ }),15286+ );15287+ }15288+ assert.lengthOf(harness.terminalEvents(), 0);15289+15290+ yield* TestClock.adjust("1 hour");15291+ yield* yieldTicks(50);@@ -10556,3 +10591,21 @@1055610591 }1055710592 return;1055810593 }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+ Reflect.get(message, "parent_tool_use_id") == null &&10611+ !(message.type === "system" && message.subtype.startsWith("task_"))
- @@ -10558,0 +10595,21 @@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+ // a task this turn starts (a forked skill) is the turn's own progress.10611+ Reflect.get(message, "parent_tool_use_id") == null &&10612+ !(10613+ message.type === "system" &&10614+ message.subtype.startsWith("task_") &&10615+ message.subtype !== "task_started"
juliusmarminge merged this943de8f
juliusmarminge closed this
Sign in to join this conversation.

Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — Claude requests now automatically fail after ten minutes without qualifying activity, changing the default waiting behavior. Human judgment is needed on that timeout policy and the unresolved concerns about foreground work being interrupted or unrelated background activity disabling the watchdog.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).