fix(a2a-server): Resolve race condition in tool completion waiting#26568
fix(a2a-server): Resolve race condition in tool completion waiting#26568
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical race condition in the @google/gemini-cli-a2a-server package where tool completion promises were being overwritten before resolution. By implementing a state-tracking mechanism, the system now correctly manages sequential tool confirmations, ensuring that the task completion promise remains stable until all pending operations are finished. This improves the reliability of the agent during high-concurrency tasks. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a race condition in the Task class where the toolCompletionPromise could be overwritten before it had a chance to resolve. The fix introduces an isCompletionPromiseResolved flag to guard the _resetToolCompletionPromise method. Additionally, new tests were added to verify this fix and cover multi-turn tool resolution and subagent progress events. Feedback indicates that the new tests for acceptUserMessage are currently ineffective because they await the asynchronous generator without calling .next(), meaning the underlying logic is not being executed.
|
Size Change: -4 B (0%) Total Size: 34 MB
ℹ️ View Unchanged
|
|
/patch |
|
🚀 [Step 1/4] Patch workflow(s) waiting for approval! 📋 Details:
⏳ Status: The patch creation workflow has been triggered and is waiting for deployment approval. Please visit the specific workflow links below and approve the runs. 🔗 Track Progress: |
|
🚀 [Step 2/4] Patch PR Created! 📋 Patch Details:
📝 Next Steps:
🔗 Track Progress: |
|
🚀 [Step 2/4] Patch PR Created! 📋 Patch Details:
📝 Next Steps:
🔗 Track Progress: |
|
🚀 [Step 3/4] Patch Release Waiting for Approval! 📋 Release Details:
⏳ Status: The patch release has been triggered and is waiting for deployment approval. Please visit the specific workflow run link below and approve the deployment. You'll receive another update when it completes. 🔗 Track Progress: |
|
🚀 [Step 3/4] Patch Release Waiting for Approval! 📋 Release Details:
⏳ Status: The patch release has been triggered and is waiting for deployment approval. Please visit the specific workflow run link below and approve the deployment. You'll receive another update when it completes. 🔗 Track Progress: |
|
❌ [Step 4/4] Patch Release Failed! 📋 Details:
🔍 Next Steps:
🔗 Troubleshooting: |
|
✅ [Step 4/4] Patch Release Complete! 📦 Release Details:
🎉 Status: Your patch has been successfully released and published to npm! 📝 What's Available:
🔗 Links: |
Summary
This PR fixes a race condition in the @google/gemini-cli-a2a-server package where Task.waitForPendingTools() could hang indefinitely. The issue was caused by multiple tool confirmations being processed sequentially, which reset the tool completion promise while it was still being awaited. We now track whether the promise has been settled to prevent premature resets.
Description
How to Validate
To verify this fix, you need to link the local development version of the a2a-server and run a high-concurrency tool task to trigger the potential race condition.
First, register the local package and link it into your testing environment:
Bash
In the repository root
cd packages/a2a-server
yarn link
Navigate to the directory where you are running the agent/IDE
cd /path/to/your/testing/directory
yarn link "@google/gemini-cli-a2a-server"
2. Run the reproduction task
Run the agent and provide a prompt that forces the scheduler to handle multiple tool calls (e.g., file system reads) in a single turn.
Reproduction Prompt:
"Read all the Python files in this project and output a brief summary of what each file does."
With Fix: The agent should successfully parallelize the file reads, receive all tool outputs, and provide the summary without hanging.
Before Fix: The agent would often "hang" indefinitely after the first few tool confirmations because the toolCompletionPromise was being overwritten before it could resolve.
Pre-Merge Checklist
Conducted bug bash with IDE on this change