fix: close Workbench SSE inspection cleanly

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
root
2026-07-18 06:07:10 +02:00
parent 2bc5fc653a
commit affd168f92
+5 -2
View File
@@ -60,7 +60,7 @@ async function inspectEvents(parsed: Parsed, env: Record<string, string | undefi
if (!response.ok || !response.body) throw codedError("workbench_sse_open_failed", `Workbench SSE returned HTTP ${response.status}`);
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
readStream: while (true) {
const item = await reader.read();
if (item.done) break;
buffer += decoder.decode(item.value, { stream: true });
@@ -70,7 +70,10 @@ async function inspectEvents(parsed: Parsed, env: Record<string, string | undefi
buffer = buffer.slice(boundary + 2);
const frame = parseSseBlock(block);
if (frame) frames.push(frame);
if (frames.filter((entry) => entry.name === "hwlab.event.v1").length >= minEvents) controller.abort();
if (frames.filter((entry) => entry.name === "hwlab.event.v1").length >= minEvents) {
await reader.cancel();
break readStream;
}
boundary = buffer.indexOf("\n\n");
}
}