A desktop coding agent with free access to frontier models.
TypeScript
fix: handoff confirms after the summary lands
ogsamrat8f27b738e662
diff --git a/apps/server/src/omnirush-gateway-broker.ts b/apps/server/src/omnirush-gateway-broker.tsindex 2c70d031..bc433d67 100644--- a/apps/server/src/omnirush-gateway-broker.ts+++ b/apps/server/src/omnirush-gateway-broker.ts@@ -1923,7 +1923,9 @@ export class OmniRushGatewayBroker {headers.set("Content-Type", request.headers.get("content-type") || "application/json");headers.set("Accept", request.headers.get("accept") || "application/json");headers.set("x-omnirush-client-request-id", requestId);- for (const name of ["x-omnirush-session-id", "x-omnirush-task-id", PARENT_SESSION_HEADER]) {+ // x-omnirush-context-wrap: the handoff plugin marks an accepted wrap's+ // compaction so the gateway can hold it as the wrap (and confirm it).+ for (const name of ["x-omnirush-session-id", "x-omnirush-task-id", PARENT_SESSION_HEADER, "x-omnirush-context-wrap"]) {const value = request.headers.get(name);if (value) headers.set(name, value);}diff --git a/apps/server/src/opencode-plugins/omnirush-budget-wrap.test.ts b/apps/server/src/opencode-plugins/omnirush-budget-wrap.test.tsindex 92939445..af74627f 100644--- a/apps/server/src/opencode-plugins/omnirush-budget-wrap.test.ts+++ b/apps/server/src/opencode-plugins/omnirush-budget-wrap.test.ts@@ -4,7 +4,7 @@ import { createHash } from "node:crypto";import { readFileSync } from "node:fs";import { join } from "node:path";-import { showWrapQuestion, startWrapNow, wrapFinished } from "./budget-wrap-rules";+import { showWrapQuestion, startWrapNow, wrapFinished } from "./budget-wrap-rules.js";import { OmniRushBudgetWrap } from "./omnirush-budget-wrap.js";const originalFetch = globalThis.fetch;@@ -13,6 +13,7 @@ const originalToken = process.env.OMNIRUSH_SERVER_TOKEN;const gatewayHeaders = new Map<string, Record<string, string>>();beforeAll(() => {+ process.env.OMNIRUSH_WRAP_IDLE_SETTLE_MS = "0";process.env.OMNIRUSH_SERVER_URL = "http://localhost:3579";process.env.OMNIRUSH_SERVER_TOKEN = "local-token";globalThis.fetch = Object.assign(async (input: Parameters<typeof fetch>[0], init?: RequestInit) => {@@ -249,6 +250,31 @@ describe("account budget wrap plugin: retry and busy", () => {});});+describe("account budget wrap plugin: queued turn", () => {+ test("a turn queued right after idle never sees the question", async () => {+ process.env.OMNIRUSH_WRAP_IDLE_SETTLE_MS = "60";+ const controls: string[] = [];+ const hooks = await OmniRushBudgetWrap({+ serverUrl: "http://127.0.0.1:4096",+ fetch: async (input, init) => {+ controls.push(operation(init));+ return Response.json({ ok: true, result: { choice: "pending" } });+ },+ });+ try {+ await modelRequest(hooks, "ses_flash", { "x-omnirush-wrap-required": "1", "x-omnirush-wrap-offer-id": "allowance-flash" });+ await hooks.event!({ event: { type: "session.idle", properties: { sessionID: "ses_flash" } } });+ await Bun.sleep(10);+ await hooks.event!({ event: { type: "session.status", properties: { sessionID: "ses_flash", status: { type: "busy" } } } });+ await Bun.sleep(120);+ expect(controls).not.toContain("offer");+ } finally {+ process.env.OMNIRUSH_WRAP_IDLE_SETTLE_MS = "0";+ await hooks.dispose!();+ }+ });+});+describe("handoff offer rules (shared with the CLI)", () => {test("CLI/desktop parity: budget-wrap-rules.ts matches PARITY.sha256", () => {const rows = readFileSync(join(import.meta.dir, "PARITY.sha256"), "utf8").split("\n").filter((line) => line && !line.startsWith("#"));diff --git a/apps/server/src/opencode-plugins/omnirush-budget-wrap.ts b/apps/server/src/opencode-plugins/omnirush-budget-wrap.tsindex bbd241b0..a0f5456e 100644--- a/apps/server/src/opencode-plugins/omnirush-budget-wrap.ts+++ b/apps/server/src/opencode-plugins/omnirush-budget-wrap.ts@@ -13,7 +13,7 @@* only while the session is idle, once per offer, and a failed wrap turns* into a notice with a retry action instead of the question again.*/-import { replacesWrapOffer, startWrapNow, wrapFinished } from "./budget-wrap-rules";+import { replacesWrapOffer, startWrapNow, wrapFinished } from "./budget-wrap-rules.js";const REQUIRED_HEADER = "x-omnirush-wrap-required";const WRAP_UP_HEADER = "x-omnirush-wrap-up";@@ -23,6 +23,8 @@ type ModelRef = { providerID: string; modelID: string };type Offer = { id: string; scopes: string; watching: boolean; inFlight: boolean; approved: boolean; backendWrapped: boolean; compacted: boolean; failedAt?: number };/** How long a failed wrap's Retry stays available (the window's notice). */const RETRY_WINDOW_MS = 30_000;+/** How long an idle session waits before the question shows. */+const idleSettleMs = () => Number(process.env.OMNIRUSH_WRAP_IDLE_SETTLE_MS ?? 600);const pending = new Map<string, Offer>();/** Sessions with a turn running (`session.status` busy until idle). */const busy = new Set<string>();@@ -171,6 +173,10 @@ export const OmniRushBudgetWrap = async (input: {body: JSON.stringify({ providerID: model.providerID, modelID: model.modelID }),},);+ // The engine's `session.compacted` event may land just after summarize answers.+ for (let waited = 0; response.ok && !entry.compacted && waited < 5_000; waited += 100) {+ await new Promise<void>((resolve) => setTimeout(resolve, 100));+ }if (!wrapFinished({ ok: response.ok, compacted: entry.compacted })) {throw new Error("the wrap did not finish (" + response.status + ")");}@@ -199,6 +205,9 @@ export const OmniRushBudgetWrap = async (input: {const entry = pending.get(sessionID);if (!entry || entry.watching || entry.inFlight) return;entry.watching = true;+ // A prompt queued behind the turn starts right after its idle: give its+ // busy event a moment, so the question never flashes over it.+ await new Promise<void>((resolve) => setTimeout(resolve, idleSettleMs()));// Only while the session is idle: a new turn hides the question and// ends this loop; the next idle starts it again.while (!disposed && pending.get(sessionID) === entry && !entry.inFlight && !busy.has(sessionID)) {