Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

docs(webv2): update project file guards and verification

joshistoast5341661e8a1a
diff --git a/docs/src/content/docs/development/Front End/project-files.mdx b/docs/src/content/docs/development/Front End/project-files.mdx
index 57e12b9fd9..4f1d462bdb 100644
--- a/docs/src/content/docs/development/Front End/project-files.mdx
+++ b/docs/src/content/docs/development/Front End/project-files.mdx
@@ -42,9 +42,11 @@ The skip is by key on purpose, because the members got there differently. `selec
`readInvkArchive()` unpacks and validates; `restoreArchiveAssets()` puts the pixels back.
+Import deliberately orders its work as **read → mint identity → validate and canonicalize → restore → remap → create**. It first reads the archive without mutating the server, then assigns the imported project a fresh id and name. The candidate is rehydrated through the Workbench reducer and serialized back to its canonical document before any asset is restored. Only then are missing assets restored, their server-assigned names remapped throughout that canonical document, and the new project created. A malformed document therefore cannot leave restored orphan assets behind, and an import can never overwrite the project whose id was recorded in the archive.
+
Restoration checks which referenced assets the server already has, uploads only the missing ones out of `images/` and `videos/`, and returns an old-to-new mapping **per kind** — the namespaces are separate, so a single flat map would let an image rewrite a video that happened to share its name. `remapAssetRefs()` then rewrites the document — the whole document this time, including the history the export left behind, so nothing keeps pointing at a pre-import name.
-The existence check is the one place the two kinds are not symmetric. Images have a bulk `POST /images/images_by_names`; videos have no equivalent, so that check fans out one `GET /videos/i/{name}` per name behind the same concurrency limit of 5. This is what `hydrateVideoRefs` in the gallery's data layer already does for the same reason. A project with no video references never issues the video check at all.
+The existence check is the one place the two kinds are not symmetric. Images have a bulk `POST /images/images_by_names`; videos have no equivalent, so that check fans out one `GET /videos/i/{name}` per name behind the same concurrency limit of 5. For video lookup, only `403` and `404` mean the asset is absent; every other non-success status aborts the import rather than being mistaken for a missing video. This is what `hydrateVideoRefs` in the gallery's data layer already does for the same reason. A project with no video references never issues the video check at all.
Restored assets upload with the category `'other'`, the canvas's private category: they appear in no gallery view and no board count. The previous frontend used `general`, which empties a stranger's project into your gallery.
@@ -52,7 +54,7 @@ An asset that is neither on the server nor in the archive is reported as danglin
**Import never overwrites.** The document always lands under a freshly minted project id, never the one in the file, so exchanging a project cannot collide and re-importing your own export cannot replace the original.
-**Cancellation is not a skip.** An unservable asset is skipped, but an aborted signal makes every asset unservable at once — so a cancelled export would otherwise pack an archive of nothing and hand it to the browser as a finished download. `isRequestCancellation()` tells the two apart where the request fails, and the signal is checked again before the archive is written.
+**Cancellation is not a skip.** An unservable asset is skipped, but an aborted signal makes every asset unservable at once — so a cancelled export would otherwise pack an archive of nothing and hand it to the browser as a finished download. `isRequestCancellation()` tells the two apart where the request fails. The signal is checked after fetching and again after packing, immediately before the browser download, so cancellation during ZIP creation cannot produce a completed-looking download.
## Reporting
@@ -66,6 +68,8 @@ Both directions can half-succeed: export skips assets the server will not serve,
The index is written whenever a project is serialized for a save, and on import. It is an index and not a truth: a project saved by an older build has no entry and shows the folder glyph, which is also what a project that has produced nothing shows.
+Each cover write is a complete replacement of that one index value, so writes are serialized. A failed write leaves the optimistic snapshot dirty; a later save or identical cover record retries that complete dirty snapshot instead of silently treating it as clean. Before the index has loaded, pending changes retain both new cover names and clears (`null`), so clearing a cover before load still removes the matching retained server entry once the read succeeds.
+
On import the cover prefers an image the restore already put on this server — the archive's `cover` entry is a thumbnail of an image the document also references, and the cover URL asks for a thumbnail anyway, so reusing it is the same picture without a second copy. The bundled bytes are the fallback for a cover whose source image is dangling. Uploading the entry unconditionally left one orphan per import: covers go up under the canvas's private `'other'` category, which appears in no gallery view and no board count, so nobody could find or delete them.
**The whole index is one value, so a write must not precede a read.** `setClientStateValue` replaces the blob outright, so recording a cover from a store that has not loaded would delete every entry but that one — and autosave reaches `recordProjectCover()` from the editor, which loads the index only when the project switcher or the Open dialog opens. Anyone who reloads straight into a project and generates hits exactly that ordering. Records made before the load are held and applied on top of the server's answer once it arrives. A read that *fails* is not a read: the store stays unloaded and the pending records wait, because merging onto a blank answer is the same destructive write by another route.
@@ -82,10 +86,16 @@ Future format changes should add a new member to the union rather than widening
`archive.ts` is the only module that imports fflate, and it does so with `await import()` so the ZIP codec never enters an initial chunk — the architecture budget fails on a new package appearing in a route's source-owner set. Both directions are bounded by `INVK_MAX_ARCHIVE_BYTES` and `INVK_MAX_ENTRIES`, because an `.invk` is a file someone was handed.
+The input `File.size` is rejected before `arrayBuffer()` allocates its bytes. On export, the accumulated entries are checked before packing and the packed ZIP is checked again afterward, because compression can change the final output size.
+
On the way in, the budget is enforced through fflate's entry filter (`createExpansionBudget()`), not over the result. `unzip` is fully buffered: by the time it returns a record of entries, every one has already been inflated, so a total measured there would describe an out-of-memory crash rather than prevent it. The filter is consulted per entry with the uncompressed size declared in the central directory, and refuses everything from the crossing point on. The refusal is raised after `unzip` settles rather than thrown from inside it, so `too-large` stays distinguishable from `not-a-project` — a throw inside fflate's walk arrives as a decode failure. An entry whose header understates its size is caught by fflate itself, which inflates into a buffer sized from that declaration and fails the decode when the stream overruns it.
`INVK_MAX_ARCHIVE_BYTES` is 2 GiB — deliberately well under 4 GiB, where ZIP32's 32-bit sizes and offsets stop being able to describe the file. fflate reads zip64 records but `zip()` never writes them, so an archive at that boundary would be produced structurally invalid rather than refused. A single video can be hundreds of megabytes, so this ceiling is reachable in practice; it fails cleanly into the `too-large` reason.
+## HTTP-contract verification
+
+The mock-backed browser journey exercises the real export action and file chooser: it exports a representative project, resets the backend, imports into a fresh browser context, and verifies the persisted project, remapped image and video references, restored-media retrieval, and cover-index entry through HTTP. Only image upload was missing from the mock backend's project-file media contract; the journey uses the existing video upload path. This verifies the request and persistence contracts, including server-assigned asset names, not binary fidelity between archived and restored bytes.
+
## Compatibility notes
The archive stores references to models, LoRAs and other generation resources, not the model files themselves. Loading a project on another install restores its canvas and images, but missing models still need to be installed or replaced.