fix: reject unrepresentable numeric usage safely - #3486
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 8, 2026, 3:08 AM ET / 07:08 UTC. ClawSweeper reviewWhat this changesThe PR safely converts numeric usage counts and large subprocess timeouts, refreshes older OpenCodex caches, and adds regression coverage and documentation. Merge readiness✅ Ready for maintainer review Keep open as a useful, review-ready fix: current main still contains the unsafe conversions, and the previous merge-conflict blocker is resolved. No introduced blocking defect was found. Priority: P2 Review scores
Verification
How this fits togetherCodexBar reads local usage logs and provider responses to display usage and spending. These changes validate numeric inputs before reporting or caching them, and safely convert timeouts used by subprocesses. flowchart TD
A[Local usage logs] --> C[Checked numeric conversion]
B[Provider metric responses] --> C
C --> D[Usage and spending reports]
A --> E[OpenCodex cache version check]
E -->|Older parser| C
E -->|Current parser| D
F[Subprocess timeout] --> G[Safe timer duration]
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Retain the focused checked conversions and transactional cache invalidation, with aggregate-overflow hardening handled separately. Do we have a high-confidence way to reproduce the issue? Yes, from source: main admits the upward-rounded Double(Int.max) boundary before trapping conversion, and the added fixtures exercise that boundary. No runtime reproduction was performed during this review. Is this the best way to solve the issue? Yes. Failable conversion after the existing rounding step is a narrow repair, and cursor versioning prevents older cached results from bypassing it. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c3f3ea1faf70. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
3c902f5 to
be1cd62
Compare
|
Checking the landing path for this completed fix. The PR still targets the old CLI-login branch even though #3484 is on main. I am retargeting it to main, preserving the numeric changes and their validation, then checking the synchronized candidate before landing. |
Prevent overflow traps when valid individual token counts add beyond the integer range. Reuse checked per-field accumulators for OpenCodex derived totals and daily/model/session/hour/window reports, and for combined native/OpenCodex reports. Keep overflow unavailable during each aggregation pass, preserve valid neighboring fields and explicit-zero/explicit-total semantics, and retain existing missing-data and serialized-cache contracts. Remove duplicated sums and visibility flags: production LOC -125. Includes changelog, docs, and an independent legacy reference. The regression crashes main with signal 5; repaired focused113 tests and full1,036 selections/87groups passed, all first-pass. make check, independent review, and final-head macOS/Linux CI passed. Aggregation follow-up to #3486.
Usage parsers could admit an unrepresentable rounded integer because Double(Int.max) rounds upward. Replace the trapping conversions in MiMo, Pi/OMP, OpenCodex, and Bedrock with failable conversion after each source's existing rounding step. Oversized finite subprocess timeouts now saturate safely.
Preserve valid neighboring fields, MiMo/OpenCodex exact integer payloads, Pi/Bedrock nearest rounding, and MiMo/OpenCodex truncation. OpenCodex's established negative-fraction fallback remains zero. Version the OpenCodex parse cursor so values clamped by an older parser are reparsed once from unchanged logs; subsequent reads reuse the corrected cache. The generation lives in the cursor transaction so an older writer cannot leave a misleading current-generation marker behind.
The refactor removes 16 production lines. Includes boundary, valid-field, rounding, and legacy-cache regressions, plus changelog and parsing documentation.
Validation: the added negative-fraction regression failed before correction, and the legacy-cache regression failed for both absent and old generations before invalidation was added. The repaired focused suites passed. Full make test passed all 1,035 selections across 87 groups on the first pass, with no retries or timeouts. make check passed. After integrating latest main, 145 tests in 9 affected suites passed; the numeric production code was unchanged. Independent P0–P2 review passed on the final integration. All checks passed for commit 9264b28: https://github.com/steipete/CodexBar/actions/runs/34197381254.
This patch fixes numeric conversion and reuse of older parsed rows. The separate, pre-existing unchecked additions in OpenCodex report aggregation are addressed separately in #3501; this PR does not claim comprehensive aggregate-overflow protection.