GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |
GeezerVison is showing github.com — fix(mcp): recover remote servers without unnecessary sign-in by martinstiago · Pull Request #61762 · anomalyco/opencode Conversation
|
|
I kept this remote-only; stdio restarts remain in #54378. #60944 changes refresh ownership and includes its own deadline, so I documented that merge-order constraint rather than pulling its implementation into this branch. If it lands first, this PR needs reconciling with its lock-owned refresh path instead of adding a second coordinator. The three inline findings are addressed, with regressions for Bun errors, close-loop backoff, and background startup grace. I also reproduced the existing foreground session-expiry test race on the unchanged PR and settled its startup catalog before restarting the fixture. Validation: 7,241 core tests passed (36 skipped), 570 repeated OAuth/connection checks, 830 repeated MCP lifecycle checks, and clean lint/typechecks. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The earlier concerns are addressed. Bun's ConnectionRefused is temporary again: a direct isTransient check with a real refused connection returns true. Connections that drop quickly keep their backoff. Background retries no longer switch the status back to pending or reopen the startup wait, and a repeat of the same failure isn't published again.
The MCP OAuth, connection and lifecycle tests pass, except one stdio test ("terminates MCP descendants…") that also fails on the base. The connection tests passed three runs in a row, and typecheck:tsc passes. The public API is unchanged; the changed Events signature in connection.ts is internal to packages/core.
No new blocking concerns. The overlap with #60944 (OAuth refresh in oauth.ts) and #54378 (reconnects, including stdio) still needs to be sorted out with whichever lands first, as the description now notes.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
ba788fa to
aad3dfa
Compare
Preserve Bun's coded TypeError handling so refused connections still retry. Retain backoff across short-lived connections and reset it after stable recovery. Keep background retries out of pending/startup grace and suppress duplicate status events. Add regressions and settle startup catalogs before the foreground expiry test. Rebase onto the pooled-connection dev: event reporters take their background flag, the pool joins with it, and close-loop tests drive the client's close seam instead of the removed handshake hook.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The earlier points still hold after the rebase. ConnectionRefused is temporary (checked directly with a real Bun error), connections that drop right after connecting keep their backoff, and background retries are quiet. The MCP tests pass (167/168; the one failure, "terminates MCP descendants…", also fails on the base), and typecheck:tsc passes. The public API is unchanged.
I'm requesting changes because the rebase onto pooled connections (pool: true) breaks reconnects for them (inline on pool.ts). I checked this with a temporary test. After a pooled remote connection drops, the project's server stays failed and never recovers. Meanwhile the background retry reconnects the shared connection the pool had already detached: the server got a second tool listing. That connection stays open after the project shuts down, and against a server that stays down it would keep retrying for as long as the process runs.
Also: the test-only close method added to the production McpClient.Connection interface (inline).
packages/core/src/mcp/pool.ts:159: The shared connection here is an McpConnection with a remote config, so it gets the new reconnect logic too. That doesn't work with the pool. On a drop, closed below detaches the slot, clears holders and stops the connection. Then watch's onClose calls retry(), which schedules start(true) on the pool's process-wide runtime. That reconnects a slot nobody can reach. On the other side, each holder's project gets closed → failed and never retries, because the pool's wrapper connection has no retry of its own. I checked this with a temporary test in the MCP pool block of mcp.test.ts. I opened one project on a pooled server, then called client.close() on the shared connection. The project's status stayed failed ("Connection closed"), while server.state.toolLists went from 1 to 2. After shutdown, it stayed connected; nothing ever stops it. Shared connections should probably not retry on their own (e.g. a retry flag in Input that the pool turns off). The project's pool wrapper could then retry by joining again, so pooled servers also recover.packages/core/src/mcp/client.ts:188: This adds a test-only method to the production Connection interface and has every connection keep its close callback just so tests can call it. The tests should close the connection for real instead, e.g. by closing the test server or the transport, as the attach tests do. Then this method and registered can go.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Preserve Bun's coded TypeError handling so refused connections still retry. Retain backoff across short-lived connections and reset it after stable recovery. Keep background retries out of pending/startup grace and suppress duplicate status events. Add regressions and settle startup catalogs before the foreground expiry test. Rebase onto the pooled-connection dev: event reporters take their background flag, the pool joins with it, and close-loop tests drive the client's close seam instead of the removed handshake hook. Shared connections no longer schedule their own reconnect: the pool sets reconnects false and each holder rejoins with backoff while it still holds its claim, so a dropped pooled server recovers with its Locations and nothing outlives them.
aad3dfa to
09649db
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The leftover shared connection from my last review is fixed. Shared connections no longer retry on their own, and after a drop the project joins the shared connection again (a rejoin) and comes back as connected. I checked this with a temporary pool test.
I'm still requesting changes, because the rejoin has two problems (inline on pool.ts):
disconnect. The status went to disabled, then about 2.5 seconds later back to connected, and the server got another tool listing.failed with nothing scheduled after it. A pooled server that fails when it first connects isn't retried at all. Both are the down-for-a-while case from #52237.The new commit adds no tests for the rejoin. One should cover a drop followed by a disconnect, and a server that's still down at the first rejoin.
The MCP tests pass (167/168; the one failure, "terminates MCP descendants…", also failed on the base), and typecheck:tsc passes. The public API is unchanged; reconnects is an internal McpConnection.Input field.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
09649db to
61400d2
Compare
Preserve Bun network errors and quiet background recovery. Use one entry-owned recovery loop for private and pooled connections, honoring Retry-After and cancelling on explicit disconnect. Keep backoff across short-lived connections, preserve pooled failure classification, and remove the production-only close test seam. Cover prolonged outages, pooled process teardown, cancellation, first-connect failures, and stable recovery.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The earlier points are fixed: a disconnect, remove or replace now cancels recovery, a pooled server that fails its first join or is still down at a rejoin keeps retrying with backoff and Retry-After, the pool's separate backoff is gone, and the test-only close method is removed. The earlier fixes still hold: ConnectionRefused is temporary, connections that drop quickly keep their backoff, and background retries stay quiet.
With the repo's 30-second test timeout, the new pool, recovery and connection tests pass (35/35), including a real killed pooled process followed by a disconnect. typecheck:tsc passes. The public API is unchanged.
One remaining concern: several new tests in mcp.test.ts wait in real time (inline). Two of them always fail under plain bun test, which uses a 5-second timeout.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Remove redundant live outage timing coverage and fixed waits from pooled recovery regressions. Preserve status, cancellation, repeated rejoin and first-connect assertions using event-driven TestClock advances. Addresses review feedback on anomalyco#61762.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The tests that waited in real time are fixed. The 14-second outage test is removed, and the disconnect and rejoin pool tests now use a fake test clock instead of sleeping. Under plain bun test (5-second default timeout), the pool tests passed 26/26 three runs in a row. The MCP tests pass (168/169; the one failure, "terminates MCP descendants…", also fails on the base), and typecheck:tsc passes. The public API is unchanged. No further concerns.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
# Conflicts: # packages/core/src/mcp/oauth.ts # packages/core/test/mcp-oauth.test.ts
Preserve Bun network errors and quiet background recovery. Use one entry-owned recovery loop for private and pooled connections, honoring Retry-After and cancelling on explicit disconnect. Keep backoff across short-lived connections, preserve pooled failure classification, and remove the production-only close test seam. Cover prolonged outages, pooled process teardown, cancellation, first-connect failures, and stable recovery. # Conflicts: # packages/core/src/mcp/connection.ts # packages/core/src/mcp/index.ts # packages/core/src/mcp/pool.ts # packages/core/test/mcp-connection.test.ts
Remove redundant live outage timing coverage and fixed waits from pooled recovery regressions. Preserve status, cancellation, repeated rejoin and first-connect assertions using event-driven TestClock advances. Addresses review feedback on anomalyco#61762.
0860f28 to
52819bd
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The rebase keeps the earlier fixes: ConnectionRefused is temporary, one recovery worker handles retries and is cancelled by a disconnect, remove or replace, and the pool tests use the test clock. The MCP OAuth, connection, recovery, lifecycle and credential tests pass (192/193; the one failure, "terminates MCP descendants…", also fails on the base), and typecheck:tsc passes. The public API is unchanged.
One new concern from the rebase: the refresh code in oauth.ts now repeats parts of what upstream already does for MCP OAuth refresh (inline).
packages/core/src/mcp/oauth.ts:53: After the rebase, parts of this repeat what dev already does: - In-flight map: #62827 moved MCP refreshes under Credential.lock, which re-reads the row before refreshing, and removed exactly this module-level refreshes map. Under the lock a second caller never sends the spent token, so the map is no longer needed. It's also one more process-wide cache keyed by refresh token. - Timeout: Credential already times out each refresh at 30s (credential.ts:170), so the timeoutOrElse in sender is a second 30s limit on the same request. Could sender keep only what is new here: turning 408/429/5xx and network failures into RefreshError with its Retry-After, and the per-origin serialization if you still want it? Then there's one owner for sharing refreshes and for their timeout.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
mcp: remote MCP servers that fail once are never retried until service restart
There was an error while loading. Please reload this page.