Skip to content

fix(codex): publish live quota while local history scans continue - #1222

Closed
sahiinthehood wants to merge 1 commit into
robinebers:mainfrom
ainatechnologies:fix/codex-quota-refresh
Closed

fix(codex): publish live quota while local history scans continue#1222
sahiinthehood wants to merge 1 commit into
robinebers:mainfrom
ainatechnologies:fix/codex-quota-refresh

Conversation

@sahiinthehood

@sahiinthehood sahiinthehood commented Sep 5, 2026

Copy link
Copy Markdown

Latest tested candidate: 6d26110 on fix/codex-quota-refresh. GitHub's closed PR head still points to the initial candidate; reopen only after issue approval/assignment to refresh the PR to the current branch tip. The description below covers that latest candidate.

Fixes #1223 (awaiting maintainer approval and assignment before reopening).

TL;DR

Keep Codex quota updates responsive when local token-history scans take longer than the provider refresh deadline. Preserve local history processing instead of letting it prevent fresh Session/Weekly values from reaching the menu bar.

What was happening

  • Codex fetched live quota successfully, then awaited pricing and all three local history scans before returning its snapshot.
  • A large local archive could exceed the 120-second provider deadline repeatedly. The store kept the old snapshot, leaving the menu-bar percentage frozen even though live quota was available.

What this changes

  • Give local history a five-second wait budget after fetching quota.
  • Keep one in-flight scan per provider instance. A slow scan continues in the background, and a later refresh collects its completed result without starting overlapping scans.
  • Publish fresh quota with an existing-style provider warning while history is pending. The store's existing last-good-history preservation remains in use.
  • Use byte-range newline searches in the streaming reader and Codex parser, preserving existing record boundaries and oversized-record behavior. A release-mode synthetic 32 MiB line-boundary benchmark improved from ~0.09s to ~0.027s (not an end-to-end scan-speed claim).
  • Run the scan at utility priority and limit native Codex parsing to two concurrent files.
  • Keep native Codex, pi, and OpenCode history aggregation and normal authentication/network error handling.
  • Document the first-launch/history delay and add regression coverage for pending scans, result collection, cancellation, fast scans, and live quota publication.

Heads-up

  • A completed background scan appears on a subsequent automatic or manual refresh; this patch does not add a new UI callback or change refresh scheduling.
  • A permanently stuck scanner still cannot provide new history, but it no longer blocks quota refreshes or causes repeated scan launches. Local history is machine-local, as before.
  • This branch is based directly on upstream main (753e2fe), with no downstream product or branding changes. No visual layout/rendering changes.

Tests

  • Full swift test --disable-sandbox -j 2: 1,318 XCTest cases, 3 explicit live-test skips, zero failures; 3 Swift Testing checks passed.
  • Final wait-budget adjustment: 7 focused provider/history cases passed.
  • Live/parity test flags disabled; automated authentication uses fixtures.
  • Cold local validation: live quota continued refreshing while the single background scan completed and wrote its persistent cache. A subsequent automatic refresh published Today, Yesterday, 30-day history, and model breakdowns.
  • Final optimized build, warm-cache relaunch: quota and local history published together in 4.65 seconds, with no history-updating warning. Process returned to ~0.1% CPU.
  • The five-second history budget accommodates the measured ~2.5-second warm cache load while remaining well below the provider deadline.
  • Release build and local ad-hoc signing passed. No release version changes or distributed artifacts. Local iCloud provisioning was unavailable; this was a local usage/history test.

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Thanks for your interest in contributing to OpenUsage!

External pull requests must reference an open issue that:

  1. Has been approved by a maintainer with the approved label.
  2. Is assigned to the pull request author (@sahiinthehood).

Please discuss the change on an issue first, wait for a maintainer to approve and assign it to you, then reopen this pull request with Fixes #123 in its description.

Read the contribution guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex quota stays stale when cold local history exceeds refresh deadline

1 participant