Repository navigation
Description
Title: Embedded agent (webchat) fails with "Network connection lost" on long requests through proxy while Claude Code works fine
Environment
- OpenClaw version: 2026.3.13
- OS: macOS (Apple Silicon, 16GB RAM)
- Node: v22.22.1
- Provider: OpenRouter (
openrouter/anthropic/claude-opus-4.6) - Network: Behind HTTP proxy (127.0.0.1:10794), required for region access
- Gateway mode: local, launchd-managed
Description
The webchat (Control UI) agent/embedded consistently fails with Network connection lost or terminated errors when making LLM requests through OpenRouter, while Claude Code using the exact same OpenRouter API key and model works perfectly fine.
The failures happen specifically on longer conversations with large context windows. Short test requests (e.g., "say hi" with max_tokens=10) through the same proxy succeed in ~2.5s.
Evidence
Gateway error log shows 20+ consecutive failures over ~2 hours:
[agent/embedded] error=Network connection lost.
[agent/embedded] error=terminated
[agent/embedded] error=LLM request timed out.
Manual curl tests through the same proxy succeed:
# Works fine - short request via proxy
curl --proxy http://127.0.0.1:10794 \
-X POST https://openrouter.ai/api/v1/chat/completions \
-d '{"model":"anthropic/claude-opus-4.6","messages":[{"role":"user","content":"say hi"}],"max_tokens":10}'
# → HTTP 200 in 2.5sClaude Code config (works fine):
{
"ANTHROPIC_AUTH_TOKEN": "sk-or-v1-...",
"ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
"ANTHROPIC_MODEL": "anthropic/claude-opus-4.6"
}CC uses the same OpenRouter key, same model, same proxy — but streams responses and handles long-running tasks without disconnection.
Analysis
The key difference appears to be how the embedded agent handles long-running HTTP requests through a proxy:
- Claude Code uses streaming and likely has robust retry/reconnect logic for long requests
- Gateway's embedded agent seems to lose connection during long requests (large context window → longer response time → proxy connection drops)
- Short requests work fine, confirming the proxy itself is functional
- The gateway's launchd plist correctly has
http_proxyandhttps_proxyset
Expected behavior
The embedded agent should handle long-running LLM requests as reliably as Claude Code does, especially when going through a proxy. Possible improvements:
- More aggressive TCP keepalive settings for the upstream HTTP client
- Streaming the upstream LLM response (if not already) to keep the connection alive
- Better retry logic on transient connection failures
- Configurable timeout for embedded agent LLM requests
Workaround
Starting a new session (/new) with a shorter context window reduces (but doesn't eliminate) the failures.
Reproduction steps
- Configure OpenClaw gateway behind an HTTP proxy (required for region access)
- Use
openrouter/anthropic/claude-opus-4.6as the model - Have a conversation with 20+ turns in the webchat (Control UI)
- Send a new message
- Observe
Network connection lostin gateway.err.log - Note that Claude Code with the same OpenRouter key/model/proxy works fine
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
Ryce commentedon Mar 18, 2026
clawsweeper commentedon Apr 26, 2026
Closing this as duplicate or superseded after Codex automated review.
Close #49919 as duplicate/superseded by the newer open canonical issue #53540, which tracks the same embedded-runner/OpenRouter large-context
Network connection lostfailure with stronger reproduction evidence. Related PR #70739 is useful context but explicitly covers the downstream Gateway-to-client SSE leg, not the upstream embedded-runner provider request leg described here.What I checked:
Network connection lost, zero tokens, and successful curl/OpenAI SDK replay outside OpenClaw. [Bug]: Embedded runner "Network connection lost" when LLM generates a tool call with large parameters (param generation latency > underlying request timeout) #53540 explicitly lists Embedded agent (webchat) fails with 'Network connection lost' on long requests through proxy while Claude Code works fine #49919 as related, making it the better canonical tracker.activeSession.prompt; this is the same embedded-runner/provider request surface covered by [Bug]: Embedded runner "Network connection lost" when LLM generates a tool call with large parameters (param generation latency > underlying request timeout) #53540. (src/agents/pi-embedded-runner/run/attempt.ts:1552, a1090b604312)Network connection lostsymptom, so this should not close as implemented. (src/agents/openai-transport-stream.ts:1163, a1090b604312)So I’m closing this here and keeping the remaining discussion on the canonical linked item.
Codex Review notes: model gpt-5.5, reasoning high; reviewed against a1090b604312.