Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/rovo-dev/rovoDevChatProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> = Promise.resolve();
const enqueuePost = (p: Thenable<any>) => {
postQueue = postQueue.then(() => p).catch(() => {});
};

while (true) {
const { done, value } = await reader.read();

Expand All @@ -241,7 +247,7 @@ export class RovoDevChatProvider {
}

for (const msg of parser.flush()) {
await this.processRovoDevResponse(sourceApi, msg);
enqueuePost(this.processRovoDevResponse(sourceApi, msg));
}
break;
}
Expand All @@ -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<boolean> {
Expand Down
Loading