Skip to content

fix: keep unrepresentable cost totals unavailable - #3501

Merged
steipete merged 1 commit into
mainfrom
codex/opencodex-checked-aggregates
Sep 8, 2026
Merged

fix: keep unrepresentable cost totals unavailable#3501
steipete merged 1 commit into
mainfrom
codex/opencodex-checked-aggregates

Conversation

@steipete

@steipete steipete commented Sep 8, 2026

Copy link
Copy Markdown
Owner

OpenCodex and combined cost reports could trap when individually representable token counts added up beyond the integer range. For example, deriving a total from input Int.max plus one output token crashes even though both fields are valid integers.

Reuse the existing checked optional-count accumulator and token-mix aggregation across derived totals, daily/model/session/hour buckets, and rolling-window totals. Keep overflow unavailable through the current aggregation pass, retain valid neighboring fields, and preserve explicit-total precedence and explicit zero. Summarize internal accumulators before projecting unavailable values into report rows, and avoid turning an unavailable present-day total into zero.

Remove duplicate sums and visibility flags: production LOC is net -125. Pricing, coverage, ordinary missing-data behavior, and serialized/cache formats remain unchanged. Materialized nil fields retain the existing partial-data contract; this patch does not add persistent overflow provenance. The regression reference now owns its original accumulator representation so it stays independent of the production refactor.

Validation: the new derived-total regression exits with signal 5 against main. The repaired focused run passed 113 tests in 8 suites, including same-day, cross-day, earlier-day overflow followed by valid rows, explicit zero, per-field preservation, and native-plus-OpenCodex report merging. Full make test passed all 1,036 selections across 87 groups on the first pass without retries or timeouts. make check and independent P0–P2 review passed. All checks passed for commit 14932f8: https://github.com/steipete/CodexBar/actions/runs/34202232775.

Includes changelog and documentation. This is the aggregation follow-up identified during #3486; that PR separately fixes numeric conversion and older parsed-cache reuse.

@clawsweeper

clawsweeper Bot commented Sep 8, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

steipete added a commit that referenced this pull request Sep 8, 2026
Replace unsafe floating-point boundary guards with failable integer conversion after each source's established rounding. Preserve valid neighboring fields and exact MiMo/OpenCodex integer payloads; saturate oversized finite subprocess timeouts.

Reparse OpenCodex caches written by older numeric parsers once, then retain normal warm-cache reuse. Production LOC: -16. Changelog and docs included. Full make test: 1,035 selections and 87 groups, all first-pass; final integration 145 focused tests passed. make check, independent review, and final-head macOS/Linux CI passed.

Report aggregation overflow is handled separately in #3501.
@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 8, 2026
@clawsweeper

clawsweeper Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed September 8, 2026, 4:02 AM ET / 08:02 UTC.

ClawSweeper review

What this changes

Use checked token accumulation in OpenCodex and combined cost reports so overflowing totals remain unavailable while valid neighboring counts survive.

Merge readiness

Ready for maintainer review

This remains a useful, focused repair: main and v0.56.8 retain the unchecked arithmetic, and the related parsing PR addresses a separate failure. No blocking defect was found in the introduced changes.

Priority: P2
Reviewed head: 14932f8eddfdd4112eba7b5e1ead70ec99ed1d81

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with substantial boundary coverage, existing-helper reuse, and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The OWNER-authored PR is exempt from external-contributor runtime proof; its reported validation exercises derived totals and aggregation boundaries through focused tests, not a claimed live-account run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The OWNER-authored PR is exempt from external-contributor runtime proof; its reported validation exercises derived totals and aggregation boundaries through focused tests, not a claimed live-account run.
Evidence reviewed 7 items Current main still contains the failure: The main revision derives totals with parts.reduce(0, +), so individually valid Int.max input and one output token exceed the integer range.
Latest release also retains unchecked addition: The same unchecked derived-total reduction exists in v0.56.8; this repair is not already shipped there.
Overflow state survives intermediate aggregation: The accumulator propagates overflow separately from missing values, and merged report summaries consume the internal day accumulators before unavailable values are projected into report rows.
Findings None None.
Security None None.

How this fits together

CodexBar turns local usage records into daily, session, model, and rolling-window cost summaries for its app and CLI. This change protects the token arithmetic between parsed records and those reports.

flowchart LR
  A[OpenCodex usage records] --> C[Checked token accumulation]
  B[Native cost reports] --> D[Combined report accumulation]
  C --> E[Daily and session buckets]
  C --> F[Rolling totals]
  D --> E
  E --> G[App and CLI cost reports]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test LOC production -125 net; tests +224 net Reusing checked accumulators removes duplicated production arithmetic while adding overflow coverage and an independent reference representation.

Technical review

Best possible solution:

Retain checked accumulation through each report pass, preserving explicit totals, valid token classes, and the existing serialized partial-data contract.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: deriving a total from Int.max input tokens and one output token reaches unchecked addition on main. The author reports a failing regression; this review did not execute tests.

Is this the best way to solve the issue?

Yes. Reusing the existing checked accumulators and retaining overflow state until summary projection is a focused repair without introducing a new persistent format.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c3f3ea1faf70.

Labels

Label changes:

  • add P2: This fixes a source-proven overflow trap in local cost aggregation with a bounded input-dependent blast radius.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The OWNER-authored PR is exempt from external-contributor runtime proof; its reported validation exercises derived totals and aggregation boundaries through focused tests, not a claimed live-account run.

Label justifications:

  • P2: This fixes a source-proven overflow trap in local cost aggregation with a bounded input-dependent blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The OWNER-authored PR is exempt from external-contributor runtime proof; its reported validation exercises derived totals and aggregation boundaries through focused tests, not a claimed live-account run.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • olddonkey: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit c807709 into main Sep 8, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant