Skip to content

SWF(bug): Stabilize repo listing pagination - #668

Merged
beardthelion merged 3 commits into
mainfrom
bug/stable-repo-listing-order
Dec 3, 2026
Merged

beardthelion merged 3 commits into
mainfrom
bug/stable-repo-listing-order

Conversation

@beardthelion

@beardthelion beardthelion commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Break equal updated_at ties by repo ID so offset pages agree on the order.

GET /api/v1/repos used only updated_at DESC after mirror deduplication. Postgres can return ties in a different order when its plan changes. The handler preserves that order through visibility filtering, then slices by offset. On two instances of the same main build against the same data, taking page one at work_mem=4MB and page two at 64MB returned three duplicate IDs.

Same main build, unchanged catalog, 4MB then 4MB: 100 distinct repos across 100 rows
Same main build, unchanged catalog, 4MB then 64MB: 97 distinct repos across 100 rows
Repeated IDs: 3; absent from the 4MB first-two-page set: 47

The query now orders by updated_at DESC, id ASC. Distinct timestamps still sort newest first. Visibility, mirror selection, star counts and X-Total-Count work as before. This fixes ties, not rows moving between pages when their timestamps change.

The endpoint test walks three offsets through tied rows whose names sort opposite to their IDs. Before:

assertion `left == right` failed: tied repos across all pages
  left: ["d", "c", "b", "a"]
 right: ["a", "b", "c", "d"]

After:

test test_support::tests::list_repos_pages_distinct_timestamps_by_visibility ... ok
test test_support::tests::list_repos_pages_tied_timestamps_in_id_order ... ok

The distinct-timestamp test checks rows, order, stars and X-Total-Count for anonymous, owner and allowlisted callers on both versions. It injects an authenticated DID through the existing router harness; it doesn't exercise HTTP-signature verification.

Formatting and workspace Clippy passed. In cargo test --workspace, the unrelated sweep timing test failed with left: 2, right: 1 and passed on its own. The four default node integration suites passed separately.

Try with DATABASE_URL set to a local Postgres 16+ instance: cargo test -p twigpine-node --lib list_repos_pages_

Summary by CodeRabbit

  • Bug Fixes
    • Repository lists now use a consistent ID order when repositories have the same activity timestamp, including across pages, making browsing and pagination more predictable.
    • Pagination displays the total number of repositories and applicable star counts for visitors with different access levels.
  • Tests
    • Added coverage for repository ordering across pages and for listing visibility, totals, and star counts across access levels.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Repository listings now order repositories by descending update time and then ascending repository ID. Tests check this order across pages and verify visible results, totals, and star counts for anonymous callers, the owner, and a listed reader.

Changes: Stable repository listing

Layer / File(s) Summary
Ordering and paginated listing checks
crates/twigpine-node/src/db/mod.rs, crates/twigpine-node/src/test_support.rs
The listing query uses ascending repository ID to break ties in update time. Tests check tied timestamps across pages and verify paginated results, totals, visibility, and star counts for three caller types.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • Twigpine/node#111: Updates visibility handling for the same repository listing endpoint and tests results for different caller access levels.
Merge Risk: Minimal · up to 58299

Repository listing order is now stable for repositories with equal update times, so offset pages no longer repeat IDs. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "SWF(bug): Stabilize repo listing pagination" matches the main change. The PR makes GET /api/v1/repos break updated_at ties by repo ID (updated_at DESC, id ASC), so offset pages stay consist…
Description check Passed The description covers the required template sections in substance. The Summary and Motivation are clear: ties in updated_at DESC ordering let offset pages disagree, and the fix orders by updated_at D…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "SWF(bug): Stabilize repo listing pagination" matches the main change. The PR makes GET /api/v1/repos break updated_at ties by repo ID (updated_at DESC, id ASC), so offset pages stay consistent. The title names the bug type and the affected area. It does not name the tie-breaking mechanism, but it is specific enough for a reviewer scanning history.

Full details: Description check

Explanation

The description covers the required template sections in substance. The Summary and Motivation are clear: ties in updated_at DESC ordering let offset pages disagree, and the fix orders by updated_at DESC, id ASC. Verification is given with test names, output, and a command to run the pagination tests. The template's 'Kind of change' checkboxes are not ticked, the 'What changed' section does not name the crate touched (twigpine-node), the 'Closes #' issue link is blank, and the 'Before you request review' checklist is not ticked. The 'Protocol & signing impact' block is not addressed, though the author notes the tests do not exercise HTTP-signature verification. These gaps are non-critical, so the description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 93a3e360-7577-428c-a4b8-52bfa0a92084
Commits

Reviewing files that changed from the base of the PR and between 45ea826 and 5829945.

Files selected for processing: 1

  • crates/twigpine-node/src/test_support.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟢 Thanks for the contribution. I do not see any actionable issues from my review.

Merge readiness

  • Branch freshness: Head merge-base matches live origin/main at 65d55405f64e35e02a0e048d1b7b2fe6dbbbd8a1 (no stale-base rebase needed for conflict or drift).
  • Merge gate: GitHub reports mergeable_state: blocked pending required review (review requested from jatmn), not merge conflicts.
  • Required checks: PR Checks workflows on head are SUCCESS (fmt + clippy, test (stable), test (beta), build --release, MSRV, changed surfaces, triage). CodeQL completed NEUTRAL (informational).
  • Local validation: cargo check -p twigpine-node on head succeeded in the review checkout; sqlx integration tests were not run here (DATABASE_URL unset). CI test jobs are the runtime oracle for list_repos_pages_*.
  • Duplicate work: No open duplicate PR located for this pagination tie-break fix.

Notes (non-blocking)

  • New tests cover anon tied-timestamp paging and distinct-timestamp visibility paging; they do not combine tied updated_at with visibility holes in one scenario. That is acceptable for this scope because filter-then-slice preserves SQL order among visible rows.
  • GraphQL legacy repos and other dedup listing helpers still order by updated_at only on unchanged paths; that behavior predates this PR and is outside the REST offset-pagination fix.

@beardthelion
beardthelion added this pull request to the merge queue Dec 3, 2026
Merged via the queue into main with commit 83f934d Dec 3, 2026
20 checks passed
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.

2 participants