Skip to content

fix: Claude CLI ignores session MCP server selections - #168393

Merged
steipete merged 1 commit into
mainfrom
fix/cli-runner-session-tool-overrides
Oct 10, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/cli-runner-session-tool-overrides

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #168207

What Problem This Solves

Fixes missing session-enabled MCP servers and ignored session disables in Claude CLI Gateway agent turns.

User Impact

Saved MCP server choices take effect on the next Claude CLI turn, including warm sessions. Global configuration and ordinary tool policy keep their existing roles; no migration or configuration change is needed.

Why This Change Was Made

The command attempt selected session tool overrides only for embedded execution. Both branches now receive that selection from their shared argument builder. This preserves the separate run-level override contract used by reply snapshots and authority narrowing.

The preparation cleanup removes repeated rejection branches, forwarding, cleanup chains, and final admission binding while preserving resource release order and error precedence. Production changes are net −19 lines; further reductions would widen this lifecycle refactor. The file still needs its existing max-lines baseline entry.

Thanks @dprev for the report.

Evidence

Tested commit: 8fba214341f52b3ebffdbb96d31931a9f9da792b, after integrating main at cdeb1e37adc6ecfba8db436f5372c37799d2f931.

  • The new regression traverses the real attempt caller, CLI runner, preparation, and serialized strict MCP overlay. All four cases pass. Reverting only the production argument relocation makes both override cases fail while both no-override controls pass.
  • Fresh AWS Linux machine, Node 24.21.0, 30 GiB RAM: 93 module/importer test files, 1,374 tests passed across eight Vitest shards; 1,132.42 seconds wall time. Core production types and all 27 core test-type graphs passed.
  • Real isolated Gateway processes with a fake claude executable recorded the actual MCP overlay. Main reproduced both wrong selections; the fix produced both expected selections. Changing the override replaced the native process (12623 → 12907); the unchanged third turn reused 12907. Exactly one captured CLI input per requested turn. This is Gateway/process proof, not a Claude service/model test.
  • Formatting, targeted type-aware lint, and the remaining source guards pass. Independent Codex review: scoped-clean through P2, no actionable findings.
Global enablement Session override Main overlay Fixed overlay
false true absent present
true false present absent

Inherited gate failure: check:changed stops at unused exports in untouched files. PUBLIC_SESSION_ENTRY_SCRIPT and isClaudeLikeLiveAgent also fail the scanner on current main fdcabd28eed7ec770fbcf5f8315c85c40f4ebde6 (169.732 seconds). The third candidate finding, isPollVoteEchoText, is already fixed upstream by c19ae6247254cf15aaefb436da6167c5bc4567a4 (#168333). All three files and scanner configurations match the candidate's base; this PR does not edit them. The remaining lint/guards were run directly after the scanner stopped the combined gate.

Hosted CI cancellation: run 38045578309 stopped after check-test-types-core-4 hit control-ui-public-session-refresh.test.ts(51,19): TS2345 (string | undefined passed as string). Upstream 06c6e83f4351fe9b94c3c53ae658a04097e437de, added after the tested base, introduced that regex-capture narrowing error. An isolated checkout of main 18b46dd0b6b51dcbd227f5bb8f7e43bc5c45746d reproduces the identical failure with pnpm tsgo:core:test --ci-graphs-json '["core-test-gateway-root"]' (exit 2, 13.043 seconds wall). This PR does not change that test or its type configuration. The command-test type graph, including the new regression, passed in hosted CI in 45.9 seconds.

Commands, cost, and exact diff size
node scripts/run-vitest.mjs src/agents/command/attempt-execution.cli-mcp.test.ts --maxWorkers=1
pnpm tsgo:core
pnpm tsgo:core:test --ci-graphs-json '["core-test-agents-root","core-test-agents-other","core-test-commands"]'
node scripts/check-changed.mjs -- src/agents/cli-runner/prepare.ts src/agents/cli-runner/cleanup.ts src/agents/command/attempt-execution.ts src/agents/command/attempt-execution.cli-mcp.test.ts

Focused regression: 429.56 seconds wall time on the shared macOS host; compiler/cache/import work dominated. Negative control: 212.84 seconds. Final Linux module proof includes the cleanup-only fixture adjustment. Per-file hosted test timing was not collected before the inherited failure cancelled the run. Two opt-in external-provider suites (Gemini and Claude compaction watchdog) were not run; the required credential-free Gateway/Claude-process proof passed.

Exact numstat:

18   0    src/agents/cli-runner/cleanup.ts
77   114  src/agents/cli-runner/prepare.ts
1    1    src/agents/command/attempt-execution.ts
207  0    src/agents/command/attempt-execution.cli-mcp.test.ts

Production: +96/−115 (net −19). Tests: +207/−0. Docs: +0/−0; the MCP guide already documents this session-scoped contract.

Select persisted tool overrides in the shared attempt argument builder so CLI and embedded dispatch use the same session facts. Consolidate repeated CLI preparation cleanup and admission assembly without changing resource release order.
@clawsweeper

clawsweeper Bot commented Oct 10, 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 agents Agent runtime and tooling size: M labels Oct 10, 2026
@steipete
steipete marked this pull request as ready for review October 10, 2026 10:37
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR forwards saved session tool overrides to CLI execution and consolidates CLI preparation cleanup.

Example: The configured docs MCP server has enabled=false, and this session saves mcpServers.docs=true.

  • Before: Claude CLI's strict MCP overlay omits docs.
  • After: The next Claude CLI turn includes docs without changing global enablement.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, source-correct repair with production Gateway/process boundary evidence and a meaningful regression; the provider service itself is outside the demonstrated scenario.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The exact-head evidence records isolated Gateway processes launching a fake Claude executable that captures the actual strict MCP overlay: both override directions change correctly, a changed selection replaces the warm process, and an unchanged following turn reuses it; this proves Gateway/process assembly rather than Claude service behavior.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Saved session MCP choices do not take effect in Claude CLI Gateway turns.
Reason: Repairs an established session-setting contract while preserving global configuration, ordinary tool policy, and embedded behavior.

Merge readiness

✅ Ready for maintainer review

This PR repairs a documented session-selection bug still present on current main; no actionable introduced defect was found.

Priority: P2
Reviewed head: 8fba214341f52b3ebffdbb96d31931a9f9da792b

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway command attempts select session settings and dispatch to embedded or CLI execution; CLI preparation turns those settings into native process arguments, MCP configuration, and cleanup ownership.

flowchart LR
 A[Saved session settings] --> B[Command attempt]
 B --> C[Shared run arguments]
 C --> D[Embedded execution]
 C --> E[CLI preparation]
 E --> F[Strict MCP overlay]
 F --> G[Claude process]
Loading

Technical review

Best possible solution:

Retain the shared session-override handoff so both execution branches honor existing selections through the established policy and overlay owners.

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

Current-main source exposes the dropped argument, and the reporter identifies the same path in official 2026.9.9; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Moving the existing selection into the shared argument builder repairs its producer without adding a competing fallback or changing the separate run-level override contract.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Session override forwarding keeps the original intent (a37a5a6: The merged session-tool feature intended embedded and CLI materialization to honor the same prepared session snapshot.)
  • Session binding policy hash keeps the original intent (48e8965: Keep binding identity session-stable while per-turn delivery restrictions continue to govern execution.)
  • Selected authentication profile validation keeps the original intent (be24db5: Prevent profile substitution and reject an unmaterializable selected account before process execution; the consolidated condition preserves both rejection cases.)
  • Context budgets and isolated preparation keeps the original intent (97af5ef: Preserve provider-owned CLI context limits and avoid unscoped cache contamination; deduplication retains the same candidate identities and limits, and private isolated-completion fields remain private.)
  • Cleanup and retained resource lifetime keeps the original intent (5e4d8ed: Use one preparation-failure cleanup owner; later retained-plugin and context-engine repairs require ordered release and deferred disposal, which the replacement composition preserves.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source -19, Tests +207. Total +188 across 4 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 96 115 -19
Tests 1 207 0 +207
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 303 115 +188

Review metrics

Metric Value Why it matters
Production versus regression code Production +96/-115; tests +207/-0 Production shrinks while the regression covers the previously missing dispatch-to-overlay boundary with four independent selection cases.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Saved MCP enablement and disablement are ignored on the Claude CLI command path, with limited blast radius and a focused repair.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-10T10:43:46.506Z sha 8fba214 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T10:49:46.784Z sha 8fba214 :: needs changes before merge. :: none

Reviewed October 10, 2026, 7:10 AM ET / 11:10 UTC (Revision 3).

@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@steipete
steipete merged commit c75be4f into main Oct 10, 2026
282 of 288 checks passed
@steipete
steipete deleted the fix/cli-runner-session-tool-overrides branch October 10, 2026 11:34
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
Select persisted tool overrides in the shared attempt argument builder so CLI and embedded dispatch use the same session facts. Consolidate repeated CLI preparation cleanup and admission assembly without changing resource release order.
RomneyDa added a commit that referenced this pull request Oct 12, 2026
…acted hotfix)

Extracted from #168393 (c75be4f): took only the
src/agents/command/attempt-execution.ts move of toolOverrides from the
embedded-only run params into the shared buildCommonRunParams, plus the new
attempt-execution.cli-mcp.test.ts regression suite. On the branch the CLI
runner (runCliAgent) never received sessionEntry.toolOverrides, so session
MCP server enable/disable selections were ignored in Claude CLI turns. Left
out the cli-runner prepare.ts/cleanup.ts consolidation: it is a refactor of
cleanup and admission assembly with no behavior change for this bug.

Extracted-from: c75be4f
Co-authored-by: Peter Steinberger <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 12, 2026
Release provenance: 89329f6 -> #168587
Release provenance: e6a9022 -> #168905
Release provenance: 15f3f12 -> #162266
Release provenance: 20805b8 -> #169430
Release provenance: 568fec8 -> #169102
Release provenance: 39dba6d -> #160440
Release provenance: 5df28c7 -> #168393
Release provenance: 10bcd8e -> #168164
Release provenance: dc5f1f5 -> #168446
Release provenance: 9f1e441 -> #168044
Release provenance: 5a235fc -> #168651
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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. size: M 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.

claude-cli: session MCP server overrides are dropped before strict MCP overlay preparation (2026.9.9)

1 participant