Repository navigation
fix: Claude CLI ignores session MCP server selections - #168393
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -19, Tests +207. Total +188 across 4 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 10, 2026, 7:10 AM ET / 11:10 UTC (Revision 3). |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
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.
…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]>
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
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 atcdeb1e37adc6ecfba8db436f5372c37799d2f931.claudeexecutable 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 reused12907. Exactly one captured CLI input per requested turn. This is Gateway/process proof, not a Claude service/model test.Inherited gate failure:
check:changedstops at unused exports in untouched files.PUBLIC_SESSION_ENTRY_SCRIPTandisClaudeLikeLiveAgentalso fail the scanner on current mainfdcabd28eed7ec770fbcf5f8315c85c40f4ebde6(169.732 seconds). The third candidate finding,isPollVoteEchoText, is already fixed upstream byc19ae6247254cf15aaefb436da6167c5bc4567a4(#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-4hitcontrol-ui-public-session-refresh.test.ts(51,19): TS2345(string | undefinedpassed asstring). Upstream06c6e83f4351fe9b94c3c53ae658a04097e437de, added after the tested base, introduced that regex-capture narrowing error. An isolated checkout of main18b46dd0b6b51dcbd227f5bb8f7e43bc5c45746dreproduces the identical failure withpnpm 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.tsFocused 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:
Production: +96/−115 (net −19). Tests: +207/−0. Docs: +0/−0; the MCP guide already documents this session-scoped contract.