fix(cli,mcp): reliable MCP stdio, cancellation, shared session lock, strict mcp args

Merged
TH
12h ago
+970-275

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/list and the handshake are answered while a tools/call is running. notifications/cancelled aborts the call's daemon request. The AI SDK forwards its abortSignal the 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_PLATFORM and sessionLock from 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.
  • SRC-4: AGENT_DEVICE_PLATFORM is checked against the full platform list (PLATFORM_SELECTORS). Before this, AGENT_DEVICE_PLATFORM=web broke commands that have no --platform flag.
  • SRC-5: A failing test run now exits through the flushed exit path.
  • SRC-7: mcp with 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-related fails on 5 provider-integration timeouts.
    • The same timeouts reproduce on base 093341a under the same host load (load average 10–15 on 4 CPUs). Contention is suspected but not proven.
  • At 21b3419: vitest-related passed. 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/call now run concurrently with a running tool call.

Generated by Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.