Fix remote compaction estimator/payload instruction small mismatch#10692
Merged
charley-oai merged 3 commits intomainfrom Feb 5, 2026
Merged
Fix remote compaction estimator/payload instruction small mismatch#10692charley-oai merged 3 commits intomainfrom
charley-oai merged 3 commits intomainfrom
Conversation
Add a shared ContextManager estimator that accepts explicit base instructions, keep the existing estimator as a wrapper, and use session base instructions for both remote pre-trim estimation and compact payload construction.\n\nAdd regression coverage to verify remote compaction uses session override instructions and trims consistently when those instructions increase estimated payload size.
Collaborator
Author
|
@codex review this |
Contributor
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Collaborator
Author
|
@codex review this |
Contributor
|
Codex Review: Didn't find any major issues. Bravo. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a deterministic mismatch in remote compaction where pre-trim estimation and the
/v1/responses/compactpayload could use different base instructions.Before this change:
model_info.get_model_instructions(...))sess.get_base_instructions())After this change:
BaseInstructionsinstance from session state.Changes
ContextManager:estimate_token_count_with_base_instructions(&self, base_instructions: &BaseInstructions) -> Option<i64>estimate_token_count(&TurnContext)as a thin wrapper that resolves model/personality instructions and delegates to the new helper.Why this matters
This removes a deterministic divergence source where pre-trim could think the request fits while the actual compact request exceeded context because its instructions were longer/different.
Scope
In scope:
Out of scope:
context_length_exceededCodex author:
codex fork 019c2b24-c2df-7b31-a482-fb8cf7a28559