Repository navigation
Studio Images: preserve gallery selections during generation - #17719
Conversation
…om the live preview
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 032cd814ca
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| () => stripEpoch.current === epoch, | ||
| ).catch(() => void loadGallery()); |
There was a problem hiding this comment.
Retry completion refreshes after concurrent shelf mutations
If a user pins an image while the last post-generation refresh is in flight, handleTogglePin increments stripEpoch, causing resyncWindow to return without applying the generated records. That is a normal return, so this .catch never retries; the successful pin path also does not resync, and useImageQueue will not report the same completed job again. The newly saved image can consequently remain missing from the strip until another completion or reload. Preserve the former loadGallery/fetchWhileStable retry behavior when a completion refresh is invalidated.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 1074fe9: resyncWindow now reports whether it applied, and refreshLoadedGallery retries up to PAGE_MAX_ATTEMPTS when a strip mutation discards it, waiting for the image-pin queue first so the retry cannot snapshot the shelf before the pin.
| let ended = false; | ||
| while (!ended) { | ||
| const keep = selectedId(); | ||
| const reach = keep ? count + pageSize : count; |
There was a problem hiding this comment.
Retire missing selections before extending the window again
If the selected image is deleted through Library, selected visually falls back but galleryCache.selectedId remains the deleted ID. With more unloaded records available, this refresh fetches one extra page and stores it in galleryCache.images; resyncWindow then uses that enlarged length as the next count. Consequently every subsequent completion refresh grows the window again (100 → 150 → 200 → …), eventually refetching the entire gallery for every queued job. Retire the missing selection after the bounded search, or avoid including spillover pages in the next base window size.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in f393f5c: collectGalleryWindow now looks past the window only for a selection the previous strip held, so a selection deleted elsewhere costs one extra page on the next refresh and none after.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1074fe9767
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| stripEpoch.current += 1; | ||
| void loadGallery(); | ||
| } | ||
| if (finished.some((job) => job.status === "done")) refreshLoadedGallery(); |
There was a problem hiding this comment.
Stop superseded completion refreshes between page requests
When many strip pages are loaded and queued jobs finish faster than the window can be refetched, this new completion path starts overlapping full-window reads. Each newer refresh invalidates the previous one, but resyncWindow checks freshness only after collectGalleryWindow finishes fetching every page. A 5,000-record window therefore still issues all 100 GETs even when invalidated during its first request. Since image_gallery.list_images also walks preceding records for each offset, long queues can accumulate substantial redundant server and network work. Pass the freshness check into the collector and stop superseded reads between page requests.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in d7e5577: collectGalleryWindow takes a stillFresh check and returns null after the first request that finds it false, and resyncWindow passes its own ticket and the caller's check, so a superseded refresh stops between pages.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7e55777c7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const epoch = stripEpoch.current; | ||
| void resyncWindow( | ||
| galleryCache.images.length, | ||
| () => stripEpoch.current === epoch, | ||
| ).catch(() => void loadGallery()); | ||
| }), | ||
| [loadGallery, resyncWindow], | ||
| ); | ||
| const fresh = () => stripEpoch.current === epoch && refreshSeq.current === ticket; | ||
| if (await resyncWindow(galleryCache.images.length, fresh)) return; |
There was a problem hiding this comment.
Wait for pending shelf mutations before collecting the window
With multiple strip pages loaded, a completion refresh that starts after handleArchive or handleDelete has sent its request snapshots an epoch that already includes the mutation's start. If the server removes the row between page GETs while the mutation response is delayed, every freshness check passes and the collector skips the shifted boundary record. When the response finally arrives, dropFromStrip only removes the affected ID, leaving a noncontiguous cache whose loadMore offsets keep skipping the other image. Wait for pendingShelfMutations to settle before collecting and applying this window.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. The skip needs the server to remove the row between two of the refresh's page GETs and the remaining GETs, each a full scan of the gallery directory, to finish before that same delete's response reaches the page. If the response arrives first, dropFromStrip bumps stripEpoch and the refresh retries. resyncWindow already has this exposure on main for unpin and archive restore.
| statusKnown: generateProbed && imageQueue.polled, | ||
| generating: busy === "generating", | ||
| queueBusy: queueBusy(imageQueue.jobs), |
There was a problem hiding this comment.
Retain the pick until pending queue submissions are observed
If a direct run finishes while handleQueue is still enqueueing jobs or awaiting its follow-up refresh, the last queue snapshot can still be idle even though the server has accepted the next job. Both probe flags remain true, so clearing busy makes this branch clear pickedDuringRun. When the queue response then arrives and the page follows that job, the live preview takes over from the image picked during the preceding run. Keep the pick while a queue submission is unobserved, or require an idle observation newer than that submission.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. handleQueue awaits the enqueue POSTs and then imageQueue.refresh(), so the direct run would have to finish inside that one POST plus one GET. The only effect is that the stage returns to the live preview while the pick stays selected in the strip, one click away.
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Problem
While a generation runs with live preview on, the Images page stage always shows the live preview. Clicking another image in the strip selects it, but the stage doesn't change, so that image's Recipe and the full-screen viewer can't be opened until the whole queue finishes. Reported in Unsloth Desktop: Bug/Feature Requests on r/unsloth ("having to wait until images queued for generation were completed in order to evaluate other images and their associated recipes").
Cause
livePreviewSrc ? <live preview> : <selected image + toolbar>, andlivePreviewSrcis set wheneverbusy === "generating". A selection never outranks it, and each queued job setsbusyagain.Runsabove 1, each finished run selects its new image, replacing the user's pick.Fix
pickReleasedinlib/generation-queue.ts). A freshly mounted page waits for its first status and queue responses before treating itself as idle.collectGalleryWindowinlib/gallery-window.ts). It re-reads the selection after each request, so a pick made mid-refresh is kept too.Boundaries
Verification
Before and after, main (
7bf13f21c3b) vs this PR, with live preview on.Two queued jobs; an older image is clicked while job 1 runs:
Runs3; the balloon is clicked during run 1, shot while run 2 runs:Live in Studio (Z-Image-Turbo GGUF, RTX 6000 Ada), driven with Playwright:
Runs3, pick during run 1, run 1 finishesEdge cases, checked on this branch:
npm run typecheckpasses. New unit tests coverpickReleasedandcollectGalleryWindow, including the pushed-out selection and a pick during a pending request. The page has no DOM test harness, soimages-gallery-thumbnails.test.tsguards how it wires these rules at the source level.