Skip to content

feat(usage): show provider account limits - #41571

Open
lks100 wants to merge 2 commits into
NousResearch:mainfrom
lks100:feat/usage-account-limits
Open

feat(usage): show provider account limits#41571
lks100 wants to merge 2 commits into
NousResearch:mainfrom
lks100:feat/usage-account-limits

Conversation

@lks100

@lks100 lks100 commented Jun 7, 2026

Copy link
Copy Markdown

Summary

Adds account-limit visibility to /usage across gateway/TUI usage paths.

  • Shows provider account-limit lines for explicit TUI /usage requests.
  • Surfaces account usage lines through the TUI gateway session.usage response.
  • Keeps provider account-limit fetches out of routine usage snapshots to avoid surprise network calls during normal UI refreshes.
  • Makes OpenAI Codex account-usage fetching tolerate credential-pool setups without the legacy Codex token store.
  • Adds tests for messaging /usage, TUI gateway usage responses, and Codex account-usage credential handling.

Notes

The OpenAI-side implementation is currently the openai-codex/ChatGPT account-limit path used by Hermes OAuth-backed Codex provider credentials. Anthropic account-limit rendering remains OAuth-gated.

The TUI build-related changes keep React/reconciler dependencies resolved from a single dependency tree and avoid pipe handle leakage in resolveOnExit exec calls; these were needed to keep the local TUI build/runtime path healthy while validating the /usage change.

Test Plan

  • venv/bin/python -m pytest tests/test_account_usage.py tests/gateway/test_usage_command.py tests/test_tui_gateway_server.py -o 'addopts=' -q
    • 237 passed in 4.17s
  • npm run build --prefix ui-tui
  • npm run type-check --prefix ui-tui
  • npm test --prefix ui-tui -- packages/hermes-ink/src/utils/execFileNoThrow.test.ts src/__tests__/createSlashHandler.test.ts src/__tests__/gatewayClient.test.ts
    • 72 passed | 1 skipped
  • git diff --cached --check

Known local test note

A full npm test --prefix ui-tui -- --run was attempted and currently has unrelated failures in:

  • src/__tests__/memoryMonitor.test.ts
  • src/__tests__/virtualHeights.test.ts

It also showed slashParity skipping/parity probe issues because the system python3 used by that test lacks yaml. Targeted TUI tests for the touched areas passed.

@liuhao1024

Copy link
Copy Markdown
Contributor

✅ Verified — Provider account-limit visibility in /usage

Reviewed the diff for TUI/gateway usage command account-limit integration.

  • Credential handling: _fetch_codex_account_usage now tolerates a missing legacy token store via try/except around _read_codex_tokens(), while still using the credential pool's api_key. The ChatGPT-Account-Id header is correctly omitted when account_id is None (confirmed by test assertion).
  • Separation of concerns: _get_account_usage_lines() is correctly kept out of _get_usage() to avoid surprise network calls during routine UI refreshes. Only explicit /usage slash commands trigger the provider API call.
  • Cross-platform coverage: Tests cover both TUI gateway (test_session_usage_includes_account_limit_lines) and messaging platform gateway (test_usage_command_includes_account_section_for_messaging_platforms with TELEGRAM/SIGNAL parametrize).

Well-structured multi-file change with good test isolation. No issues found.

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/tui Terminal UI (ui-tui/ + tui_gateway/) provider/openai OpenAI / Codex Responses API labels Jun 8, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for carrying provider-limit visibility into the TUI. Current main still lacks this specific TUI surface: tui_gateway/server.py:6489-6512 returns only token usage and Nous credits_lines, while ui-tui/src/app/slash/commands/session.ts:582-619 renders no provider account block.

Problems

  • The added session.usage fetch is synchronous (tui_gateway/server.py PR right-side line 4051). Provider usage requests use a 15-second HTTP timeout (agent/account_usage.py:509), while current dispatch invokes methods inline unless listed in _LONG_HANDLERS (tui_gateway/server.py:1271); session.usage is not currently listed. This can stall the TUI RPC reader.
  • The Codex credential change has been superseded by current main's resolver at agent/account_usage.py:439-494. Commit 130e2337c24810bc0afa793495795b832cf593be hardens that path against wrong-account pool fallback; preserve that implementation during salvage.

Suggested changes

  • Salvage the TUI RPC/type/rendering portion and run its account fetch on the long-handler worker path (or an equivalent bounded worker).
  • Retain current-main Codex credential resolution and its newer regression coverage rather than restoring the older broad exception path.

This is an automated hermes-sweeper review.

Comment thread tui_gateway/server.py
@@ -4023,6 +4051,9 @@ def _(rid, params: dict) -> dict:
usage["credits_lines"] = credits

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

session.usage is dispatched inline unless it is added to _LONG_HANDLERS; this call can issue a provider HTTP request with a 15-second timeout. Please run this RPC through the long-handler worker path (or offload this fetch) so a slow usage endpoint cannot block the TUI reader and delay control RPCs.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform area/usage-cost Token accounting, usage reporting, billing, cost tracking labels Jul 14, 2026

@GottZ GottZ left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This was generated by AI during triage.

Summary

Four PRs address or reference this complex: #2486 introduced provider account limits for CLI and messaging /usage, #13428 rebuilt and merged that implementation onto current main, #41571 adds the still-missing TUI surface, and #56543 fixes a separate TUI source-resolution failure. The build changes in #41571 and #56543 are distinct: React/react-reconciler aliasing prevents duplicate-React hook failures, while the .js-to-TypeScript resolver fixes NodeNext imports during esbuild bundling.

Related pull requests

  • #2486 [closed] related — (+907/-108) — superseded by merged #13428: this was the original implementation of OpenAI Codex, Anthropic OAuth, and OpenRouter account-limit fetching plus CLI/gateway /usage wiring; #13428 preserved its account-usage module and authorship while rebuilding the integration against current main to avoid dropping later rate-limit and cached-agent behavior.
  • #13428 [merged] related — (+678/-6) — merged reference implementation: it resolves the original CLI and messaging-gateway cause by appending provider quota and credit data to /usage, including persisted-provider fallback and off-event-loop gateway fetching, while retaining newer mainline usage behavior.
  • #41571 related — (+223/-12) — keep open for targeted salvage: the diff adds the missing session.usage response field, TUI types, and rendering for provider account limits, but the contributor keep_open review on #41571 identifies a blocker because the synchronous provider fetch can hold the TUI RPC reader for up to 15 seconds. Move session.usage onto the long-handler worker path or provide equivalent bounded off-reader execution, preserve current main's wrong-account-safe Codex resolver, and keep the React/react-reconciler aliasing only if independently justified and tested.
  • #56543 related — (+32/-2) — keep open as a separate fix: its esbuild resolver maps NodeNext-style relative .js imports to existing .ts/.tsx/.jsx sources and directly addresses clean-checkout TUI rebuild failures. This is not the duplicate-React dependency-tree defect addressed by #41571's alias changes, and the contributor keep_open review reports no verified blocker.

Duplicates

#2486 and #13428 implement substantially the same core CLI/messaging account-limit feature, with #13428 being the current-main rebuild that superseded #2486. #41571 is only partially overlapping because its material addition is TUI exposure; #56543 is not a duplicate of #41571 because the two build changes address distinct defects.

Suggested consolidation

Merge #41571 only after addressing its contributor keep_open review by moving the provider fetch off the inline TUI RPC reader and preserving current main's hardened Codex credential resolver; then consolidate only its TUI RPC/type/rendering work and any independently validated React alias fix. #2486 can remain closed as superseded by merged #13428, while #56543 should remain open and be evaluated separately rather than closed as a duplicate.

Cross-PR triage: Reviewed 4 pull requests and 0 issues in this complex. Each diff was read against this issue; Assessment working set: 92 kB of PR diffs, 12 kB of issue/PR text, 4 kB of discussion (5 comments), 1 verify verdict. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

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

Labels

area/usage-cost Token accounting, usage reporting, billing, cost tracking comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have provider/openai OpenAI / Codex Responses API sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants