Repository navigation
fix(billing): stop the plan-limit prune looping forever on a zero batch - #11079
ayobamiseun wants to merge 1 commit into
Conversation
pruneApiPlanLimitData took its batch size straight from the caller with
no floor. `take(0)` returns nothing, so `staleNotices.length >= batch`
reads 0 >= 0 as a full batch and the mutation reschedules itself at
runAfter(0) with the same zero. The result is an unbounded chain of
scheduled executions that deletes nothing while the retention backlog
is never touched.
`limit` is operator-callable by design — its own arg comment says it
exists so tests can drive the drain — and 0 is a natural value to type
when probing that. The cron passes {}, so only an operator trips it.
The guard already exists verbatim in both prunes that were modelled on
this one (convex/userPreferences.ts, convex/intelHistory.ts, whose
header names this function as its model) and in convex/agentFeedback.ts.
It was applied to every derivative and never back-ported to the
original. This adds the same three lines.
Tests: zero, negative, fractional, NaN and Infinity each make progress
and terminate. Red proof: with the handler reverted, all five fail.
|
@ayobamiseun is attempting to deploy a commit to the World Monitor Team on Vercel. A member of the Team first needs to authorize it. |
Strix Security Review✅ No open security findings. PR summary: Fixes the plan-limit retention prune so a caller-supplied batch size of zero (or a negative, fractional, NaN or infinite value) can no longer make the mutation reschedule itself forever without deleting anything; the batch is floored at one and non-finite values fall back to the default. Review summaryThe change adds a lower bound and a non-finite fallback to the caller-supplied batch size in Ruled out (1)
Review 1 on this PR · Reviewed by Strix |
[Low impact] The PR appears safe to merge. Summary
Reviews (1) · Last reviewed commit: "fix(billing): stop the plan-limit prune ..." · Reviewed by Greptile |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
auditbenchaibot
left a comment
There was a problem hiding this comment.
🤖 Automated review by Audit Bench Ai, not a personal review. It was posted through the GitHub account connected to Audit Bench Ai. Install the Audit Bench Ai GitHub App to have reviews posted by a separate bot account.
No actionable comments were generated in this review. 🎉
Merge risk: ⚪ Minimal · up to fbb34a1
The change adds defensive input validation mirroring existing patterns across other prune tasks, accompanied by comprehensive test coverage without changing default cron behavior.
Merge readiness: ⛔ Not ready to merge
Pre-merge checks: ✅ 9 · ❌ 1
❌ Failed checks: 1 error
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| CI checks | ❌ | 1 of 59 failing: Vercel. | Open the failing runs on GitHub and fix them before merging. |
✅ Passed checks: 9 passed
| Check name | Status | Explanation |
|---|---|---|
| Merge conflicts | ✅ | Merges cleanly into main. |
| Secrets | ✅ | No keys, passwords or tokens in the changed code. |
| Blocking issues | ✅ | No critical or high-severity issues in the changed lines. |
| Tests | ✅ | Tests were changed alongside the code. |
| PR size | ✅ | 43 lines changed. |
| Title check | ✅ | The title clearly states that it fixes an infinite loop on zero batch sizes during plan-limit pruning. |
| Description check | ✅ | The description provides a thorough explanation of the bug, the fix, sibling implementations, and test coverage. |
| Linked issues check | ✅ | No issue links were referenced in the description. |
| Out of scope changes check | ✅ | All changes are strictly focused on sanitizing the prune limit argument and validating it with tests. |
📝 Walkthrough
This pull request fixes an issue in pruneApiPlanLimitData where passing an invalid or zero batch limit caused an infinite rescheduling loop without deleting any records. It adds normalization to enforce a minimum batch size of 1 and falls back to the default prune batch for non-finite values, matching existing sibling cleanup routines. Tests have been added to verify that various edge-case limits successfully make progress and terminate.
| File | Changes |
|---|---|
convex/__tests__/apiPlanLimitPrune.test.ts |
Adds parameterized tests ensuring invalid and non-positive limit arguments allow the prune to make progress and terminate. |
convex/apiPlanLimitNotices.ts |
Sanitizes and enforces a minimum batch size of 1 for requested prune limits to prevent infinite rescheduling loops. |
ℹ️ Review info
- Commit:
fbb34a1 - Verdict: ✅ Pass
- Findings: none
- Review: local checks plus AI review of the changed lines
- Scope: Reviewed 2/2 selected files (of 2 total): 2 reviewed by AI, 0 from cache, 0 passed local checks with nothing risky enough to send to AI. Found 0 finding(s), No secrets found.
💬 Reply to any inline comment and Audit Bench Ai will recheck that code and answer in the thread. Mention @auditbench in the conversation to ask about the whole PR.
🛠️ Open the full report and fix with AI
Thanks for using Audit Bench Ai! Free pull request reviews for open source: paste any public PR at auditbenchai.com/scan.
Reviewed by Audit Bench Ai · Build fast. Check what ships. · Review any public PR free
Summary
pruneApiPlanLimitDatatakes its batch size straight from the caller with no floor:With
limit: 0(whichv.optional(v.number())accepts), both.take(0)calls return nothing,staleNotices.length >= batchreads0 >= 0as a full batch, and the mutation reschedules itself atrunAfter(0)with the same zero. That is an unbounded chain of scheduled executions that deletes nothing, while the 90-day retention backlog is never touched.limitis operator-callable by design — its own argument comment says it exists so tests can drive the drain-over-multiple-runs behaviour — and zero is a natural value to type when probing that. The cron passes{}, so only an operator reaches it.Why this is a back-port rather than a new idea
The guard already exists, word for word, in both prunes that were modelled on this one, and in a third:
convex/userPreferences.tsconvex/intelHistory.tspruneApiPlanLimitData"convex/agentFeedback.tsconvex/apiPlanLimitNotices.tsThe fix was applied to every derivative and never back-ported to the original they copied. This adds the same three lines, byte-identical to the siblings.
I deliberately did not also clamp
retentionMs:convex/intelHistory.tsexplains why that override stays shortening-capable, and the same reasoning holds here.Tests
convex/__tests__/apiPlanLimitPrune.test.tsgains a table case over0,-5,0.5,NaNandInfinity. Each must delete something and the reschedule chain must terminate, driven the same way the existing backlog test drives it.Red proof: with
convex/apiPlanLimitNotices.tsreverted to itsmainversion, all five fail.Verification
apiPlanLimitPrune,intelHistory,userPreferences,agentFeedbackconvex suites — 229 pass, 0 failnpm run typecheck:api, Biome,git diff --check— cleanSummary by CodeRabbit