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.
Gallery listings
Paths are relative to the webv2 src/ directory.
Gallery ordinary listings are Query-owned sparse pages shared by grid, picker, Preview, and deep-reveal flows. The Gallery widget's media kind (both, images, or videos) is part of the canonical listing filter, present only when restricted; the picker always lists both kinds. Page key = account lifetime + canonical listing filters + aligned absolute offset; each result keeps its authoritative total and absolute item positions so hydrated gaps never compact. Consumers own separate visible ranges and scroll anchors. Cold numbered page after page zero first requests count-only metadata, then reads only its clamped 60-item page; virtual scrolling discovers count from its first item page. Recent local completions use a temporary overlay, with listing-scoped membership evidence bounded by recent-item limit so an authoritative item does not reappear in overlay when its page is evicted. Sparse viewports render that overlay as rows apart from backend slots, beside the listing's newest end (leading rows in DESC, trailing in ASC), and cannot interleave it, so they overlay only recents created after the listing's newest item. That cut comes from the cached page holding the newest end (page zero in DESC, the last page in ASC) and survives that page leaving the view while its cache entry stays valid. A narrow cache subscription does not keep the page observed or trigger extra reads. Invalidation, eviction, or a failed refresh suspends the overlay until the newest-end page loads successfully again; until it first loads, nothing is overlaid. The page lifecycle retains evidence of successful backend reads separately from Query status because optimistic patches and their rollbacks are manual successes; they cannot end an invalidation or failed-refresh suspension. Returning to the suspended newest-end page requests a fresh read even if a manual patch reset Query's freshness clock. Loaded pages elsewhere cannot set it, since newer items may sit in pages not yet read. Paginated mode never overlays recents. An older recent (such as an existing image a workflow echoed) belongs inside the backend listing range, not ahead of it; the listing places it, or the post-run gallery refresh does once its board attach lands. Query layer retains at most ten inactive idle pages per listing while protecting observed pages, and schedules at most four distinct page reads per QueryClient. Deep reveal resolves an item's filtered listing rank, reads its containing page, verifies item at returned absolute position, and retries that rank/page check at most once if offsets shifted. Persisted Preview selection keeps listing identity, media kind included, from when item was selected (a stamp without a media kind lists both); changing active Gallery filters does not rewrite that cursor. While a search is active, the Gallery's searchScope setting can widen the listing from the selected board to ALL_READABLE_BOARDS_ID (all): the caller's own unboarded items plus every non-archived board they may read, as the backend's board_id=all defines it. Only the listing's board id changes (getGalleryListingBoardId); the selected board, the auto-add board and upload destinations stay put, uploads are refused while it applies, and a selection made in it is stamped all, so Preview steps through the search's results. Clearing the search returns the scope to board. Preview re-resolves a stale item page after listing mutations; its async navigation is fenced by captured account epoch so a late page cannot stamp selection into a newer account lifetime.
Selection and destination
The multi-selection belongs to the listing on screen. settleGalleryValues (ui/galleryStateView.ts), applied to every write of gallery values, drops selectedImageNames when a write changes what the listing holds (board, view, search, search scope, starred or media filter) without setting the selection itself; the primary item stays for Preview, and the grid acts on it only while it is listed. It also ends a comparison when a write moves the primary item onto the comparison image it already holds (a Ctrl/Cmd-click, a range, a deletion's successor): Select for compare waits for its second image only while the comparison image is set on the selected one. A deletion that reaches an item no loaded page holds, or more than one item, always confirms, listing the items, whatever the user's "Don't ask again". Item deletion and "Delete board and media" both report where the media is still used before it goes (mediaUsage entry: POST /api/v1/gallery/usage and the report types; react entry: GalleryMediaUsagePanel, the section both dialogs render, which loads the report view only once a check settles). The server's answer is conservative: it counts every media name a project document holds, Gallery selection, recents and workflow last runs included. The host narrows it (workbench/image-actions/mediaUsageReport.ts): projects loaded in the tab are scanned from memory, a few other named projects (up to 4 MiB each, measured decoded) are read and scanned, the rest stay as the server counts them. Each project entry carries the content and caller's workspace revisions its names were read at, from the same transaction. A loaded project's scan stands when it reports every name the server found, or when those revisions are the ones the tab's copy builds on (the sync store's revision and workspaceRevision; never while the copy is in conflict or schema-refused, since it then holds local work beside revisions it does not build on): an unsaved edit then removed what it dropped, and nothing is read. Otherwise (the server is ahead, or either side's revisions are unknown) the server's copy is read, ahead of closed projects and within the same cap, and a name either copy uses counts; when the read fails or is skipped, the project keeps what its copy uses and the server's count, with "Its saved version couldn’t be checked." The scan (workbench/image-actions/mediaUsage.ts) names the surfaces it knows (live work, staged canvas results, canvas snapshots) and fails safe: a name anywhere else in the project counts as "Elsewhere in the project", except in fields listed there as only showing or recording media (Gallery state, workflow last runs, last submitted graphs) or as session state never saved (queue, run log, undo histories). An item request counts the items asked about: the server checks only those the caller may delete, without naming them; workflows, the legacy editor, projects kept for repair, queued jobs and other accounts pass through. A use, or a check that could not finish, always asks; a silent deletion first looks again at the projects in this tab, for a use added while the check ran. A second deletion that needs asking while a dialog is open is refused with a notice; a deletion already under way for an item (checking, asking or deleting) drops a repeated request for it; the board dialog checks only once deleting the media is ticked, once per opening, through the adapter's getBoardMediaUsage, stops a running check when the box is unticked or the dialog closes by any path (closing leaves the opening's query key), and keeps the opening's answer while unticked. Once the check answers, the checkbox, description, button and typed-name threshold count the items the server says go: on a shared board only the caller's own ("your N items"), and none at all when they added none.
New results without a board of their own go to autoAddBoardId when one is chosen, else to the project's inbox (Uncategorized for a gallery without one); only followSelectedBoard, off by default, makes them follow the selected board. While following is off, selecting a board, Find in Gallery and reveals therefore never move the destination; while it is on, anything that selects a board moves it, by definition. Earlier builds stored autoAddBoardId: 'follow' for following, their default; it reads as the default destination. The header's Saving to control and the board list's destination marker name it as submissions resolve it (useGalleryDestination), redirection to the inbox included.
Move, star and archive report an Undo (notify.undoable). Undo puts back each item's own board or star flag as known before the action, leaving out items whose prior value was not known; it is last write wins, so a change made to the same items since is overwritten. An archive's Undo restores the destination in the project that archived, by its id, only while that project has chosen no other since.
The server refuses a request body naming more than 1,000 images or videos (GALLERY_REQUEST_MAX_NAMES, mirroring invokeai/app/api/routers/_limits.py), so the transports in data/backend.ts send longer name lists in batches of that size, one after another: delete, star, unstar, adding images to a board and removing them from one, and resolving images by name. Their answers merge. A batch that fails, or an abort, after earlier batches succeeded stops the run, records the failure as a debug breadcrumb (gallery.batch-request-failed; the caller's partial-failure notice reports it) and reports the earlier batches' items as done and the rest as failed; a failure or abort before anything succeeded rejects as one request would, and an account change rejects whatever succeeded. The usage check (data/mediaUsage.ts) batches the same way, gives each request its own share of the check's time budget, and fails whole when any batch fails. Name lists join and per-name counts add exactly. A document listed by several batches keeps its revisions only when they agree. A batch past the server's 100-document listing cap may leave out a document another batch lists: that document is marked namesIncomplete. A project open in this tab is then always checked against its saved copy as well; any other flagged document is listed unread with its count shown as "at least". The server's in-use total stands whenever documents went unlisted, even after a scan narrowed a project, since the unlisted documents' uses count nowhere else. Counts that cannot be deduplicated across batches err high: documents a batch left unlisted each count as another ("N more projects or workflows"), and queued jobs and other accounts' documents count once per batch that found them. A selection download makes one archive per 1,000 images, with a notice saying how many are coming.
Realtime refresh and external reveal
Uploads, reconnects, and all of the signed-in user's completed queue items refresh the listings, including completions from other frontend tabs and devices. Gallery owns socket-completion invalidation; Queue does not also refresh for those events. Bursts coalesce for 250 ms and passes stay at least 1 second apart, with a trailing pass for later events. Hidden tabs keep one pending refresh until shown. Query invalidations serialize and await active refetches, so a slow listing read lands before a later pass begins. Frontend origins (webv2:) refresh only: they never select an item, change filters, board or page, or request external reveal. Image and video results share this completion path.
An external client asks for its results to be revealed by enqueueing with POST /api/v1/queue/default/enqueue_batch and batch.destination set to gallery:reveal. The request is honored only for the signed-in user's items (any user's on a single-user server) whose origin does not start with webv2:. Every other destination only refreshes, gallery included: legacy web sends it on every workflow and upscale run.
The reveal is best effort. Each completed item asks once; a reveal that stands down is dropped, not retried, except in a hidden tab. Every visible tab or device signed in as that user may reveal. The reveal takes the last non-intermediate image or video the item saved, in the order of its session results and of the outputs within each, and lands on it as Find in Gallery does: board, page and selection, plus the starred-only filter, the media filter and the images/assets view when the item needs them, after which Preview follows the selection and the grid scrolls to it. With the Gallery widget closed, the selection still changes, unseen. It raises no widget and leaves Canvas, Generate panels and the route untouched. Only while the Gallery widget is mounted is it announced, once, in the Gallery's polite live region; a Gallery mounted later does not repeat it.
It never takes the Gallery from the user. These conditions are checked when the completion arrives, before and after its result is read, and immediately before the first Gallery change; the first failure drops the reveal:
- the user is not typing (this window has focus and a text field in it does);
- the project on screen at arrival is still the active one and has no open run of its own;
- no search text, semantic text or semantic query narrows the listing (an open but empty semantic field does not count);
- at most one item is selected;
- no other reveal, such as Find in Gallery or an image-map click, is locating its item;
- the user has not navigated the Gallery since arrival: board, selection, view, starred-only, media filter, search, page, or a claimed navigation;
- no newer reveal request has arrived. Only the newest completion reveals, so a batch of several runs reveals at most its last completed item.
A hidden tab defers instead: the newest request waits until the tab is shown, and the conditions are checked then.
Known limitations:
- The status event does not say whether an item is a workflow-call child, which inherits its parent's destination. A child's completion supersedes a reveal still in flight before its read finds it is a child and reveals nothing; if the parent then fails or is cancelled, the earlier item is not revealed.
- An image or video a graph passes through from its inputs counts as an output, so it is picked if it is the last non-intermediate one.
- Videos are recognized only as a node's top-level video output; a video inside a workflow-call return value is not, so such an item reveals its last saved image instead, if any.
Board destinations
Where results and uploads land is decided from a cached board listing, never guessed: canAddToCachedGalleryBoard (features/gallery/data/queryCache.ts) takes a board as a destination only when a cached listing holds it with add_media, archived or not; a board no listing holds is not one. Submissions and uploads call ensureGalleryBoardDestinations first. It resolves optimistically: any cached listing of every readable board (archived included) decides at once, whatever its age; one older than a minute or invalidated is read again in the background for the next resolution; only with no such listing cached is one read awaited, and if that read fails nothing is a destination and results go to the inbox. No surface observes that listing just in case: the Gallery panel's own listing serves when it shows archived boards, and otherwise the first submission or upload reads one. A failed gallery-bound run, workflow run or upload, including one a board refused with 403 or answered 404 for, calls invalidateGalleryBoardDestinations: the gallery is invalidated and the listing of every readable board is read again at once, with no observer needed. A submission or upload made after that read lands decides from the new listing; one made before it lands still decides from the old listing and shares the read. The gallery upload action refuses a real board the ensured listing does not take uploads for before sending anything, and says whether the board is view-only or gone. Graph compilation applies the same predicate to explicit workflow board fields; a refused board resolves like Auto. A board the server answers 403 for exists but is unreadable: it stays named by the project and is shown as the project board meanwhile; only a 404 (deleted) reconciles the project's references. Hosts without board sharing fold every board into the caller's own through useHostGalleryBoards, which the panel, board menus and workflow board fields share.
Image storage and failed image loads
features/gallery/storage is the admin-only entry for server image storage: the subfolder layout setting and the image move/recovery job (data/imageStorage.ts). It stays apart from queries so the editor's gallery reads never load that transport. When a move this client follows stops, it invalidates the gallery listings and refreshes mounted thumbnails.
While a move runs, the server answers every thumbnail and full image read with 409, for every user, and nothing tells a non-admin tab when it ends. An image element's onError carries no status, so gallery thumbnails and the Preview image report their failed URL through useGalleryImageRecovery (ui/useGalleryImageRecovery.ts) to one shared probe (data/imageRecovery.ts), never retrying per element. The probe re-requests one failed URL at a time with fetch, uncached, so it can read the status:
- 409, 502, 503, 504, or no answer at all: the server cannot serve images yet, because a move holds the files or the server is restarting mid-move. It asks again 15 s later, then every 30 s, without a cap, paused while the document is hidden and resumed as soon as it is shown. The URL stays waiting.
- 2xx with an image content type: images are served again. The recovery revision rises and every image that failed before it reloads once, with a
gallery_image_recoveryquery parameter so the browser asks again. Images that loaded keep their URL. Each failure reports the revision its element's URL carried. A failure that already carried the current revision, and was not refused by the server since, failed after the server served it again: that image is broken, not waiting, and is dropped. A failure of a plain or older URL always recovers. - Anything else (404, another refusal, a page in place of the image): that URL is dropped. Other failed URLs are probed next.
The first probe waits 2 s, so a screen of tiles failing together costs one request. Recovery state belongs to the URL an element shows: an index-keyed slot handed another item asks for that item's plain URL. The probe lives for one account lifetime: an account change aborts its request, clears its timer and forgets its URLs.