Skip to content

fix: acp/zed race condition between MCP initialisation and prompt#20205

Merged
scidomino merged 4 commits intogoogle-gemini:mainfrom
kartikangiras:acpzed
Feb 28, 2026
Merged

fix: acp/zed race condition between MCP initialisation and prompt#20205
scidomino merged 4 commits intogoogle-gemini:mainfrom
kartikangiras:acpzed

Conversation

@kartikangiras
Copy link
Contributor

Summary

Fix a race condition in ACP/Zed mode where GeminiAgent.prompt could be handled before MCP server connections had finished initialising, causing the model to produce inconsistent responses.

Details

Config.initialize() intentionally starts MCP server connections in the background so the interactive CLI prompt appears quickly.

Two code paths violated this contract:

config.ts set interactive: true without experimentalZedIntegration: true, so MCP always ran in the background and was never awaited — even though the a2a-server is not a terminal and has no reason to skip waiting.

zedIntegration.ts had no guard to wait for MCP to be ready before invoking the model.

Related Issues

fixes #18893

How to Validate

  • Configure one or more MCP servers in ~/.gemini/settings.json.
  • Start the CLI in ACP mode: [gemini --experimental-acp].
  • Send a prompt immediately after session initialisation (before MCP would have had time to connect in the old code).
  • Verify the model consistently has access to the configured MCP tools on the very first response.
  • Run the unit tests: npx vitest run [zedIntegration.test.ts] packages/a2a-server/src/config/config.test.ts

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

Signed-off-by: Kartik Angiras <angiraskartik@gmail.com>
@kartikangiras kartikangiras requested review from a team as code owners February 24, 2026 18:42
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kartikangiras, 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 resolves a critical race condition in the ACP/Zed mode that caused inconsistent model responses due to premature handling of prompts before MCP server connections were fully initialized. The changes ensure that the system reliably waits for MCP initialization, providing a more stable and consistent user experience. Additionally, unit tests were added to validate the fix.

Highlights

  • Race Condition Fix: Addressed a race condition in ACP/Zed mode where GeminiAgent.prompt could be handled before MCP server connections were fully initialized, leading to inconsistent model responses.
  • MCP Initialization Handling: Ensured that the system waits for MCP to be ready before invoking the model, preventing issues related to uninitialized MCP server connections.
  • Configuration Updates: Modified config.ts to properly await MCP initialization, especially in non-interactive or Zed integration scenarios.
  • Testing Improvements: Added a unit test to verify that MCP initialization is awaited before processing a prompt in zedIntegration.test.ts.
Changelog
  • packages/a2a-server/src/config/config.ts
    • Ensured MCP initialization is awaited before proceeding with configuration loading.
    • Added waitForMcpInit to Config class.
  • packages/cli/src/zed-integration/zedIntegration.ts
    • Modified Session class to await MCP initialization before processing prompts.
  • packages/core/src/config/config.ts
    • Added a promise to track MCP initialization status.
    • Added waitForMcpInit method to await MCP initialization.
Activity
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize 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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a race condition where prompts could be handled before MCP server initialization was complete. This is fixed by introducing a mechanism to await MCP initialization within the Config class. This mechanism is then used in the a2a-server and Zed integration code paths to ensure MCP servers are ready before processing prompts. The changes include corresponding updates to tests to validate the new behavior.

@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Feb 24, 2026
}
});

this.mcpInitializationPromise = mcpInitialization;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the mcpInitialization variable and just immediately assign it to this.mcpInitializationPromise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i have assigned it to the this.mcpInitializationPromise

@scidomino
Copy link
Collaborator

please revert the changes to package-lock.json.

Signed-off-by: Kartik Angiras <angiraskartik@gmail.com>
@kartikangiras
Copy link
Contributor Author

@scidomino i have reverted the changes to package-lock.json.

@scidomino scidomino enabled auto-merge February 28, 2026 17:20
@scidomino scidomino added this pull request to the merge queue Feb 28, 2026
Merged via the queue into google-gemini:main with commit b2214a6 Feb 28, 2026
27 checks passed
@kartikangiras kartikangiras deleted the acpzed branch February 28, 2026 17:44
BryanBradfo pushed a commit to BryanBradfo/gemini-cli that referenced this pull request Mar 5, 2026
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Acp/ZedIntegration Race between mcp initialization and first prompt

2 participants