GeezerVison is showing github.com — fix(workbuddy): keep exact decimals for quota rounding by shu-chen-dot-ca · Pull Request #8566 · lidge-jun/opencodex
Conversation
shu-chen-dot-ca
commented
Nov 11, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
WorkBuddy's credit totals were summed exactly, but then turned back into JavaScript numbers before the dashboard rounded the unavailable share. Converting to a number can erase the difference between an exact half-percent tie and a value just below it. With two 0.5-credit packages reporting 0.4975 and 0.49750000000000005 remaining, the exact remaining sum is 0.99500000000000005. The unavailable share is just under 0.5%, but the quota bar showed 1% instead of 0%.
src/providers/workbuddy-credit-balance.ts: the balance gets an optional exact: { total, remaining } pair of plain decimal strings. Quoted summary values keep their text. Unquoted numbers keep their established meaning (their shortest decimal, as the existing sum already used), since JSON.parse has already rounded them. Estimated remaining (total - used - frozen, floored at zero) is subtracted exactly. Input is bounded before any BigInt arithmetic: at most 16 integer digits (balances above MAX_SAFE_INTEGER are already rejected) and 32 fractional digits, plus the existing 512-package and 16-group limits. If any package lacks a bounded exact form (a subnormal number, an over-long quoted fraction), the pair is omitted and the numeric fields behave as before. When the pair is present, total and remaining are the nearest numbers to the exact text.
normalizeWorkBuddyCredits accepts responses with only the numeric fields as before. It rejects a balance whose exact pair is malformed (not exactly two plain-decimal strings, signs, exponents, out of bounds) or encodes different numbers than total/remaining, the same way it already rejects malformed groups.
src/providers/quota/workbuddy.ts: the enterprise-meter fallback carries the same pair for quoted limitNum/credit.
gui/src/quota-summary.ts: the quota bar rounds from the exact pair when present. Because exact sums carry no roundoff, a remaining balance above the total is treated as contradictory and the credits window is omitted. Without the pair, the existing numeric path and its 512-package roundoff tolerance are unchanged.
- The pair covers
total and remaining only, the two values the percentage uses. used, frozen and group amounts are displayed with at most two fraction digits and do not round at a percentage boundary, so they stay numeric. The balance stays display-only: routing, ranking and account eligibility do not read it.
structure/providers/workbuddy.md describes the pair, its bounds and its validation.
Closes #8324
Verification
Bun 1.4.4, Linux, head f13b434b9 on dev 2e8f63da8 (0 behind at push time). The tested tree is identical to the pushed head.
- New regressions:
tests/providers/workbuddy-quota.test.ts (exact text and numeric binding, DTO JSON round trip through normalizeWorkBuddyCredits, numeric-only payloads, estimated remaining with frozen credits, MAX_SAFE_INTEGER total with 32-digit fractions, subnormal and over-long values omitting the pair, 13 malformed or inconsistent exact shapes, enterprise fallback below-half/tie/over-used/subnormal) and gui/tests/quota-summary.test.ts (below-half 0%, exact tie 1%, just-above 1%, full 0%, exact over-total omitted while the weekly window stays). On unchanged dev these fail: 3 backend and 1 GUI test. With the change: bun test tests/providers/workbuddy-quota.test.ts 14 pass / 0 fail; cd gui && bun test --isolate tests/quota-summary.test.ts tests/workbuddy-credits.test.tsx tests/quota-summary-bar.test.tsx 30 pass / 0 fail.
bun run typecheck && bun run privacy:scan && bun run structure:check && bun run lint:gui && OCX_TEST_MAIN_TIMEOUT_MS=3600000 bun run test --parallel=4 --timeout 30000 with the exclusions below: passed, 0 failures.
- Full-suite exceptions, each failing the same way on unchanged
dev on this shared host and outside the files this PR touches:
tests/clients/link-supervisor.test.ts: EACCES, because its fixed /tmp/opencodex-link-supervisor-test directory belongs to another local user.
tests/update/update-orchestrated-entry.test.ts "npm child fences identity, deadline and sync before mutation and installs the pinned version".
tests/config/config-ownership-concurrent-record.test.ts "a registration racing uninstall is either removed or refused, never left unreported" (Cover refused uninstall in concurrent config ownership test #8379).
- The other tests in those two files ran separately and passed (67 pass, 2 filtered out).
- CodeRabbit's only finding (docstring coverage 73% < 80%) is addressed by doc comments on the six touched functions that lacked them.
| Before |
After |
 |
 |
Checklist
- Scope stays focused and avoids unrelated cleanup.
- Docs or release notes were updated when needed.
- Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.
Review readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
-
Required local validation passed; commands, results, and any full-suite exception are documented.
-
I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
-
I resolved all correct Codex and CodeRabbit findings.
-
My PR is ready for review.
Summary by CodeRabbit
- Bug Fixes
- WorkBuddy quota summaries now calculate unavailable credit percentages more accurately, including around rounding boundaries.
- Invalid or over-total credit balances no longer produce misleading percentage displays; valid quota windows remain available.
- Precise decimal credit balances are preserved for more reliable enterprise quota totals and percentage displays.
- Documentation
- Clarified how precise credit balances affect the displayed quota percentage and when that information may be unavailable.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
✅ Deterministic PR hygiene checks passed.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
✅ READY
- all PR quality gates passed; the review readiness checklist is complete.
Review readiness checklist
- ✅ Required local validation passed; commands, results, and any full-suite exception are documented.
- ✅ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
- ✅ I resolved all correct Codex and CodeRabbit findings.
- ✅ My PR is ready for review.
✅ 4/4 boxes ticked.
This pull request is already Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers: @lidge-jun @Ingwannu
Hygiene
✅ Deterministic PR hygiene checks passed.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Nov 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

No actionable comments were generated in the recent review.
Walkthrough
-
WorkBuddy quota balances now preserve bounded exact decimal totals and remaining amounts through aggregation and enterprise quota handling. The dashboard uses exact ratios for percentage rounding when available and validates numeric-only balances.
Changes: WorkBuddy quota precision
| Layer / File(s) |
Summary |
Exact balance aggregation and validation src/providers/workbuddy-credit-balance.ts, tests/providers/workbuddy-quota.test.ts, structure/providers/workbuddy.md |
Balances can carry optional exact decimal totals and remaining values. Package aggregation retains exact sums when inputs are bounded, and normalization rejects malformed or inconsistent metadata. Tests cover JSON round trips and numeric-only compatibility. The documentation describes the optional metadata. |
Enterprise quota projection src/providers/quota/workbuddy.ts, tests/providers/workbuddy-quota.test.ts |
Enterprise quota handling uses exact total and remaining values when available. It retains the existing numeric calculation otherwise. Tests check exact metadata and percentage cases in serialized quota reports. |
Dashboard percentage calculation gui/src/quota-summary.ts, gui/tests/quota-summary.test.ts |
The dashboard rounds from exact ratios when available. Without exact ratios, it accepts only positive totals and remaining values within the stated tolerance. Invalid over-total balances do not supply the credits window. Tests cover rounding boundaries and a valid weekly quota window. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Low
Possibly related PRs
- lidge-jun/opencodex#8323: Introduced the WorkBuddy unavailable-credit window and numeric balance aggregation that this change extends with exact values.
- lidge-jun/opencodex#7604: Added the WorkBuddy credit balance model and display-only quota flow extended by this change.
Merge Risk: Minimal · up to f13b4
-
This change makes WorkBuddy quota percentages more accurate near whole-percent rounding boundaries. Existing numeric-only payloads behave as before, and the balance is not used for routing or account eligibility. No actionable merge-blocking risk remains.
Pre-merge checks: 4
-
| Check name |
Status |
Explanation |
| Description Check |
 |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
 |
The title "fix(workbuddy): keep exact decimals for quota rounding" matches the main change. The PR adds an optional exact-decimal total/remaining pair to WorkBuddy credit balances so the quota bar rou… |
| Linked Issues check |
 |
Issue #8324 (direct) requires exact precision through provider aggregation, quota transport, and dashboard normalization. It also requires numeric DTO compatibility, bounded validation, and display-on… |
| Out of Scope Changes check |
 |
The whole-PR diff of gui/src/quota-summary.ts is limited to the WorkBuddy unavailable-share path. It adds an import of workBuddyExactRatio and WorkBuddyCreditBalance from src/providers/workbuddy-credi… |
Full details: Title check
-
Explanation
The title "fix(workbuddy): keep exact decimals for quota rounding" matches the main change. The PR adds an optional exact-decimal total/remaining pair to WorkBuddy credit balances so the quota bar rounds values just below a half-percent tie correctly. The changed files (workbuddy-credit-balance.ts, workbuddy.ts, quota-summary.ts, and their tests and docs) all support this aim. The title is concise and specific, and it follows a conventional commit style.
Full details: Linked Issues check
-
Explanation
Issue #8324 (direct) requires exact precision through provider aggregation, quota transport, and dashboard normalization. It also requires numeric DTO compatibility, bounded validation, and display-only use. The whole-PR diff of gui/src/quota-summary.ts (merge base to head) confirms the dashboard path. It adds workBuddyUnavailablePercent, which uses the exact pair when present. It returns no percentage for a nonpositive total or a remaining balance above the total. Without the pair, it keeps the numeric path with the 1 + Number.EPSILON * 1024 tolerance. The change to roundedUnavailablePercent now takes exact ratios and rounds an exact half up. The provider and enterprise-fallback behavior, the normalization checks, and the documentation are described in the PR summary and were assessed in the prior review. Those files were not re-read in this pass. The incremental diff from the previous reviewed head (c9d2d8c) could not be read, so the prior conclusions are kept for unchanged areas. The tests listed in the PR cover below-half (0%), exact tie (1%), just-above (1%), full usage, over-total omission, and malformed or inconsistent exact metadata. Minor note: the objectives cite head 17b536327, while the reviewed head is f13b434. This does not change the coding assessment.
Full details: Out of Scope Changes check
-
Explanation
The whole-PR diff of gui/src/quota-summary.ts is limited to the WorkBuddy unavailable-share path. It adds an import of workBuddyExactRatio and WorkBuddyCreditBalance from src/providers/workbuddy-credit-balance. That import is required by the exact path. No routing, ranking, or account-eligibility code appears in the reviewed diff. The other changed files, per the PR summary and prior review, are src/providers/workbuddy-credit-balance.ts, src/providers/quota/workbuddy.ts, structure/providers/workbuddy.md, and the WorkBuddy provider and GUI tests. Each supports #8324. The prior review found no unrelated cleanup. The incremental diff could not be read, so a change since c9d2d8c is not fully verified.
Finishing Touches
-
Generate unit tests (beta)
-
- 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
-
Commits
-
Reviewing files that changed from the base of the PR and between c9d2d8c and f13b434.
Files selected for processing: 3
-
gui/src/quota-summary.ts
src/providers/quota/workbuddy.ts
src/providers/workbuddy-credit-balance.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Rebased onto dev 2e8f63da8 (it was 108 commits behind); no conflicts. The only dev change in a touched file was in unrelated parts of gui/src/quota-summary.ts.
Added doc comments to textDecimal, addDecimals, packageAmount, parseWorkBuddyCredits, roundedUnavailablePercent and fetchWorkBuddyQuota for CodeRabbit's docstring-coverage warning. No behaviour change.
Re-ran on head 17b536327: bun run typecheck && bun run privacy:scan && bun run structure:check && bun run lint:gui && OCX_TEST_MAIN_TIMEOUT_MS=3600000 bun run test --parallel=4 --timeout 30000 passed, with these exclusions, all of which fail the same way on unchanged dev on this shared host:
tests/clients/link-supervisor.test.ts: EACCES on a fixed /tmp path owned by another local user.
tests/update/update-orchestrated-entry.test.ts "npm child fences identity, deadline and sync before mutation and installs the pinned version".
tests/config/config-ownership-concurrent-record.test.ts "a registration racing uninstall is either removed or refused, never left unreported" (Cover refused uninstall in concurrent config ownership test #8379).
The rest of those two files ran and passed (67 pass, 2 filtered out). bun test tests/providers/workbuddy-quota.test.ts passed with 14 pass / 0 fail, and the GUI quota tests with 30 pass / 0 fail.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Maintainer integration (merge manager, owner backlog decision B: contributor bug fixes are reviewed and merged when correct).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
lidge-jun
Awaiting requested review from lidge-jun
lidge-jun is a code owner
Ingwannu
Awaiting requested review from Ingwannu
Ingwannu is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|