Repository navigation
fix: reconnect closed MCP sessions; fail fast on expired OAuth sign-in (0.9.4) - #16
Merged
Merged
Conversation
The session was opened once at startup and never replaced, so after the connection dropped every tool call failed with ClosedResourceError until restart. Run the connection in its own task, drop dead sessions, reconnect on the next call, and retry once only when the send itself failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the IdP refuses the stored refresh token (invalid_grant/invalid_token, e.g. Keycloak's 60-day offline-session cap), the SDK fell through to a full authorization inside the request and blocked 300 s until TimeoutError. Delete the dead token, post a sign-in link at once, finish sign-in in the background, and return a clear sign_in_expired result. Release 0.9.4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
On 2026-10-22 the GEO Slack agent (
slack-agents-geo, lib 0.9.3) failed two ways whileagent-geoitself was healthy:anyio.ClosedResourceError.mcp_httpopened its session once at startup and never replaced it after the connection dropped.TimeoutErroron every call.REFRESH_TOKEN_ERROR error="invalid_token" reason="Token is not active".mcp-serverscaps offline sessions at 60 days (offlineSessionMaxLifespanEnabled: true). The owner chose to keep that cap.What changed
tools/mcp_http.pyClosedResourceError/BrokenResourceError). Such a request never reached the server.CONNECTION_CLOSEDafter the request was sent.Session terminated, meaning the server restarted and answered 404 for our session id.list_toolsruns at connect, so the SDK's output-schema cache never sends a request after a tool ran.oauth/flow.py,oauth/errors.py, callersinvalid_grant/invalid_tokennow:SignInExpired(a subclass ofReauthRequired, so background pollers keep their existing notice).mcp_http_oauthmapSignInExpiredto asign_in_expiredresult: "Your sign-in to X has expired. I've just sent you a sign-in link. Please sign in, then ask again." The request does not wait 300 s and noTimeoutErroris raised.Release: version 0.9.4, CHANGELOG
[0.9.4],docs/oauth.md, regeneratedllms-full.txt.Testing
tests/test_mcp_client.py: send-failure reconnect and single retry, retry at most once, no replay after send, concurrent reconnect, reconnect failure, and connect/close lifecycle in one task.tests/test_oauth_sign_in_expired.py,tests/a2a/test_oauth.py: the refused-refresh paths.ruff checkandruff formatare clean.Session terminated, and the next call reconnected and succeeded. Before this change, every call after either failure failed until restart.🤖 Generated with Claude Code