Skip to content

Correctly calculate remaining context size - #3190

Merged
pakrym-oai merged 3 commits into
mainfrom
pakrym/correctly-calculate-remaining-context-size
Sep 4, 2025
Merged

pakrym-oai merged 3 commits into
mainfrom
pakrym/correctly-calculate-remaining-context-size

Conversation

@pakrym-oai

@pakrym-oai pakrym-oai commented Sep 4, 2025 •

Copy link
Copy Markdown
Contributor

We had multiple issues with context size calculation:

  1. initial_prompt_tokens calculation based on cache size is not reliable, cache misses might set it to much higher value. For now hardcoded to a safer constant.
  2. Input context size for GPT-5 is 272k (that's where 33% came from).

Fixes #2825.

… percentage API

Refactor TokenUsage to use a BASELINE_TOKENS constant (12000) for system and tool overhead estimation. Remove baseline parameter from percent_of_context_window_remaining and update callsites to use the new signature. Clarify doc comments accordingly.
@pakrym-oai
pakrym-oai enabled auto-merge (squash) September 4, 2025 23:33
@pakrym-oai
pakrym-oai merged commit 7df9e9c into main Sep 4, 2025
@pakrym-oai
pakrym-oai deleted the pakrym/correctly-calculate-remaining-context-size branch September 4, 2025 23:34
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context window exceeded despite context left

2 participants