Skip to content

core: account for all post-response items in auto-compact token checks#11132

Merged
charley-oai merged 3 commits intomainfrom
cc/compact-token-delta
Feb 9, 2026
Merged

core: account for all post-response items in auto-compact token checks#11132
charley-oai merged 3 commits intomainfrom
cc/compact-token-delta

Conversation

@charley-oai
Copy link
Collaborator

Summary

  • change compaction pre-check accounting to include all items added after the last model-generated item, not only trailing codex-generated outputs
  • use that boundary consistently in get_total_token_usage() and get_total_token_usage_breakdown()
  • update history tests to cover user/tool-output items after the last model item

Why

last_token_usage.total_tokens is API-reported for the last successful model response. After that point, local history may gain additional items (user messages, injected context, tool outputs). Compaction triggering must account for all of those items to avoid late compaction attempts that can overflow context.

Testing

  • just fmt
  • cargo test -p codex-core

@charley-oai
Copy link
Collaborator Author

@codex review this

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@charley-oai charley-oai merged commit 0883e5d into main Feb 9, 2026
32 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 9, 2026
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.

2 participants