Skip to content

Read MCP stdin on its own thread (M01-04d slice 4, PR 1b) - #54

Merged
WahdanZ merged 2 commits into
mainfrom
m01-04d-4-1b-stdin-thread
Nov 18, 2026
Merged

WahdanZ merged 2 commits into
mainfrom
m01-04d-4-1b-stdin-thread

Conversation

@WahdanZ

@WahdanZ WahdanZ commented Nov 18, 2026

Copy link
Copy Markdown
Owner

What

PR 1b of M01-04d slice 4 (0 ✅ → 1a ✅ → 1b → 2 → 3 → 4). No bridge removed; MCP JSON, CLI output, exit codes and approval order unchanged. User approval: SAFETY-CRITICAL APPROVED for this scope; decision: EOF while a dialog is open keeps today's behavior.

  • MCPServer.run (@MainActor async): a dedicated reader thread (same readLine framing) feeds an unbounded AsyncStream (user decision: no request is ever dropped; the pipe no longer applies back-pressure). A main-actor loop handles one request at a time and writes each reply before taking the next line. Exit 0 only after every buffered line was handled.
  • Re-entrancy: the approval stays synchronous inside handle ("one request at a time; an approval never yields"); the preview is still used up before asking.
  • runOnMain takes an async body; --mcp and --cli mcp share the one reader. CLI.run takes its subcommand from CLI.subcommand (its old mcp case is unreachable and now returns 64).

Tests

  • Run-loop fingerprint flipped: ticks>0 (main run loop free while waiting for input). Negative control with the old blocking loop: only this check fails (544/1).
  • Re-entrancy: one ask while a second confirm waits; replies in order; a used preview is refused, nothing moved.
  • EOF during an open dialog → reply written, exit 0; EOF during an approved move → file in the isolated Trash and its Trash-log record before exit.
  • 30 requests behind a 600 ms dialog → all replies in order; existing EOF / 50-burst / 20-behind-dialog checks kept.
  • Idle --mcp still terminates on SIGTERM (no handler).

Checks (local)

  • Build OK; warning budget OK (4, baselined)
  • Package 146; check-approval-sites.sh pass; check-no-test-hooks.sh pass (Release, --expect-hooks)
  • Self-test Release 494/0; test-hooks 545/0; CI smoke by hand OK incl. --cli mcp

Before merge

  • mc-reviewer and mc-safety-architect (Opus) clean
  • Manual dialog checks in a logged-in session on this build (decline, no-click timeout, approve a missing path, CLI, window)

🤖 Generated with Claude Code

…e main actor (M01-04d slice 4, PR 1b)

No bridge removed; MCP JSON, CLI output, exit codes and approval order are
unchanged.
- MCPServer.run: a dedicated reader thread (same readLine framing) feeds an
  unbounded AsyncStream; a main-actor loop handles one request at a time and
  writes each reply before taking the next line. Exit 0 only after every
  buffered line was handled. The approval never yields, so the dialog's
  modal loop cannot run another request; the preview is still used up
  before asking.
- runOnMain takes an async body; --mcp and --cli mcp share the one reader.
  CLI.run takes its subcommand from CLI.subcommand.
- Self-test: run-loop fingerprint flipped (ticks>0: the main run loop is
  free while waiting for input; the old blocking loop fails it); re-entrancy
  (one ask while a second confirm waits, replies in order, a used preview
  refused); EOF during an open dialog (today's behavior) and during an
  approved move (exit after the move and its log record); 30 requests behind
  a dialog; idle --mcp still dies on SIGTERM.
…cy guarantee

Docs and a comment only. D-018 records the stdin thread / one-request-at-a-
time design and the user's decisions (unbounded buffer, an open dialog
outlives EOF, no SIGTERM handling); RISK-018..020 track them. The
MCPServer.run comment now names the single consumer and synchronous
handle as the guarantee, with the main-queue rule only as a second layer.
@WahdanZ
WahdanZ merged commit 11311c3 into main Nov 18, 2026
2 of 3 checks passed
@WahdanZ
WahdanZ deleted the m01-04d-4-1b-stdin-thread branch November 18, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant