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

Signed-off-by: Kartik Angiras <angiraskartik@gmail.com>
This commit is contained in:
kartik
2026-02-28 23:03:08 +05:30
committed by GitHub
parent 6c65a2d813
commit b2214a6676
5 changed files with 39 additions and 2 deletions

View File

@@ -129,6 +129,7 @@ describe('GeminiAgent', () => {
mockConfig = {
refreshAuth: vi.fn(),
initialize: vi.fn(),
waitForMcpInit: vi.fn(),
getFileSystemService: vi.fn(),
setFileSystemService: vi.fn(),
getContentGeneratorConfig: vi.fn(),
@@ -486,6 +487,7 @@ describe('Session', () => {
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
setApprovalMode: vi.fn(),
isPlanEnabled: vi.fn().mockReturnValue(false),
waitForMcpInit: vi.fn(),
} as unknown as Mocked<Config>;
mockConnection = {
sessionUpdate: vi.fn(),
@@ -500,6 +502,28 @@ describe('Session', () => {
vi.clearAllMocks();
});
it('should await MCP initialization before processing a prompt', async () => {
const stream = createMockStream([
{
type: StreamEventType.CHUNK,
value: { candidates: [{ content: { parts: [{ text: 'Hi' }] } }] },
},
]);
mockChat.sendMessageStream.mockResolvedValue(stream);
await session.prompt({
sessionId: 'session-1',
prompt: [{ type: 'text', text: 'test' }],
});
expect(mockConfig.waitForMcpInit).toHaveBeenCalledOnce();
const waitOrder = (mockConfig.waitForMcpInit as Mock).mock
.invocationCallOrder[0];
const sendOrder = (mockChat.sendMessageStream as Mock).mock
.invocationCallOrder[0];
expect(waitOrder).toBeLessThan(sendOrder);
});
it('should handle prompt with text response', async () => {
const stream = createMockStream([
{

View File

@@ -521,6 +521,8 @@ export class Session {
const pendingSend = new AbortController();
this.pendingPrompt = pendingSend;
await this.config.waitForMcpInit();
const promptId = Math.random().toString(16).slice(2);
const chat = this.chat;