diff --git a/docs/development/lessons.md b/docs/development/lessons.md index 906dded6b..f4ce82059 100644 --- a/docs/development/lessons.md +++ b/docs/development/lessons.md @@ -51,6 +51,7 @@ When work exposes a consequential risk or a recurring problem, add a lesson or u - **Check:** Dismiss `opendirector.modelSetup.v1` before the first navigation, and open a project the script itself created when the server is already populated. Point assistant-fixture scripts at their own web URL, and keep `/src` or `/tests` imports out of the production lane. `npm run check:browser-manifest` checks the dismissal, the fixture URL, and those imports. - **Fixture-mode follow-up:** [PR #266 review](https://github.com/ThinkFlowLab/OpenDirector/pull/266#issuecomment-6906025718) found browser workflows passing with local HTTP-generation fixtures but failing before business assertions under nightly's generic provider. Declare the required fixture modes in the manifest and check the running API and web proxy before executing each fixture lane. Reproduce the workflow's service commands and script grouping; separately correct local startup commands do not validate CI wiring. - **Save-observation follow-up:** [Issue #300](https://github.com/ThinkFlowLab/OpenDirector/issues/300) reproduced a stale saved label satisfying a browser wait before the edited text binding was committed. `asset.writeText` had succeeded, but the `creation.batch` containing `canvas.materialize` was still in flight; its later applied receipt installed the binding and the content was `AB`. Wait for the specific persisted binding, settings or position before asserting a save, retain the content check, and bound and release test gates even on failure. A visible saved label alone does not identify which edit was acknowledged. +- **Rejected delivery follow-up:** The video-role scenario in [Nightly run 45813157219](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/45813157219/job/139885967384) saw a first-frame rejection after the directory reported unknown support. A controlled reload test reproduced replay of the rejected command when its follow-up snapshot read failed. Retire a definitive rejection before refreshing the snapshot, and separately verify that accepted and unresolved deliveries still preserve their command ID. - **Assistant completion follow-up:** [PR #465's browser run](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/45526547494/job/138913562926) read a saved reply while the Agent still held its write lease. The assistant panel test must wait for both the reply's final status and removal of the active turn ID. Delaying lease release reproduced the failure on the upstream baseline. - **Shared model catalog follow-up:** [Nightly run 45309310680](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/45309310680/job/138160760923) reached the empty-video-selector test after an earlier script saved a video model. A new page still reads the shared server's catalog. For a UI test of an empty category, scope that catalog response to the test page and verify the flow with a model already present on the shared server. diff --git a/src/backend/creationClient.ts b/src/backend/creationClient.ts index 679643d45..c8f43c44c 100644 --- a/src/backend/creationClient.ts +++ b/src/backend/creationClient.ts @@ -297,6 +297,10 @@ export class CreationClient { }; this.deliveries.set(intent, body); this.saveDeliveries(); + const clearDelivery = () => { + if (this.deliveries.get(intent) === body) this.deliveries.delete(intent); + this.saveDeliveries(); + }; const perform = async () => { let receipt: CommandReceipt; try { @@ -315,18 +319,20 @@ export class CreationClient { error instanceof ApiError && [400, 401, 403, 413, 422].includes(error.status ?? 0) ) { - if (this.deliveries.get(intent) === body) - this.deliveries.delete(intent); - this.saveDeliveries(); + clearDelivery(); } throw error; } } - await this.refresh(); - if (this.deliveries.get(intent) === body) this.deliveries.delete(intent); - this.saveDeliveries(); - if (receipt.status === "rejected") + if (receipt.status === "rejected") { + // A definitive rejection created no job. Retire it before a + // failed refresh or reload can replay it as the next submission. + clearDelivery(); + await this.refresh().catch(() => {}); throw new CreationCommandError(receipt); + } + await this.refresh(); + clearDelivery(); return receipt; }; return perform; diff --git a/tests/creationClient.test.ts b/tests/creationClient.test.ts index 37d6f4f68..41f198a21 100644 --- a/tests/creationClient.test.ts +++ b/tests/creationClient.test.ts @@ -439,6 +439,58 @@ test("an accepted command whose snapshot refresh fails retains its original deli } }); +test("a confirmed generation rejection is not replayed after reload when refresh fails", async () => { + const previousStorage = Object.getOwnPropertyDescriptor(globalThis, "sessionStorage"); + const saved = new Map(); + Object.defineProperty(globalThis, "sessionStorage", { + configurable: true, + value: { + getItem: (key: string) => saved.get(key) ?? null, + setItem: (key: string, value: string) => saved.set(key, value), + removeItem: (key: string) => saved.delete(key), + }, + }); + const previousFetch = globalThis.fetch; + const snapshot = empty(); + const client = new CreationClient(snapshot.project.id); + client.install(snapshot); + const commandIds: string[] = []; + globalThis.fetch = async (url, options) => { + assert.ok(String(url).endsWith("/commands")); + const { commandId } = JSON.parse(options!.body as string); + commandIds.push(commandId); + // The server returns the same rejection when the original ID is replayed. + const rejected = commandId === commandIds[0]; + return Response.json({ + commandId, + projectId: snapshot.project.id, + status: rejected ? "rejected" : "accepted", + inputFingerprint: "a".repeat(64), + changed: [], + jobIds: rejected ? [] : [crypto.randomUUID()], + issues: rejected ? [{ code: "capability_unavailable", message: "First frame unsupported" }] : [], + eventCursor: 1, + }); + }; + client.refresh = async () => { throw new TypeError("connection lost after rejection"); }; + const payload = { specId: crypto.randomUUID(), expectedSpecRevision: 1 }; + try { + const first = await client.command("generation.submit", payload).catch((error) => error); + const reopened = new CreationClient(snapshot.project.id); + reopened.install(snapshot); + reopened.refresh = async () => snapshot; + assert.equal((await reopened.command("generation.submit", payload)).status, "accepted"); + assert.notEqual(commandIds[0], commandIds[1]); + assert.ok(first instanceof CreationCommandError); + assert.equal(first.receipt.issues[0]?.code, "capability_unavailable"); + } finally { + globalThis.fetch = previousFetch; + if (previousStorage) + Object.defineProperty(globalThis, "sessionStorage", previousStorage); + else Reflect.deleteProperty(globalThis, "sessionStorage"); + } +}); + class CommandCapture extends CreationClient { override async textContent() { return "Actual source";