Repository navigation
Description
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
- Configure an agent with
claude-opus-4-6as primary model and a fallback model chain - In a session, have the agent spawn a background process via
exec(background: true) - Have the agent monitor the process using
process(poll)with 2-minute poll intervals - Wait for the total run time to exceed
DEFAULT_AGENT_TIMEOUT_SECONDS(600s / 10 minutes) - 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:
abortRun(true)setstimedOut = true- The failover decision checks
timedOut && !timedOutDuringCompaction→ enters fallback branch - A
FailoverError: LLM request timed out.is thrown - The system falls over to the next configured model
- 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).
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
miguelmanlyx commentedon Mar 22, 2026
Looks like this looks like a timeout problem on anthropic. Might be worth trying npx ai-doctor. It usually points out what is breaking.
Hollychou924 commentedon Mar 22, 2026
andychu666 commentedon Mar 22, 2026
Adding concrete repro data from my logs.
Repro scenario
Batch lesson-extraction job: 47 sessions enqueued for a
memory-lancedb-proworker. Agent monitored progress viaprocess(poll)with ~2 min intervals. 5 consecutive polls exceeded the 600s run timeout — no LLM request was pending.Result: 61K tokens sent to fallback model (Gemini 3.1 Pro), 0 completion tokens, $0.145 wasted.
clawsweeper commentedon Apr 28, 2026
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
timeoutCauseortimedOutDuringToolExecutionsignal 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 orprocess(poll)with a fallback chain, and observe that current failover policy still treatstimedOut && !timedOutDuringCompactionas 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
timeoutCauseortimedOutDuringToolExecutiondirection 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:
What I checked:
src/agents/pi-embedded-runner/run/attempt.ts:2275, a102f4dede6a)src/agents/pi-embedded-runner/run/failover-policy.ts:57, a102f4dede6a)src/agents/pi-embedded-runner/run/assistant-failover.ts:184, a102f4dede6a)src/agents/pi-embedded-subscribe.handlers.tools.ts:135, a102f4dede6a)src/agents/timeout.ts:3, a102f4dede6a)Likely related people:
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)src/agents/pi-embedded-runner/run/attempt.ts,src/agents/pi-embedded-runner/run/compaction-timeout.ts,CHANGELOG.md)CHANGELOG.md,src/agents/pi-embedded-runner/run/attempt.ts,src/agents/pi-embedded-runner/run/failover-policy.ts)Remaining risk / open question:
agents.defaults.timeoutSecondsor per-run timeout.Codex review notes: model gpt-5.5, reasoning high; reviewed against a102f4dede6a.
fix(failover-policy): gate LLM-phase-timedOut early-return per upstream
docs(rfc): trim D.2 superseded swim references + add D.4 Swim 41 forw…