Skip to content

fix(codex): preserve usage data and show refresh failures - #208

Merged
matej21 merged 1 commit into
mainfrom
fix/codex-usage-freshness
Sep 21, 2026
Merged

matej21 merged 1 commit into
mainfrom
fix/codex-usage-freshness

Conversation

@matej21

@matej21 matej21 commented Sep 21, 2026

Copy link
Copy Markdown
Member

Summary

  • Set an explicit okena/<version> User-Agent on Codex usage, reset-credit, and token-refresh requests. Usage requests also advertise Accept: application/json.
  • Remove the local session usage fallback and its unused dependency. Failed API requests preserve the last successful API snapshot instead of replacing it with historical session data.
  • Show the age of the last successful update, a stale indicator, the last error, failed-attempt count, and the next retry/update countdown in the usage popover. Keep the popover accessible before the first successful fetch.
  • Refresh the countdown while the popover is open, retain exponential backoff during failures, and clear errors on recovery. Hover does not bypass failure backoff.
  • Surface missing credentials, failed token refresh, HTTP/network failures, and invalid usage responses instead of silently leaving the widget unchanged.

Context

An API failure could previously replace current usage with a days-old local session snapshot, causing percentages to jump. That fallback also counted as a successful fetch. Diagnostics now distinguish a fresh API snapshot from a failed refresh.

Live requests with the same credentials returned Cloudflare challenges with an absent/Python User-Agent and JSON with the Okena User-Agent. The shared HTTP client already sets an Okena User-Agent on main; this change makes that requirement explicit at the Codex request sites. It does not establish that headers alone explain every observed 403.

Verification

  • Targeted crate tests cover failure/recovery freshness, first-fetch failure, bounded retry backoff, and rejecting missing usage while accepting a genuine zero.
  • cargo test -p okena-ext-codex: 8 tests passed.
  • cargo clippy -p okena-ext-codex --all-targets --no-deps: passed; the dependency okena-transport emits an existing unused action_url warning.
  • Changed-file rustfmt check and git diff --check: passed.
  • Desktop visual behavior has not been manually exercised.

@matej21

matej21 commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

The initial PR check failed in the unrelated updater test installer::tests::timeout_restores_the_previous_binary at installer.rs:410: the returned error did not contain timed out. The assertion does not print the actual error, so its cause is not established. The push workflow for the same commit passed. All 7 installer tests, including the failing test, also passed locally. Re-running the failed CI job without code changes.

@matej21

matej21 commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

The failed job passed on rerun without code changes: https://github.com/contember/okena/actions/runs/35606308593 . Linux checks/tests, Windows compilation, and mobile checks are now green. The original updater-test failure remains unexplained; it did not reproduce locally or on this rerun.

@matej21
matej21 merged commit af62699 into main Sep 21, 2026
14 of 15 checks passed
@matej21
matej21 deleted the fix/codex-usage-freshness branch September 21, 2026 14:24
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