Skip to content

fix(tui): harden usage heartbeat and auth-profile auto-switch#180

Closed
andrei-hasna wants to merge 1 commit into
mainfrom
openloops/open-codewith/ba552fdd-8450-4711-93c1-256417dea351-f7c56d73
Closed

fix(tui): harden usage heartbeat and auth-profile auto-switch#180
andrei-hasna wants to merge 1 commit into
mainfrom
openloops/open-codewith/ba552fdd-8450-4711-93c1-256417dea351-f7c56d73

Conversation

@andrei-hasna

Copy link
Copy Markdown
Contributor

Summary

Improves the auth-profile usage heartbeat and auto-switch so profile selection is smarter and usage endpoints are not hammered under rate limits (the recurring Jul-7 reset incidents where a health loop kept hitting Codewith usage limit hit).

Do not hammer usage endpoints under rate limits

  • Track the earliest future reset for a profile whose cached codex usage is exhausted (used_percent >= 100), and suppress usage heartbeats for that profile until the reset. Nothing changes until reset, so re-polling every heartbeat_interval just hammered a limit we already knew about.
  • Degrades gracefully: when the reset is missing or already elapsed, the check falls through to the existing interval/backoff, so heartbeats are never permanently blocked.

Smarter auto-switch profile selection

  • Ordered strategy now returns the first healthy profile in configured order and only defers to an Unknown profile when nothing is known-healthy, instead of optimistically grabbing the first Unknown.
  • Skip auto-switching onto a profile whose most recent usage heartbeat failed within the failure backoff (we could not confirm it is available).

Tests / validation (in codex-rs/)

  • cargo test -p codex-core usage_profile_health — 18 passed (new: earliest_exhausted_reset_at, ordered healthy-before-unknown)
  • cargo test -p codex-tui chatwidget popups/status modules — 251 passed (new: usage_heartbeat_suppressed_for_exhausted_profile_until_reset, auto_switch_skips_recently_failed_profile_for_unknown_candidate)
  • cargo clippy -p codex-core -p codex-tui --all-targets — clean
  • cargo fmt --check — clean

Preserves config defaults and TOML back-compat; no behavior change when auto-switch is disabled.

🤖 Generated with Claude Code

…smarter

Under rate limits the auth-profile usage heartbeat kept re-polling an
already-exhausted profile every interval once its cached snapshot lapsed
freshness, hammering the usage endpoint until reset (the Jul-7 reset
incidents). Auto-switch could also optimistically pick an Unknown or
just-failed profile over a known-healthy one.

- Track the earliest future reset for a profile whose cached codex usage
  is exhausted and suppress heartbeats for it until that reset, falling
  back to the normal interval/backoff when the reset is missing or has
  elapsed so heartbeats are never permanently blocked.
- Ordered auto-switch now returns the first healthy profile in configured
  order and only defers to an Unknown profile when nothing is known
  healthy, instead of grabbing the first Unknown it sees.
- Skip auto-switching onto a profile whose most recent usage heartbeat
  failed within the failure backoff.

Adds core + TUI tests; preserves config defaults and TOML back-compat.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@andrei-hasna

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #211. Replacement #211 consolidates the current TUI/thread-routing stack and explicitly supersedes this PR. Please continue review on #211.

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