fix(ui): don't strand the viewer under the progress overlay, for images or videos - #9475
fix(ui): don't strand the viewer under the progress overlay, for images or videos#9475lstein wants to merge 47 commits into
Conversation
…king The image viewer holds the last progress preview on screen until the final image's onLoad fires. Two problems with that. The reveal was gated on a preload of imageDTO.image_url — the full-resolution PNG — so on a slow connection the stale latent preview stayed up for the entire multi-megabyte download. A 256px thumbnail is already generated for every image and is typically higher resolution than the preview it replaces. Gate on that instead; DndImage renders it via Chakra's fallbackSrc and swaps the full image in, in place, once it arrives. The preload also used the raw URL while DndImage requests useMediaUrl(...), which appends ?media_cookie_version=N. Different key, so the bytes were fetched twice (measured: 2 requests mismatched vs 1 matched). Route the preload through useMediaUrl so it is byte-identical. The reuse is the document's list of available images, keyed by URL rather than the HTTP cache, so it still holds in multiuser mode where images are served Cache-Control: private, no-store. Separately, the viewer's progress atoms are distinct stores from the global ones in services/events/stores, and only the latter were reset on socket lifecycle transitions. socket.io has no event replay, so a drop spanning the terminal queue_item_status_changed loses that event permanently and nothing is left to clear the opaque overlay covering the finished image — the reported "backgrounded the tab, came back, only a reload fixes it". Reset the viewer's atoms on connect/connect_error/disconnect too, matching setEventListeners. onLoadImage is not a guaranteed callback in any case: Chakra reports a failed load as onError, useImage only re-runs when src changes, the load can beat the terminal event, and an all-intermediate item never changes the selection. So the deferred clear also gets a backstop deadline. The armed flag and its timer live together in createDeferredClear — as separate state, a path that reset the flag but leaked the timer let a deadline outlive the generation that armed it and blank a later one's live preview. The backstop does not clear while other sessions still have previews, since nulling $progressImage tears down the whole overlay including multi-GPU tiles, and the reconnect reset only replaces the map when it holds something, because connect_error fires once per reconnection attempt. The terminal-status policy moves to a pure getTerminalProgressAction so the branchy decision is testable without a socket or a React tree. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…review Starting a new generation soon after the previous one finishes made the viewer flicker: the new previews would appear, then the previous generation's finished image would cover them for two seconds, then the previews resumed. Waiting between generations avoided it. The flash is the "reveal selected image" feature (invoke-ai#9217), which briefly hides the progress overlay so a mid-generation gallery click is visible. Its only guard against the auto-switch handoff was $isProgressImageResolving — a timing guard, and the timing loses: the auto-switch selection is dispatched only after onInvocationComplete's async DTO fetch, then waits for the thumbnail preload, and the next generation's first invocation_progress event slots into that window and resets the flag. By the time the handoff reaches the viewer it is indistinguishable from a user click, so the reveal fires over the live preview. Distinguish them by identity instead of timing: auto-switch records the image name in a small registry at dispatch, and the reveal effect consumes it on the selection's first render. Consumption happens on every rendered-image change, not only when the reveal conditions hold, because in the common (unraced) case the image renders with no progress showing and a leftover entry would suppress a genuine user selection of the same image later. Entries also expire after 30 seconds. Recording is unconditional but consumption requires the image to actually render, so a superseded auto-switch (two completions within one thumbnail-fetch window — routine with parallel multi-GPU sessions), a viewer unmounted by comparison mode, or a duplicate invocation_complete event would otherwise leave an immortal entry whose only future effect is to swallow a genuine click on that image — the very dead-click the reveal exists to prevent. The TTL is generous for the dispatch-to-render handoff it protects; expiring early merely readmits the 2-second flash on a very slow connection, which is the milder failure. The suppression branch still lowers $isTemporarilyShowingSelectedImage — the effect has already cancelled any running reveal's timer by that point, so returning with the atom raised would wedge the reveal on. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
During a video render, the progress-preview overlay swallowed every gallery thumbnail click: the selection changed underneath, but the opaque overlay stayed on top, so nothing visibly happened until a tab switch remounted the viewer. Three causes, three fixes: - CurrentVideoPreview never implemented the temporary reveal that CurrentImagePreview got in invoke-ai#9217. Port it: clicking a thumbnail mid-render now lifts the overlay for 2 s so the click visibly lands, then the live preview returns. An actively-playing video is never re-covered (audio would keep running under an opaque overlay with unreachable controls); the overlay returns when the player closes. - The reveal's previous-item tracking was per-component, so any click that switched media type (image <-> video swaps the mounted preview component) reset it and the reveal was swallowed. The ref now lives in the shared ImageViewerContext; the image side is careful not to null it while a preload is still pending (adversarial-review finding: the mount run would otherwise erase the previous-video fact and kill the video->image reveal). - After completion, the "preview resolves into the final media" clear only fired from the final media's load callback. On a slow connection that lags far behind completion, and an errored <video> never fires it - stranding the overlay permanently. The video error handler now clears a pending resolve, and a 10 s failsafe in the context drops the illusion rather than strand the overlay. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…GPU) CurrentImagePreview tiles per-session previews when more than one render runs concurrently; CurrentVideoPreview only ever rendered the single shared latest preview, so parallel sessions overwrote each other's frames in place. Port the ProgressImageTiles branch, mirroring the image viewer exactly ($activeProgressData is already tracked per-session in the shared context). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
JPPhoto
left a comment
There was a problem hiding this comment.
A few things to fix:
-
invokeai/frontend/web/src/features/gallery/components/ImageViewer/CurrentVideoPreview.tsx:115treats any video-name change as a user reveal. An asynchronously auto-selected completed video can therefore hide a newer render's progress preview for 2 seconds.#9434fixes this for images withautoSwitchedImages, but PR 9475 defers the video equivalent. Test: enable auto-switch, finish video B, start video C, let C emit progress, then let B's selection arrive; the progress overlay must remain visible. -
invokeai/frontend/web/src/features/gallery/components/ImageViewer/context.tsx:187and:216clear global progress state without checking active sessions. If session A finishes while session B remains active, A's preview is removed from$progressData, but the global image/event can be cleared by the failsafe, metadata load, error path, or cancellation. B's tile then disappears until another B progress event. Test: emit progress for A and B, finish A, leave B active without another event, then trigger the 10-second failsafe or A's clear path; B's preview must remain visible.
Some alternative paths worth considering:
-
Instead of the current shared
lastRenderedItemNameRef,isTemporarilyShowingSelectedImage, and global resolve timer: use an item-owned reducer/state machine. Track each item asrunning,resolving,canceled, orfailed, with item-specific media readiness, reveal source, and timeout. -
Instead of the current implicit combination of progress state, completion handoff, and selection reveal: use three explicit state machines. Keep queue progress, completed-item handoff, and selected-media reveal separate, with events carrying
item_idand source. -
Instead of patching only the shared clear path: add
progressOwnerItemIdandresolveItemId, makeonLoadImageitem-specific, and derive the displayed fallback from$activeProgressDatawhen the current global owner finishes. Also extend the#9434auto-switch registry to videos.
JPPhoto
left a comment
There was a problem hiding this comment.
Merge blockers:
-
invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/boardIdSelected.ts:18-32,47-57: probe cancellation compares onlyselectLastSelectedItem, not the full selection. During a pending probe, normal multi-select removal or same-item reselect can keep the last item unchanged, so the probe survives and later replaces the user's selection with the first gallery item or null. Effect: selection corruption. Likelihood: normal supported interaction. Recovery: manually rebuild selection. Test: dispatchselectionChanged(['first.png','second.png']), start probe, dispatchselectionChanged(['second.png']), advance 6 s, assert selection remains['second.png']. -
invokeai/frontend/web/src/services/events/onInvocationComplete.tsx:267-295,488-545: a transient DTO lookup failure recordsretryable, but retry occurs only if a duplicate completion event arrives. One completion with no duplicate leaves output absent from gallery and board state. Effect: silent output loss. Likelihood: plausible API/network or commit race. Recovery: manual refetch or lucky duplicate event. Test: return null once fromgetImageDTOSafe/getVideoDTOSafe, send one completion, advance timers, and assert a later lookup or visible retry.
Other findings/issues:
invokeai/frontend/web/src/features/gallery/components/ImageViewer/CurrentVideoPreview.tsx:125-150,393-435: temporary reveal starts whenvideoNamemounts, beforeloadeddataorcanplay; the video only preloads metadata. Effect: the 2 s reveal can expire before the first frame is decoded, returning the progress overlay over a black video. Likelihood: normal on slow networks or large videos. Recovery: wait for media load, then click again. Test: delay frame readiness beyond 2 s and assert the overlay stays lowered until media is drawable.
Corner/impossible cases:
invokeai/frontend/web/src/services/events/onInvocationComplete.tsx:69-79,508-543: after 1000 distinct invocation keys, the bounded dedupe cache can evict an older key; a delayed duplicate then repeats gallery insertion, board-count updates, and possibly auto-switch. Effect: duplicate UI/state. Likelihood: rare long-lived session or delayed replay. Recovery: refetch gallery and board data. Test: process 1001 unique completions, replay the first, and assert no second delivery.
Suggestions:
-
Instead of comparing only the active item for probe cancellation: compare the full selection state or explicitly match every
selectionChangedaction. -
Instead of duplicate-only DTO retry: use bounded per-output refetch with backoff and a terminal failure state.
-
Instead of starting video reveal on DTO/name mount: gate it on
loadeddataorcanplay, with an explicit timeout fallback. -
Instead of coordinating reveal through shared timing/ref state: model progress and selection as per-session state machines with explicit
idle,resolving,media-ready, andrevealedstates.
…puts Two merge blockers from JPPhoto's fourth round. The board/view probe compared only the *active* item to decide whether a selection had landed under it. Narrowing a multi-selection, or re-picking the item already active, leaves that item unchanged while still being the user settling what they want — so the probe survived those and replaced their selection when it woke. It now compares the whole selection: the state is immutable, so a new array reference is exactly "the selection was written", and cancelling a probe more often than strictly necessary costs nothing. An output lost to a transient DTO lookup failure was only recovered if the server happened to re-deliver the completion event. Nothing re-emits one, so in practice the image was simply absent from the gallery and the board counts until something unrelated refetched them. A delivery that leaves outputs missing now refetches exactly those names at 1s, 3s and 9s, bounded — an output still missing after that is not coming back from a retry — with the entry left retryable so a re-delivery can still recover it for free. Each attempt takes the same path as a re-delivery, so only missing names are fetched, landed outputs are untouched, and the global side effects are not re-run; a new pass supersedes the refetch already queued, so duplicates cannot run two chains. This is the retry work from the follow-up branch, brought down to where the blocker was raised. Tests come with it, including the sequences from the review.
…puts Carried from invoke-ai#9475, where JPPhoto raised both as merge blockers; this branch shares the listener and the completion handler. - The board/view probe compared only the active item, so narrowing a multi-selection or re-picking the item already active left it running to overwrite the user's selection. It now compares the whole selection. - An output lost to a transient DTO lookup failure was only recovered if the server happened to re-deliver the completion event, which nothing makes it do. Missing outputs are now refetched at 1s, 3s and 9s, bounded, each attempt taking the same path as a re-delivery so landed outputs are untouched and the global side effects are not re-run.
…al-item-owned The bounded output refetch moved down into invoke-ai#9475, where JPPhoto raised it as a merge blocker, so this branch no longer introduces it — it inherits it, along with the probe-cancellation fix. The only conflict was the test file's import: this branch replaced the auto-switch marker module with the selection descriptor, so the descriptor's import stands. What this branch still adds on top: the item-owned reveal state machine, the selection generation token, and gating a reveal on the item's media having painted.
|
Both blockers fixed at Probe cancellation compared only the active itemConfirmed, and your test recipe is the clearest statement of it: It now compares the whole selection. The state is immutable, so a new array reference is exactly "the selection was written" — which covers narrowing, re-selection, and any writer added later — and cancelling a probe more often than strictly necessary costs nothing. Your sequence and the re-selection variant are both tests, and both fail against the active-item comparison. An output lost to a failed lookup only retried on a duplicateConfirmed. Nothing re-emits a completion event, so "wait for a duplicate" meant, in practice, that the image was absent from the gallery and the board counts until something unrelated refetched them. You'd already suggested the fix — bounded per-output refetch with backoff — and I had it staged on the follow-up branch; you're right that it belongs here, so I've brought it down. A delivery that leaves outputs missing now refetches exactly those names at 1s / 3s / 9s. Bounded on purpose: an output still missing after that is not coming back from a retry, and the entry is left retryable so a re-delivery can still recover it for free. Each attempt takes the same path as a re-delivery — only the missing names are fetched, the outputs that landed are untouched, the canvas flag and On the other two
#9434 carries the same listener and completion handler and has both fixes as of Suite is 1956 tests with tsc, eslint, prettier, knip and dpdm clean; both fixes mutation-checked rather than trusted green. |
…verlay fix The two PRs had become one change maintained in two branches: three commits existed in both with identical subjects, 9475's marker and completion dedupe were ported byte-identical from 9434, and 9434 had since taken 9475's extracted reveal controller. They conflicted in four files in either merge order, so the split was costing a resolution per round with a standing risk of the two copies drifting. The reveal is resolved to 9475's controller throughout. 9434 carried a stateless getSelectedItemRevealDecision() whose caller managed the previous-item ref, the auto-switch marker and the timer by hand; the controller owns all of it and adds the sequencing 9434's version had no way to express -- resolve-window deferral, the SELECTION_CLEARED sentinel, and the StrictMode re-arm. Every branch the decision function encoded has a counterpart test on the controller. Everything else 9434 contributed to those files is kept: the thumbnail-gated preload (gating on the full-resolution image held a stale latent preview on screen for the whole download), the overlay clear on preload error as well as success, and its onInvocationComplete coverage. CurrentImagePreview's wiring test is rewritten against the controller. Two of its four assertions described the inlined implementation; one is now covered by a real unit test on the controller (the marker is consumed on every rendered-item change even with no progress showing), and the other becomes the same routing check CurrentVideoPreview already carries. The only test dropped without a counterpart asserted that the decision function returned nothing but 'reveal' or 'hide' -- a statement about an API that no longer exists. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The merge resolution replaced invoke-ai#9434's inlined reveal with this branch's controller, and rewrote the wiring test that went with it. That test carried the only assertion on either branch that the component writes $isTemporarilyShowingSelectedImage -- it matched the literal hide path the inlined version had -- and the rewrite dropped it. Nothing else covers it. selectedItemReveal.test.ts substitutes its own setRevealed, so the controller tests are structurally incapable of observing the atom, and CurrentVideoPreview's assertions are all on the read side (withProgress, the metadata gate). Neither component is ever mounted: this directory has no DOM test environment. An adversarial review of the merge proved the gap by replacing setRevealed with a no-op in both previews: all 26 assertions across the two wiring tests still passed, and so did the full suite, with the reveal completely dead -- a mid-render gallery click doing nothing, which is the bug both PRs exist to fix. Both tests now fail against that mutation. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…into the reveal machine invoke-ai#9475 absorbed invoke-ai#9434, so this branch picks up invoke-ai#9434's thumbnail-gated preload, its error-path overlay clear and its onInvocationComplete coverage, all of which merge cleanly onto the machine. One conflict, in CurrentVideoPreview's wiring test: invoke-ai#9475 gained an assertion that the reveal is actually connected to $isTemporarilyShowingSelectedImage, after an adversarial review showed the whole suite stayed green with that wiring replaced by a no-op. Carried forward against this branch's shape — the machine is built once in context.tsx for both previews, so the check moves there and is made once rather than per component. CurrentImagePreview's wiring test arrived from the merge still describing the controller this branch replaced, and is rewritten against the machine: sync, the item-named readiness, attach, and negative assertions that none of the three superseded implementations survive beside it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Consolidated: this PR now contains #9434, which is closed in favour of it. The description is The short version: the reveal resolves to this branch's controller throughout. #9434 carried a An adversarial review of the resolution found one thing, and it was mine: the rewritten wiring test One rule from #9434 deliberately did not survive, documented in the description: two changes of the #9520 is rebased on this and stays stacked; it is ~690 lines of restructuring on top. |
JPPhoto
left a comment
There was a problem hiding this comment.
Merge blockers:
-
invokeai/frontend/web/src/services/events/onInvocationComplete.tsx:92-94,567-587: retry timers survive socket/auth teardown;setEventListeners.tsx:77-82anduseSocketIO.ts:96-107provide no disposal. A stale callback can fetch old output through the current store and mutate the new session's gallery/board caches. Effect: cross-session or foreign-content contamination. Likelihood: plausible during logout, account switch, or reconnect within 13 s. Recovery: reload or refetch caches. Test: fail the first DTO lookup, replace auth/socket, advance timers, assert no old fetch or dispatch. -
invokeai/frontend/web/src/features/gallery/components/ImageViewer/selectedItemReveal.ts:151-155: first rendered item is always suppressed whenlastRenderedItemNameRefis null. With progress visible, a normal first click selecting a video from an empty viewer therefore leaves the video behind the overlay. Effect: core video reveal path fails on first use. Likelihood: normal when generation is active before any item was rendered. Recovery: select another item or reopen the viewer. Test: mount with null prior render, select a video during progress, assert the temporary overlay is cleared.
Other findings/issues:
-
invokeai/frontend/web/src/features/gallery/components/ImageViewer/CurrentVideoPreview.tsx:125-150,393-435: reveal timing starts fromvideoName, beforeloadeddataorcanplay;preload="metadata"and near-zero seeking do not prove a decoded frame exists. Effect: slow videos can reveal as black/blank, then re-cover after the timer. Likelihood: plausible on slow storage/network or large videos. Recovery: wait for load, then reselect. Test: delay media readiness beyond the reveal timeout and assert the overlay remains cleared only after a frame is ready. -
invokeai/frontend/web/src/services/events/onInvocationComplete.tsx:123-155,180-201: retry success unconditionally increments cached board totals, even if another refresh or delivery already inserted the output during the retry window. Name-list insertion dedupes, but board counts do not. Effect: stale or doubled board image counts until refetch. Likelihood: plausible during the 1-13 s retry window. Recovery: board refetch or reload. Test: prepopulate the output in board caches, run a failed lookup followed by retry success, assert totals remain unchanged.
Corner/impossible cases to note:
invokeai/frontend/web/src/services/events/onInvocationComplete.tsx:81-88,567-585: the 1000-entry LRU can evict a retry state before its timer fires; the callback then silently returns. Effect: bounded retry recovery is skipped and output remains absent. Likelihood: rare high-throughput/replay burst. Recovery: manual refetch or duplicate completion. Test: schedule a retry, process over 1000 distinct completions, advance the timer, assert the retry still runs.
Suggestions:
-
Instead of shared
lastRenderedItemNameRefplus timing guards: use per-sessionidle,resolving(item_id), andlive(item_id)states with an explicit selection-generation token. Add media-readiness state to distinguish initial render, user selection, auto-switch, rapid A/B/A, and decoded-frame availability. -
Instead of leaving retry timers attached to an obsolete socket handler: return a disposer from
setEventListeners, cancel timers during socket/auth teardown, and attach retries to an auth/session generation. -
Instead of unconditional retry count updates: make board-total updates idempotent against current cached membership or perform one authoritative invalidation after delivery.
-
Instead of starting video reveal from
videoName: gate reveal onloadeddataorcanplay, with a bounded fallback for media that never becomes ready.
…t click Two merge blockers and two findings from JPPhoto's fifth round. Scheduled refetches survived socket and auth teardown. The timers close over an event from the session that scheduled them but dispatch into whatever store is current when they fire, so a logout, account switch or reconnect inside the 13s window would fetch the old session's output and insert it into the new session's gallery and board caches. setEventListeners now returns a disposer, and useSocketIO calls it before disconnecting. The reveal suppressed the first item the viewer ever rendered, on the grounds that the viewer opening onto an existing selection is not a click. But a viewer sitting empty while a generation runs is a state the user has been shown, and their first click there is a click like any other — it was landing behind the overlay. An empty selection now records the cleared-selection sentinel whether or not anything rendered before, so that click reveals while the open-onto-a-selection render still does not. Also, since this is the third round it has come up: the video reveal no longer starts its two seconds at mount. preload="metadata" and the near-zero seek do not prove a frame exists, so the reveal could run out over a black element and then re-cover it. The controller now holds the claim until the item reports a decoded frame (onLoadedData), bounded by a 1s grace so media that never loads still makes the click land. Readiness is reported as *which* item has painted rather than a boolean, because a boolean would be reset from a different effect than the one that reads it. And retry success no longer bumps cached board totals: seconds after the fact another refresh may already have inserted the output, and unlike the name-list insert those increments do not dedupe. A retry now asks the server for the affected boards instead.
…etry Carried from invoke-ai#9475, where JPPhoto raised the first as a merge blocker; this branch shares the completion handler. - Scheduled refetches survived socket and auth teardown. They close over an event from the session that scheduled them but dispatch into whatever store is current when they fire, so a logout or account switch inside the retry window would insert the old session's output into the new session's caches. setEventListeners returns a disposer now, and useSocketIO calls it before disconnecting. - Retry success no longer bumps cached board totals: by then another refresh may already have inserted the output, and unlike the name-list insert those increments do not dedupe. A retry asks the server for the affected boards instead.
|
All four addressed at Blocker — retry timers survive socket/auth teardownConfirmed, and worse than "stale fetch": the timer closes over an event from the session that scheduled it, but
Blocker — the first rendered item is always suppressedConfirmed. The rule existed for the render that happens when the viewer opens onto an existing selection, which is not a click — but a viewer sitting empty while a generation runs is a state the user has already been shown, so their first click there is a click like any other, and it was landing behind the overlay. An empty selection now records the cleared-selection sentinel whether or not anything rendered before it. That distinguishes the two: "nothing has ever rendered" still suppresses, "the viewer showed you nothing, and now you picked something" reveals. Both directions are tests. Video reveal starting before a frame existsYou've raised this three times and I kept pointing at the follow-up branch; that was the wrong call, so it's fixed here. The controller now holds the claim instead of spending the two seconds: a reveal is owed when the selection lands and shown when the item reports a decoded frame ( Readiness is reported as which item has painted, not a boolean — a boolean is reset from a different effect than the one that reads it, and a passive effect's Retry success double-counting board totalsConfirmed. Seconds after the fact another refresh or delivery may already have inserted the output; the name-list insert dedupes, the board totals are blind increments and do not. A retry now asks the server for the affected boards instead of bumping the cache — retries are rare enough that one authoritative refresh beats making every optimistic update idempotent. Corner case: LRU eviction before the timer firesFixed too, since it was cheap: the missing names are captured in the timer's closure rather than read back from the LRU, so an eviction can no longer turn the refetch into a silent give-up. If the entry survives and says the work is done, the timer still stands down. Suite is 1947 tests with tsc, eslint, prettier, knip and dpdm clean; every fix above mutation-checked rather than trusted green. #9434 carries the shared handler and socket-teardown changes as of |
JPPhoto
left a comment
There was a problem hiding this comment.
Merge blockers:
invokeai/frontend/web/src/services/events/onInvocationComplete.tsx:563-581,660-665: teardown clears queued timers only; pending DTO deliveries continue and can schedule new retries after disposal.setEventListeners.tsx:1049-1051has no closed/session guard. Effect: old-session DTOs can mutate the new user's gallery and board caches. Likelihood: plausible logout/account switch during a DTO request. Recovery: reload/refetch. Test: hold DTO lookup pending, call disposer, resolve failure, advance timers; current code performs a second lookup.
Other findings/issues:
invokeai/frontend/web/src/services/events/setEventListeners.test.ts:1-24: replaces the prior 644-line executable socket integration suite with two source-text checks. Workflow invalidation, queue cancellation, own/foreign routing, and node/progress isolation now have no runtime coverage. Effect: listener regressions can pass CI. Likelihood: every future edit to this shared listener, including this PR's lifecycle changes. Recovery: restore behavior-level socket tests. Test: retain a mock socket and trigger representative workflow, queue, foreign-event, and teardown paths.
Another corner/impossible case that can probably be left alone:
invokeai/frontend/web/src/services/events/onInvocationComplete.tsx:648-650: every retryable duplicate callsrunTrackedDelivery(..., 0), resetting backoff. A persistent duplicate stream during DTO outage can start 1 s retry chains indefinitely. Effect: unbounded request/cache-invalidation load while output remains missing. Likelihood: rare replay/duplicate stream. Recovery: stops only when duplicates stop or page reloads. Test: repeatedly emit the same failed completion before each retry and assert globally bounded attempts.
Suggestions:
-
Instead of clearing only timer handles: mark the handler disposed with a session generation, check it before and after every await and before
scheduleRetry, and abort in-flight RTKQ requests where possible. -
Instead of source-string teardown checks: restore executable socket fixtures and test pending-lookup disposal, event routing, queue invalidation, and cross-user isolation.
-
Instead of resetting retry attempt to zero for every duplicate: preserve per-invocation attempt state while allowing one duplicate to supersede its queued timer.
… socket suite Restores services/events/setEventListeners.test.ts, which I destroyed in b874b90: I wrote the file without checking it existed, and its 644 lines of executable socket coverage — workflow invalidation, queue cancellation, own/foreign routing, cross-user isolation — went with it, replaced by two source-string checks. The suite is back, and the teardown it needed is now an executable test in it rather than a grep: the mocked handler carries a dispose(), and the disposer setEventListeners returns is asserted to call it. The blocker behind that test: disposal only cleared queued timers. A DTO request already in flight came back afterwards, dispatched into whatever store had replaced the old one, and scheduled fresh retries against it — so a logout or account switch during a lookup could put one user's output in the next user's gallery. The handler now knows it has been disposed and checks after every await: nothing already fetched is dispatched, nothing new is scheduled, and an event delivered after teardown does nothing at all. Also, a duplicate delivery restarted the backoff from one second, so a stream of duplicates during an outage could keep starting fresh chains — the bound existed but nothing was bounded by it. The attempt count lives on the retry state now, and a duplicate resumes the chain where it had got to.
… socket suite Carried from invoke-ai#9475, where JPPhoto raised both; this branch shares the completion handler and the socket listeners. - setEventListeners.test.ts is restored: I destroyed its 644 lines of executable socket coverage by writing the file without checking it existed. The teardown assertion that replaced it is now an executable test inside the restored suite. - Disposal only cleared queued timers, so a DTO request already in flight came back afterwards and dispatched into whatever store had replaced the old one. The handler now knows it is disposed and checks after every await. - A duplicate delivery restarted the backoff from one second; the attempt count lives on the retry state now, so a duplicate resumes the chain.
|
All three addressed at The deleted socket suite — my mistake, and thank you for catching itYou're right, and it was worse than a trade-off: I wrote The suite is restored intact, and the teardown coverage that motivated the file is now inside it as an executable test rather than a grep: the mocked completion handler carries a Blocker — disposal only stopped queued timersConfirmed, exactly as you described: the timer handles were cleared, but a DTO request already in flight came back afterwards, dispatched into whatever store had replaced the old one, and scheduled fresh retries against it. The handler now knows it has been disposed and checks that after every await, not just before starting: an output fetched for the ended session is not dispatched, no retry is scheduled for it, and an event delivered after teardown does nothing at all. Your test recipe is one of the three new cases — hold the lookup pending, dispose, resolve the failure, advance: no second lookup, and nothing left armed. That last assertion is checked before advancing the clock, since a timer armed and then fired reads as "no timer" afterwards. I did not go as far as aborting in-flight RTKQ requests. The guard makes their results inert, which covers the effect you named; cancelling the requests themselves would be a change to Backoff reset by duplicatesFixed rather than left alone — you were right that it makes the bound meaningless, and the fix is small. The attempt count lives on the retry state now, so a duplicate resumes the chain where it had got to instead of starting a fresh one at one second. A stream of duplicates through an outage gets one shared chain of three attempts, not three per duplicate. Worth noting my first attempt at this did not work: I stored the attempt count from the pass doing the delivering, which for a duplicate is zero, so it overwrote the very thing it was meant to preserve. The mutation check caught it — the test passed against both the fix and its absence until I made the duplicates arrive after each retry fired, which is the shape you described. Suite is 1972 tests with tsc, eslint, prettier, knip and dpdm clean. #9434 carries the same changes as of |
…xt round A fresh adversarial pass over 042350c, done deliberately before the reviewer's next round, converged on his known categories. - An in-flight delivery disposed mid-fetch still ran $lastProgressEvent.set(null) after the gallery guards returned. That store is module-global across handler sessions, so a stale delivery resolving after a logout or account switch blanked the progress event the new session had put there. Guarded, and the disposal test now asserts the store is never touched. - The DTO fetch loops kept issuing lookups after disposal — requests under the replacement session's credentials, cache writes into its store. Both loops now stop. - Three load-bearing pieces had no test that failed without them, and test-insensitivity is where review rounds keep coming from: - the video path's post-fetch disposal guard (every disposal test used image events; its mutation survived the whole suite); - the reveal controller's resolve-window hold for an unpainted claim (deleting it silently re-created the swallowed-click failure); - the settle-listener registration in store.ts (every listener test builds its own store; deleting the registration failed nothing). Each now has a test pinned via mutation from a verified cwd — two of this session's mutation runs previously "passed" by running against a path that did not exist.
…9475 Carried across; this branch shares the completion handler. - A delivery disposed mid-fetch still blanked the module-global $lastProgressEvent, wiping the next session's progress event. - The DTO fetch loops kept issuing lookups after disposal. - The video path's post-fetch disposal guard and the store.ts settle-listener registration had no test that failed without them; both are now pinned by mutation. This branch keeps its pure reveal decision (the controller lives on invoke-ai#9475); only the handler, its tests, and the store wiring test carry.
JPPhoto
left a comment
There was a problem hiding this comment.
To fix:
invokeai/frontend/web/src/features/gallery/components/ImageViewer/CurrentImagePreview.test.ts:8-10andinvokeai/frontend/web/src/features/gallery/components/ImageViewer/CurrentVideoPreview.test.ts:6-12,15-86: tests inspect source text, not mounted components or real media/effect lifecycles. Effect: wiring/order regressions can leave the overlay or reveal broken while tests pass. Likelihood: normal future refactor. Recovery: manual browser repro. Test: add DOM/browser integration coverage for preload, media events, context swaps, and unmount.
Corner/impossible cases that can likely be ignored:
invokeai/frontend/web/src/services/events/onInvocationComplete.tsx:103,664-698: after 1000 distinct completion keys, an older dedupe entry can be evicted; a delayed duplicate then repeats gallery work, board-count increments, and auto-switch. Effect: duplicate UI/state. Likelihood: rare long-lived session or replay burst. Recovery: refetch gallery and board data. Test: process 1001 unique completions, replay the first, assert no second delivery.
Suggestions:
-
Instead of source-string preview checks, use a mounted DOM/browser harness or a tested component adapter.
-
Instead of a fixed 1000-entry LRU as the sole duplicate guard, retain completion identity through the replay window or make gallery and board updates idempotent.
…or it JPPhoto's round-7 finding, and a fair one: the preview components' tests inspected source text, so a wiring or ordering regression could leave the overlay or the reveal broken with every test green. The package had no DOM test environment at all. The wiring the two components shared — one controller per mount, run on every input change with a cleanup that cancels only the timer, the flag lowered on unmount — moves into useSelectedItemReveal, and the video's painted-name readiness into usePaintedItemName beside it. Both components become a hook call; the hook is mounted under happy-dom (new dev dependency) with real effect lifecycles and mutation-verified coverage for exactly the things source text cannot see: - the image -> video component swap over the shared ref, including the outgoing component's timer being cancelled before it can cut the incoming reveal short; - unmount lowering the flag with no timer left to re-raise it; - StrictMode's double-invoked effects; - readiness driven by a real <video> element's loadeddata event, and reset when the element is swapped for another video. The remaining source-text assertions shrink to what they are good for: pinning that the components actually call the tested hook, with the right readiness expression on each path.
|
Addressed at Source-text tests → mounted DOM coverageYou're right, and this was the standing debt I'd been flagging each round: the package had no DOM test environment at all, so the component tests could only grep. Fixed via the adapter route you suggested:
The remaining source-text assertions shrink to the one thing they're good for — pinning that the components actually call the tested hook, with the right readiness expression per path (preload-settled for images, What this does not cover, stated plainly: the full components still aren't mounted — their dnd/hotkeys/toast dependencies make that a project-infrastructure decision rather than a PR-sized one. The hook boundary means a component-level regression is now limited to "stopped calling the hook / fed it the wrong expression", which the residual text checks pin. The LRU eviction cornerAgreed it can wait, and one note for the record: the retry path no longer depends on the entry surviving (the scheduled refetch captures its missing names at schedule time), and retry-path board totals are already server-authoritative rather than incremented. What remains exposed to a post-eviction replay is a first-delivery re-run — your "retain completion identity through the replay window" is the right shape for that, and I'd fold it into the same follow-up as making the optimistic inserts idempotent, rather than grow this PR further. Suite is 1984 tests with tsc, eslint, prettier, knip and dpdm clean. |
Summary
During a render, the viewer is effectively locked. The progress-preview overlay is opaque and
sits on top of the selected media; gallery clicks change the selection underneath, but nothing
visibly happens until a tab switch remounts the viewer panel. Found while chaining Wan i2v renders
with a gallery full of videos: every click during a multi-minute render is silently swallowed.
Note
This PR now also contains #9434 (viewer progress-image handoff), which is closed in favour of
this one. The two had converged into a single change maintained in two branches — three commits
existed in both with identical subjects, this branch's auto-switch marker and completion dedupe
were ported byte-identical from #9434, and #9434 had since adopted this branch's extracted reveal
controller. They conflicted in four files in either merge order, so the split was costing a
resolution per review round with a standing risk of the two copies drifting. Sections 5–7 below
are #9434's; its review history is on that PR.
1. Videos never got the temporary reveal
CurrentImagePreviewlifts the overlay for 2 s when the user clicks a thumbnail mid-render(#9217).
CurrentVideoPreviewshowed the overlay unconditionally whenever a progress imageexisted. The reveal is now ported: the clicked video appears (first frame + play button) for 2 s,
then the live preview returns. An actively-playing video is never re-covered — an explicit play is
a stronger signal than the click that revealed it, and re-covering would leave audio running under
an opaque overlay with unreachable controls. The overlay returns when the player is closed.
2. Media-type switches reset the reveal's memory
The reveal fires on a change of rendered item. That previous-item tracking was a per-component
ref, but image↔video clicks swap the mounted preview component, so the ref reset and the first
reveal after every type switch was swallowed. The ref now lives in the shared
ImageViewerContext.3. An auto-switch to a finished item read as a user click
The reveal fires on any change of the selected item, so an auto-switch to a just-finished render
hid the next render's live preview for 2 s. The auto-switch selection is dispatched only after
onInvocationComplete's DTO fetch, so a quickly-started next render's first progress event canland ahead of it and reset
$isProgressImageResolving— timing cannot distinguish the handoff froma click. Fixed by identity: the gallery records the name it is auto-switching to and the reveal
consumes it on that item's first render. The marker is scoped to the selection it was recorded
for, settled by a redux listener matching on state change rather than action type, so an
auto-switch that never renders is dropped the moment the selection moves on and can never swallow
a genuine later click on the same item.
4. Multi-GPU: concurrent sessions overwrote each other's video preview
CurrentImagePreviewtiles per-session previews when more than one render runs concurrently; thevideo overlay only ever rendered the single shared latest preview, so parallel sessions overwrote
each other's frames in place. The tiles branch is now ported, mirroring the image viewer.
5. The reveal was slow (from #9434)
CurrentImagePreviewgated rendering behind an off-DOM preload of the full-resolution PNG (oftenseveral MB), and only that
onLoadcleared the overlay — so the stale latent preview stayed onscreen for the entire download. A 256px WEBP thumbnail already exists for every image and is
typically higher resolution than the latent preview it replaces; the reveal is now gated on it,
and
DndImageswaps the full image in, in place, once it finishes.The preload also used the raw
imageDTO.image_urlwhileDndImagerequestsuseMediaUrl(imageDTO.image_url), which appends a media-cookie version — a different key, so thesame bytes were fetched twice (measured: 2 requests when the URLs differ, 1 when they match). The
reuse here is the document's list of available images, keyed by URL and not the HTTP cache, so it
still holds in multiuser mode where images are served
Cache-Control: private, no-store.6. A failed preload wedged the overlay (from #9434)
The preload now settles on success or error and reports through the lifecycle's identity-gated
onLoadImage(sessionId), so a failed load cannot wedge the overlay and a late-settling thumbnailfrom an earlier session cannot cut a different session's resolve illusion short.
7. Duplicate
invocation_completedeliveries re-ran the gallery work (from #9434)A duplicate completion double-counted the optimistic board totals and re-dispatched the auto-switch.
The handler now tracks processed invocations itself and returns before any gallery work on a
duplicate, marking the key before the DTO-fetch await so a duplicate landing mid-flight is rejected
too. The shared
completedInvocationKeysByItemIdmap could not be used: the workflow coordinatorpre-marks first-delivery events for non-active workflow items, so keying the early return off it
would have skipped gallery work for legitimate queued workflow completions.
How the merge was resolved
Four files conflicted; all four resolved toward this branch's reveal controller.
#9434 carried a stateless
getSelectedItemRevealDecision()whose caller managed the previous-itemref, the auto-switch marker and the timer by hand.
createSelectedItemRevealControllerowns all ofthat and adds sequencing the decision function had no way to express: the resolve-window deferral
(a click landing inside the window keeps its identity until the window ends, so it can still be
revealed), the
SELECTION_CLEAREDsentinel (re-selecting the item that was just cleared is aclick, and must reveal), and the StrictMode re-arm. Those are the two "inherited holes" an earlier
revision of this PR listed as open — they are fixed here, not deferred.
Everything else #9434 contributed to the conflicted files is kept: the thumbnail-gated preload, the
error-path overlay clear, and its
onInvocationCompletecoverage.CurrentImagePreview's wiringtest is rewritten against the controller; of its four assertions, one is now covered by a real unit
test on the controller (the marker is consumed on every rendered-item change even with no progress
showing) and one became the routing check
CurrentVideoPreviewalready carries. The only testdropped without a counterpart asserted that the decision function returned nothing but
'reveal'or
'hide'— a statement about an API that no longer exists.Every behavior that had a test on either branch still has one: the merged tree's test inventory is a
superset of both sides apart from those ten titles, nine of which were checked individually against
their counterparts.
One rule did not survive, deliberately. The controller's resolve-window deferral preserves a
single deferred identity, so two changes of the rendered item entirely inside one resolve window
that end back on the item showing when the window opened read as "nothing changed" and do not
reveal; #9434's function would have revealed. Its answer was right for the wrong reason — the ref
had advanced only because that version overwrote it unconditionally, which is the bug that lost the
first click in the far more common single-change case. The window is bounded by
RESOLVE_TIMEOUT_MS(3 s) and the sequence needs an intervening null render, so the controller'sbehavior is kept.
One coverage hole the merge opened, now closed. The rewritten wiring test dropped #9434's only
assertion that the component writes
$isTemporarilyShowingSelectedImage, and nothing else coversit: the controller's tests substitute their own
setRevealed,CurrentVideoPreview's assertionsare all on the read side, and neither component is ever mounted. Replacing
setRevealedwith ano-op in both previews left all 26 wiring assertions — and the full suite — green with the reveal
completely dead. Both wiring tests now fail against that mutation.
Review
Fresh-context adversarial reviews attacked the atom lifecycle (unmount-order interleavings on
preview-component swaps, cross-component stale timers, stuck-ON reveal), the shared ref (preload
lag, rapid A→B→A clicks, deselect paths), the auto-switch registry (unconsumed entries,
wrong-render consumption, TTL/bound edges), the error-handler clear, and — separately — the merge
resolution itself, hunting for a fix that vanished with the side it came from.
Stacked on this
#9520 refactors the reveal into an item-owned state machine on top of this branch. It is
review-ready but should land after this one; its diff is this PR plus ~660 lines of restructuring.
Testing
pnpm lint(tsc, eslint, prettier, dpdm) and the fullvitestsuite are clean on the merged tree.