Skip to content

fix(mcp): back off before respawning a failed server - #98

Closed
hilariie wants to merge 1 commit into
mainfrom
claude/port-monorepo-pr-4d2e94
Closed

hilariie wants to merge 1 commit into
mainfrom
claude/port-monorepo-pr-4d2e94

Conversation

@hilariie

Copy link
Copy Markdown
Contributor

Ports genkit-ai/genkit#6957 (still open upstream, at genkit-ai/genkit@b01ef020e).

Why

A server that can't start was started again on every tool listing. In a host it was worse: all servers share one listing, so the broken server got a new process every time the healthy ones were listed, and every time a tool call on any of them failed.

Changes

  • A connection that fails before completing a request, including one that never finishes its handshake, waits before the server is started again: 1s, doubling with each failure in a row, up to 30s. During the wait, listings and tool calls fail at once with UNAVAILABLE and an error saying how long is left. A timed-out request does not count as completed.
  • A server that worked and then died is still replaced on next use, with no wait.
  • restart() / host.reconnect() start the server straight away and reset the wait.

Differences from upstream

  • Conflict in _client.py: kept this repo's McpConnection(self._name, ..., host=self._host) call.
  • The waiting error passes cause= instead of only setting __cause__, so its message and Dev UI entry say why the server failed, like the package's other errors.
  • test_a_server_that_timed_out_and_then_died_waits_too uses an 8s STALL_TIMEOUT_MILLIS instead of 3s, matching the host tests, since the timeout also bounds the handshake and 3s flaked under heavy load.
  • README and McpHost docstring say reconnect() skips the wait.

Verification

genkit-mcp suite (264 tests), ruff, ty and pyright pass locally.

Part of genkit-ai/genkit#6194.

Port of genkit-ai/genkit#6957. A connection that fails before completing a
request, including one that never finishes its handshake, now waits before
the server is started again: 1s, doubling with each failure in a row, up to
30s. Meanwhile listings and tool calls fail at once with UNAVAILABLE. A
server that answered and then died is still replaced on next use, and
restart()/host.reconnect() skip the wait.

On top of upstream: the waiting error passes its cause so the message and
Dev UI say why the server failed, the timed-out-then-died test uses an 8s
timeout like the host stall tests, and the host docs say reconnect() skips
the wait.

Upstream-Commit: genkit-ai/genkit@b01ef02
Upstream-PR: genkit-ai/genkit#6957
@hilariie hilariie closed this Nov 11, 2026
@hilariie
hilariie deleted the claude/port-monorepo-pr-4d2e94 branch November 11, 2026 14:23
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