fix: track body truncation explicitly instead of inferring from cap l…#166
fix: track body truncation explicitly instead of inferring from cap l…#166greatjourney589 wants to merge 2 commits into
Conversation
|
Warning Review limit reached
More reviews will be available in 5 minutes and 38 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. 📝 WalkthroughWalkthroughThis PR introduces explicit body truncation tracking to fix a bug where the poller continuously re-truncates cached issue and pull request bodies, defeating the detail cache and consuming unnecessary GitHub API quota. The implementation adds a ChangesExplicit body truncation tracking with no-downgrade poller semantics
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@src/lib/db.ts`:
- Around line 321-330: Wrap the ALTER TABLE and subsequent UPDATE backfill into
a single transaction so the schema addition and backfill are atomic: for both
the issues and pulls branches (the checks using issuesCols.some and
pullsCols.some), begin a transaction (e.g., db.exec('BEGIN') or use the
library's transaction helper), perform db.exec('ALTER TABLE ... ADD COLUMN
body_truncated ...'), then run the prepared UPDATE (the
db.prepare(...).run(ISSUE_BODY_CAP) and db.prepare(...).run(PULL_BODY_CAP)), and
finally COMMIT; ensure you ROLLBACK on error so a partial ALTER without backfill
cannot be left behind.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: bd620d74-1764-42d2-95b8-91e6edc7e854
📒 Files selected for processing (6)
src/app/api/issue/[owner]/[name]/[number]/route.tssrc/app/api/pull/[owner]/[name]/[number]/route.tssrc/app/api/related-issues/[owner]/[name]/[number]/route.tssrc/lib/body-cap.tssrc/lib/db.tssrc/lib/refresh.ts
099a56e to
5e2ea1e
Compare
…l-migration data loss (MkDev11#165)
Summary
Track issue/PR body truncation with an explicit
body_truncatedflag instead ofinferring it from the stored body length.
Previously the detail routes decided whether to serve a cached body by comparing
its length to the cap (
body.length !== 8000for issues,!== 4000for pulls).This was fragile:
forever, triggering a fresh GitHub fetch on every poll cycle.
to a capped slice by the next poller sweep.
one side changed.
Now truncation is recorded explicitly:
src/lib/body-cap.tsis the single source of truth for the caps(
ISSUE_BODY_CAP = 8000,PULL_BODY_CAP = 4000) and exposescapBody(),which clamps a body and reports whether it was actually shortened (strict
>cap, so an exact-length body is not truncated).body_truncatedcolumn onissues/pulls, with a guarded migration thatbackfills existing rows (rows at exactly the cap length are flagged truncated —
the safe direction, since a false-truncated flag just costs one self-healing
re-fetch).
!body_truncated, and store the fulluncapped body with the flag cleared.
full body is overwritten only when the incoming body is itself complete, the
stored body is already truncated, or the incoming text is at least as long.
Related Issues
Fixes #165.
Type of Change
Testing
pnpm buildpassesChecklist
Summary by CodeRabbit