Skip to content

Fix Codex adapter: session-token auth and real rate_limit shape - #3

Merged
devudilip merged 1 commit into
mainfrom
claude/ration-quota-tracker-g3uwc6
Aug 28, 2026
Merged

devudilip merged 1 commit into
mainfrom
claude/ration-quota-tracker-g3uwc6

Conversation

@devudilip

Copy link
Copy Markdown
Owner

What happened

First live test showed the Codex card stuck on "Not logged in" even with an active chatgpt.com session. A DevTools capture revealed two gaps:

  1. Auth: GET /backend-api/wham/usage requires the same short-lived bearer token the ChatGPT page mints from the browser session — cookies alone return 401.
  2. Shape: the live response nests the usage windows under rate_limit (rate_limit.primary_window / secondary_window, with limit_window_seconds identifying the 5h vs. weekly window), and additional_rate_limits[] entries wrap their own rate_limit block — different from the flat shapes the adapter was built against.

The fix

  • The adapter now does exactly what the page does: GET /api/auth/session (cookie-authed) for the token, then the usage call with Authorization: Bearer <token>. The token lives only in function scope — tests assert it never reaches the adapter's persistent cache and that the session call itself carries no Authorization header. A 200 session response without an accessToken is the logged-out signal and maps to unauthenticated without touching the usage endpoint.
  • wham_rate_limit (the live shape, recorded as a redacted fixture) is now the primary schema variant; the flat primary_window and five_hour_limit shapes remain as fallbacks. Windows are labeled from limit_window_seconds (18000 → "Session (5h)", 604800 → "Weekly"); additional_rate_limits entries become extra lanes (e.g. gpt-reserve).
  • Adapter version bumped to 2. README and CONTRIBUTING updated to state the session-token policy precisely: minted from the provider's own session endpoint at fetch time, used in-memory, never persisted.

Verification

  • npm run ci green: typecheck + 57 tests + build.
  • Fixture test asserts the live capture parses to Session (5h) 76%, Weekly 96%, gpt-reserve 100% — matching the capturing account's ChatGPT usage page (24% / 4% used).
  • After merge: rebuild, reload the unpacked extension, re-enable Codex — lanes should appear.

🤖 Generated with Claude Code

https://claude.ai/code/session_015gwwHsEgVxtmfRn3dEkBif


Generated by Claude Code

Verified against a live capture: the wham/usage endpoint requires the
same short-lived bearer the ChatGPT page mints from the browser session,
so cookies alone came back as 'Not logged in'. The adapter now does what
the page does — GET /api/auth/session (cookie-authed) for the token,
use it in-memory for the single usage request, never persist it (tested:
nothing reaches the adapter cache; the session call itself carries no
Authorization header). A 200 session response without an accessToken is
the logged-out signal and maps to unauthenticated without touching the
usage endpoint.

The live response also nests the windows under rate_limit (with
limit_window_seconds identifying the 5h/weekly windows) rather than at
the top level, and additional_rate_limits entries wrap their own
rate_limit block. That shape is now the primary schema variant, recorded
as a redacted fixture; the flat variants remain as fallbacks. Adapter
version bumped to 2. README/CONTRIBUTING updated to state the
session-token policy precisely.
@devudilip
devudilip merged commit 012cd58 into main Aug 28, 2026
1 check passed
@devudilip
devudilip deleted the claude/ration-quota-tracker-g3uwc6 branch August 28, 2026 20:36
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