Skip to content

Fix Codex weekly window detection - #268

Merged
Finesssee merged 2 commits into
nesszer:mainfrom
anthfgreco:agent/fix-codex-weekly-window
Aug 8, 2026
Merged

Fix Codex weekly window detection#268
Finesssee merged 2 commits into
nesszer:mainfrom
anthfgreco:agent/fix-codex-weekly-window

Conversation

@anthfgreco

@anthfgreco anthfgreco commented Aug 6, 2026

Copy link
Copy Markdown

Fixes #267

Summary

  • Identify Codex session and weekly usage windows from duration/reset metadata instead of array position.
  • Preserve an absent 5-hour session as an informational unavailable lane.
  • Calculate provider pace from the weekly quota when no session window is present.
  • Mark the unavailable session consistently in the tray status, Settings usage section, and CLI output.

Root cause

Codex weekly-only payloads were promoted into the primary window, while array payloads assumed the first window was always the 5-hour session. That mislabeled weekly usage and left the weekly and pace lanes incorrect.

Validation

  • cargo fmt --all
  • git diff --check
  • cargo test --manifest-path rust/Cargo.toml codex
  • cargo test --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml commands::bridge
  • cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings
  • cargo clippy --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml --all-targets -- -D warnings
  • Frontend Vitest was unavailable because apps/desktop-tauri/node_modules is not installed.
  • Cua proof was skipped per the requested config-only scope.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@Finesssee

Copy link
Copy Markdown
Collaborator

Thanks for the PR, I will review it ASAP.

@Finesssee
Finesssee marked this pull request as ready for review August 7, 2026 04:02

@Finesssee Finesssee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes (narrow, one structural blocker)

Blocking: rust/src/providers/codex/api.rs:587-596 (no_session_primary()) is a behavioral duplicate of rust/src/providers/claude/web_api.rs:652-661 (synthetic_no_session_primary()). Both construct the identical informational 5-hour "No active session" RateWindow: 0.0%, window_minutes: Some(300), the same "No active 5h session" description, is_informational = true.

With this PR there are now two independent copies of one cross-provider invariant ("the shared 5h-session lane is absent"). The next time the wording, minutes, or placeholder shape changes for one provider, the other silently diverges — and every downstream surface (tray label, Settings usage bar, CLI line, hooks, forecasts) keys off this exact contract.

Remedy: add a canonical constructor in rust/src/core/rate_window.rs, e.g. RateWindow::no_active_session(), using the existing SESSION_WINDOW_MINUTES constant, and call it from both providers. Codex's version is the better one to promote — it already uses SESSION_WINDOW_MINUTES where Claude's uses the literal 300, so promoting it fixes both.

Everything else in the normalization design looks strong: the fix reuses the canonical is_informational contract that guard/hooks/forecast/tray consumers already honor, deletes the duplicated typed-response parsing path, and hardens the integer boundaries (u32::try_from, json_i64). Verified locally in a read-only worktree at 2cbb67d: cargo test -p codexbar codex → 79 passed, commands::bridge → 5 passed. This is intentionally a narrow request — land the shared constructor and this is an approve.

Codex no_session_primary() and Claude synthetic_no_session_primary()
were duplicate provider-local copies of the same informational 5h
session placeholder. Promote the shared shape to a canonical
RateWindow::no_active_session() built on RateWindow::informational()
plus SESSION_WINDOW_MINUTES, and call it from both providers.

@Finesssee Finesssee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve

The blocking duplication is resolved: RateWindow::no_active_session() in rust/src/core/rate_window.rs is now the single canonical constructor (built on RateWindow::informational("No active 5h session") plus SESSION_WINDOW_MINUTES), and both provider-local copies — Codex no_session_primary() and Claude synthetic_no_session_primary() — are deleted with all call sites migrated. Field-for-field behavior is identical (0.0%, 5h window, same description, informational), confirmed by the unchanged provider tests.

Validation basis (accurate, exact head 5540635): this repository has no GitHub required checks configured on main (no branch protection, no required status checks), so approval rests on local validation run against this exact head:

  • vitest run src/surfaces/settings/providers/sections/UsageSection.test.tsx (pnpm 10.18.1, vitest 3.2.4): 2/2 passed — includes the new informational-unavailable-lane test
  • Full frontend suite pnpm run test: 37 files / 228 tests passed
  • cargo test rate_window: 6 passed (new core test covers informational=true, minutes=300, description, 0%, no reset)
  • cargo test codex: 79 passed · claude: 77 passed · commands::bridge: 5 passed
  • cargo fmt clean; cargo clippy --all-targets -- -D warnings clean on both the rust and src-tauri crates

@Finesssee
Finesssee merged commit 75e33d3 into nesszer:main Aug 8, 2026
1 check passed
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.

[Bug]: Weekly usage and pace break when 5-hour limit is absent

2 participants