Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: ask once for a session handoff

Samrat Talukdar3cf853c35ff5
diff --git a/apps/app/src/react-app/shell/budget-wrap-consent.tsx b/apps/app/src/react-app/shell/budget-wrap-consent.tsx
index 9557ae8f..e6ab0510 100644
--- a/apps/app/src/react-app/shell/budget-wrap-consent.tsx
+++ b/apps/app/src/react-app/shell/budget-wrap-consent.tsx
@@ -7,12 +7,18 @@ import { toast } from "@/components/ui/sonner";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { useControlAction, type OmniRushControlAction } from "./control/control-provider";
-type Choice = "pending" | "accept" | "decline" | "done";
-type Offer = { sessionID: string; offerID: string; scopes: string; choice: Choice; error?: string };
+// The same rules as the engine plugin and the CLI (apps/server/src/
+// opencode-plugins/budget-wrap-rules.ts): one question per session and
+// offer, only while the session is idle; every answer is final, and a failed
+// wrap becomes a notice with a retry action, never the question again.
+type Choice = "pending" | "accept" | "decline" | "done" | "failed";
+const FINAL: readonly Choice[] = ["decline", "done", "failed"];
+type Offer = { sessionID: string; offerID: string; scopes: string; choice: Choice; held?: boolean };
type WrapStore = {
offers: Offer[];
offer: (sessionID: string, offerID: string, scopes: string) => Choice;
- choose: (sessionID: string, offerID: string, choice: Choice, error?: string) => void;
+ hold: (sessionID: string, offerID: string) => void;
+ choose: (sessionID: string, offerID: string, choice: Choice) => void;
clear: (sessionID: string, offerID: string) => void;
};
@@ -20,26 +26,37 @@ const useWrapStore = create<WrapStore>()(persist((set, get) => ({
offers: [],
offer: (sessionID, offerID, scopes) => {
const existing = get().offers.find((entry) => entry.sessionID === sessionID && entry.offerID === offerID);
- if (existing) return existing.choice;
+ if (existing) {
+ // The session is idle again: an unanswered question may show.
+ if (existing.held) set((state) => ({ offers: state.offers.map((entry) => entry === existing ? { ...entry, held: false } : entry) }));
+ return existing.choice;
+ }
set((state) => ({ offers: [
{ sessionID, offerID, scopes, choice: "pending" },
...state.offers.filter((entry) => entry.sessionID !== sessionID),
] }));
return "pending";
},
- choose: (sessionID, offerID, choice, error) => set((state) => ({
+ hold: (sessionID, offerID) => set((state) => ({
offers: state.offers.map((entry) => entry.sessionID === sessionID && entry.offerID === offerID
- ? { ...entry, choice, error } : entry),
+ ? { ...entry, held: true } : entry),
})),
+ choose: (sessionID, offerID, choice) => set((state) => ({
+ offers: state.offers.map((entry) => entry.sessionID === sessionID && entry.offerID === offerID
+ ? { ...entry, choice } : entry),
+ })),
+ // The gateway withdrew the offer. An answer is kept, so the same offer
+ // never asks again; only an unanswered question goes away.
clear: (sessionID, offerID) => set((state) => ({
- offers: state.offers.filter((entry) => entry.sessionID !== sessionID || entry.offerID !== offerID),
+ offers: state.offers.filter((entry) => entry.sessionID !== sessionID || entry.offerID !== offerID
+ || FINAL.includes(entry.choice)),
})),
}), {
name: "omnirush:budget-wrap-consent:v2",
storage: createJSONStorage(() => localStorage),
// Persist final choices, not a live popup: after a full app restart the
// engine must renew an offer before Accept can start a real compaction.
- partialize: (state) => ({ offers: state.offers.filter((entry) => entry.choice === "decline" || entry.choice === "done") }),
+ partialize: (state) => ({ offers: state.offers.filter((entry) => FINAL.includes(entry.choice)) }),
}));
function fields(args: unknown): { sessionID: string; offerID: string; scopes: string } | null {
@@ -52,10 +69,19 @@ function fields(args: unknown): { sessionID: string; offerID: string; scopes: st
return { sessionID, offerID, scopes: "scopes" in args && typeof args.scopes === "string" ? args.scopes : "" };
}
-/** The choice stays on screen, and in local storage, until the person answers. */
+function retryWrap(sessionID: string, offerID: string) {
+ const store = useWrapStore.getState();
+ const entry = store.offers.find((item) => item.sessionID === sessionID && item.offerID === offerID);
+ if (!entry || entry.choice !== "failed") return;
+ // The engine starts it once the session is idle.
+ store.choose(sessionID, offerID, "accept");
+ toast.info("Wrapping up", { description: "Saving a handoff for this session." });
+}
+
+/** The question is asked once per session and offer, only while the session is idle. */
export function BudgetWrapConsent() {
const offers = useWrapStore((state) => state.offers);
- const pending = offers.find((entry) => entry.choice === "pending");
+ const pending = offers.find((entry) => entry.choice === "pending" && !entry.held);
const updateAction = useMemo<OmniRushControlAction>(() => ({
id: "budget.wrap.update",
@@ -72,12 +98,19 @@ export function BudgetWrapConsent() {
const operation = "operation" in args ? args.operation : undefined;
const store = useWrapStore.getState();
if (operation === "offer") return { choice: store.offer(parsed.sessionID, parsed.offerID, parsed.scopes) };
- if (operation === "finish") {
+ if (operation === "hold") store.hold(parsed.sessionID, parsed.offerID);
+ else if (operation === "finish") {
store.choose(parsed.sessionID, parsed.offerID, "done");
toast.success("Wrap up complete", { description: "Your handoff is saved. You can keep working while tokens remain." });
} else if (operation === "fail") {
- store.choose(parsed.sessionID, parsed.offerID, "pending", "The wrap could not finish. Choose whether to retry.");
- toast.warning("Wrap up did not finish", { description: "Choose Wrap up again to retry, or keep working." });
+ // Final for this offer: a notice with a retry action, not the question again.
+ store.choose(parsed.sessionID, parsed.offerID, "failed");
+ const { sessionID, offerID } = parsed;
+ toast.warning("Wrap up did not finish", {
+ description: "Your session is unchanged. You can retry, or keep working.",
+ action: { label: "Retry", onClick: () => retryWrap(sessionID, offerID) },
+ duration: 30_000,
+ });
}
else if (operation === "clear") store.clear(parsed.sessionID, parsed.offerID);
else return { ok: false, error: "Unknown wrap operation" };
@@ -86,7 +119,10 @@ export function BudgetWrapConsent() {
}), []);
useControlAction(updateAction);
- return <Dialog open={Boolean(pending)} onOpenChange={() => undefined}>
+ // Closing the question (Esc, outside click) is "Keep working".
+ return <Dialog open={Boolean(pending)} onOpenChange={(open) => {
+ if (!open && pending) useWrapStore.getState().choose(pending.sessionID, pending.offerID, "decline");
+ }}>
<DialogContent showCloseButton={false} data-testid="budget-wrap-consent">
<DialogHeader>
<DialogTitle>Save a handoff for this session?</DialogTitle>
@@ -94,7 +130,6 @@ export function BudgetWrapConsent() {
Your {pending?.scopes.replace(",", " and ") || "token"} allowance is nearly used. A wrap saves a summary of this session so you can resume it later. You can keep working while tokens remain, whether you wrap or not.
</DialogDescription>
</DialogHeader>
- {pending?.error ? <p className="text-sm text-destructive">{pending.error}</p> : null}
<DialogFooter>
<Button variant="outline" data-testid="budget-wrap-decline" onClick={() => {
if (pending) useWrapStore.getState().choose(pending.sessionID, pending.offerID, "decline");
diff --git a/apps/server/src/opencode-plugins/PARITY.sha256 b/apps/server/src/opencode-plugins/PARITY.sha256
new file mode 100644
index 00000000..0bde0347
--- /dev/null
+++ b/apps/server/src/opencode-plugins/PARITY.sha256
@@ -0,0 +1,3 @@
+# Handoff offer rules: the same file in omnirush-cli (assets/extensions/omnirush/budget-wrap/) and omnirush-gui (apps/server/src/opencode-plugins/).
+# A change to one must be ported to the other and this list updated in both.
+afdcd2591be97d3aa45ea03c9a37e47a0861b09bb3f067d5f932b0492d2eea69 budget-wrap-rules.ts
diff --git a/apps/server/src/opencode-plugins/budget-wrap-rules.ts b/apps/server/src/opencode-plugins/budget-wrap-rules.ts
new file mode 100644
index 00000000..5fa34deb
--- /dev/null
+++ b/apps/server/src/opencode-plugins/budget-wrap-rules.ts
@@ -0,0 +1,63 @@
+/**
+ * Handoff (wrap) offer rules, shared by the desktop app and the CLI.
+ * The same file ships in omnirush-cli and omnirush-gui (PARITY.sha256).
+ *
+ * The gateway offers a wrap once the allowance nears its end
+ * (`x-omnirush-wrap-required`, keyed by `x-omnirush-wrap-offer-id`). These
+ * rules keep that offer to one question per session and offer:
+ * - it is asked only while the session is idle, never over a running turn;
+ * - any answer is final for that offer: "Keep working", closing the
+ * question, a finished wrap or a failed one;
+ * - a failed wrap becomes a quiet notice with a retry action, never the
+ * question again;
+ * - an accepted wrap waits for the session to be idle before it starts.
+ */
+
+export type WrapChoice = "pending" | "accept" | "decline" | "done" | "failed";
+
+/** Choices that end the question for this session and offer. */
+export const FINAL_WRAP_CHOICES: readonly WrapChoice[] = ["decline", "done", "failed"];
+
+export function isFinalWrapChoice(choice: string | undefined): boolean {
+ return FINAL_WRAP_CHOICES.includes(choice as WrapChoice);
+}
+
+/** Whether the question may be on screen now. */
+export function showWrapQuestion(input: { choice: string | undefined; busy: boolean }): boolean {
+ return input.choice === "pending" && !input.busy;
+}
+
+/** Whether an accepted wrap may start now (never over a running turn). */
+export function startWrapNow(input: { choice: string | undefined; busy: boolean; inFlight: boolean }): boolean {
+ return input.choice === "accept" && !input.busy && !input.inFlight;
+}
+
+/**
+ * Whether a wrap finished: the engine answered and reported the session
+ * compacted (it only does so after a summary without error). The gateway's
+ * own confirmation (`x-omnirush-wrap-up`) is not required: a wrap served
+ * from bonus tokens is just as complete.
+ */
+export function wrapFinished(input: { ok: boolean; compacted: boolean }): boolean {
+ return input.ok && input.compacted;
+}
+
+/** What an offer becomes after its wrap fails: final, retried only on request. */
+export const WRAP_FAILED_CHOICE: WrapChoice = "failed";
+
+/** Whether a new offer from the gateway replaces the remembered one. */
+export function replacesWrapOffer(previous: { offerID: string } | undefined, offerID: string): boolean {
+ return !previous || previous.offerID !== offerID;
+}
+
+export const WRAP_TEXT = {
+ title: "Save a handoff for this session?",
+ body: "A wrap saves a summary of this session so you can resume it later. You can keep working while tokens remain, whether you wrap or not.",
+ accept: "Wrap up",
+ decline: "Keep working",
+ started: "Saving a handoff for this session.",
+ finished: "Your handoff is saved. You can keep working while tokens remain.",
+ failedTitle: "Wrap up did not finish",
+ failedBody: "Your session is unchanged. You can retry, or keep working.",
+ retry: "Retry",
+} as const;
diff --git a/apps/server/src/opencode-plugins/omnirush-budget-wrap.test.ts b/apps/server/src/opencode-plugins/omnirush-budget-wrap.test.ts
index 87fc7765..b001cf4f 100644
--- a/apps/server/src/opencode-plugins/omnirush-budget-wrap.test.ts
+++ b/apps/server/src/opencode-plugins/omnirush-budget-wrap.test.ts
@@ -1,5 +1,10 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
+import { createHash } from "node:crypto";
+import { readFileSync } from "node:fs";
+import { join } from "node:path";
+
+import { showWrapQuestion, startWrapNow, wrapFinished } from "./budget-wrap-rules";
import { OmniRushBudgetWrap } from "./omnirush-budget-wrap.js";
const originalFetch = globalThis.fetch;
@@ -121,4 +126,114 @@ describe("account budget wrap plugin", () => {
expect(headers["x-omnirush-context-wrap"]).toBeUndefined();
} finally { await hooks.dispose!(); }
});
+ test("a wrap served from bonus tokens (no gateway confirmation) still finishes", async () => {
+ const controls: string[] = [];
+ let hooks: Hooks;
+ hooks = await OmniRushBudgetWrap({
+ serverUrl: "http://127.0.0.1:4096",
+ fetch: async (input, init) => {
+ const url = String(input);
+ if (url.includes("/experimental/ui-control/request")) {
+ const action = operation(init);
+ controls.push(action);
+ return Response.json({ ok: true, result: { choice: action === "offer" ? "accept" : "ok" } });
+ }
+ if (url.endsWith("/session/ses_pot/summarize")) {
+ await modelRequest(hooks, "ses_pot", {}, "compaction");
+ await hooks.event!({ event: { type: "session.compacted", properties: { sessionID: "ses_pot" } } });
+ return new Response("true", { status: 200 });
+ }
+ throw new Error("unexpected URL: " + url);
+ },
+ });
+ try {
+ await modelRequest(hooks, "ses_pot", { "x-omnirush-wrap-required": "1", "x-omnirush-wrap-offer-id": "allowance-pot" });
+ await hooks.event!({ event: { type: "session.idle", properties: { sessionID: "ses_pot" } } });
+ await Bun.sleep(30);
+ expect(controls).toContain("finish");
+ expect(controls).not.toContain("fail");
+ } finally { await hooks.dispose!(); }
+ });
+
+ test("a failed wrap is reported once and never compacts again by itself", async () => {
+ const controls: string[] = [];
+ let compactCalls = 0;
+ let choice = "accept";
+ const hooks = await OmniRushBudgetWrap({
+ serverUrl: "http://127.0.0.1:4096",
+ fetch: async (input, init) => {
+ const url = String(input);
+ if (url.includes("/experimental/ui-control/request")) {
+ const action = operation(init);
+ controls.push(action);
+ if (action === "fail") choice = "failed";
+ return Response.json({ ok: true, result: { choice: action === "offer" ? choice : "ok" } });
+ }
+ compactCalls += 1;
+ return new Response("{}", { status: 500 });
+ },
+ });
+ try {
+ await modelRequest(hooks, "ses_fail", { "x-omnirush-wrap-required": "1", "x-omnirush-wrap-offer-id": "allowance-fail" });
+ await hooks.event!({ event: { type: "session.idle", properties: { sessionID: "ses_fail" } } });
+ await Bun.sleep(50);
+ expect(compactCalls).toBe(1);
+ expect(controls.filter((item) => item === "fail")).toHaveLength(1);
+ await hooks.event!({ event: { type: "session.idle", properties: { sessionID: "ses_fail" } } });
+ await Bun.sleep(30);
+ expect(compactCalls).toBe(1);
+ } finally { await hooks.dispose!(); }
+ });
+
+ test("a running turn hides the question and an accepted wrap waits for idle", async () => {
+ const controls: string[] = [];
+ let compactCalls = 0;
+ let hooks: Hooks;
+ hooks = await OmniRushBudgetWrap({
+ serverUrl: "http://127.0.0.1:4096",
+ fetch: async (input, init) => {
+ const url = String(input);
+ if (url.includes("/experimental/ui-control/request")) {
+ const action = operation(init);
+ controls.push(action);
+ return Response.json({ ok: true, result: { choice: action === "offer" ? "accept" : "ok" } });
+ }
+ compactCalls += 1;
+ await hooks.event!({ event: { type: "session.compacted", properties: { sessionID: "ses_busy" } } });
+ return new Response("true", { status: 200 });
+ },
+ });
+ try {
+ await modelRequest(hooks, "ses_busy", { "x-omnirush-wrap-required": "1", "x-omnirush-wrap-offer-id": "allowance-busy" });
+ await hooks.event!({ event: { type: "session.status", properties: { sessionID: "ses_busy", status: { type: "busy" } } } });
+ await Bun.sleep(20);
+ expect(compactCalls).toBe(0);
+ expect(controls).not.toContain("offer");
+ await hooks.event!({ event: { type: "session.idle", properties: { sessionID: "ses_busy" } } });
+ await Bun.sleep(30);
+ expect(compactCalls).toBe(1);
+ expect(controls).toContain("finish");
+ } finally { 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("#"));
+ for (const row of rows) {
+ const [hash, name] = row.split(/\s+/);
+ expect(createHash("sha256").update(readFileSync(join(import.meta.dir, name!))).digest("hex")).toBe(hash!);
+ }
+ expect(rows.length).toBe(1);
+ });
+
+ test("asks only while idle, starts only while idle, finishes on a compacted session", () => {
+ expect(showWrapQuestion({ choice: "pending", busy: false })).toBe(true);
+ expect(showWrapQuestion({ choice: "pending", busy: true })).toBe(false);
+ for (const choice of ["decline", "done", "failed", "accept"]) expect(showWrapQuestion({ choice, busy: false })).toBe(false);
+ expect(startWrapNow({ choice: "accept", busy: true, inFlight: false })).toBe(false);
+ expect(startWrapNow({ choice: "accept", busy: false, inFlight: false })).toBe(true);
+ expect(wrapFinished({ ok: true, compacted: false })).toBe(false);
+ expect(wrapFinished({ ok: true, compacted: true })).toBe(true);
+ });
});
diff --git a/apps/server/src/opencode-plugins/omnirush-budget-wrap.ts b/apps/server/src/opencode-plugins/omnirush-budget-wrap.ts
index 47541d0f..e7a23cf9 100644
--- a/apps/server/src/opencode-plugins/omnirush-budget-wrap.ts
+++ b/apps/server/src/opencode-plugins/omnirush-budget-wrap.ts
@@ -8,7 +8,13 @@
* accepted offer asks the engine to compact on the model it last ran on.
* The compaction record itself contains the generated handoff summary; no
* warning or synthetic prompt is written to the session trace.
+ *
+ * The question rules are shared with the CLI (`budget-wrap-rules.ts`): asked
+ * 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";
+
const REQUIRED_HEADER = "x-omnirush-wrap-required";
const WRAP_UP_HEADER = "x-omnirush-wrap-up";
const OFFER_HEADER = "x-omnirush-wrap-offer-id";
@@ -16,6 +22,8 @@ const SESSION_HEADER = "x-omnirush-session-id";
type ModelRef = { providerID: string; modelID: string };
type Offer = { id: string; scopes: string; watching: boolean; inFlight: boolean; approved: boolean; backendWrapped: boolean; compacted: boolean };
const pending = new Map<string, Offer>();
+/** Sessions with a turn running (`session.status` busy until idle). */
+const busy = new Set<string>();
/** The model each session last sent a request on (the compaction runs on it). */
const models = new Map<string, ModelRef>();
const MAX_TRACKED_SESSIONS = 256;
@@ -117,7 +125,8 @@ export const OmniRushBudgetWrap = async (input: {
return;
}
const id = headers.get(OFFER_HEADER) || `legacy:${headers.get("x-omnirush-wrap-scopes") ?? ""}`;
- if (current?.id === id) return;
+ if (!replacesWrapOffer(current ? { offerID: current.id } : undefined, id)) return;
+ if (current?.inFlight) return;
if (current) void update(sessionID, current, "clear");
remember(pending, sessionID, {
id, scopes: headers.get("x-omnirush-wrap-scopes") || "token", watching: false,
@@ -160,8 +169,9 @@ export const OmniRushBudgetWrap = async (input: {
body: JSON.stringify({ providerID: model.providerID, modelID: model.modelID }),
},
);
- if (!response.ok) throw new Error("automatic budget wrap returned " + response.status);
- if (!entry.compacted || !entry.backendWrapped) throw new Error("the wrap was not confirmed by the engine and gateway");
+ if (!wrapFinished({ ok: response.ok, compacted: entry.compacted })) {
+ throw new Error("the wrap did not finish (" + response.status + ")");
+ }
await notify(
"Wrap up complete",
"Your handoff is saved. You can keep working while tokens remain.",
@@ -170,11 +180,15 @@ export const OmniRushBudgetWrap = async (input: {
await update(sessionID, entry, "finish");
pending.delete(sessionID);
} catch {
- // A failed wrap requires a fresh click. Never retry on the next idle.
+ // A failed wrap is final for this offer: the window shows a notice
+ // with a retry action, never the question again, and nothing retries
+ // on the next idle unless the person asks.
entry.approved = false;
entry.inFlight = false;
+ entry.compacted = false;
+ entry.backendWrapped = false;
await update(sessionID, entry, "fail");
- await notify("Wrap up did not finish", "Choose Wrap up again to retry, or keep working.", "warning");
+ await notify("Wrap up did not finish", "Your session is unchanged. You can retry, or keep working.", "warning");
}
}
@@ -182,13 +196,18 @@ export const OmniRushBudgetWrap = async (input: {
const entry = pending.get(sessionID);
if (!entry || entry.watching || entry.inFlight) return;
entry.watching = true;
- while (!disposed && pending.get(sessionID) === entry && !entry.inFlight) {
+ // 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)) {
const offered = await update(sessionID, entry, "offer");
if (offered === "decline" || offered === "done") { pending.delete(sessionID); break; }
- if (offered === "accept") { await compact(sessionID); continue; }
+ if (busy.has(sessionID)) break;
+ if (startWrapNow({ choice: offered, busy: busy.has(sessionID), inFlight: entry.inFlight })) { await compact(sessionID); continue; }
+ // "pending" (unanswered) or "failed" (a retry may come from the notice).
await new Promise<void>((resolve) => setTimeout(resolve, 3_000));
}
entry.watching = false;
+ if (busy.has(sessionID) && pending.get(sessionID) === entry && !entry.inFlight) void update(sessionID, entry, "hold");
}
return {
@@ -208,13 +227,29 @@ export const OmniRushBudgetWrap = async (input: {
const entry = pending.get(sessionID);
if (entry?.inFlight) entry.compacted = true;
}
- if (event.type === "session.idle") void watch(sessionID);
+ if (event.type === "session.status" && record(event.properties) && record(event.properties.status)) {
+ const type = event.properties.status.type;
+ if (type === "busy" || type === "retry") {
+ const entry = pending.get(sessionID);
+ // The compaction itself runs the session too; only a person's
+ // turn hides the question.
+ if (!entry?.inFlight) {
+ busy.add(sessionID);
+ if (entry) void update(sessionID, entry, "hold");
+ }
+ } else if (type === "idle") busy.delete(sessionID);
+ }
+ if (event.type === "session.idle") {
+ busy.delete(sessionID);
+ void watch(sessionID);
+ }
},
dispose: async () => {
disposed = true;
listeners.delete(noteBudgetResponse);
pending.clear();
models.clear();
+ busy.clear();
},
};
};
diff --git a/evals/specs/budget-wrap-consent.e2e.test.ts b/evals/specs/budget-wrap-consent.e2e.test.ts
index da975469..04e40fc0 100644
--- a/evals/specs/budget-wrap-consent.e2e.test.ts
+++ b/evals/specs/budget-wrap-consent.e2e.test.ts
@@ -74,8 +74,33 @@ test("a quota handoff waits for a choice, honors decline, and offers again after
await dismissed();
});
+ await step("a running turn hides the question until the session is idle", async () => {
+ expect(await offer("allowance-four")).toMatchObject({ ok: true, result: { choice: "pending" } });
+ await user.see({ testId: "budget-wrap-consent" });
+ expect(await offer("allowance-four", "hold")).toMatchObject({ ok: true });
+ await dismissed();
+ await user.notSee({ testId: "budget-wrap-consent" });
+ expect(await offer("allowance-four")).toMatchObject({ ok: true, result: { choice: "pending" } });
+ await user.see({ testId: "budget-wrap-consent" });
+ });
+
+ await step("a failed wrap is a notice with a retry, never the question again", async () => {
+ await user.click({ role: "button", label: "Wrap up" });
+ await dismissed();
+ expect(await offer("allowance-four", "fail")).toMatchObject({ ok: true });
+ await user.see({ text: "Wrap up did not finish" });
+ await user.notSee({ testId: "budget-wrap-consent" });
+ expect(await offer("allowance-four")).toMatchObject({ ok: true, result: { choice: "failed" } });
+ expect(await offer("allowance-four", "clear")).toMatchObject({ ok: true });
+ expect(await offer("allowance-four")).toMatchObject({ ok: true, result: { choice: "failed" } });
+ await user.notSee({ testId: "budget-wrap-consent" });
+ await user.click({ role: "button", label: "Retry" });
+ expect(await offer("allowance-four")).toMatchObject({ ok: true, result: { choice: "accept" } });
+ await user.notSee({ testId: "budget-wrap-consent" });
+ });
+
evidence.recordAssertionEvidence(
- "An unanswered wrap stays visible; decline is remembered; a changed allowance asks again; a restart requires renewal",
+ "An unanswered wrap stays visible while idle; decline is remembered; a changed allowance asks again; a restart requires renewal; a running turn hides it; a failure is a retry notice",
"The desktop shell kept the choice open while running. Decline was remembered for that allowance. A changed allowance reopened it; acceptance and completion dismissed it. After a full app reload, an unanswered offer stayed hidden until the server renewed it.",
true,
);