Skip to content

fix(google_genai): cancelling one MCP caller no longer cancels the others - #582

Merged
brianstrauch merged 1 commit into
temporalio:mainfrom
pcbeingused333:fix/google-genai-mcp-cancel-shared-wait
Nov 16, 2026
Merged

brianstrauch merged 1 commit into
temporalio:mainfrom
pcbeingused333:fix/google-genai-mcp-cancel-shared-wait

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Fixes #571

Cause. Activities that open the same MCP server at the same time share one _ConnectionRecord and wait on its _ready future. session() awaited that future directly. Cancelling one caller also cancels the future, so every other caller waiting on it receives CancelledError, and the connect itself is cancelled.

Fix. session() now waits with asyncio.shield(self._ready). The cancelled caller still stops, and get_connection still releases that caller's in-flight hold. The shared future, the owner task that is opening the session, and the other callers continue. Those callers receive the session once the factory finishes.

Test. test_cancelling_one_mcp_caller_leaves_the_other_waiting pauses the session factory on an event, starts two get_connection callers, cancels the first, then releases the factory. Against the current main implementation the shared future is cancelled and the test fails. With this change the second caller receives the session. The surrounding MCP unit tests in the same file also pass.

This change was prepared with the help of an AI coding assistant.

…hers

session() awaited the shared connect future directly, so cancelling one
caller cancelled that future and every other caller waiting on it.
Shield the wait. Only the cancelled caller stops.
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 16, 2026 09:19

@brianstrauch brianstrauch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@brianstrauch
brianstrauch enabled auto-merge (squash) November 16, 2026 18:49
@brianstrauch
brianstrauch merged commit 799b7a3 into temporalio:main Nov 16, 2026
16 checks passed
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.

[Bug] google_genai: cancelling one MCP caller also cancels other callers

2 participants