Files
hermes-agent/website/docs/reference
anarch666 c28fa1b404 MCP: park single-instance stdio servers quietly instead of self-probing forever
A stdio MCP server that owns a single-writer resource (a PGLite datastore lock, a
device, a pid file) can only ever have ONE live child system-wide. When a second
Hermes context starts, its own copy of the child dies before the MCP handshake
because the resource is already held:

    GBrain's local database is already open through 'gbrain serve' (MCP, PID 2509385)

The initial-connect ladder then burns its 3 attempts, the server parks, and
_PARKED_RETRY_INTERVAL makes the parked server self-probe every 300s - each probe
spawning another child that is guaranteed to lose the same race. The loop is
unbounded and never converges: measured here at ~285 park events/day over 18 days
(16,068 spawn attempts). The functional damage is to triage - errors.log fills with
"parked until a reconnect is requested" lines and buries real failures.

Two changes:

- New `single_instance: true` stdio server option. When the initial ladder is
  exhausted and the child never reached the handshake, the server parks QUIETLY:
  no timed self-probe at all, because the conflict is provably unwinnable (the
  resource is held by another process). Only an explicit reconnect
  (/reload-mcp, `hermes mcp` refresh) revives it, which is the correct trigger -
  that is what happens once the owning instance exits.

- The parked self-probe now backs off for everyone: _PARKED_RETRY_INTERVAL (300s)
  doubling per consecutive still-failed probe, capped at _PARKED_PROBE_BACKOFF_MAX
  (3600s), and reset by _mark_session_proven() once a session is healthy again.
  A transient park keeps its original cadence, so nothing recovers more slowly
  than before in the ordinary network-blip case.

Tests: tests/tools/test_mcp_single_instance_park.py (new) covers the quiet park and
the backoff ladder, cap and reset.

Verified on a566d20d22 (upstream main at the time of writing), diff applies clean:
- 16/16 in the targeted set: the new file plus test_mcp_parked_self_probe.py,
  test_mcp_parked_probe_no_browser.py, test_mcp_rapid_drop_budget.py,
  test_mcp_reconnect_log_hygiene.py.
- The wider tests/tools/test_mcp_* + connectors run shows only PRE-EXISTING
  failures in test_mcp_oauth_manager.py (24 failed / 6 passed) - identical on a
  pristine checkout with the patch reverted, so not a regression from this change.
2026-11-19 10:38:40 -08:00
..