Repository navigation
feat(assets): adopt cursor pagination in the Generated tab jobs walk - #12769
mattmillerai wants to merge 33 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds cursor-aware Jobs pagination (after cursor with offset fallback), throws JobsApiError on non-OK responses, rewrites assetsStore history paging with cursor state and head-refresh semantics (refreshHistoryHead), and updates callers/tests to use fetchHistoryPage and refreshHistoryHead call shapes. ChangesCursor Pagination & History Refresh
Sequence DiagramsequenceDiagram
participant Component as GraphView/Queue
participant Store as assetsStore
participant API as fetchHistoryPage
participant Jobs as /jobs API
Component->>Store: refreshHistoryHead()
Store->>API: { offset: 0 }
API->>Jobs: GET /jobs?offset=0
Jobs-->>API: { items, has_more, next_cursor }
API-->>Store: FetchHistoryPageResult (items, hasMore, nextCursor)
Store->>Store: mergeHistoryAssets or replaceHistoryWithHeadPage
Store-->>Component: updated history
Note over Store: loadMoreHistory uses cursor when available
Component->>Store: loadMoreHistory()
alt nextCursor available
Store->>API: { after: nextCursor }
else fallback to offset
Store->>API: { offset: lastOffset }
end
API->>Jobs: GET /jobs?after=cursor or offset=N
Jobs-->>API: { items, has_more, next_cursor }
API-->>Store: FetchHistoryPageResult
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 6 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (5)
src/platform/remote/comfyui/jobs/fetchJobs.ts (1)
68-70: 💤 Low valueConsider including status text in error message for easier debugging.
Adding
res.statusTextwould provide more context when investigating failures (e.g., distinguishing "400 Bad Request" from "400 INVALID_CURSOR").♻️ Suggested improvement
if (!res.ok) { - throw new Error(`[Jobs API] Failed to fetch jobs: ${res.status}`) + throw new Error(`[Jobs API] Failed to fetch jobs: ${res.status} ${res.statusText}`) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/platform/remote/comfyui/jobs/fetchJobs.ts` around lines 68 - 70, Update the error thrown on non-OK responses in the fetchJobs flow so it includes both res.status and res.statusText for better context; locate the check that throws new Error(`[Jobs API] Failed to fetch jobs: ${res.status}`) (in src/platform/remote/comfyui/jobs/fetchJobs.ts / the fetchJobs handler) and change the message to include res.statusText (e.g., combine status and statusText into the thrown Error message) so failures show both numeric code and human-readable status.src/views/GraphView.test.ts (1)
103-107: ⚡ Quick winAdd behavioral assertions for the new history-refresh path.
This mock shape update is necessary, but the suite still doesn’t verify that
status/execution_successflows callassetsStore.refreshHistoryHead()
under the assets-open or linear-mode conditions introduced inGraphView.vue.
Please add focused event-path tests so this integration can’t regress silently.As per coding guidelines,
src/**/*.test.tsshould “write tests for all
changes, especially bug fixes to catch future regressions” and aim for
behavioral coverage of critical/new features.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/views/GraphView.test.ts` around lines 103 - 107, The test suite currently mocks useAssetsStore but lacks assertions that the new history-refresh code path in GraphView.vue calls assetsStore.refreshHistoryHead; add focused behavioral tests in GraphView.test.ts that simulate the two event flows (status change and execution_success) under the two relevant conditions (assets-open and linear-mode) and assert that the mocked refreshHistoryHead() is called (and not called when conditions are false). Locate and extend the existing mocked useAssetsStore (updateHistory and refreshHistoryHead) and add tests that trigger the component events or lifecycle/state changes used by GraphView (e.g., emitting the status/execution_success events or toggling the assets-open/linear-mode flags) and verify refreshHistoryHead was invoked the expected number of times.Source: Coding guidelines
src/stores/assetsStore.test.ts (1)
30-47: 💤 Low valueConsider using a function declaration for the helper.
Per coding guidelines, prefer function declarations over function expressions for pure functions. This helper could be declared as:
-const mockHistoryPage = ( - jobs: JobListItem[], - { - hasMore = false, - nextCursor, - offset = 0, - total = jobs.length, - limit = 200 - }: Partial<Omit<FetchHistoryPageResult, 'jobs'>> = {} -): FetchHistoryPageResult => ({ - jobs, - total, - offset, - limit, - hasMore, - nextCursor -}) +function mockHistoryPage( + jobs: JobListItem[], + { + hasMore = false, + nextCursor, + offset = 0, + total = jobs.length, + limit = 200 + }: Partial<Omit<FetchHistoryPageResult, 'jobs'>> = {} +): FetchHistoryPageResult { + return { + jobs, + total, + offset, + limit, + hasMore, + nextCursor + } +}Based on learnings: "Prefer pure function declarations over function expressions (e.g., use function foo() { ... } instead of const foo = () => { ... }) for pure functions in the repository."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/stores/assetsStore.test.ts` around lines 30 - 47, The helper is defined as a const arrow function (mockHistoryPage) but the repo prefers pure function declarations; change the arrow function to a named function declaration (function mockHistoryPage(jobs: JobListItem[], opts: Partial<Omit<FetchHistoryPageResult, 'jobs'>> = {}) : FetchHistoryPageResult) preserving the same parameter defaults and return structure (jobs, total, offset, limit, hasMore, nextCursor) and keep types JobListItem and FetchHistoryPageResult intact so callers/tests remain unchanged.Source: Learnings
src/stores/assetsStore.ts (2)
157-178: 💤 Low valueConsider binary search for sorted insertion.
The current implementation uses
findIndex(O(n)) for each insertion, resulting in O(n·m) complexity. Since the list maintains sorted order bycreated_at, a binary search would reduce this to O(m·log n). Additionally, the repeatednew Date()calls insidefindIndexcreate many short-lived objects.This is acceptable given the MAX_HISTORY_ITEMS=1000 bound, but could be optimized if refresh latency becomes noticeable.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/stores/assetsStore.ts` around lines 157 - 178, mergeHistoryAssets currently uses findIndex with repeated new Date() calls, giving O(n·m) behavior and many short-lived Date objects; replace the linear search with a binary search over allHistoryItems.value (which is sorted by created_at) to compute insertIndex in O(log n), and convert each asset.created_at and existing item.created_at to timestamps once (e.g., const assetTime = +new Date(asset.created_at ?? 0)) to avoid repeated Date construction; keep skipping duplicates via loadedIds and maintain the same push/splice logic (use the computed insertIndex === -1 meaning append) and respect MAX_HISTORY_ITEMS if applicable.
335-335: Fix:job.idmatchesasset.idfor this overlap check
loadedIdsis populated withAssetItem.idfrommapHistoryToAssets, andmapTaskOutputToAssetItemsetsid: taskItem.jobId;TaskItemImpl.jobIdis derived directly fromjob.id, sopage.jobs.some(job => loadedIds.has(job.id))compares the same id space.The only reason
reachesLoadedItemscould befalsedespite overlap is filtering:mapHistoryToAssetsonly addscompletedjobs that havepreview_output, whilepage.jobsincludes other terminal statuses/jobs.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/stores/assetsStore.ts` at line 335, reachesLoadedItems is false due to mapHistoryToAssets only adding AssetItems for completed jobs with preview_output, so loadedIds lacks IDs for other terminal jobs present in page.jobs; update mapHistoryToAssets (and/or mapTaskOutputToAssetItem where AssetItem.id is set) to also include terminal jobs from history even if they lack preview_output (or otherwise ensure loadedIds includes job.id for those terminal statuses), so page.jobs.some(job => loadedIds.has(job.id)) correctly detects overlap with TaskItemImpl.jobId/job.id.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/platform/remote/comfyui/jobs/fetchJobs.ts`:
- Around line 68-70: Update the error thrown on non-OK responses in the
fetchJobs flow so it includes both res.status and res.statusText for better
context; locate the check that throws new Error(`[Jobs API] Failed to fetch
jobs: ${res.status}`) (in src/platform/remote/comfyui/jobs/fetchJobs.ts / the
fetchJobs handler) and change the message to include res.statusText (e.g.,
combine status and statusText into the thrown Error message) so failures show
both numeric code and human-readable status.
In `@src/stores/assetsStore.test.ts`:
- Around line 30-47: The helper is defined as a const arrow function
(mockHistoryPage) but the repo prefers pure function declarations; change the
arrow function to a named function declaration (function mockHistoryPage(jobs:
JobListItem[], opts: Partial<Omit<FetchHistoryPageResult, 'jobs'>> = {}) :
FetchHistoryPageResult) preserving the same parameter defaults and return
structure (jobs, total, offset, limit, hasMore, nextCursor) and keep types
JobListItem and FetchHistoryPageResult intact so callers/tests remain unchanged.
In `@src/stores/assetsStore.ts`:
- Around line 157-178: mergeHistoryAssets currently uses findIndex with repeated
new Date() calls, giving O(n·m) behavior and many short-lived Date objects;
replace the linear search with a binary search over allHistoryItems.value (which
is sorted by created_at) to compute insertIndex in O(log n), and convert each
asset.created_at and existing item.created_at to timestamps once (e.g., const
assetTime = +new Date(asset.created_at ?? 0)) to avoid repeated Date
construction; keep skipping duplicates via loadedIds and maintain the same
push/splice logic (use the computed insertIndex === -1 meaning append) and
respect MAX_HISTORY_ITEMS if applicable.
- Line 335: reachesLoadedItems is false due to mapHistoryToAssets only adding
AssetItems for completed jobs with preview_output, so loadedIds lacks IDs for
other terminal jobs present in page.jobs; update mapHistoryToAssets (and/or
mapTaskOutputToAssetItem where AssetItem.id is set) to also include terminal
jobs from history even if they lack preview_output (or otherwise ensure
loadedIds includes job.id for those terminal statuses), so page.jobs.some(job =>
loadedIds.has(job.id)) correctly detects overlap with TaskItemImpl.jobId/job.id.
In `@src/views/GraphView.test.ts`:
- Around line 103-107: The test suite currently mocks useAssetsStore but lacks
assertions that the new history-refresh code path in GraphView.vue calls
assetsStore.refreshHistoryHead; add focused behavioral tests in
GraphView.test.ts that simulate the two event flows (status change and
execution_success) under the two relevant conditions (assets-open and
linear-mode) and assert that the mocked refreshHistoryHead() is called (and not
called when conditions are false). Locate and extend the existing mocked
useAssetsStore (updateHistory and refreshHistoryHead) and add tests that trigger
the component events or lifecycle/state changes used by GraphView (e.g.,
emitting the status/execution_success events or toggling the
assets-open/linear-mode flags) and verify refreshHistoryHead was invoked the
expected number of times.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0a3e3d99-e00b-4a26-b511-1783242969cf
📒 Files selected for processing (11)
src/components/queue/QueueProgressOverlay.vuesrc/platform/missingMedia/missingMediaAssetResolver.test.tssrc/platform/missingMedia/missingMediaAssetResolver.tssrc/platform/missingMedia/missingMediaScan.test.tssrc/platform/remote/comfyui/jobs/fetchJobs.test.tssrc/platform/remote/comfyui/jobs/fetchJobs.tssrc/platform/remote/comfyui/jobs/jobTypes.tssrc/stores/assetsStore.test.tssrc/stores/assetsStore.tssrc/views/GraphView.test.tssrc/views/GraphView.vue
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #12769 +/- ##
==========================================
+ Coverage 80.61% 82.64% +2.03%
==========================================
Files 2292 1942 -350
Lines 118024 112083 -5941
Branches 33639 32296 -1343
==========================================
- Hits 95148 92636 -2512
+ Misses 22324 19105 -3219
+ Partials 552 342 -210
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 357 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Applies verified findings from multi-model review of #12769: - next_cursor accepts null (z.string().nullish()) so a backend serializing absent-as-null can't crash the whole history fetch at the zod boundary - JobsApiError carries the HTTP status and response body; the store's cursor recovery now drops the cursor for the offset fallback only on a 400 (stale/rejected cursor) and only while its walk is still current — transient failures and superseded continuations propagate so a valid cursor is never discarded - an empty page without a cursor is terminal (offset paging cannot advance by zero), while an empty page that still mints a cursor keeps walking - refreshHistoryHead coalesces event bursts into the in-flight refresh plus exactly one trailing refresh, so a job completing mid-refresh is picked up instead of being satisfied by a response dispatched before it existed
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/stores/assetsStore.ts (2)
372-377:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDetect overlap from walked history rows, not only mapped asset IDs.
Line 372 compares raw
job.idvalues againstloadedIds, butloadedIdsis filled only aftermapHistoryToAssets()drops non-preview history rows. If the refreshed head page reaches the already-walked portion through a filtered-out job,reachesLoadedItemsstays false and Lines 373-377 unnecessarily fall back toupdateHistory(), which resets the user's scroll position even though the page already overlaps the loaded window. Track a separate set of walked history job IDs for this check instead.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/stores/assetsStore.ts` around lines 372 - 377, The current overlap check uses loadedIds (populated after mapHistoryToAssets filters out non-preview rows) so reachesLoadedItems can be false when the refreshed page overlaps already-walked rows that were filtered; introduce and maintain a separate set (e.g., walkedHistoryIds) of raw history job IDs as you walk history, use that set instead of loadedIds when computing reachesLoadedItems in the block containing the existing reachesLoadedItems / updateHistory logic, and ensure walkedHistoryIds is kept in sync whenever history is advanced or reset so the overlap detection correctly avoids unnecessary calls to updateHistory().
373-378:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftAvoid clearing the current walk before the restart succeeds.
Line 377 calls
updateHistory(), and that path clearshistoryOffset,historyNextCursor,allHistoryItems, andloadedIdsbefore the fetch runs. If this restart hits a transient error, the oldhistoryAssetslist stays visible but the internal pagination state is already gone, so the nextloadMoreHistory()starts again at offset 0 and can collapse the list back to the first page. Keep the existing walk state until the replacement fetch succeeds, or restore it on failure.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/stores/assetsStore.ts` around lines 373 - 378, The current restart flow in updateHistory() clears historyOffset, historyNextCursor, allHistoryItems, and loadedIds immediately, which can leave UI state inconsistent if the replacement fetch fails; change updateHistory()/the restart path so it first performs the fetch into local/temp variables (e.g., tempOffset/tempCursor/tempAllHistoryItems/tempLoadedIds) without mutating the store, and only replace the store fields (historyOffset, historyNextCursor, allHistoryItems, loadedIds) after the fetch succeeds; on fetch failure, leave the existing store state intact (or explicitly roll back to the previous values) so loadMoreHistory() won't restart from an empty pagination state unexpectedly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/stores/assetsStore.ts`:
- Around line 372-377: The current overlap check uses loadedIds (populated after
mapHistoryToAssets filters out non-preview rows) so reachesLoadedItems can be
false when the refreshed page overlaps already-walked rows that were filtered;
introduce and maintain a separate set (e.g., walkedHistoryIds) of raw history
job IDs as you walk history, use that set instead of loadedIds when computing
reachesLoadedItems in the block containing the existing reachesLoadedItems /
updateHistory logic, and ensure walkedHistoryIds is kept in sync whenever
history is advanced or reset so the overlap detection correctly avoids
unnecessary calls to updateHistory().
- Around line 373-378: The current restart flow in updateHistory() clears
historyOffset, historyNextCursor, allHistoryItems, and loadedIds immediately,
which can leave UI state inconsistent if the replacement fetch fails; change
updateHistory()/the restart path so it first performs the fetch into local/temp
variables (e.g., tempOffset/tempCursor/tempAllHistoryItems/tempLoadedIds)
without mutating the store, and only replace the store fields (historyOffset,
historyNextCursor, allHistoryItems, loadedIds) after the fetch succeeds; on
fetch failure, leave the existing store state intact (or explicitly roll back to
the previous values) so loadMoreHistory() won't restart from an empty pagination
state unexpectedly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f2a718eb-f3b2-40c5-9574-1b85d825c6f6
📒 Files selected for processing (5)
src/platform/remote/comfyui/jobs/fetchJobs.test.tssrc/platform/remote/comfyui/jobs/fetchJobs.tssrc/platform/remote/comfyui/jobs/jobTypes.tssrc/stores/assetsStore.test.tssrc/stores/assetsStore.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/platform/remote/comfyui/jobs/jobTypes.ts
- src/platform/remote/comfyui/jobs/fetchJobs.test.ts
- src/platform/remote/comfyui/jobs/fetchJobs.ts
- src/stores/assetsStore.test.ts
Calls the reusable Comfy-Org/github-workflows cursor-review.yml (single source of truth for panel, judge, prompts, scripts) instead of a standalone copy. Label-gated to the team; secret-bearing jobs skip fork PRs. Judge overridden to Opus 4.8.
dante01yoon
left a comment
There was a problem hiding this comment.
Read-only review at 5e95fcc (not approving, per request). This is the careful one, and overall it's well-reasoned: the epoch counter invalidating superseded walks, the coalescing single-trailing refreshHistoryHead, the gap-restart-vs-whole-timeline-replace decisions, and the contained throw-propagation are all solid and well-tested. I verified the "Breaking" change is actually contained — api.getHistory/api.getQueue both still try/catch and return empty, and the store's updateHistory/loadMoreHistory wrappers catch as well.
Two findings inline: one issue: (a stuck-cursor guard the sibling #12774 has but this walk lacks) and one question: on the OSS missing-media behavior change.
Heads-up: your open #12464 (FE-740) and #12398 (FE-746) also touch assetsStore.ts / missingMediaAssetResolver.ts — no duplicate logic, but plan for a rebase whichever lands second.
There was a problem hiding this comment.
Re-review at 7e95419
- issue (stuck-cursor guard) — fixed in 2264e4f. The history jobs walk now mirrors the flat-output walk's non-advancing-cursor guard, and I confirmed it actually terminates in production (
loadMoreHistoryearly-returns on!hasMoreHistory) with a genuine red-green regression test. Thread replied. - question (OSS missing-media throw) — confirmed intentional; the throw is load-bearing for cursor recovery (400
INVALID_CURSOR→ drop cursor vs transient → retry), and the cloud-branch symmetry is the point. Accepted. Thread replied.
No new issues in the delta since 5e95fcc (the rest is a rebase onto main). CI green on this head (39 success / 9 skipped). Threads left open for you to resolve.
022a125
- Guard loadMoreHistory's success assignment against a superseding reload so a stale continuation can't blank historyAssets mid-reload - Re-sync the epoch after replaceHistoryWithHeadPage so post-replace errors surface instead of being swallowed by the staleness guard - Drop historyNextCursor once paging terminates, so state never carries a live cursor alongside hasMoreHistory === false - Reset historyError before the empty-list early return in doRefreshHistoryHead; document replaceHistoryWithHeadPage's epoch bump
…e-generated-tab-jobs-sourced
christian-byrne
left a comment
There was a problem hiding this comment.
issue: vi.clearAllMocks() in both beforeEach blocks only resets call history -- it does not remove .mockResolvedValue/.mockReturnValue implementations. docs/testing/vitest-patterns.md explicitly requires vi.resetAllMocks(). Stale implementations from one test can bleed into the next, especially when *Once chains run dry. Also, clearAllMocks currently fires after store = useAssetsStore() -- the correct order is: reset first, then create the pinia/store, then configure per-test mocks.
beforeEach(() => {
vi.resetAllMocks()
setActivePinia(createTestingPinia({ stubActions: false }))
store = useAssetsStore()
})- Guard the missing-media history walk against page-fetch failures: degrade to a partial scan instead of aborting the whole resolution - Defer the cursor-recovery destructive reset until the offset-0 fallback page arrives, so a failed fallback keeps the loaded list consistent - Absorb empty-string next_cursor as absent instead of failing the parse - Log malformed jobs responses with URL context before rethrowing - Align JobsApiError with peer API error classes ((message, status)) - Rename historyCursorMode -> hadCursorThisWalk to reflect sticky semantics - Insert same-timestamp head items before existing ones for deterministic merge order - Encode status params, deprecate fetchHistory in favor of fetchHistoryPage - Drop no-op historyAssets resets; clarify head-refresh and gap-restart docs - Cover job-completion -> refreshHistoryHead wiring, recovery replacement IDs, and undisplayable-page cursor continuation in tests
dante01yoon
left a comment
There was a problem hiding this comment.
please double confirm 1.48 backport label added
…ected leading refresh (#13783) ## ELI-5 When new jobs finish, the Generated tab re-fetches the top of the history list. To avoid hammering the server, overlapping refreshes share one in-flight fetch and schedule at most one "trailing" follow-up refresh (so a fetch that started a hair too early still catches the completion that triggered it). The bug: that trailing follow-up was chained with `.then(...)`. If the leading refresh's promise ever *rejected*, the `.then` callback would never run, the trailing slot would stay stuck holding a settled-rejected promise, and **every future refresh would return that same dead promise forever** — the head-refresh mechanism freezes permanently. The fix swallows the leading rejection before scheduling the trailing refresh, so the trailing slot always clears and a fresh refresh runs. The original caller still sees the rejection. ## Why this is future-proofing (and how it's tested) This freeze is **unreachable today**: `doRefreshHistoryHead` and everything it delegates to (`updateHistory`, the fetch helpers) catch internally, so the leading promise never actually rejects. This PR guards against a later refactor that adds an uncaught `await` on that path — consistent with the review thread that deferred it out of the source PR. I verified this empirically: making `fetchHistoryPage` reject and calling `refreshHistoryHead()` never produces a rejected promise through the store's public API. **Judgment call — extraction vs. the one-line fix.** The minimal in-place change would be `headRefreshInFlight.catch(() => {}).then(...)`. But because the store swallows all internal errors, the leading promise can't be made to reject through the public API, so a regression test for the fix *cannot fail without the fix* when written at the store level. To get a real red-green test, I extracted the trailing-edge coalescing state machine into a small pure function, `createTrailingRefreshCoalescer`, and unit-tested it directly by injecting a `run` that rejects. Behavior is identical — `refreshHistoryHead` is now `createTrailingRefreshCoalescer(() => doRefreshHistoryHead())`. If reviewers prefer the surgical one-liner instead, it's a trivial revert of the extraction. Red-green confirmed: reverting the `.catch(() => {})` makes the new "keeps refreshing after a rejected leading run" test fail (trailing promise rejects and the run count stalls); restoring it passes. ## Stacked PR Based on `matt/fe-962-...` (#12769), where this code lives — it is not yet on `main`. GitHub will retarget this PR to `main` when #12769 merges. ## Changes - `createTrailingRefreshCoalescer` (new, pure, module-scope): coalesces concurrent calls into one leading run + one trailing run; swallows the leading rejection for the trailing chain only. - `refreshHistoryHead` now delegates to it (no behavior change). - 3 unit tests for the coalescer, including the rejected-leading-run regression. ## Tests - `pnpm vitest run src/stores/assetsStore.test.ts` — 101 passed. - `pnpm typecheck`, `eslint`, `oxfmt --check` on the changed files — clean.
995e240
…#13781) ## ELI-5 When you scroll the Generated tab, the app pages through your job history with a "cursor". If that cursor goes stale (e.g. after a server restart) the server rejects the page with a 400 and the app restarts the walk from the beginning so you don't get skipped or duplicated rows. Today the app treats *any* 400 on that request as "stale cursor". That's fine right now because a rejected cursor is the only 400 the endpoint can return — but if the endpoint ever starts returning 400 for other reasons, an unrelated error would wrongly nuke your loaded history back to the top. This teaches the app to read the server's actual machine-readable error code and only reset when it really is a rejected cursor. ## Summary Classify a rejected jobs pagination cursor by the server's structured error code instead of the bare HTTP 400 status, so future non-cursor 400s don't trigger the history offset fallback. ## Changes - **What**: - `JobsApiError` now parses the machine-readable `code` from the JSON error body and exposes it as `errorCode` (undefined when the body isn't the structured error shape, e.g. a proxy error page). - `assetsStore.isRejectedCursorError` narrows from `status === 400` to `errorCode === 'INVALID_CURSOR'`. - Recovery tests construct errors with realistic JSON bodies; added coverage for a non-JSON body (no `errorCode`) and a non-cursor 400 (cursor preserved). - **Breaking**: none — behavior is identical for today's traffic (see below). ## Review Focus - **Server contract confirmed first.** The `/jobs` list endpoint returns its errors as a structured JSON body carrying a machine-readable `code` field, and emits `INVALID_CURSOR` for a rejected pagination cursor. That endpoint's only 400 today is the rejected cursor, so old (`status === 400`) and new (`errorCode === 'INVALID_CURSOR'`) conditions cannot disagree for current traffic — no behavior change now. The narrowing is defense-in-depth for when the endpoint gains other 400 cases, and is strictly more correct: an unrelated 400 or a non-JSON proxy 400 no longer resets the walk to offset 0. - **Judgment call:** the deferred review note suggested parsing the code in `fetchJobsRaw`. I parse it in the `JobsApiError` constructor instead — the body already flows in there, so the single throw site is unchanged and the parsing lives with the field it populates. Same observable result. - Stacked on the cursor-pagination PR (its branch is the base) since `JobsApiError` / `isRejectedCursorError` only exist there; GitHub retargets to `main` once that merges. ## Verification - `vitest run` on `fetchJobs.test.ts` + `assetsStore.test.ts`: 124 passed. - eslint + oxfmt clean on the four changed files. - Type-check introduces zero new errors (identical error count with the change stashed vs applied, against the base branch). --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
…cursor-pagination-in-the-generated-tab-jobs-sourced # Conflicts: # apps/desktop-ui/src/components/install/DesktopSettingsConfiguration.vue
…ests The two jobDetailView tests still called the pre-cursor-pagination api.getHistory mock, which isn't imported/mocked with a getHistory method in this file, breaking typecheck and every CI job downstream of it. Switch them to the fetchHistoryPage mock pattern the rest of the file uses.
|
Merged |
dante01yoon
left a comment
There was a problem hiding this comment.
Re-review of the commits since my last review on b0082ea817: 995e24034b (#13783, trailing-refresh coalescer), da1a4b61d1 (#13781, structured errorCode), the main merge d2532f0527, and 9c7d72869c (stale api.getHistory mock).
Earlier findings: all still fixed (stuck-cursor guard, OSS missing-media throw accepted, JSDoc on fetchHistoryAssets, truncation and epoch-guard tests). The new commits don't reopen any of them.
New commits
- Narrowing
isRejectedCursorErrortoerrorCode === 'INVALID_CURSOR'is the right direction, and the non-JSON-body and non-cursor-400 tests cover the fallbacks. One contract issue inline: the error-body schema is hand-declared, but the generated one exists. - The coalescer is correct.
trailingchains on thefinally-wrappedinFlight, soinFlightis alreadynullwhen the trailinginvoke()runs, and the.catch(() => {})keeps a rejected leading run from latching. Its JSDoc is far past the 1–2 line limit, though (inline).
Branch state
The branch conflicts with main in 10 files and needs a real rebase. main moved fetchJobs into packages/api-client/src/fetchJobs.ts (with its own JobsApiError and a cursor walk for flat outputs), deleted src/platform/missingMedia/missingMediaAssetResolver.ts and its tests, and changed assetsStore.ts, GraphView.vue, and QueueProgressOverlay.vue. The two stacked commits, which still carry Co-authored-by: Claude trailers, will be rewritten by the rebase anyway.
| // thread; the structured error is a few hundred bytes at most. | ||
| const MAX_ERROR_PARSE_LENGTH = 10_000 | ||
|
|
||
| const zJobsErrorBody = z.object({ code: z.string() }) |
There was a problem hiding this comment.
issue: this hand-declares the /jobs error-body contract. @comfyorg/ingest-types/zod already exports zErrorResponse ({ code, message, details?, organization_id? }, described as the standard error response with a machine-readable code), and the jobs list types come from the same spec. Could this be zErrorResponse.pick({ code: true }) (or zErrorResponse itself), so INVALID_CURSOR classification follows the generated contract instead of a local copy?
|
|
||
| const MAX_ERROR_BODY_LENGTH = 200 | ||
|
|
||
| // Cap synchronous JSON.parse so an oversized error body can't block the UI |
There was a problem hiding this comment.
issue: new comment. The repo rule is no added comments. The size cap can carry its reason in the constant's name, or in the commit message.
| * trailing run clears its slot coalesces into that trailing run rather than | ||
| * starting a second leading run, preserving the at-most-one-trailing guarantee. | ||
| */ | ||
| export function createTrailingRefreshCoalescer( |
There was a problem hiding this comment.
issue: the JSDoc above this export is about 15 lines and narrates the implementation (the microtask gap, why the rejection is swallowed). The rule for an exported API is one or two lines stating the contract, e.g. "Coalesces concurrent calls into one leading run and at most one trailing run." The rest belongs in the commit message, and the tests already pin the at-most-one-trailing and rejected-leading-run cases.
suggestion (non-blocking): #13783 says the rejected leading run can't happen today, and offers the one-line inFlight.catch(() => {}).then(...) as an alternative. If you'd rather not keep an exported helper only for testability, that smaller change is fine with me.
ELI-5
The Generated tab shows finished jobs newest-first and loads more as you scroll. Today it asks the server for "items 200–400" (offset paging). If a job finishes while you're scrolling, every item shifts down one slot, so the next page repeats or skips things. Worse, every time a job finished the app threw the whole list away and re-downloaded page one — goodbye scroll position.
Now the server hands back a bookmark (
next_cursor) with each page and we ask for "the page after this bookmark." Bookmarks don't slip when new items arrive, so the scroll walk is drift-free. When a job finishes, we fetch just the newest page and slot the new items in at the top instead of rebuilding everything. If a bookmark goes stale (e.g. the server restarted), we fall back to the old counting method for one page and pick up a fresh bookmark from the response. Old backends that don't hand out bookmarks keep working exactly as before.Summary
Migrates the Generated tab's jobs walk from offset to keyset cursor pagination (
after/next_cursor), now that core (Comfy-Org/ComfyUI#14363) and cloud (BE-885) share one cursor contract onGET /api/jobs.Changes
fetchHistoryPagetakes{ offset?, after? }, sendsafterinstead ofoffsetwhen present, and surfacesnext_cursorfrom the pagination responseoffsetremains the fallback for backends that don't mint cursors400 INVALID_CURSORafter a server restart) is dropped and the page retried once via the offset fallbackfetchJobsRawnow throws on failure instead of fabricating an emptyhasMore: falsepage, so failures are distinguishable from the end of the timeline;api.getHistory/api.getQueuealready catch, the store's error paths now actually run, and the missing-media resolver degrades a failed history page to a partial scan instead of aborting the whole resolutionrefreshHistoryHead()that merge-prepends the head page instead of resetting scroll state; it replaces the list when the page spans the whole timeline (pruning server-side deletions, e.g. cleared history) and restarts the walk when >1 page of new jobs would leave an unfillable gaphasMoreHistoryderives from the server'spagination.has_more(instead of batch length), with two local terminal overrides: an empty cursorless page and a cursor that didn't advancefetchHistoryPage/fetchHistory/fetchQueuenow propagate fetch failures instead of returning empty results (all callers audited and handle it)Review Focus
beforeparam, so "fetch newer than X" is not expressible — head-page merge is the prepend mechanism per FE-962refreshHistoryHeadgap/whole-timeline decisions inassetsStore.tsgetAllAssetsByTagwalk inassetService— no overlapping filesLinear: FE-962