A desktop coding agent with free access to frontier models.
TypeScript
fix: chat titles kept when the engine stops reading
ogsamratce4752454e0f
diff --git a/apps/server/src/omnirush-gateway-broker.ts b/apps/server/src/omnirush-gateway-broker.tsindex a9e4cadc..35b000d2 100644--- a/apps/server/src/omnirush-gateway-broker.ts+++ b/apps/server/src/omnirush-gateway-broker.ts@@ -2320,14 +2320,25 @@ export class OmniRushGatewayBroker {this.onModelRequest?.(session, { schema: 1, kind: "title", route: path, model, status: response.status, request: parsed, text: replyText(reply, contentType), completed: completed && answerCompleted(reply.slice(-STRICT_TAIL_CHARS), contentType), ...(bytes >= MAX_TITLE_REPLY_BYTES ? { reply_truncated: true } : {}) });} catch { /* a listener never breaks the request */ }};- return stream.pipeThrough(new TransformStream<Uint8Array, Uint8Array>({- transform: (chunk, controller) => {- if (bytes < MAX_TITLE_REPLY_BYTES) { reply += decoder.decode(chunk, { stream: true }); bytes += chunk.byteLength; }- controller.enqueue(chunk);+ // Recorded once: at the end of the reply, or when the engine stops reading it (the 2.x engine cancels the+ // title stream once it has the title); the reply's own tail says whether the answer finished.+ let recorded = false;+ const once = (completed: boolean) => { if (!recorded) { recorded = true; record(completed); } };+ const reader = stream.getReader();+ return new ReadableStream<Uint8Array>({+ pull: async (controller) => {+ try {+ const { done, value } = await reader.read();+ if (done) { once(true); controller.close(); return; }+ if (bytes < MAX_TITLE_REPLY_BYTES) { reply += decoder.decode(value, { stream: true }); bytes += value.byteLength; }+ controller.enqueue(value);+ } catch (error) {+ once(false);+ controller.error(error);+ }},- // shortcut: a title the engine stops reading mid-stream is not recorded (no cancel hook in these types); add one if aborts show up.- flush: () => record(true),- }));+ cancel: (reason) => { once(true); return reader.cancel(reason); },+ });}/**diff --git a/apps/server/src/title-capture.test.ts b/apps/server/src/title-capture.test.tsindex 7e876428..21b6743e 100644--- a/apps/server/src/title-capture.test.ts+++ b/apps/server/src/title-capture.test.ts@@ -67,4 +67,22 @@ describe("title capture", () => {expect(records[0]![1].text).toBe("Half");expect(records[0]![1].completed).toBe(false);});++ test("a title the engine stops reading once it has it is still recorded", async () => {+ const records: Array<[string, Record<string, unknown>]> = [];+ const gateway = broker(records, TITLE_STREAM);+ const response = await gateway.handle(post({ "x-omnirush-title": "1" }), "responses");+ // The 2.x engine reads up to the completed answer and cancels the rest of the stream.+ const reader = response.body!.getReader();+ let seen = "";+ while (!seen.includes("response.completed")) {+ const { done, value } = await reader.read();+ if (done) break;+ seen += new TextDecoder().decode(value);+ }+ await reader.cancel();+ expect(records).toHaveLength(1);+ expect(records[0]![1].text).toBe("Tidy parser é \"q\"");+ expect(records[0]![1].completed).toBe(true);+ });});