A desktop coding agent with free access to frontier models.
TypeScript
fix: stream guard trimmed the completion marker before checking it
Samrat Talukdare4b796575e9d
diff --git a/apps/server/src/omnirush-gateway-broker.test.ts b/apps/server/src/omnirush-gateway-broker.test.tsindex 6b586027..57ebcaf2 100644--- a/apps/server/src/omnirush-gateway-broker.test.ts+++ b/apps/server/src/omnirush-gateway-broker.test.ts@@ -245,3 +245,28 @@ describe("upstream stream guard", () => {expect(await response.json()).toEqual({ output: [] });});});+++describe("upstream stream guard with realistic frame sizes", () => {+ test("recognises a completion frame larger than the rolling window delivered in one chunk", async () => {+ const created = 'event: response.created\ndata: {"type":"response.created","response":{"id":"resp_big"}}\n\n';+ const text = 'event: response.output_text.delta\ndata: {"type":"response.output_text.delta","delta":"Hi again! What would you like to work on?"}\n\n';+ // Real completed frames embed the whole response object; make this one ~12 KiB.+ const padding = JSON.stringify({ output: [{ type: "message", content: [{ type: "output_text", text: "x".repeat(12_000) }] }] });+ const completed = 'event: response.completed\ndata: {"type":"response.completed","response":' + padding + '}\n\n';+ const response = await sseBroker([created, text, completed]).handle(gatewayRequest({ model: "gpt-6-astra", input: "hi", stream: true }), "responses");+ const body = await readAll(response);+ expect(body).toBe(created + text + completed);+ expect(body).not.toContain("upstream_stream_interrupted");+ });++ test("recognises a completion marker split across chunk boundaries", async () => {+ const created = 'event: response.created\ndata: {"type":"response.created","response":{"id":"resp_split"}}\n\n';+ const completed = 'event: response.completed\ndata: {"type":"response.completed","response":{"id":"resp_split","status":"completed"}}\n\n';+ const cut = completed.indexOf("response.comp") + 8;+ const response = await sseBroker([created, completed.slice(0, cut), completed.slice(cut)]).handle(gatewayRequest({ model: "gpt-6-astra", input: "hi", stream: true }), "responses");+ const body = await readAll(response);+ expect(body).toBe(created + completed);+ expect(body).not.toContain("upstream_stream_interrupted");+ });+});diff --git a/apps/server/src/omnirush-gateway-broker.ts b/apps/server/src/omnirush-gateway-broker.tsindex fd4351dc..650f7c44 100644--- a/apps/server/src/omnirush-gateway-broker.ts+++ b/apps/server/src/omnirush-gateway-broker.ts@@ -68,8 +68,14 @@ export function guardEventStream(}const chunk = result.value;if (!terminal) {- tail = (tail + decoder.decode(chunk, { stream: true })).slice(-4096);- if (TERMINAL_EVENT_PATTERN.test(tail)) terminal = true;+ // Test the join of the previous tail and the whole new chunk BEFORE+ // trimming: the response.completed frame carries the full response+ // object (often well over 4 KiB), so trimming first would drop the+ // marker that sits at the start of that frame and every completed+ // stream would be reported as interrupted.+ const window = tail + decoder.decode(chunk, { stream: true });+ if (TERMINAL_EVENT_PATTERN.test(window)) terminal = true;+ tail = window.slice(-4096);}controller.enqueue(chunk);},