Repository navigation
[python/google_genai] preserve MCP failure occurring after connection establishment (#572) - #630
Merged
brianstrauch merged 2 commits intoNov 18, 2026
Conversation
… establishment (temporalio#572) Fixes temporalio#572 ### Root cause When an MCP connection fails after establishing a session, _ConnectionRecord._run() caught the exception and re-raised it because self._ready.done() was true. Because self._owner is a background task not awaited outside aclose(), re-raising caused an unhandled task exception (Task exception was never retrieved). Furthermore, the failure was lost from the connection record, causing subsequent calls to session() to return a stale session instead of raising the error. ### Fix - Add self._failure to _ConnectionRecord. - On post-connection failure in _run(), store the error in self._failure, cancel any active idle timer handle, and do not re-raise standard exceptions into the un-awaited owner task. - In _ConnectionRecord.session(), check self._failure and raise it if set. - BaseExceptions (CancelledError, SystemExit, etc.) continue to propagate. ### Tests - Added test_mcp_failure_after_connect_reported_and_creates_fresh_connection verifying that post-connect failures are raised on session(), subsequent requests obtain a fresh connection, and no unhandled task exceptions are logged. - Full test suite passing (278 passed).
brianstrauch
left a comment
Member
There was a problem hiding this comment.
The implementation appears sound, but the regression test falsely passes when unhandled task exceptions are reintroduced, confirmed through mutation testing. Full-suite execution was blocked by a locked dependency download failure.
… clear traceback references
brianstrauch
enabled auto-merge (squash)
November 18, 2026 16:36
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.
Fixes #572
Root cause
When an MCP connection fails after establishing a session,
_ConnectionRecord._run()caught the exception and re-raised it becauseself._ready.done()was true. Becauseself._owneris a background task not awaited outsideaclose(), re-raising caused an unhandled task exception (Task exception was never retrieved). Furthermore, the failure was lost from the connection record, causing subsequent calls tosession()to return a stale session instead of raising the error.Fix
self._failureto_ConnectionRecord._run(), store the error inself._failure, cancel any active idle timer handle, and do not re-raise standard exceptions into the un-awaited owner task._ConnectionRecord.session(), checkself._failureand raise it if set.CancelledError,SystemExit, etc.) continue to propagate.Tests
test_mcp_failure_after_connect_reported_and_creates_fresh_connectionverifying that post-connect failures are raised onsession(), subsequent requests obtain a fresh connection, and no unhandled task exceptions are logged.