Skip to content

fix(cli): local terminal chat sends model requests without the configured proxy - #173530

Merged
steipete merged 2 commits into
openclaw:mainfrom
masatohoshino:fix/local-chat-managed-proxy
Oct 16, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
masatohoshino:fix/local-chat-managed-proxy

Conversation

@masatohoshino

@masatohoshino masatohoshino commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #173529

What Problem This Solves

Fixes: with proxy.proxyUrl configured, openclaw chat, openclaw terminal, openclaw tui --local, and bare openclaw without a reachable Gateway send their in-process model requests directly instead of through the proxy, and bare openclaw opens onboarding without the managed proxy, while openclaw agent --local uses it.

User Impact

User impact: the local terminal chat, and onboarding opened by bare openclaw, now route egress through the configured proxy, the same as openclaw agent --local and openclaw onboard. These commands now also follow the proxy's destination policy and proxy.loopbackMode, as openclaw agent --local does. A Gateway-connected openclaw tui still connects to its Gateway directly.

Why This Change Was Made

The CLI starts the configured proxy from each command's startup policy. chat, terminal, and tui were set to bypass it, although chat and terminal always run the embedded agent in the CLI process and tui --local does too. They now follow the agent rule: chat and terminal always route, tui routes only with --local.

Bare openclaw has no command, so no startup policy applies. It picks onboarding, the local TUI, or a Gateway-bound TUI only after probing for a Gateway. The proxy now starts at that point, right before onboarding or the local TUI opens, and the existing CLI cleanup stops it. Gateway-bound targets are unchanged. That launch decision moved into the existing run-main-policy.ts together with its TTY messages, because run-main.ts is over its line cap. The network proxy docs now list these commands as protected.

Evidence

Tested at 71b3d0c5508 (base upstream/main b53ba16c63a; the later upstream commits do not touch these files). The head bd6748a3825 adds only the lint fix described under Checks.

Both sides ran the source build through pnpm openclaw on Linux with Node 24.18.0, with a fresh isolated HOME and profile for each command. Config: proxy.proxyUrl=http://127.0.0.1:13128, a local forward proxy that logs each request, and one model at http://172.17.0.1:18990/v1, a keyless OpenAI-compatible mock on a non-loopback address (loopback is exempt in the default gateway-only mode). The Gateway port was set to an unused port, so bare openclaw did not find a Gateway. The TUI commands ran in a pseudo-terminal; for bare openclaw, hi was typed into it. The last run drops the model, so bare openclaw opens onboarding.

Config used on both sides (~/.openclaw-p194/openclaw.json, synthetic values)
{
  "proxy": { "proxyUrl": "http://127.0.0.1:13128" },
  "models": {
    "mode": "replace",
    "providers": {
      "stub": {
        "baseUrl": "http://172.17.0.1:18990/v1",
        "apiKey": "dummy-key",
        "api": "openai-completions",
        "models": [
          {
            "id": "m",
            "name": "Stub",
            "reasoning": false,
            "input": ["text"],
            "contextWindow": 32000,
            "maxTokens": 1000
          }
        ]
      }
    }
  },
  "agents": { "defaults": { "model": { "primary": "stub/m" } } }
}

The onboarding run omits agents.

Before (base b53ba16c63a):

# banner: OpenClaw 2026.10.3 (b53ba16)    (TUI header of the build that ran)

$ openclaw --profile p194 agent --local --message hi
  cli:   [proxy] routing process HTTP traffic through external proxy http://127.0.0.1:13128
  reply: STUB-ANSWER
  model server: POST /v1/chat/completions
  recording proxy: CONNECT 172.17.0.1:18990

$ openclaw --profile p194 chat --message hi    # in a pseudo-terminal
  cli:   (no managed proxy line)
  reply: STUB-ANSWER
  model server: POST /v1/chat/completions
  recording proxy: (nothing recorded)

After (this PR):

# banner: OpenClaw 2026.10.3 (71b3d0c)    (TUI header of the build that ran)

$ openclaw --profile p194 agent --local --message hi
  cli:   [proxy] routing process HTTP traffic through external proxy http://127.0.0.1:13128
  reply: STUB-ANSWER
  model server: POST /v1/chat/completions
  recording proxy: CONNECT 172.17.0.1:18990

$ openclaw --profile p194 chat --message hi    # in a pseudo-terminal
  cli:   [proxy] routing process HTTP traffic through external proxy http://127.0.0.1:13128
  reply: STUB-ANSWER
  model server: POST /v1/chat/completions
  recording proxy: CONNECT 172.17.0.1:18990

Observed result: on the base, only agent --local reaches the model through the proxy. With this change, all four local chat entry points do (chat, terminal, tui --local, and bare openclaw), and onboarding starts behind the proxy. In the TUI paths, the proxy line prints before the TUI draws. At this head, Ctrl+C during chat startup exits with 130 and sends no model request.

terminal, tui --local, bare openclaw, and onboarding, before and after

Before (base b53ba16c63a):

$ openclaw --profile p194 terminal --message hi    # in a pseudo-terminal
  cli:   (no managed proxy line)
  reply: STUB-ANSWER
  model server: POST /v1/chat/completions
  recording proxy: (nothing recorded)

$ openclaw --profile p194 tui --local --message hi    # in a pseudo-terminal
  cli:   (no managed proxy line)
  reply: STUB-ANSWER
  model server: POST /v1/chat/completions
  recording proxy: (nothing recorded)

$ openclaw --profile p194    # in a pseudo-terminal, types "hi"
  cli:   (no managed proxy line)
  reply: STUB-ANSWER
  model server: POST /v1/chat/completions
  recording proxy: (nothing recorded)

# same setup without agents.defaults.model
$ openclaw --profile p194    # in a pseudo-terminal: no model configured, so onboarding opens
  cli:   (no managed proxy line)
  then:  ┌  Hi — I'm OpenClaw. I keep this system running. Let's get you set up.

After (this PR):

$ openclaw --profile p194 terminal --message hi    # in a pseudo-terminal
  cli:   [proxy] routing process HTTP traffic through external proxy http://127.0.0.1:13128
  reply: STUB-ANSWER
  model server: POST /v1/chat/completions
  recording proxy: CONNECT 172.17.0.1:18990

$ openclaw --profile p194 tui --local --message hi    # in a pseudo-terminal
  cli:   [proxy] routing process HTTP traffic through external proxy http://127.0.0.1:13128
  reply: STUB-ANSWER
  model server: POST /v1/chat/completions
  recording proxy: CONNECT 172.17.0.1:18990

$ openclaw --profile p194    # in a pseudo-terminal, types "hi"
  cli:   [proxy] routing process HTTP traffic through external proxy http://127.0.0.1:13128
  reply: STUB-ANSWER
  model server: POST /v1/chat/completions
  recording proxy: CONNECT 172.17.0.1:18990

# same setup without agents.defaults.model
$ openclaw --profile p194    # in a pseudo-terminal: no model configured, so onboarding opens
  cli:   [proxy] routing process HTTP traffic through external proxy http://127.0.0.1:13128
  then:  ┌  Hi — I'm OpenClaw. I keep this system running. Let's get you set up.

Checks: the touched test files (pnpm test <file> --maxWorkers=1, wall time below), oxfmt --check on the changed files, pnpm tsgo:core, pnpm tsgo:core:test, and the line-cap ratchet (scripts/check-line-cap-ratchet.mts); the broad suites, including lint, run in this PR's CI. The three changed tests fail on the base (expected 'bypass' to be 'default'; the bare-root tests see no proxy start before the local TUI or the onboarding wizard) and pass with the fix. The other 27 tests in the two files pass on both.

Test file --maxWorkers=1 wall CI seconds (Vitest duration; shard total)
src/cli/command-path-policy.test.ts 7.4 s (28.1 s with a cold compile cache) 4.56 s; 6.55 s
src/cli/run-main.bare-root.test.ts 22.8 s with a cold compile cache, about 18 s of it compiling (6.9 s warm) 2.82 s; 4.33 s

The second commit only rewrites the switch in resolveBareRootLaunchPolicy as early returns, for oxlint consistent-return; there is no behavior change, and both test files pass on it.

Simplification pass: no further cut. No mechanism is removed. Named commands keep the command catalog as their only proxy policy. Bare openclaw gets one decision point, resolveBareRootLaunchPolicy, beside shouldStartProxyForCli; it replaces the inline nested TTY-message ternary in run-main.ts and also decides proxy startup. Still protected: the Gateway-connected tui, bare openclaw with a Gateway, and remote Gateway inference setup keep their direct connection, and the TTY messages are unchanged. Delta against b53ba16c63a: production +44/−14 (run-main.ts 3 lines shorter; the 29-line policy function holds the growth), tests +16/−1, docs +1/−1.

Not covered: the onboarding run shows only that the proxy starts before the wizard; no provider request was made in it. The Gateway-connected tui keeps its bypass. A policy expectation for tui without --local and a bare-root test that asserts no proxy start for a Gateway-bound TUI cover this; nothing ran against a real Gateway. HTTPS proxy endpoints and other proxy.loopbackMode values were not exercised; these commands now use the same startup proxy path as agent --local. Each command ran once per side.

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: S labels Oct 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Starts the existing managed proxy for local terminal chat and bare-command local onboarding or chat.

Example: Run openclaw chat --message hi with proxy URL http://127.0.0.1:13128 and model endpoint http://172.17.0.1:18990/v1.

  • Before: The model receives the request directly and the recording proxy sees nothing.
  • After: The proxy records CONNECT 172.17.0.1:18990 and the model returns STUB-ANSWER.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner-level repair with shipped CLI request traces, preserved Gateway routing, and green exact-head checks.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied Linux Node CLI traces exercise all four local chat entry points against a recording forward proxy and synthetic model server, showing CONNECT traffic and successful replies after the fix; onboarding demonstrates activation before wizard dispatch, and the final commit is behavior-equivalent.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Local terminal model requests silently bypass the operator's configured forward proxy.
Reason: Restores the established process-egress contract for local execution while preserving direct Gateway-client routing.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR repairs a verified proxy-startup omission still present on current main, with relevant CLI request traces and no actionable correctness findings.

Priority: P2
Reviewed head: bd6748a3825ccb25a6206fd940bc750f40d21dea

Before merge

None.

Findings

None.

Agent review details

How this fits together

CLI startup selects local execution or a Gateway connection; local execution installs process-wide proxy routing before launching the embedded agent or onboarding, then releases it through existing cleanup.

flowchart TD
  A[CLI invocation] --> B[Startup policy]
  B --> C[Local runtime]
  B --> D[Gateway client]
  C --> E[Managed proxy]
  E --> F[Model endpoint]
  D --> G[Gateway]
Loading

Technical review

Best possible solution:

Land the focused startup repair using the existing managed proxy owner and cleanup lifecycle.

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

Current-main source establishes the startup omission, and the supplied CLI traces show its effect; this read-only review executed no target code.

Is this the best way to solve the issue?

The patch fixes the owning startup policy for all reported local entry points without adding provider-specific routing or another proxy owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2a48809c5ce3.

Provenance checked

  • Local-command proxy policy changes intended behavior with a stated reason (2633b14: Process-local runtime traffic uses the configured proxy while control-plane clients retain direct connections.)
  • Bare-root Gateway and local launch selection keeps the original intent (96f0983: The selected Gateway remains authoritative for inference and onboarding instead of falling back to client-local setup.)
  • TTY guidance and startup policy placement keeps the original intent (4bf68b9: Consolidate CLI execution and reporting while retaining output and lifecycle ordering.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jesse Merhi: Raw commit 2633b14 adds src/cli/command-catalog.ts:214 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2633b1491413; files: src/cli/command-catalog.ts)
  • Peter Steinberger: Raw commit 4bf68b9 adds src/cli/run-main.ts:1081 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4bf68b98ab51; files: src/cli/run-main.ts)

PR surface

Source +30, Tests +15, Docs 0. Total +45 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 44 14 +30
Tests 2 16 1 +15
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 61 16 +45

Review metrics

Metric Value Why it matters
Production versus test changes Production +44/-14; tests +16/-1 Growth adds the missing bare-root proxy decision while moving existing TTY selection into the policy module and extending existing regression coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #173529
Summary: This PR addresses the canonical local-terminal proxy omission; local catalog refresh has a separate startup boundary.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The defect affects operators with configured proxies using local terminal chat; agent --local and Gateway execution provide working alternatives.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-15T22:59:56.358Z sha 71b3d0c :: needs maintainer review before merge. :: none

Reviewed October 16, 2026, 5:19 AM ET / 09:19 UTC (Revision 2).

@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 16, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 16, 2026
@steipete steipete self-assigned this Oct 16, 2026
@steipete
steipete merged commit 35c5097 into openclaw:main Oct 16, 2026
208 of 217 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

vincentkoc added a commit that referenced this pull request Oct 16, 2026
* commit 'ac03ca0b6d26a7dc55d0d262e40d2549631b1ea7': (25 commits)
  fix: apply shared plugin model policy to decisions (#156621)
  perf: shortlist transcript relevance scores before metadata reads (#174058)
  fix: strip standalone trailing NO_REPLY from replies (#171990)
  fix(ci): avoid repeated discovery during changed-test planning (#174069)
  fix(sqlite): preserve transaction outcomes when warnings throw (#157151)
  fix(ai): native video handoff to chat-completions providers + preflight video cost (#170920)
  fix(litellm): image generation fails when the backend returns image URLs (#173508)
  test(memory,gateway,infra,subagents): remove low-value tests (batch d152) (#174034)
  perf(memory): bound derived worker snapshot and pricing retention (#174067)
  fix(test): reduce eager imports during test startup (#174056)
  refactor(codex): share lifecycle preflight fixtures (#174062)
  test(gateway,matrix,agents,ui): remove low-value tests (batch d150) (#174025)
  perf(infra): batch usage refresh maintenance (#174050)
  fix(gateway): revert cold session list worker regression (#174052)
  refactor(config): consolidate browser meeting configuration (#173947)
  fix(cron): keep global-session deliveries on the selected agent (#173855)
  test(compaction): assert structured stale-writer failure (#174064)
  fix(cli): local terminal chat sends model requests without the configured proxy (#173530)
  test(ui): restore bootstrap preference locale after each case (#174065)
  fix: download session files through the development proxy (#173973)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
…ured proxy (openclaw#173530)

* fix(cli): route local chat and TUI egress through the managed proxy

* fix(cli): return the bare-root launch policy on every path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Local terminal chat (openclaw chat, terminal, tui --local) sends model requests without the configured proxy.proxyUrl

2 participants