A desktop coding agent with free access to frontier models.
TypeScript
fix: a retried turn confirms its chat again
ogsamrated87d2ba87c5
diff --git a/apps/server/src/model-modes/PARITY.sha256 b/apps/server/src/model-modes/PARITY.sha256index 859b8874..b8386d41 100644--- a/apps/server/src/model-modes/PARITY.sha256+++ b/apps/server/src/model-modes/PARITY.sha256@@ -2,5 +2,5 @@# A change to one must be ported to the other and this list updated in both.609bbc9cb508b4f79295e0b2f1f4707bd1facbee83835d5db7eac02fa088f43b model-modes.mjsef8a96d1e71ea3f5f3ab7a96796d042c009d90cc2896e7132b8dfc4486540699 model-modes.d.mts-7aa8c758c3d9a148911bda110d90f4542a67be9d996718228feb788680100f67 strict-sessions.mjs-81049cae72b0dfe53f769835acd649b50aff1737c8c3e40f1647328a09f9ef05 strict-sessions.d.mts+41d945bb9aab9be941dd1840a61384982a37b986e7d2e7306c57d32ffc2b6e2c strict-sessions.mjs+7c98a499302e9d32799998f6960f0f5f3b4ff47b85fe24c5cc54bbfa084df54d strict-sessions.d.mtsdiff --git a/apps/server/src/model-modes/model-modes.test.ts b/apps/server/src/model-modes/model-modes.test.tsindex 2e9dd0af..86273ce6 100644--- a/apps/server/src/model-modes/model-modes.test.ts+++ b/apps/server/src/model-modes/model-modes.test.ts@@ -377,4 +377,47 @@ describe("model modes", () => {expect(still.headers.get("x-should-retry")).not.toBe("false");expect(hits).toBe(4);});++ test("broker: under enforce a failed first bind is bound again on the retry, before anything goes upstream", async () => {+ const dir = mkdtempSync(path.join(tmpdir(), "strict-rebind-"));+ const order: string[] = [];+ let bindFails = 1;+ const b = new OmniRushGatewayBroker({+ credentials: { gatewayUrl: "https://gateway.example/omnirush/v1", accessToken: "access-token", refreshToken: "refresh-token" },+ engineToken: "local-engine-token",+ strictStateFile: path.join(dir, "strict-sessions.json"),+ bindTimeoutMs: 100,+ chatPin: () => ({ box: false, revision: null, capturePolicy: "legacy" }),+ fetch: async (input) => {+ const url = new URL(String(input));+ if (url.pathname === "/omnirush/collect/capabilities") return Response.json({ schema_versions: [1, 2, 3], strict_sessions: { mode: "enforce", bind: true, path: "/omnirush/device/session-binding", header: "X-OmniRush-Strict-Session" } });+ if (url.pathname === "/omnirush/device/session-binding") {+ if (bindFails > 0) { bindFails -= 1; order.push("bind 503"); return Response.json({ detail: "unavailable" }, { status: 503 }); }+ order.push("bind 200");+ return Response.json({ binding: { model: "gpt-6-astra", mode: "native", capture_policy: "legacy", verified: true }, enforcement: "enforce", kept: [] });+ }+ if (gatewayRefuses > 0) {+ gatewayRefuses -= 1;+ order.push("upstream 503");+ return Response.json({ detail: "strict_session_unavailable", error: { type: "server_error", code: "strict_session_unavailable", message: "Try again.", omnirush: { code: "strict_session_unavailable", retry: true } } }, { status: 503, headers: { "x-should-retry": "true", "retry-after": "0" } });+ }+ order.push("upstream");+ return Response.json({ output: [] });+ },+ });+ let gatewayRefuses = 0;+ // The kept enforce (no capabilities answer in this process yet) holds the first request.+ writeFileSync(path.join(dir, "strict-sessions.json"), JSON.stringify({ "https://gateway.example": { mode: "enforce", path: "/omnirush/device/session-binding", header: "x-omnirush-strict-session" } }));+ const post = (id = "ses_rebind") => b.handle(request({ model: "gpt-6-astra", tools: [{ type: "function", name: "bash" }] }, { "x-omnirush-session-id": id }), "responses");+ expect((await post()).status).toBe(503);+ expect((await post()).status).toBe(200);+ expect(order).toEqual(["bind 503", "bind 200", "upstream"]);+ // The gateway cannot confirm a bound chat: it is bound again before the same request goes up.+ await b.sessionUploadCapabilities();+ order.length = 0;+ gatewayRefuses = 1;+ expect((await post("ses_second")).status).toBe(200);+ expect(order).toEqual(["bind 200", "upstream 503", "bind 200", "upstream"]);+ rmSync(dir, { recursive: true, force: true });+ });});diff --git a/apps/server/src/model-modes/strict-sessions.d.mts b/apps/server/src/model-modes/strict-sessions.d.mtsindex 6fdc6bac..f6349777 100644--- a/apps/server/src/model-modes/strict-sessions.d.mts+++ b/apps/server/src/model-modes/strict-sessions.d.mts@@ -25,4 +25,4 @@ export type BindPost = (path: string, body: Record<string, unknown>, signal: Aboexport function strictSessions(capabilities: unknown): StrictSessions | null;export function bindingConflictMessage(binding: unknown, model: string): string;export function modelUsedMessage(modelsUsed: unknown, model: string): string;-export function sessionBinder(post: BindPost, options?: { timeoutMs?: number }): (chat: BindChat) => Promise<BindOutcome>;+export function sessionBinder(post: BindPost, options?: { timeoutMs?: number }): ((chat: BindChat) => Promise<BindOutcome>) & { forget(id: string): void };diff --git a/apps/server/src/model-modes/strict-sessions.mjs b/apps/server/src/model-modes/strict-sessions.mjsindex 40ff264f..92b8c414 100644--- a/apps/server/src/model-modes/strict-sessions.mjs+++ b/apps/server/src/model-modes/strict-sessions.mjs@@ -86,6 +86,7 @@ function detailOf(answer) {* the root chat's own pin, for binding it first). A session bound (or one the* server will not bind: a Claude chat, a refused model) is not asked again in* this process; the cache is keyed on the client's own id, never the echo.+ * bind.forget(id) drops a session from that cache, so its next request binds again.*/export function sessionBinder(post, { timeoutMs = BIND_TIMEOUT_MS } = {}) {const settled = new Set();@@ -104,7 +105,7 @@ export function sessionBinder(post, { timeoutMs = BIND_TIMEOUT_MS } = {}) {...(pin.revision ? { revision: pin.revision } : {}),...(capturePolicy ? { capture_policy: capturePolicy } : {}),});- return async function bind(chat) {+ async function bind(chat) {if (!chat || !chat.path || !chat.sessionId || !chat.model || settled.has(chat.sessionId)) return { ok: true };const unconfirmed = { refused: { code: SESSION_BIND_UNCONFIRMED, message: UNCONFIRMED_MESSAGE, retry: true } };if (chat.enforce && !chat.capturePolicy) return unconfirmed;@@ -138,5 +139,8 @@ export function sessionBinder(post, { timeoutMs = BIND_TIMEOUT_MS } = {}) {}// No answer (network, 5xx, timeout, another status): enforce holds the request, observe lets it go.return chat.enforce ? unconfirmed : { ok: true };- };+ }+ // A session bound before is asked again (the gateway said it could not confirm the chat).+ bind.forget = (id) => { settled.delete(id); };+ return bind;}diff --git a/apps/server/src/omnirush-gateway-broker.ts b/apps/server/src/omnirush-gateway-broker.tsindex 2819ab8a..c685ea92 100644--- a/apps/server/src/omnirush-gateway-broker.ts+++ b/apps/server/src/omnirush-gateway-broker.ts@@ -1294,6 +1294,8 @@ export class OmniRushGatewayBroker {private readonly chatPin?: BrokerOptions["chatPin"];/** The strict sessions ({ path, header }) of the last capabilities answer (null: off, or an older server). */private strictBind: StrictSessions | null = null;+ /** The server whose capabilities answer `strictBind` is (null: none in this process yet). */+ private strictOrigin: string | null = null;private readonly strictStateFile?: string;private readonly onCapturePolicy?: BrokerOptions["onCapturePolicy"];private readonly onBinding?: BrokerOptions["onBinding"];@@ -1366,7 +1368,7 @@ export class OmniRushGatewayBroker {this.onCapturePolicy = options.onCapturePolicy;this.onBinding = options.onBinding;this.strictStateFile = options.strictStateFile;- if (this.state) this.strictBind = this.savedStrict()[originOf(this.state.gatewayUrl)] ?? null;+this.reasoningSummaryFor = options.reasoningSummaryFor ?? defaultReasoningSummaryFor;}@@ -2058,8 +2060,8 @@ export class OmniRushGatewayBroker {// One model per chat: a main chat's agent request on another model than its first is refused here.const fixed = this.fixedModelRefusal(request, path, body);if (fixed) return fixed;- // The last capabilities answer's switch: a model request never waits for one.- const strict = this.state ? this.strictBind : null;+ // The last capabilities answer's switch (this server's, kept on disk until it answers): a model request never waits for one.+ const strict = this.currentStrict();const unbound = strict ? await this.strictBindRefusal(strict, request, path, body) : null;if (unbound) return unbound;const forwardedBody = path === "responses" && body !== undefined@@ -2074,7 +2076,16 @@ export class OmniRushGatewayBroker {if (!this.state) break;try {const response = await this.forward(request, path, forwardedBody, attempt === 0 ? accessToken : this.state.accessToken, requestId, strict?.header ?? null);- return await this.strictRetry(response, () => this.forward(request, path, forwardedBody, this.state?.accessToken, requestId, strict?.header ?? null), request.signal);+ return await this.strictRetry(response, async () => {+ // The gateway could not confirm the chat: it is bound again before the same request goes up.+ const session = request.headers.get("x-omnirush-session-id");+ if (strict && session) {+ this.bindSession.forget(session);+ const refused = await this.strictBindRefusal(strict, request, path, body);+ if (refused) return refused;+ }+ return this.forward(request, path, forwardedBody, this.state?.accessToken, requestId, strict?.header ?? null);+ }, request.signal);} catch (error) {if (request.signal.aborted) throw error;failure = fetchFailure(error);@@ -2243,6 +2254,14 @@ export class OmniRushGatewayBroker {return response;}+ /** The strict sessions in force for the current server: its last answer in this process, else the one kept on disk. */+ private currentStrict(): StrictSessions | null {+ if (!this.state) return null;+ const origin = originOf(this.state.gatewayUrl);+ if (this.strictOrigin === origin) return this.strictBind;+ return this.savedStrict()[origin] ?? null;+ }+private savedStrict(): Record<string, StrictSessions | null> {if (!this.strictStateFile) return {};try {@@ -2257,6 +2276,7 @@ export class OmniRushGatewayBroker {/** A capabilities answer's strict sessions: in force now, and kept on disk for this server. */private rememberStrict(gatewayUrl: string, capabilities: TraceCapabilities): void {this.strictBind = strictSessions(capabilities);+ this.strictOrigin = originOf(gatewayUrl);if (!this.strictStateFile) return;try {mkdirSync(dirname(this.strictStateFile), { recursive: true, mode: 0o700 });