fix: read Codex weekly quota from the correct rate-limit window (CLFY-25) #55

Merged
owlburtoe merged 1 commit from clfy-25-codex-week-quota into master 2026-07-17 14:27:40 -04:00
Owner

The premise was wrong (headline)

CLFY-25 assumed the permanent "Week: ~" lived in parseAnthropicUsage's seven_day branch. A live capture disproves that: with an Anthropic model active the footer renders both windows correctly — Usage: 49% … │ Week: 4%. The seven_day parser matches the live shape exactly.

The "~" is the Codex / OpenAI path, reproduced live with GPT-5.6 Sol active (Week: ~). The reporter was on a Codex model.

Root cause

parseOpenAIUsage read rate_limit.secondary_window.used_percent unconditionally. But the live Codex payload (plan_type: "prolite") has:

"rate_limit": {
  "primary_window":   { "used_percent": 16, "limit_window_seconds": 604800, "reset_at": 1784815409 },
  "secondary_window": null
}

secondary_window is null; the 7-day window (604800s) is in primary_window. Which window is weekly varies by plan — the standard shape (already in the test) puts a 5h window in primary and the weekly in secondary; here it's inverted.

Fix

openAIWeeklyWindow picks, of primary_window/secondary_window, the longest window that spans a weekly scale (limit_window_seconds ≥ 6 days), reading its used_percent + reset_at:

  • prolite → primary_windowWeek 16%
  • standard → secondary_window (604800 > 18000) → Week 42% (unchanged)
  • a sub-weekly-only window is omitted, not mislabeled "Week"
  • no span reported anywhere → legacy secondary→primary fallback

Anthropic parser is left untouched (it's correct); added a regression test for its live field format (float utilization, microsecond ISO resets_at with +00:00 offset).

Capture

Both payloads captured through pi's modelRegistry OAuth path — response shape only, never the token or headers — and recorded (PII redacted) in docs/plans/2026-07-17-cc-quota-payloads.md, per the repo's capture-don't-guess rule.

Test plan

  • bun run test — 15/15 suites green (new prolite + sub-weekly + live-Anthropic cases)
  • tsc --strict clean
  • Live-reproduced the bug (Week: ~ on GPT-5.6 Sol) and confirmed Anthropic renders Week correctly

Closes CLFY-25

## The premise was wrong (headline) CLFY-25 assumed the permanent "Week: ~" lived in `parseAnthropicUsage`'s `seven_day` branch. A live capture disproves that: with an Anthropic model active the footer renders **both** windows correctly — `Usage: 49% … │ Week: 4%`. The `seven_day` parser matches the live shape exactly. The "~" is the **Codex / OpenAI** path, reproduced live with `GPT-5.6 Sol` active (`Week: ~`). The reporter was on a Codex model. ## Root cause `parseOpenAIUsage` read `rate_limit.secondary_window.used_percent` unconditionally. But the live Codex payload (`plan_type: "prolite"`) has: ```jsonc "rate_limit": { "primary_window": { "used_percent": 16, "limit_window_seconds": 604800, "reset_at": 1784815409 }, "secondary_window": null } ``` `secondary_window` is **null**; the 7-day window (`604800s`) is in **`primary_window`**. Which window is weekly varies by plan — the standard shape (already in the test) puts a 5h window in `primary` and the weekly in `secondary`; here it's inverted. ## Fix `openAIWeeklyWindow` picks, of `primary_window`/`secondary_window`, the **longest window that spans a weekly scale** (`limit_window_seconds ≥ 6 days`), reading its `used_percent` + `reset_at`: - prolite → `primary_window` → **Week 16%** ✅ - standard → `secondary_window` (604800 > 18000) → **Week 42%** ✅ (unchanged) - a sub-weekly-only window is **omitted**, not mislabeled "Week" - no span reported anywhere → legacy secondary→primary fallback Anthropic parser is left untouched (it's correct); added a regression test for its live field format (float `utilization`, microsecond ISO `resets_at` with `+00:00` offset). ## Capture Both payloads captured through pi's `modelRegistry` OAuth path — response shape only, **never the token or headers** — and recorded (PII redacted) in `docs/plans/2026-07-17-cc-quota-payloads.md`, per the repo's capture-don't-guess rule. ## Test plan - [x] `bun run test` — 15/15 suites green (new prolite + sub-weekly + live-Anthropic cases) - [x] `tsc --strict` clean - [x] Live-reproduced the bug (`Week: ~` on GPT-5.6 Sol) and confirmed Anthropic renders Week correctly Closes CLFY-25
fix: read Codex weekly quota from the correct rate-limit window
All checks were successful
Plane Sync / Close referenced Plane work items (pull_request) Successful in 3s
82f268403c
The footer's Codex 'Week' quota rendered a permanent '~'. parseOpenAIUsage read
rate_limit.secondary_window unconditionally, but a live capture (plan_type
'prolite') showed secondary_window is null and the 7-day window is in
primary_window (limit_window_seconds 604800). Which window is weekly varies by
plan, so openAIWeeklyWindow now picks the longest weekly-scale window of
primary/secondary, reading its used_percent + reset_at. A sub-weekly-only window
is omitted rather than mislabeled 'Week'.

Captured both provider payloads through pi's modelRegistry OAuth path (response
shape only, no tokens) and recorded them under docs/plans/. The capture also
disproved the ticket's premise: Anthropic renders Week correctly live (the
seven_day parser matches the live shape); the bug was Codex-only. Anthropic
regression test added for the live field format (float utilization, microsecond
ISO reset with +00:00 offset).

Closes CLFY-25
owlburtoe merged commit 16e9b6fdfe into master 2026-07-17 14:27:40 -04:00
owlburtoe deleted branch clfy-25-codex-week-quota 2026-07-17 14:27:41 -04:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
owlburtoe/pi-claudify!55
No description provided.