Skip to content

Run --mcp and --cli inside a live main run loop (M01-04d slice 4, PR 1a) - #53

Merged
WahdanZ merged 2 commits into
mainfrom
m01-04d-4-1a-main-runloop
Nov 18, 2026
Merged

WahdanZ merged 2 commits into
mainfrom
m01-04d-4-1a-main-runloop

Conversation

@WahdanZ

@WahdanZ WahdanZ commented Nov 18, 2026

Copy link
Copy Markdown
Owner

What

PR 1a 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 exactly this scope.

  • Entry.runOnMain: a main-actor Task + while true { CFRunLoopRun() } — never dispatchMain(). Used by --mcp and --cli; --cli bench (spins RunLoop.main itself), the self-test, --selftest-child and the window app keep their own paths. Bench routing via one CLI.subcommand helper.
  • MCPServer mutable state, call, approve, preview helpers and HumanApproval.ask are @MainActor (still synchronous); CLI.run too. askWithDialog and its main-thread guard unchanged.
  • Documented scope addition (review-driven): making call @MainActor produced a new Sendable warning in scan_caches' parallel measure. It now measures into an OSAllocatedUnfairLock-guarded array (compiler-checked: no unsafe pointer, no @unchecked); JSON output byte-identical to the old binary.

Proof

  • PR 0's run-loop baseline flipped on purpose: the MCP approval now runs inside the running main run loop (mode=kCFRunLoopDefaultMode, main=1; ticks stays 0 until PR 1b).
  • Negative control (not committed): with dispatchMain() instead of the loop, exactly that check fails (536/1, probe mode=nil).
  • Test-hooks probe delay now runs the main run loop in modal-panel mode until a modal-mode timer fires (the dialog's timeout mechanism), asserted in the three delayed-approval checks.
  • New: --cli bench sdks finishes within 60 s with its header; --cli mcp ping + EOF → one reply, exit 0.

Checks (local)

  • Build OK; warning budget OK (4, baselined; the new warning fixed in code)
  • Package 146 pass; check-approval-sites.sh pass; check-no-test-hooks.sh pass (Release, --expect-hooks)
  • Self-test Release 493/0; test-hooks 537/0; CI smoke steps by hand OK
  • mc-reviewer: approve; mc-safety-architect (Opus): approve — findings fixed in 2fa0fee; re-review of the fixes in progress

Before merge

  • Re-reviews of 2fa0fee (Sonnet + Opus) clean
  • Manual approval-dialog check in a logged-in session (decline, 5 s timeout, approve a missing path, CLI/bench/--cli mcp, window app)

🤖 Generated with Claude Code

No bridge removed; MCP JSON, CLI output, exit codes and approval order are
unchanged.
- Entry.runOnMain: a main-actor Task plus CFRunLoopRun (never dispatchMain,
  which leaves the main run loop unserviced). --mcp and --cli use it;
  --cli bench, the self-test and the window app keep their own paths.
- MCPServer's state, call, approve and preview helpers and
  HumanApproval.ask are @mainactor (still synchronous); CLI.run too.
- scan_caches measures through a nonisolated helper so the parallel
  measure doesn't capture main-actor state (fixes a new Sendable warning
  in code, no baseline entry).
- Self-test: the PR 0 run-loop baseline is flipped on purpose (approval
  now runs in kCFRunLoopDefaultMode; ticks stay 0 until PR 1b); a
  dispatchMain negative control fails exactly that check. New bench
  smoke check (bench stays outside the loop).
… probe (M01-04d slice 4)

- scan_caches measures in parallel into an OSAllocatedUnfairLock-guarded
  array (no unsafe pointer, no @unchecked Sendable); output unchanged.
- Test-hooks probe delay now runs the main run loop in modal-panel mode
  until a modal-mode timer fires, so the dialog's timeout mechanism is
  exercised inside runOnMain; asserted in the delayed-approval checks.
- One CLI.subcommand helper decides bench routing for Entry and CLI.run.
- runOnMain doc comment states what dispatchMain actually leaves unserviced.
- New --cli mcp subprocess check; bench check: 60 s deadline, header asserted.
@WahdanZ
WahdanZ merged commit 9f518cf into main Nov 18, 2026
2 checks passed
@WahdanZ
WahdanZ deleted the m01-04d-4-1a-main-runloop branch November 18, 2026 12:58
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