fix(gateway): show usage limits before first turn - #54271
Conversation
Part of the account-usage-before-first-turn cluster — overlaps with open #45882 ( |
tonydwb
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 providerchain stops when config containsmodel.provider: autoorcustom. Currentagent/account_usage.py:684-686deliberately returns no account snapshot for those values, so the proposed runtime-default resolver is never reached. - This branch is merge-conflicting because commit
619bd782738adfa87544d0fda7a1114defe86e4cmoved the handler togateway/slash_commands.py:3943.
Suggested changes
- Treat empty,
auto, andcustomprovider 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.
| @@ -3476,6 +3475,41 @@ async def _handle_usage_command(self, event: MessageEvent) -> str: | |||
| provider = provider or persisted.get("billing_provider") | |||
There was a problem hiding this comment.
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.
Summary
/usageresolve account-limit context before any model-backed turn exists.Why
Account/quota information should be available from gateway commands even in a fresh session. Requiring a prior model-backed message makes
/usageless useful for account diagnostics after/resetor gateway startup.Tests
python -m compileall -q gateway/slash_commands.py tests/gateway/test_usage_command.pyruff check gateway/slash_commands.py tests/gateway/test_usage_command.pypython -m pytest tests/gateway/test_usage_command.py -q -o 'addopts='git merge-treeagainstupstream/main: clean