Skip to content

Agent run timeout during tool execution misclassified as LLM timeout, triggers unnecessary model fallback #52147

Closed

Description

@andychu666

Bug type

Agent behavior

Summary

Agent run timeout during long tool execution (e.g. process(poll)) is misclassified as "LLM request timed out", triggering unnecessary model fallback — even though the primary model responded correctly.

Steps to reproduce

  1. Configure an agent with claude-opus-4-6 as primary model and a fallback model chain
  2. In a session, have the agent spawn a background process via exec (background: true)
  3. Have the agent monitor the process using process(poll) with 2-minute poll intervals
  4. Wait for the total run time to exceed DEFAULT_AGENT_TIMEOUT_SECONDS (600s / 10 minutes)
  5. Observe: the run is aborted with "FailoverError: LLM request timed out." and falls back to the next model in the chain

Alternatively: any tool call that takes a long time (browser automation, long exec, repeated process polling) can trigger the same behavior.

Expected behavior

Tool execution time should not count toward the LLM request timeout. The primary model had already responded successfully and the agent was executing tool calls — no LLM request was in flight when the timeout fired.

Precedent: PR #46889 added timedOutDuringCompaction to exempt compaction operations from triggering failover. Long-running tool execution should receive the same treatment.

Actual behavior

The run-level timer fires after 600s regardless of what the agent is doing. When it fires during tool execution:

  1. abortRun(true) sets timedOut = true
  2. The failover decision checks timedOut && !timedOutDuringCompaction → enters fallback branch
  3. A FailoverError: LLM request timed out. is thrown
  4. The system falls over to the next configured model
  5. The fallback model receives the full context (~61K tokens) but has no useful work to do (the original task was already being handled)

Gateway log sequence (redacted):

WARN  embedded run timeout: runId=<redacted> sessionId=<redacted> timeoutMs=600000
DEBUG run cleanup: runId=<redacted> sessionId=<redacted> aborted=true timedOut=true
WARN  embedded_run_failover_decision: stage=assistant decision=fallback_model failoverReason=timeout provider=anthropic model=claude-opus-4-6 timedOut=true status=408
ERROR lane task error: lane=main durationMs=630119 error="FailoverError: LLM request timed out."

The primary model (Opus) had completed its response. The agent was in a process(poll) loop monitoring a background worker:

  • Poll 1: 2 min wait → got output
  • Poll 2: 2 min wait → got output
  • Poll 3: 2 min wait → got output
  • Poll 4: 2 min wait → got output
  • Poll 5: started, aborted at ~17s by run timeout

Total tool execution time: ~10 minutes. No LLM request was pending.

OpenClaw version

2026.3.13 (61d171a)

Operating system

Ubuntu 24.04.4 LTS, Linux 6.17.0-19-generic x86_64

Install method

npm (global)

Model

claude-opus-4-6 (Anthropic) — primary model that was "timed out"

Provider / routing chain

anthropic/claude-opus-4-6 → openrouter/google/gemini-3.1-pro-preview (fallback #1) → openrouter/openai/gpt-5.4 (fallback #2) → ollama/qwen3.5:9b (fallback #3)

Additional provider/model setup details

Default agent timeout is the built-in DEFAULT_AGENT_TIMEOUT_SECONDS = 600. No custom agents.defaults.timeoutSeconds override was set.

The fallback model (gemini-3.1-pro-preview via OpenRouter) consumed ~61K input tokens at $0.145 cost but produced 0 completion tokens — confirming it had no useful work to do.

Logs, screenshots, and evidence

Source code analysis (minified bundle auth-profiles-DDVivXkv.js)

Timeout declaration and abort:

// Line 109601-109602
let timedOut = false;
let timedOutDuringCompaction = false;

Failover condition (line 111112):

if (!aborted && failoverFailure || timedOut && !timedOutDuringCompaction) {
    // → enters fallback branch even when timeout was caused by tool execution
}

User-facing error (line 111176):

if (timedOut && !timedOutDuringCompaction && payloads.length === 0) return {
    payloads: [{ text: "Request timed out before a response was generated...", isError: true }],
    // ...
};

Note: timedOutDuringCompaction is the only exemption. There is no timedOutDuringToolExecution or equivalent.

Compaction precedent (PR #46889)

The timedOutDuringCompaction mechanism proves the design intent: certain non-LLM operations should not trigger failover. Tool execution is a missing case.

Impact and severity

  • Affected: Any agent using long-running tools (process polling, browser automation, multi-minute exec tasks) with a fallback model chain configured
  • Severity: Blocks workflow + unnecessary cost — the fallback model is invoked with the full conversation context but produces no useful output
  • Frequency: Deterministic — any tool execution exceeding DEFAULT_AGENT_TIMEOUT_SECONDS (600s) will trigger this
  • Consequence: (1) Wasted API cost on the fallback model, (2) original task is interrupted mid-execution, (3) misleading "LLM request timed out" error when the LLM was not involved

Additional information

Suggested fix

Add a timedOutDuringToolExecution flag (or refactor to a general timeoutCause enum) so tool execution time is exempt from the failover path, consistent with the existing compaction exemption:

// Current: only compaction is exempt
if (timedOut && !timedOutDuringCompaction) { /* failover */ }

// Proposed: tool execution also exempt
if (timedOut && !timedOutDuringCompaction && !timedOutDuringToolExecution) { /* failover */ }

// Or better: general timeout cause
if (timedOut && timeoutCause === 'llm_request') { /* failover */ }

Alternatively, the run deadline could be extended while tool execution is actively in flight (same approach as PR #46889 does for compaction).

Activity

  1. miguelmanlyx commented on Mar 22, 2026

    @miguelmanlyx

    Looks like this looks like a timeout problem on anthropic. Might be worth trying npx ai-doctor. It usually points out what is breaking.

  2. Hollychou924 commented on Mar 22, 2026

    @Hollychou924
  3. andychu666 commented on Mar 22, 2026

    @andychu666
    Author

    Adding concrete repro data from my logs.

    Repro scenario

    Batch lesson-extraction job: 47 sessions enqueued for a memory-lancedb-pro worker. Agent monitored progress via process(poll) with ~2 min intervals. 5 consecutive polls exceeded the 600s run timeout — no LLM request was pending.

    12:27:55 — exec (check worker status)
    12:28:54 — process(poll, timeout=120s) — waited 2 min
    12:31:20 — process(poll, timeout=120s) — waited 2 min
    12:33:26 — process(poll, timeout=120s) — waited 2 min
    12:35:30 — process(poll, timeout=120s) — waited 2 min
    12:37:34 — process(poll) started...
    12:37:51 — 💥 run timeout at exactly 600s, fallback triggered
    

    Result: 61K tokens sent to fallback model (Gemini 3.1 Pro), 0 completion tokens, $0.145 wasted.

  4. clawsweeper commented on Apr 28, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.

    Keep open. Current main mitigates the original no-custom-config 600s case by defaulting agent runtime timeouts to 48 hours, but the reported misclassification still exists for any configured run timeout: non-compaction run timeouts still feed assistant profile rotation/model fallback as timeout, with no active-tool timeout cause.

    Required change / next step:

    This is a narrow, source-backed runner/failover bug with clear likely files and validation; it does not require product strategy or security review before an automated repair attempt.

    Security review:

    Security review: This is a non-PR issue with no proposed patch, and the report is not itself a security-sensitive change.

    Review details

    Best possible solution:

    Add phase-aware timeout state to the embedded runner, preferably a small timeoutCause or timedOutDuringToolExecution signal derived from active tool lifecycle state, and have assistant failover treat tool-phase run timeouts as run/tool timeouts instead of model failover signals.

    Do we have a high-confidence way to reproduce the issue?

    Yes. A high-confidence source-level reproduction is to set a short agents.defaults.timeoutSeconds, run a long tool or process(poll) with a fallback chain, and observe that current failover policy still treats timedOut && !timedOutDuringCompaction as rotation/fallback; no live long-running repro was run because this review is read-only.

    Is this the best way to solve the issue?

    Yes, the reporter's timeoutCause or timedOutDuringToolExecution direction is the narrow maintainable fix. Raising the default runtime timeout reduces frequency but does not solve configured shorter run deadlines or the misleading fallback classification.

    Acceptance criteria:

    • pnpm test src/agents/pi-embedded-runner/run/failover-policy.test.ts src/agents/pi-embedded-runner/run/assistant-failover.test.ts src/agents/pi-embedded-runner/run/compaction-timeout.test.ts
    • pnpm test src/agents/pi-embedded-subscribe.handlers.tools.test.ts
    • pnpm check:changed (run via Testbox per repo policy before handoff)

    What I checked:

    Likely related people:

    • @steipete: Current-main blame for the central timeout timer, failover policy, assistant failover, and tool lifecycle files points to Peter Steinberger through the local history snapshot; shortlog for the affected files also shows Peter as the main recent contributor. (role: recent maintainer / current-main owner of affected runner surface; confidence: medium; commits: 11a56db5c1e2, 90419df6633f; files: src/agents/pi-embedded-runner/run/attempt.ts, src/agents/pi-embedded-runner/run/failover-policy.ts, src/agents/pi-embedded-runner/run/assistant-failover.ts)
    • @asyncjason: The issue explicitly cites feat: make compaction timeout configurable via agents.defaults.compaction.timeoutSeconds #46889, and the changelog credits @asyncjason for the shipped compaction deadline extension that prevents unnecessary rotation during compaction timeouts, the closest existing precedent for this missing tool-timeout classification. (role: adjacent compaction-timeout precedent contributor; confidence: medium; commits: da6467f7ba6f; files: src/agents/pi-embedded-runner/run/attempt.ts, src/agents/pi-embedded-runner/run/compaction-timeout.ts, CHANGELOG.md)
    • @mverrilli: The changelog credits @mverrilli for prior work classifying external timeout aborts during compaction to prevent unnecessary auth-profile rotation, which is directly adjacent to the remaining tool-execution timeout classification gap. (role: adjacent timeout-classification precedent contributor; confidence: low; files: CHANGELOG.md, src/agents/pi-embedded-runner/run/attempt.ts, src/agents/pi-embedded-runner/run/failover-policy.ts)

    Remaining risk / open question:

    • The reporter's exact default-600s reproduction no longer matches current defaults because current main defaults agent runtime timeout to 48 hours; validation should use an explicit shorter agents.defaults.timeoutSeconds or per-run timeout.
    • The repair must preserve legitimate provider request/model idle timeout retry and fallback behavior; only run timeouts that fire while tool items are active should bypass model fallback.

    Codex review notes: model gpt-5.5, reasoning high; reviewed against a102f4dede6a.

  5. locked as resolved and limited conversation to collaborators on May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions