Skip to content

Hosted search usage causes premature auto-compaction #47825

Open

Description

@upman

Hosted Responses search reports billing usage in usage.input_tokens, usage.output_tokens, and usage.total_tokens, which can exceed retained context size.
Codex uses last_token_usage.total_tokens for context accounting: Calling a gateway with hosted search reports the entire search loop's token usage.

Codex assumes that count is the number of tokens in the context window.

Please separate billable token usage from context occupancy so hosted tool loops do not trigger premature auto-compaction.

Activity

  1. added
    bugSomething isn't working
    contextIssues related to context management (including compaction)
    rate-limitsIssues related to rate limits, quotas, and token usage reporting
    on Sep 24, 2026
  2. 84dnnvbdvp-debug commented on Sep 24, 2026

    @84dnnvbdvp-debug

    The current source path makes this look like a real accounting-contract mismatch rather than just a UI problem. response.completed copies provider usage.total_tokens verbatim into TokenUsage; that response becomes last_token_usage, while ContextManager::get_total_token_usage() treats last_token_usage.total_tokens as active context and context_window_token_status() uses it for both auto-compaction and the full-window threshold. The TUI even documents last_token_usage.total_tokens as the latest active context size.

    One regression I’d add is two runs with the same retained transcript but different provider-reported aggregate usage: the hosted-search run reports a much larger total_tokens because of internal search/model passes. Billing/telemetry should preserve that full provider usage, but active_context_tokens and the compaction decision should remain identical until the retained transcript itself grows. I’d cover both Total and BodyAfterPrefix scopes; the latter also seeds its server-observed prefill from usage.input_tokens. I would not derive occupancy by subtracting cached input either—cached prompt tokens are cheaper, but they still occupy the model context.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcontextIssues related to context management (including compaction)rate-limitsIssues related to rate limits, quotas, and token usage reporting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions