Repository navigation
Description
Bug type
Behavior bug (incorrect output/state without crash)
Summary
The embedded runner fails with "Network connection lost." when the LLM generates a tool call whose parameters are large enough that producing them takes longer than the underlying request timeout. This is not specific to any one tool — it happens for any tool call where time-to-produce-params > underlying timeout. The Write tool with a large content argument is just the easiest reproducer.
Note on history. I originally filed this as a "large accumulated context (~100K tokens) via repeated
web_fetch" bug and hypothesized it was UndicibodyTimeout. After more investigation that framing turned out to be a symptom; the title, summary, and steps below have been rewritten with the more accurate picture. Earlier comments and the Codex review reference the older framing.
Steps to reproduce
The easiest reproducer is asking a slow model to write a large file in one tool call inside a subagent:
- On OpenClaw 2026.3.13+, configured with OpenRouter (any API key), in a session run:
Use sessions_spawn to create one subagent with model openrouter/anthropic/claude-opus-4.6 and runTimeoutSeconds: 0. Task: "Use the Write tool to create a single ~50KB markdown file at notes.md with a detailed history of the Roman Empire." - The subagent's LLM call to emit the
Writetool invocation fails withstopReason: "error",errorMessage: "Network connection lost.", andinput_tokens: 0, output_tokens: 0.
The original reproducer (subagent doing ~32 sequential web_fetch calls and then summarizing ~130K tokens of accumulated context) also fails, but it is harder to isolate — large input pushes the model toward generating a large output, which is what actually triggers the failure.
Expected behavior
The LLM call should succeed (or at minimum, OpenClaw should retry with appropriate backoff and surface a clearer error than a generic network failure).
Actual behavior
The call returns zero tokens with errorMessage: "Network connection lost.". OpenClaw retries (default retry budget) but retries also fail until the run gives up. No output file is produced.
Why it happens (current understanding)
- A tool call's
parameters(e.g. thecontentfield of aWriteinvocation) are part of the LLM response payload. - On the OpenRouter → Anthropic path I tested, tool-call parameters are not streamed incrementally on the wire — the model generates the full parameter JSON server-side and the call is emitted to the client only after generation finishes.
- End-to-end response latency is therefore roughly
param_size / model_throughput. For a slow model (Opus) generating a largecontentarg (tens of KB), this can exceed the underlying socket/idle timeout. The connection is dropped and the failure surfaces as"Network connection lost."(classified by theis-network-errorpackage).
I have only verified this with OpenRouter. I don't know whether other providers exhibit the same behavior — providers that genuinely stream tool-call argument deltas should not, since the chunks would keep the connection alive.
Workaround
Instruct the model to never write more than ~X KB in one tool call and to use multiple tool calls for large files (e.g. Write then Append). This is fragile because models don't reliably follow the instruction, especially when the request implies a single large output.
Possible fixes
- Increase the idle timeout for LLM calls in subagents so slow tool-call generation doesn't trip it. (Trivial; just makes the failure window wider.)
- Enable tool-use streaming where supported (e.g. Anthropic's
fine-grained-tool-streaming-2025-05-14beta or equivalent). When the upstream emits partial tool-call arguments as deltas, those chunks keep the connection alive and openclaw's existing per-chunk idle timer resets cleanly. This is the better fix but only applies to providers/models that support it.
OpenClaw version
2026.3.13 (61d171a)
Operating system
Ubuntu 22.04 (DigitalOcean droplet, 2GB RAM)
Install method
pnpm global
Model
openrouter/anthropic/claude-opus-4.6
Provider / routing chain
openclaw → openrouter → anthropic
Additional provider/model setup details
Default OpenRouter provider with API key in auth-profiles.json. No proxy, no Cloudflare AI Gateway, no custom middleware. Gateway running as systemd user service on loopback (port 18789). contextTokens: 200000, compaction.mode: "safeguard".
Logs, screenshots, and evidence
The original report's curl/SDK replay still isolates the failure to inside openclaw rather than the upstream provider:
# Curl replay of an equivalent payload (same machine, same API key, same endpoint):
Run 1: HTTP=200 TTFB=8564ms TTLB=29469ms (385 chunks)
Run 2: HTTP=200 TTFB=4620ms TTLB=26856ms (404 chunks)
Run 3: HTTP=200 TTFB=7465ms TTLB=28809ms (399 chunks)
Run 4: HTTP=200 TTFB=8587ms TTLB=30926ms (382 chunks)
Run 5: HTTP=200 TTFB=4561ms TTLB=25669ms (397 chunks)
# 5/5 success — proves the issue is NOT in OpenRouter/Anthropic API.
# OpenAI Node.js SDK replay (same payload, same machine): also 5/5 success.
Impact and severity
- Affected: any user whose model generates large tool-call parameters (large
Writecontent, large structured payloads, etc.). - Severity: High — the call fails completely, all work in the subagent is lost, retries also fail.
- Frequency: reliably reproducible with slow model + single large
Write.
Additional information
Earlier hypotheses corrected:
- Not
bodyTimeout. OpenClaw already setsbodyTimeout/headersTimeoutto 30 min viaensureGlobalUndiciStreamTimeouts(); an A/B test withbodyTimeout: 0showed no change in failure rate. - Not "large accumulated context". Large context was a symptom, not the cause: large inputs prompt the model to generate large outputs, and large output is what triggers the bug.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
Hollychou924 commentedon Mar 24, 2026
yilunzhang commentedon Mar 24, 2026
Additional findings
1. Reproduces on main agent (not subagent-specific)
Tested by setting
agents.defaults.model.primarytoopenrouter/anthropic/claude-opus-4.6and running the same task directly (nosessions_spawn):Same failure pattern — confirms this is an embedded runner issue, not subagent-specific.
2. bodyTimeout is NOT the cause
The commenter's hypothesis about
undici bodyTimeoutbeing too short was a reasonable guess, but doesn't match the evidence.Timing between last successful tool result and the error:
Gap: 137 seconds — well under both the default 300s bodyTimeout and OpenClaw's configured 30-minute bodyTimeout.
A/B test (3 runs each): Patching
bodyTimeout: 0(disabled) vs originalbodyTimeout: timeoutMs(30 min) showed no difference in failure rate. Both fail ~50% of the time with identical error patterns.Direct API replay succeeds 5/5: The same ~104K token payload, sent via both curl and the OpenAI Node.js SDK from the same machine to the same endpoint, succeeds every time with TTFB of 4.5-8.5s. This rules out any timeout-based hypothesis.
Summary
The error occurs 137 seconds into the request cycle (compaction + serialization + fetch). Something in the embedded runner's request pipeline causes the fetch to fail in a way classified as "Network connection lost" by
is-network-error. It's not bodyTimeout, not headersTimeout, and not an upstream provider issue. The root cause is inside the embedded runner itself.clawsweeper commentedon Apr 27, 2026
Codex review: this still needs some work.
Summary
This issue preserves concrete failures reported on an official OpenClaw release; current timeout and SSE keepalive improvements do not establish that the large-tool-argument failure is fixed.
Reproducibility: no. high-confidence current-main reproduction is available: source establishes finite silence deadlines, while the reporter's historical evidence does not identify which deadline or transport produced the network error.
Next step
Establish a current large-argument OpenRouter reproduction with sanitized wire timings, effective provider and run budgets, and the raw error cause before specifying a repair.
Review details
Best possible solution:
Use the existing provider timeout for measured silent generations, then repair the responsible transport boundary if current traces show an unexpected abort.
Do we have a high-confidence way to reproduce the issue?
No high-confidence current-main reproduction is available: source establishes finite silence deadlines, while the reporter's historical evidence does not identify which deadline or transport produced the network error.
Is this the best way to solve the issue?
A broad default-timeout increase is premature; the existing provider override and recent keepalive repair should be evaluated against a current timed reproduction before specifying another change.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning medium; reviewed against aec6e7a56eb0.
Label changes
Label changes:
No label changes.
Label justifications:
P2: Large generated tool arguments can prevent an agent task from completing, but current-version frequency and the responsible boundary remain unverified.impact:session-state: The reported run terminates before generated work becomes an executed tool call or output file.Evidence reviewed
What I checked:
src/agents/embedded-agent-runner/run/llm-idle-timeout.ts:182, aec6e7a56eb0)src/agents/embedded-agent-runner/run/attempt-stream.ts:360, aec6e7a56eb0)src/config/schema.help.models.ts:24, aec6e7a56eb0)extensions/openrouter/index.ts:245, aec6e7a56eb0)src/agents/provider-transport-fetch.sse.integration.test.ts:85, a2e804c62266)Likely related people:
src/agents/embedded-agent-runner/run/llm-idle-timeout.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.Reviewed October 10, 2026, 2:36 PM ET / 18:36 UTC.
[-][Bug]: Embedded runner "Network connection lost" on LLM call after accumulating large context (~100K+ tokens) via tool results[/-][+][Bug]: Embedded runner "Network connection lost" when LLM generates a tool call with large parameters (param generation latency > underlying request timeout)[/+]yilunzhang commentedon Apr 27, 2026
Edited the title and body of this issue to reflect a sharper understanding of the bug.
The earlier framing ("
Network connection loston LLM call after accumulating ~100K+ tokens of context via tool results") was the symptom I first noticed; the actual cause is the size of the tool-call parameters the LLM is generating, not the size of the input context. The easiest reproducer is nowWritewith a large file in one tool call from a slow model in a subagent —Writeis just an example, any tool call wheretime-to-produce-params > underlying timeoutwill hit this.Earlier comments above (including the Codex automated review) are based on the older framing. Likely fixes from my side are listed in the rewritten body: increase the idle timeout for subagent LLM calls, and/or enable tool-use streaming (e.g. Anthropic
fine-grained-tool-streaming-2025-05-14) where supported.clawsweeper commentedon Apr 29, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.
Keep open. Current main has timeout plumbing that can mitigate configured setups, but it does not prove a complete fix for the default OpenRouter to Anthropic large tool-parameter path: OpenRouter still uses the OpenAI-compatible transport, native Anthropic fine-grained tool streaming is not applied to that route, and there is no regression covering a silent OpenAI-compatible stream while large tool-call arguments are generated.
Required change / next step:
The report is valid enough to keep open, but a fix needs maintainer/provider-policy choice before automation: increasing default timeouts, adding OpenRouter-specific Anthropic streaming, or changing large tool-payload behavior each has different compatibility and latency tradeoffs.
Review details
Best possible solution:
Keep this as the canonical tracker for OpenRouter/Anthropic large tool-parameter generation failures. The durable fix should add a synthetic OpenAI-compatible streaming regression that withholds tool-call argument chunks, then implement the chosen provider/runtime policy: supported provider-side tool-argument streaming, a safe timeout policy for silent tool-argument generation, or a tool-loop strategy that avoids requiring one huge
Writepayload.Acceptance criteria:
What I checked:
api: "openai-completions", so static/default OpenRouter routes do not use the native Anthropic Messages transport. (extensions/openrouter/provider-catalog.ts:48, acae48b790fa)openrouter/anthropic/..., are also resolved asapi: "openai-completions". (extensions/openrouter/index.ts:59, acae48b790fa)docs/providers/openrouter.md. (docs/providers/openrouter.md:170, acae48b790fa)fine-grained-tool-streaming-2025-05-14beta header, but this is in the Anthropic Messages transport path rather than the OpenRouter OpenAI-compatible path. (src/agents/anthropic-transport-stream.ts:670, acae48b790fa)extensions/openrouter/stream.ts:31, acae48b790fa)streamWithIdleTimeoutraces each async iteratornext()against that timer, so a transport that withholds chunks while building tool arguments can still time out. (src/agents/pi-embedded-runner/run/llm-idle-timeout.ts:75, acae48b790fa)Likely related people:
src/agents/pi-embedded-runner/run/llm-idle-timeout.ts,src/agents/pi-embedded-runner/run/attempt.ts,src/agents/openai-transport-stream.ts)Remaining risk / open question:
models.providers.openrouter.timeoutSecondsor use no-timeout subagent runs, but the default direct-agent OpenRouter path still lacks source or test proof for this report.Codex review notes: model gpt-5.5, reasoning high; reviewed against acae48b790fa.
31 remaining items
steipete commentedon Oct 22, 2026
Thanks for filing this. We're closing issues opened before April 2026 that no longer look actionable on current
main.Transport timeouts and streaming for this path have been reworked since April, and we couldn't confirm the 'Network connection lost' failure on large tool-call arguments on current main; there has been no confirmation on a recent release. If it still happens, please open a fresh issue with your version, provider route, and logs.