Skip to content

Embedded agent (webchat) fails with 'Network connection lost' on long requests through proxy while Claude Code works fine #49919

Closed as not planned

Description

@link-king

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.5s

Claude 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:

  1. Claude Code uses streaming and likely has robust retry/reconnect logic for long requests
  2. Gateway's embedded agent seems to lose connection during long requests (large context window → longer response time → proxy connection drops)
  3. Short requests work fine, confirming the proxy itself is functional
  4. The gateway's launchd plist correctly has http_proxy and https_proxy set

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

  1. Configure OpenClaw gateway behind an HTTP proxy (required for region access)
  2. Use openrouter/anthropic/claude-opus-4.6 as the model
  3. Have a conversation with 20+ turns in the webchat (Control UI)
  4. Send a new message
  5. Observe Network connection lost in gateway.err.log
  6. Note that Claude Code with the same OpenRouter key/model/proxy works fine

Activity

  1. Ryce commented on Mar 18, 2026

    @Ryce
  2. clawsweeper commented on Apr 26, 2026

    @clawsweeper
    Contributor

    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 lost failure 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:

    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.

  3. locked as resolved and limited conversation to collaborators on Apr 28, 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