Skip to content

fix(mcp): wire_send uses a cheap pidfile liveness check, not the full scan (#350)#353

Merged
laulpogan merged 1 commit into
mainfrom
fix/mcp-send-cheap-daemon-check
Jun 20, 2026
Merged

fix(mcp): wire_send uses a cheap pidfile liveness check, not the full scan (#350)#353
laulpogan merged 1 commit into
mainfrom
fix/mcp-send-cheap-daemon-check

Conversation

@laulpogan

Copy link
Copy Markdown
Collaborator

Willard reported painfully slow MCP on Windows. Root cause confirmed in code, not theory.

The bug

tool_send — i.e. every wire_send, the primary MCP action — called daemon_liveness() purely to populate one diagnostic boolean (daemon_seen = snap.pidfile_alive). But daemon_liveness() also runs the machine-wide orphan scan the send path never reads:

On Unix that's a cheap pgrep + /proc; on Windows it's seconds, paid on every send. (The code comment even called these annotations "cheap to compute" — true on Unix, false on Windows.)

Fix

New ensure_up::daemon_pidfile_alive() — one daemon.pid read + one pid_is_alive (one tasklist on Windows) → the identical daemon_seen boolean for a fraction of the cost. Both tool_send branches use it. wire_status keeps full daemon_liveness() (it legitimately reports orphans).

Scope / verification

🤖 Generated with Claude Code

… scan (#350)

Willard reported painfully slow MCP on Windows. Root cause confirmed in code:
`tool_send` (every `wire_send`, the primary MCP action) called
`daemon_liveness()` purely to read one diagnostic boolean (`daemon_seen` =
`snap.pidfile_alive`). But `daemon_liveness()` also runs the machine-wide
orphan-detection scan the send path never uses:
- `find_processes_by_cmdline("wire daemon")` → PowerShell `Get-CimInstance` on
  Windows (enumerates ALL processes, ~1-3s cold),
- `list_sessions()` → reads `agent-card.json` from EVERY by-key home (Willard's
  box has hundreds — see #351's session proliferation), each an NTFS dir read,
- `pid_is_alive` per session daemon pid → a `tasklist.exe` spawn each.

On Unix that's a cheap `pgrep` + `/proc`; on Windows it's seconds — paid on
every send. The annotation only needs `daemon_seen`.

Fix: new `ensure_up::daemon_pidfile_alive()` — one `daemon.pid` read + one
`pid_is_alive` (one `tasklist` on Windows) — yielding the identical boolean.
`tool_send`'s two branches use it instead of full `daemon_liveness()`.
`wire_status` keeps the full scan (it legitimately reports orphans).

Cross-platform; Windows CI (`install-smoke-windows`) compile-verifies. The
deeper Windows wins (native Win32 to kill the remaining PowerShell/tasklist/reg
spawns, #350) and the MCP/CLI identity split (#351) remain tracked; this removes
the per-send hot-path scan, the dominant cost.

Test `daemon_pidfile_alive_false_without_pidfile`. 610 lib tests; fmt+clippy clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying wireup-landing with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9a2f63d
Status: ✅  Deploy successful!
Preview URL: https://f7cb7293.wireup-landing.pages.dev
Branch Preview URL: https://fix-mcp-send-cheap-daemon-ch.wireup-landing.pages.dev

View logs

@laulpogan laulpogan merged commit a7f50a6 into main Jun 20, 2026
13 checks passed
@laulpogan laulpogan deleted the fix/mcp-send-cheap-daemon-check branch June 20, 2026 20:27
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