Skip to content

fix(usage): ignore invalid Codex quota windows - #1913

Merged
decode2 merged 1 commit into
mainfrom
fix/codex-usage-window-validation
Oct 8, 2026
Merged

decode2 merged 1 commit into
mainfrom
fix/codex-usage-window-validation

Conversation

@decode2

@decode2 decode2 commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Linked issue

Fixes #1911

PR type

  • Bug fix

Summary

  • Reject missing, malformed, non-positive and non-finite Codex quota-window durations instead of displaying a fabricated 0m window.
  • Preserve real zero-percent usage and weekly-only plans without assuming a five-hour quota.
  • Keep the previous valid snapshot when a response contains no valid Codex header windows.

Changes

File Change
lib/shell-usage.ts Validate Codex JSON numbers and header durations; do not convert an absent duration into a zero-minute window.
tests/shell-usage.test.ts Cover invalid durations, strict malformed header conversion, finite values, real zero usage and weekly-only plans.
tests/gentle-shell.test.ts Exercise after_provider_response from no data through valid weekly quota and later incomplete headers.
docs/gentle-shell.md Explain provider-reported windows and retained valid snapshots without an assumed five-hour limit.

Verification

  • Four new regressions failed before the implementation.
  • node --experimental-strip-types --test tests/shell-usage.test.ts tests/shell-bar.test.ts tests/gentle-shell.test.ts: 357 passed.
  • Type check: no regressions against the recorded baseline.
  • git diff --check: passed.
  • Native consolidated review: approved and acknowledged for the exact committed candidate.
  • Separate read-only verifier: scoped verification passed, including 357/357 tests and synthetic NaN/Claude compatibility checks.
  • Other provider parsers and NaN's valid zero-duration billing-period windows remain unchanged.
  • Full-suite validation through the existing sequential runner with equivalent direct stage commands: 5,332 tests passed, 44 skipped, zero failures. Provider contract, runtime harness, types, generated runtime modules and package contents all passed.
  • An initial run inherited the private temporary-file umask and failed an unrelated transport-permissions fixture. Restoring the original umask passed that isolated test and the complete suite without any source changes.
  • All CI checks, including packed installation and platform-specific coverage, must pass before merge.

Contributor checklist

  • Linked issue is approved.
  • One focused work-unit commit includes tests and documentation.
  • Conventional commit format; no attribution trailers.
  • Exactly one PR type label: type:bug.

Shellcheck and changed-skill execution are not applicable: no shell scripts or skills changed.

Summary by CodeRabbit

  • Bug Fixes
    • Codex quota windows now appear only when usage and duration are valid, with durations greater than zero. Missing, blank, invalid, or non-finite durations no longer appear as zero-minute windows or create an assumed five-hour quota.
    • Valid windows showing 0% usage remain visible. Responses without valid quota windows no longer replace the last valid usage snapshot.

@decode2 decode2 added the type:bug Bug fix label Oct 8, 2026
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 325637b4-c3a0-4cc1-8ff2-512f041716bc
📥 Commits

Reviewing files that changed from the base of the PR and between d5ac853 and 5ee483a.

📒 Files selected for processing (4)
  • docs/gentle-shell.md
  • lib/shell-usage.ts
  • tests/gentle-shell.test.ts
  • tests/shell-usage.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

Codex usage parsing now ignores windows with missing, non-finite, or non-positive durations. Tests cover valid zero-percent windows, malformed headers and payloads, and preservation of the previous snapshot when response headers contain no valid window.

Changes

Codex usage window validation

Layer / File(s) Summary
Validate Codex usage windows
lib/shell-usage.ts, tests/shell-usage.test.ts
Header and payload parsing reject windows with invalid usage or duration values. Tests confirm that valid zero-percent windows remain available.
Verify snapshot handling
tests/gentle-shell.test.ts, docs/gentle-shell.md
Regression coverage checks that incomplete headers do not replace a valid snapshot and that valid secondary windows remain visible. Documentation describes the parsing behavior.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: alan-thegentleman

Merge Risk: ⚪ Minimal · up to 5ee48

Invalid Codex quota durations are ignored, and incomplete responses preserve the last valid snapshot. No material merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: ignoring invalid Codex quota windows.
Linked Issues check ✅ Passed Issue #1911 requires valid provider-reported Codex windows only. The PR validates finite usage and positive finite durations in parseWindow. headerWindow uses strict numeric conversion and rejects…
Out of Scope Changes check ✅ Passed The changes stay within issue #1911. Source changes update Codex JSON and header window validation. Tests add regression coverage for the required parsing and response-event behavior. Documentation ex…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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

Comment @coderabbitai help to get the list of available commands.

@decode2
decode2 merged commit 9782d26 into main Oct 8, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(usage): incomplete Codex windows render a fabricated 0m quota

1 participant