Skip to content

fix(github): pin work-item list ordering to updated-desc so cursor pagination reaches every page - #8658

Merged
OrcaWin merged 2 commits into
stablyai:mainfrom
moseoh:fix/work-items-cursor-sort
Jul 14, 2026
Merged

OrcaWin merged 2 commits into
stablyai:mainfrom
moseoh:fix/work-items-cursor-sort

Conversation

@moseoh

@moseoh moseoh commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #8649.

The Tasks page paginates GitHub work items with an updatedAt cursor (updated:<oldest item's updatedAt), but the underlying gh invocations never pinned a sort order:

Page Actual order Order the cursor assumes
Page 0 (gh issue list) created-desc updated-desc
Page 1+ (--search "updated:<cursor") best-match updated-desc

Items created long ago but updated recently never appeared on any page: page 0 (created order) skipped them, and every later page excluded them via the cursor. The pager therefore advertised pages the fetch chain could never reach (the search-API count is correct; the fetched rows fall short), clicking those pages clamped to the last real page, and cross-page ordering was scrambled (e.g. #1082 rendering between #1308 and #1499).

The fix appends sort:updated-desc to every list/search invocation (issues and PRs), so the fetch order matches the cursor field on the first and all subsequent pages. The REST fallback path already pinned sort=updated&direction=desc; the primary gh CLI path was the only one missing it.

Screenshots

Before After
before after

Testing

  • pnpm lint (pre-commit oxlint/react-doctor/oxfmt; repository config)
  • pnpm typecheck
  • pnpm test — all src/main/github suites pass (359/359); the workstation's full run has pre-existing environment-dependent failures (git pathspec/relay/ssh) that fail identically on main
  • pnpm build
  • Added regression tests: plain list queries carry sort:updated-desc; cursor pages combine updated:<cursor sort:updated-desc
  • Live verification against a 588-open-issue repo: the cursor chain previously died around page 5 of 17; with the fix it traverses 585/588 unique issues across the expected number of pages with monotonic updatedAt ordering
  • Verified in the running dev app: the Tasks issue list now reaches the last advertised page

AI Review Report

  • Traced both list sub-paths (recent + queried) and confirmed they share buildWorkItemListArgs, so issues and PRs get the same ordering pin; the count path (countWorkItems) is unaffected and already consistent.
  • Empirically confirmed the gh CLI behaviors driving the bug (default created-desc without --search; best-match with it) and the fix (sort:updated-desc honored in both gh issue list and gh pr list).
  • Cross-platform: the change only appends a search qualifier string — no shortcuts, paths, or shell behavior. gh invocation shape is identical on macOS/Linux/Windows.
  • Rate limits: pinning the sort routes page-0 lists through the search API (pages 1+ already did). Search-bucket budget accounting for list calls is a possible follow-up; noted below.

Security Audit

The change appends a constant qualifier to an existing --search argument built from already-parsed query parts — no new user input reaches the command line, and gh is still invoked via execFile-style argument arrays (no shell interpolation).

Notes

  • The list remains ordered by recent activity (updatedAt), Orca's existing Tasks semantic — consistent across pages after this fix, but intentionally not the issue-number ordering the reporter suggested in [Bug] Issue pagination shows wrong pages after clicking page numbers #8649's expected behavior. Switching to created-order would be a product-level change touching the shared merge sort, so it's left to maintainer preference.
  • Known residual edge (pre-existing): the cursor uses a strict updated:<, so items sharing the boundary item's exact timestamp can be skipped (3/588 in live verification, and items updated mid-traversal drift). Fixing it needs <= plus seen-ID dedupe in the renderer chain — separable follow-up.
  • Follow-up candidate: list calls now always consume the search rate-limit bucket, but only countWorkItems participates in the search budget guard (noteRateLimitSpend('search')). Wiring list calls into that accounting would make the guard estimate more accurate.
  • Follow-up candidate: jumping to a far page chains sequential cursor fetches (page N needs page N−1's cursor), which is inherent to cursor pagination over a multi-repo merge. When a single repo is selected, the search API's page/per_page offset form could jump directly (within its 1,000-result window).

…gination reaches every page

The Tasks page paginates work items with an updatedAt cursor
(updated:<oldest-item), but the underlying gh calls never pinned a sort:
'gh issue list' defaults to created-desc and '--search' defaults to
best-match. Items created long ago but updated recently therefore never
appeared on any page — page 0 (created order) skipped them and every
later page excluded them via the cursor — so the pager advertised pages
the fetch chain could never reach, clicks on them clamped to the last
real page, and cross-page ordering was scrambled.

Append sort:updated-desc to every list/search invocation so the fetch
order matches the cursor field on the first and all subsequent pages.

Verified against a live 588-issue repo: the cursor chain previously
died around page 5; it now traverses 585/588 unique issues (the
remainder is the pre-existing strict '<' boundary edge for items
sharing the cursor's exact timestamp).

Fixes stablyai#8649
@moseoh
moseoh marked this pull request as ready for review July 14, 2026 03:21
@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

GitHub work-item list arguments now always include a --search predicate with sort:updated-desc, combining it with updated:<cursor> for cursor-based pagination. Renderer pagination now uses a shared accumulator that deduplicates inclusive cursor results, fills pages, handles exhaustion and cancellation, and integrates with TaskPage. Tests cover query variants, ordering, cursor behavior, and pagination scenarios.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The pagination fix aligns cursor pages with updated-desc, but it does not satisfy #8649's explicit newest-first-by-number ordering requirement. Update the work-item list ordering to match the issue's newest-first sort expectation while preserving cursor pagination and page reachability.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: pinning GitHub work-item list ordering to updated-desc for cursor pagination.
Description check ✅ Passed The description includes all required sections with a clear summary, screenshots, testing, AI review, security audit, and notes.
Out of Scope Changes check ✅ Passed All changes stay within GitHub work-item pagination, renderer pagination helpers, and related tests; no unrelated features were added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@OrcaWin
OrcaWin requested a review from AmethystLiang July 14, 2026 04:31
…oundaries

Builds on the sort-pin fix: switch the pagination cursor from strict
'updated:<' to inclusive 'updated:<=' so items sharing the boundary row's
exact updatedAt are no longer skipped between pages (the residual 3/588 edge
in stablyai#8649).

The inclusive bound re-fetches the boundary rows, so dedupe them by repoId+id
(a bare item.id like 'issue:9' collides across repos). Extract the page
accumulation out of the 12k-line TaskPage component into a pure, unit-tested
helper (accumulateWorkItemPages) that dedupes and backfills: it accumulates
fresh rows across fetches and emits uniform pageSize pages, so deduped pages
never shrink below the size totalPages (count / effectivePageSize) assumes —
which would otherwise strand the tail items and break the no-count degraded
pager.

Also hoist the updated-desc ordering into a named WORK_ITEM_LIST_SORT_QUALIFIER
constant so the cursor's ordering contract has one home.

Tradeoff: when per-repo fetch size equals pageSize, the boundary dedupe costs
one extra fetch per page; acceptable for interactive pagination and bounded by
the gh rate-limit guard. Persisting the cursor/buffer across calls is a
possible follow-up.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e52b250a-5ce5-4657-bde1-56f1ba7aeb5a

📥 Commits

Reviewing files that changed from the base of the PR and between 345fe56 and 05a7f9d.

📒 Files selected for processing (5)
  • src/main/github/client-work-items.test.ts
  • src/main/github/client.ts
  • src/renderer/src/components/TaskPage.tsx
  • src/renderer/src/components/task-page-work-item-pagination.test.ts
  • src/renderer/src/components/task-page-work-item-pagination.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/github/client-work-items.test.ts

Comment on lines +6307 to +6309
if (result.newPages.length > 0) {
setPages((prev) => [...prev, ...result.newPages])
setCurrentPage(target < result.loadedPages ? target : result.loadedPages - 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Update the current page even if no new pages are loaded.

If result.newPages.length === 0 (e.g., data changed on the server and fewer pages exist than expected), but the user clicked a specific target page beyond the currently loaded ones, they will remain on their current page rather than advancing to the last available page.

Moving setCurrentPage outside the if block ensures the user is navigated as far as possible toward their target (it gracefully falls back to result.loadedPages - 1).

💡 Proposed fix
         if (result.newPages.length > 0) {
           setPages((prev) => [...prev, ...result.newPages])
-          setCurrentPage(target < result.loadedPages ? target : result.loadedPages - 1)
         }
+        setCurrentPage(target < result.loadedPages ? target : result.loadedPages - 1)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (result.newPages.length > 0) {
setPages((prev) => [...prev, ...result.newPages])
setCurrentPage(target < result.loadedPages ? target : result.loadedPages - 1)
if (result.newPages.length > 0) {
setPages((prev) => [...prev, ...result.newPages])
}
setCurrentPage(target < result.loadedPages ? target : result.loadedPages - 1)

@OrcaWin
OrcaWin merged commit 7d8c4fd into stablyai:main Jul 14, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…gination reaches every page (stablyai#8658)

* fix(github): pin work-item list ordering to updated-desc so cursor pagination reaches every page

The Tasks page paginates work items with an updatedAt cursor
(updated:<oldest-item), but the underlying gh calls never pinned a sort:
'gh issue list' defaults to created-desc and '--search' defaults to
best-match. Items created long ago but updated recently therefore never
appeared on any page — page 0 (created order) skipped them and every
later page excluded them via the cursor — so the pager advertised pages
the fetch chain could never reach, clicks on them clamped to the last
real page, and cross-page ordering was scrambled.

Append sort:updated-desc to every list/search invocation so the fetch
order matches the cursor field on the first and all subsequent pages.

Verified against a live 588-issue repo: the cursor chain previously
died around page 5; it now traverses 585/588 unique issues (the
remainder is the pre-existing strict '<' boundary edge for items
sharing the cursor's exact timestamp).

Fixes stablyai#8649

* fix(github): make work-item cursor pagination lossless at updatedAt boundaries

Builds on the sort-pin fix: switch the pagination cursor from strict
'updated:<' to inclusive 'updated:<=' so items sharing the boundary row's
exact updatedAt are no longer skipped between pages (the residual 3/588 edge
in stablyai#8649).

The inclusive bound re-fetches the boundary rows, so dedupe them by repoId+id
(a bare item.id like 'issue:9' collides across repos). Extract the page
accumulation out of the 12k-line TaskPage component into a pure, unit-tested
helper (accumulateWorkItemPages) that dedupes and backfills: it accumulates
fresh rows across fetches and emits uniform pageSize pages, so deduped pages
never shrink below the size totalPages (count / effectivePageSize) assumes —
which would otherwise strand the tail items and break the no-count degraded
pager.

Also hoist the updated-desc ordering into a named WORK_ITEM_LIST_SORT_QUALIFIER
constant so the cursor's ordering contract has one home.

Tradeoff: when per-repo fetch size equals pageSize, the boundary dedupe costs
one extra fetch per page; acceptable for interactive pagination and bounded by
the gh rate-limit guard. Persisting the cursor/buffer across calls is a
possible follow-up.

---------

Co-authored-by: OrcaWin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Issue pagination shows wrong pages after clicking page numbers

2 participants