diff --git a/src/rovo-dev/rovoDevChatProvider.ts b/src/rovo-dev/rovoDevChatProvider.ts index 33132bcb1..768741515 100644 --- a/src/rovo-dev/rovoDevChatProvider.ts +++ b/src/rovo-dev/rovoDevChatProvider.ts @@ -226,6 +226,12 @@ export class RovoDevChatProvider { let isFirstByte = true; let isFirstMessage = true; + // Queue posts to the webview to avoid backpressure blocking the stream reader + let postQueue: Promise = Promise.resolve(); + const enqueuePost = (p: Thenable) => { + postQueue = postQueue.then(() => p).catch(() => {}); + }; + while (true) { const { done, value } = await reader.read(); @@ -241,7 +247,7 @@ export class RovoDevChatProvider { } for (const msg of parser.flush()) { - await this.processRovoDevResponse(sourceApi, msg); + enqueuePost(this.processRovoDevResponse(sourceApi, msg)); } break; } @@ -253,9 +259,13 @@ export class RovoDevChatProvider { isFirstMessage = false; } - await this.processRovoDevResponse(sourceApi, msg); + // Do not await here; enqueue to prevent blocking the reader + enqueuePost(this.processRovoDevResponse(sourceApi, msg)); } } + + // Ensure all queued posts are delivered before returning + await postQueue; } private processRovoDevResponse(sourceApi: StreamingApi, response: RovoDevResponse): Thenable {