fix: clamp page overflow to last page in /refractor status (#141) #142
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
ai-working
bug
enhancement
feature
in-queue
performance
security
tech-debt
todo
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-discord#142
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "issue/141-bug-refractor-status-page-overflow-shows-no-data-i"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #141
What changed
When a user passes a page beyond the total (e.g.
/refractor status page:999), the API returns{"count": 13, "items": []}. The cog was falling through to the "No refractor data found" message without checking thatcount > 0.Added a re-fetch guard in
refractor_status(after the initial API call): ifitemsis empty buttotal_count > 0, the page is clamped toceil(total_count / PAGE_SIZE)and a second request is made with the corrected offset. This mirrors the clamping already done by the pagination buttons inRefractorPaginationView._fetch_and_update.Files changed
cogs/refractor.py— 12-line insertion aftertotal_countis computedTest coverage
REF-22 in
tests/refractor-integration-test-plan.mddescribes this exact scenario. No automated test exists for this path; manual verification against team 31 on dev (13 cards) is recommended.AI Code Review
Files Reviewed
cogs/refractor.py(modified — 12-line insertion)Findings
Correctness
No issues found.
The guard (
if not items and total_count > 0) fires exactly when the API returns{"count": N, "items": []}due to an out-of-range offset. The ceiling-division formula(total_count + PAGE_SIZE - 1) // PAGE_SIZEis correct.pageis set tototal_pagesbefore buildingclamped_params, so(page - 1) * PAGE_SIZEcomputes the right offset for the last page.Two things I checked specifically:
paramspassed toRefractorPaginationViewis stale (still has the original out-of-range offset) — not a bug._fetch_and_updatestrips"offset"frombase_paramsand recomputes it fromself.page, so the view always fetches the correct page regardless.pageandtotal_pagesare recomputed again at lines 400–401 after the guard — the recomputation uses the updatedtotal_countfrom the re-fetch; since the total hasn't changed, both values remain correct and the subsequentpage = min(page, total_pages)is a no-op clamp at the already-correct last-page value.Security
No issues found. All params are from validated
app_commandschoices or computed from them.Style & Conventions
No issues found. Filter-and-reappend pattern for
params([(k, v) for k, v in params if k != "offset"]+append) is consistent with_fetch_and_update. Comment is clear and scoped.Suggestions
db_getto return{"count": 13, "items": []}on the first call and a populated list on the second would lock this in permanently — optional, doesn't block merge.Verdict: APPROVED
Correct fix for the described edge case. Logic is sound, no security or convention issues. The interaction with the stale
paramspassed toRefractorPaginationViewis safe because the view always recomputes its own offset. Gitea blocks self-approval — posting as COMMENT.Automated review by Claude PR Reviewer