Skip to content

fix: render last-measured usage for stale reset windows - #204

Merged
Loongphy merged 2 commits into
mainfrom
fix/usage-stale-snapshot
Nov 14, 2026
Merged

Loongphy merged 2 commits into
mainfrom
fix/usage-stale-snapshot

Conversation

@Loongphy

Copy link
Copy Markdown
Owner

Summary

Usage cells reused the auto-switch inference that treats an elapsed resets_at as a refilled quota (remainingPercentAt → 100). When the API could not refresh, an expired snapshot displayed a fake full quota — whether the window lapsed by one minute or thirty days. This separates the decision-side inference from what the display actually measured:

  • remainingPercentAt keeps its optimistic elapsed-window inference for scoring, but gains a resets_at > 0 bound so dirty timestamps (0, negative) no longer fabricate 100%.
  • New measuredRemainingPercent reports the stored 100 - used_percent point value with no reset inference.
  • formatRateLimitFullAlloc (the only usage-cell formatter, shared by list, list --live, switch, remove) now renders the measured percent plus a reset time only when a real future resets_at exists; missing, invalid, or elapsed timestamps render the measured percent with a stale marker instead of 100% or -.
  • Narrow columns keep a compact stale flag (N%!) instead of shortening to a bare N% that would pass for a live reading.
  • JSON output is unchanged: used_percent/resets_at are emitted raw; docs/json-api.md now states the snapshot-staleness contract.

Test plan

  • zig build clean; zig build test test-helpers full suite green.
  • New pinned tests: stale marker on missing/invalid/elapsed resets_at, future-reset cells unchanged, measuredRemainingPercent clamping, decision-side remainingPercentAt semantics, narrow-cell and table width sweeps for the compact flag.
  • ReleaseSafe E2E against isolated CODEX_HOME fixture (expired / null / zero / future resets_at): list --skip-api renders 0% (stale), 70% (stale), 20% (stale), 90% (14:25); list --skip-api --json keeps raw snapshot fields.

Usage cells reused the auto-switch inference that treats an elapsed
resets_at as a refilled quota, so stale snapshots displayed a fake 100%.
The inference stays scoped to decision code (remainingPercentAt with a
resets_at > 0 bound); display cells now show the last-measured remaining
percent via measuredRemainingPercent and mark missing, invalid, or
elapsed reset timestamps as stale instead of a reset time or dash.
Narrow columns shortened N% (stale) to a bare N%, which passed for a
live reading. The stale marker now collapses to N%! instead of shedding
outright, pinned by a cell-writer test and a table width sweep.
@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

Greptile CLI Reused the Greptile CLI review of 06b09be by Loongphy. The code matches this PR, so no new review ran.

[Medium impact] The PR appears safe to merge; the previous stale-marker issue is fixed.

Summary

The PR separates measured usage from the reset-time guess used to choose accounts.

  • Usage tables mark old rate-limit readings as stale.
  • Account scoring treats only positive elapsed resets as restored.

The previous narrow-table finding is fixed. No new actionable issues were found.

Reviews (1) · Last reviewed commit: "fix: keep a compact stale flag on narrow..." · Reviewed by Greptile

@pkg-pr-new

pkg-pr-new Bot commented Nov 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

@loongphy/codex-auth-darwin-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-darwin-arm64@06b09be

@loongphy/codex-auth-darwin-x64

npx https://pkg.pr.new/@loongphy/codex-auth-darwin-x64@06b09be

@loongphy/codex-auth-linux-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-linux-arm64@06b09be

@loongphy/codex-auth-linux-x64

npx https://pkg.pr.new/@loongphy/codex-auth-linux-x64@06b09be

@loongphy/codex-auth-win32-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-win32-arm64@06b09be

@loongphy/codex-auth-win32-x64

npx https://pkg.pr.new/@loongphy/codex-auth-win32-x64@06b09be

@loongphy/codex-auth

npx https://pkg.pr.new/@loongphy/codex-auth@06b09be

commit: 06b09be

@Loongphy
Loongphy merged commit 5d5205a into main Nov 14, 2026
13 checks passed
@Loongphy
Loongphy deleted the fix/usage-stale-snapshot branch November 14, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant