fix(providers): adapt to Claude 429 edge limits and Codex window schema change#4
Open
danielbanariba wants to merge 1 commit into
Open
Conversation
…ma change Two independent upstream API changes broke usage reporting: Codex (chatgpt.com/backend-api/wham/usage) now returns the 7-day window as primary_window (limit_window_seconds 604800) with secondary_window null, breaking the positional session/weekly assumption. Classify windows by duration instead of position, fall back to positions only for legacy payloads without limit_window_seconds, and treat a single-window payload as valid instead of a partial_data failure. A missing window yields null (renders "-- left"), not 0. Claude (api.anthropic.com/api/oauth/usage) now rate-limits at the edge, returning 429 with retry-after ~340s even unauthenticated. GJS's Soup.Message.get_status() validates against the Soup.Status enum, which has no 429 entry and throws "429 is not a valid value for enumeration Status" — misclassifying the rate limit as a network error and skipping backoff. Read the status_code property instead. Also set a 30s Soup session timeout (a hung request otherwise wedges the scheduler's per-provider queue until restart) and raise the default poll interval 180s -> 600s to respect the edge limit. State now keeps the last known usage on failure instead of blanking the panel, and render surfaces a RATE_LIMITED warning so retained data is not mistaken for current.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Both providers stopped reporting usage after independent upstream API changes:
chatgpt.com/backend-api/wham/usage) now returns the 7-day window asprimary_window(limit_window_seconds: 604800) withsecondary_window: null. The positional session/weekly mapping put the weekly figure under "Session" and left "Weekly" dead.api.anthropic.com/api/oauth/usage) now rate-limits at the edge, returning429withretry-after ~340seven unauthenticated. Under GJS this surfaced as a hard throw:Soup.Message.get_status()validates its return against theSoup.Statusenum, which has no429entry, so it throws — the 429 was misclassified as a network error and the rate-limit backoff never engaged. The panel went blank.Changes
Codex window handling (
shared/core/normalize.js,shared/providers/codex.js)limit_window_seconds >= 86400→ weekly) instead of position; fall back to positions only for legacy payloads without a duration.ok) instead of apartial_datafailure.null→ renders-- left, not a misleading0%.Claude / GNOME runtime (
extension/lib/runtime/fetch.js,shared/core/scheduler.js)status_codeproperty instead ofget_status(), so unlisted-but-valid HTTP codes (429, 451, …) don't throw.Resilience (
shared/core/state.js,shared/ui/render.js)RATE_LIMITEDwarning so retained data is clearly labeled as stale rather than mistaken for current.Testing
bun test— 61 pass, 0 fail (9 files). New/updated coverage:normalize.test.js— flipped real payload (7d in primary / null secondary), classic both-windows mapping, legacy positional fallback.codex-provider.test.js— single-windowok, no-windowsschema_changed.state.test.js— last-known data retained on failure.scheduler.test.js— 600s interval.ui-render.test.js— rate-limited warning alongside retained data.Verified live against both real APIs (GJS against the actual
Soupruntime): Codex weekly reads correctly from the relocated window, and the Claude 429 is now handled as a rate limit with backoff instead of throwing.Notes / follow-ups (not in this PR)
kde/shared/code/runtime.jsxhrFetch()has no request timeout — same queue-wedge risk exists there, but QMLXMLHttpRequest(Qt5 V4 / Qt6) has notimeout/ontimeout, so a QML-side watchdog would be needed. Worth a separate issue.classifyCodexWindows()keeps the first window per duration class; if the API ever returns two same-duration windows the second is dropped. No such payload observed.