Skip to content

fix(db,poll): harden budget ledger, finding events, and revue coverage - #30

Merged
kleinbem merged 1 commit into
mainfrom
fix/cr-findings-2026-12-05
Dec 5, 2026
Merged

kleinbem merged 1 commit into
mainfrom
fix/cr-findings-2026-12-05

Conversation

@kleinbem

@kleinbem kleinbem commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

Relates to #14

Addresses verified CodeRabbit steward findings:

  • #689: Remove the 50-row cap in Db::load_budget_ledger and filter by the active refill/lookback window (plus provisional rows) so repos with limit > 50 do not undercount active spends.
  • #690: Add migrations/0003_refill_samples.sql (budget_state.refill_samples_json) and persist/restore BudgetLedger::refill_samples across save/load so the 7-day rolling max survives restarts and updates.
  • #691: Collect new GitHub observations in poll_repo and apply them via Db::update_budget_ledger under ledger_lock instead of calling save_budget_ledger with a pre-request snapshot, preventing poll saves from clobbering concurrent webhook throttle deadlines.
  • #692: Wrap save_budget_ledger in a transaction and delete stored provisional spend rows no longer present in ledger.spends while keeping all confirmed spend history intact.
  • #693: Run Db::update_finding_status (SELECT, guarded UPDATE, and finding_events INSERT) in one SQLite transaction so concurrent updates cannot record a stale from_status.
  • #694: Update the stale-report guard in Db::apply_revue_coverage to also skip when blob_sha is None for a different reviewed_commit with unreviewed_lines > 0.

Verification

  • cargo test (30 tests passed, including 5 new regression tests in tests/db_tests.rs)
  • cargo clippy --all-targets --all-features -- -D warnings (clean)

Summary by CodeRabbit

  • Bug Fixes
    • Budget tracking now retains a more complete record of recent spending and refill history, improving rolling-limit calculations.
    • Provisional spending is removed when no longer applicable, while confirmed spending remains recorded.
    • Older coverage reports are less likely to overwrite newer, unreviewed changes.
    • Concurrent finding-status updates are handled more reliably, helping keep status history consistent.

Address CodeRabbit proactive review findings #689, #690, #691, #692, #693, #694:
- Load all spends in the active refill/lookback window instead of capping at 50 rows (#689)
- Persist dated refill_samples across budget ledger save/load (#690)
- Route poll_repo budget updates through update_budget_ledger so webhook throttle deadlines are not clobbered (#691)
- Delete removed provisional spends on save while preserving confirmed spend history (#692)
- Run update_finding_status read/update/event insert in a single transaction (#693)
- Skip stale apply_revue_coverage updates when blob_sha is absent and newer unreviewed lines exist (#694)
@kleinbem kleinbem added the cr-review Ask CodeRabbit to review this PR label Dec 5, 2026
@kleinbem
kleinbem enabled auto-merge (squash) December 5, 2026 03:12
@coderabbitai

coderabbitai Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change persists refill samples and active budget spends, reconciles provisional spends, and applies polling outcomes through the locked ledger update path. It also makes finding-status updates conditional on the previously read status and changes the Revue coverage guard for reports without a blob SHA.

Changes: Budget ledger updates

Layer / File(s) Summary
Budget state and ledger loading
migrations/0003_refill_samples.sql, src/db.rs, tests/db_tests.rs
The database stores refill samples. Ledger loading restores refill history and loads spends from the active window without the previous 50-row limit. Tests cover loading 60 confirmed spends and restoring refill samples.
Serialised ledger persistence
src/db.rs, tests/db_tests.rs
Ledger saves acquire the ledger lock and update budget and spend state in a transaction. Saves remove provisional spends absent from the ledger and retain confirmed spends. The rate-limit test checks this behaviour.
Polling event updates
src/ingest/poll.rs
poll_repo collects check-run and bot-message events, then applies them through update_budget_ledger with a fresh timestamp.

Finding status updates

Layer / File(s) Summary
Conditional status update and event recording
src/db.rs, tests/db_tests.rs
Finding status updates compare the current status within a transaction and record the event in that transaction. The test checks that recorded events form a contiguous chain and end at the persisted status.

Revue coverage guard

Layer / File(s) Summary
Coverage update guard
src/db.rs, tests/db_tests.rs
The coverage guard skips a report without a blob SHA when existing unreviewed coverage belongs to a different reviewed commit. The test also checks that a report for the same reviewed commit clears the unreviewed lines.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related issues

  • Issue 14 tracks the ledger load cap, refill history, poll updates, provisional spend removal, finding-status concurrency, and stale coverage changes addressed here.

Possibly related PRs

Merge Risk: Minimal · up to 17fb5

The change makes budget-ledger persistence and finding-status updates safer under concurrent writes. No concrete merge-blocking defect was established; the main residual edge is a delayed bot comment arriving after a newer save, which is narrow and low impact.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names three areas (db, poll, revue coverage) and the verb 'harden'. The changeset does touch budget ledger persistence, finding-status events, and revue coverage handling, so the title match…
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 names three areas (db, poll, revue coverage) and the verb 'harden'. The changeset does touch budget ledger persistence, finding-status events, and revue coverage handling, so the title matches the main change. It names the subsystems but not the specific fixes, such as transactional saves and the refill-sample persistence, which is acceptable for a title.

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

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c2da26bc-0e1f-4a9f-8454-137b18057664
Commits

Reviewing files that changed from the base of the PR and between a397959 and 17fb5a9.

Files selected for processing: 4

  • migrations/0003_refill_samples.sql
  • src/db.rs
  • src/ingest/poll.rs
  • tests/db_tests.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.

@kleinbem
kleinbem merged commit 20a79ee into main Dec 5, 2026
6 checks passed
@kleinbem
kleinbem deleted the fix/cr-findings-2026-12-05 branch December 5, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cr-review Ask CodeRabbit to review this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant