Skip to content

fix(gateway): show usage limits before first turn - #54271

Open
timsmykov wants to merge 1 commit into
NousResearch:mainfrom
timsmykov:tim/usage-fresh-session-account-limits-20260628
Open

fix(gateway): show usage limits before first turn#54271
timsmykov wants to merge 1 commit into
NousResearch:mainfrom
timsmykov:tim/usage-fresh-session-account-limits-20260628

Conversation

@timsmykov

Copy link
Copy Markdown

Summary

  • Let gateway /usage resolve account-limit context before any model-backed turn exists.
  • Resolve provider/base URL from the live/cached agent, persisted billing metadata, session model overrides, config, runtime defaults, then a final OpenAI Codex fallback.
  • Keep account-limit fetching off the event loop and preserve existing session-token/history behavior.

Why

Account/quota information should be available from gateway commands even in a fresh session. Requiring a prior model-backed message makes /usage less useful for account diagnostics after /reset or gateway startup.

Tests

  • python -m compileall -q gateway/slash_commands.py tests/gateway/test_usage_command.py
  • ruff check gateway/slash_commands.py tests/gateway/test_usage_command.py
  • python -m pytest tests/gateway/test_usage_command.py -q -o 'addopts='
  • Local git merge-tree against upstream/main: clean

Copilot AI review requested due to automatic review settings June 28, 2026 13:33

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@alt-glitch alt-glitch added type/feature New feature or request comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have labels Jun 28, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Part of the account-usage-before-first-turn cluster — overlaps with open #45882 (show account usage without active agent) and the broader #41571 (show provider account limits). Tracking these as related_to; a maintainer should pick the canonical implementation.

@tonydwb tonydwb 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.

Code Review Summary

Verdict: LGTM

Shows usage limits before the first model-backed turn by cascading through session overrides, gateway config, and runtime agent kwargs. The fallback chain is well-structured and each level is wrapped in try/except. Tests verify both the config-provider path and the codex fallback.

Reviewed by Hermes Agent

@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 addressing the fresh-session /usage gap. The problem remains on current main: gateway/slash_commands.py:3965-3996 only resolves an account provider from a live/cached agent or persisted billing metadata, so a new session has no provider to fetch.

Problems

  • The proposed if not provider chain stops when config contains model.provider: auto or custom. Current agent/account_usage.py:684-686 deliberately returns no account snapshot for those values, so the proposed runtime-default resolver is never reached.
  • This branch is merge-conflicting because commit 619bd782738adfa87544d0fda7a1114defe86e4c moved the handler to gateway/slash_commands.py:3943.

Suggested changes

  • Treat empty, auto, and custom provider values as unresolved before calling _resolve_runtime_agent_kwargs(), and add a fresh-session regression test for that path.
  • Salvage the focused change into the current mixin using _load_gateway_config(); linked #45882 identifies this as the same account-usage-before-first-turn cluster and requests a canonical implementation.

This is an automated hermes-sweeper review.

Comment thread gateway/slash_commands.py
@@ -3476,6 +3475,41 @@ async def _handle_usage_command(self, event: MessageEvent) -> str:
provider = provider or persisted.get("billing_provider")

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.

A configured model.provider: auto or custom is truthy, so this branch prevents the runtime resolver from running; agent/account_usage.py:684-686 then returns no snapshot for both values. Treat unresolved provider sentinels like empty values here and add a regression test.

@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 15, 2026
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/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have 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