fix(cli,mcp): reliable MCP stdio, cancellation, shared session lock, strict mcp args
Merged
TH
12h ago+970+970+012345678901234567890123456789-275-275-012345678901234567890123456789
Summary
Fixes audit findings SRC-1 (high), SRC-2, SRC-3, SRC-4, SRC-5 and SRC-7 from the 2026-11-10 audit.
- SRC-1: MCP stdio now serves every line:
- A blank line no longer stalls the requests after it.
- A malformed line gets a -32700 response, and the next line is still served.
- A final line with no newline is served at end of input.
- SRC-2:
ping,tools/listand the handshake are answered while atools/callis running.notifications/cancelledaborts the call's daemon request. The AI SDK forwards itsabortSignalthe same way. - SRC-3: CLI, MCP and the AI SDK now share one session-lock policy:
- MCP and AI SDK tool calls read
AGENT_DEVICE_SESSION,AGENT_DEVICE_SESSION_LOCK,AGENT_DEVICE_PLATFORMandsessionLockfrom the serving process. - A session or platform in tool input never turns the lock on.
- The resolver moved to
@agent-device/command-surface, next to the config-backed flag defaults.
- MCP and AI SDK tool calls read
- SRC-4:
AGENT_DEVICE_PLATFORMis checked against the full platform list (PLATFORM_SELECTORS). Before this,AGENT_DEVICE_PLATFORM=webbroke commands that have no--platformflag. - SRC-5: A failing
testrun now exits through the flushed exit path. - SRC-7:
mcpwith any flag or argument now fails with INVALID_ARGS. - SRC-6 (token cache) is deferred. The token's scope (tenant/runId/daemonBaseUrl/session) and a refresh-on-401 retry need a decision.
23 files changed. Docs updated: agent-setup.md, ai-sdk.md, sessions.md, mcp help.
Validation
- Tested SHA
b2e89f9: format, lint, typecheck, layering, fallow and build pass.vitest-relatedfails on 5 provider-integration timeouts.- The same timeouts reproduce on base
093341aunder the same host load (load average 10–15 on 4 CPUs). Contention is suspected but not proven.
- At
21b3419:vitest-relatedpassed. The unit suite showed only the known root/chmod baseline failures, plus 3 closure-budget failures that are fixed at head. - I reverted each fix and reran its new test: the tests for SRC-3, SRC-4, SRC-5 and SRC-7 fail on the old code.
- CI obligations: run the unit suite and provider integration.
- Risk: MCP requests other than
tools/callnow run concurrently with a running tool call.
Generated by Claude Code
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.