Skip to content

fix(models): label codex weekly usage windows correctly#31938

Merged
steipete merged 1 commit intoopenclaw:mainfrom
bmendonca3:bm/agent-runner-stall-ratelimit
Mar 2, 2026
Merged

fix(models): label codex weekly usage windows correctly#31938
steipete merged 1 commit intoopenclaw:mainfrom
bmendonca3:bm/agent-runner-stall-ratelimit

Conversation

@bmendonca3
Copy link

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: Codex secondary usage window was labeled solely from limit_window_seconds, which can report 86400 even when reset cadence is clearly weekly.
  • Why it matters: openclaw models status can display Day ... while showing multi-day reset countdowns, which misrepresents codex quota scope.
  • What changed: codex usage parsing now infers secondary label from reset cadence as a fallback (using primary/secondary reset gap) and keeps explicit weekly windows intact.
  • What did NOT change (scope boundary): no auth/profile probing, transport, or CLI rendering pipeline changes outside codex usage label selection.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • openclaw models status now labels codex secondary usage as Week when reset cadence indicates a weekly budget, even if API window seconds report 24h.

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node v22, Vitest
  • Model/provider: openai-codex usage parser path
  • Integration/channel (if any): N/A
  • Relevant config (redacted): N/A

Steps

  1. Parse codex usage payload where:
    • primary_window.reset_at = T
    • secondary_window.limit_window_seconds = 86400
    • secondary_window.reset_at = T + 5 days
  2. Run usage formatting in models status pipeline.
  3. Observe secondary label.

Expected

  • Secondary label is Week (cadence is clearly weekly).

Actual

  • Before fix: secondary label was Day whenever limit_window_seconds mapped to 24h.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Before:

  • pnpm vitest src/infra/provider-usage.fetch.codex.test.ts -t "reset cadence"
  • Failure: expected Week label, received Day.

After:

  • pnpm vitest src/infra/provider-usage.fetch.codex.test.ts
  • pnpm vitest src/infra/provider-usage.test.ts src/infra/provider-usage.format.test.ts src/commands/models/list.status.test.ts
  • pnpm check

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:
    • explicit weekly secondary windows remain Week.
    • ambiguous 86400 secondary window with weekly reset cadence now maps to Week.
    • standard daily case (short reset cadence) remains Day.
  • Edge cases checked:
    • codex usage parser tests and broader provider usage/model-status tests pass.
  • What you did not verify:
    • live codex dashboard/API account-specific behavior in a real OAuth account.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert this commit.
  • Files/config to restore: N/A (code-only parser change).
  • Known bad symptoms reviewers should watch for: unexpected Week labeling where reset cadence is not actually long-lived.

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: cadence-based fallback could over-label Week if reset timestamps are malformed.
    • Mitigation: fallback only applies in the 24h-labeled secondary window case and requires a large reset-gap threshold.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

Fixes incorrect labeling of codex secondary usage windows by using reset timestamp cadence as a fallback when API reports ambiguous 24-hour durations. The change extracts window label resolution into a dedicated function that checks if the gap between secondary and primary window reset times exceeds 3 days, correctly identifying weekly windows even when limit_window_seconds reports 86400.

Key improvements:

  • Prevents openclaw models status from displaying misleading "Day" labels for weekly quota windows
  • Adds comprehensive test coverage for the reset cadence inference path
  • Maintains backward compatibility - explicit weekly windows (604800 seconds) and sub-24-hour windows remain unchanged

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Clean bug fix with focused scope, comprehensive test coverage including the specific edge case being addressed, proper handling of optional parameters, and no breaking changes to existing behavior
  • No files require special attention

Last reviewed commit: 181b888

@steipete steipete merged commit 16e7fc2 into openclaw:main Mar 2, 2026
28 of 29 checks passed
@steipete
Copy link
Contributor

steipete commented Mar 2, 2026

Landed via temp rebase onto main.

  • Gate: pnpm -s vitest run src/infra/provider-usage.fetch.codex.test.ts
  • Land commit: 351c18c
  • Merge commit: 16e7fc2

Thanks @bmendonca3!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: models status states "Day" but displays weekly usage for openai-codex

2 participants