Repository navigation
Normalize context compaction before API requests - #27289
Closed
daniel-oai wants to merge 1 commit into
Closed
daniel-oai wants to merge 1 commit into
daniel-oai wants to merge 1 commit into
Conversation
Contributor
Author
|
Closing per principal review. This is not currently a slam-dunk change: it conflicted with current main in the request formatting path and needs a fresh design/review pass against the new inter-agent message normalization before reopening. |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Fixes #27269.
Remote compaction can yield
ResponseItem::ContextCompaction, but the Responses API rejectscontext_compactionin request input. This change centralizes model/API-bound normalization so encryptedContextCompactionpayloads are sent as the API-supportedcompactionitem, and empty context-compaction markers are omitted from model history.The app-server/UI lifecycle path remains unchanged: UI compaction markers still flow through
TurnItem::ContextCompactionand v2ThreadItem::ContextCompaction.Root Cause
Remote compaction post-processing preserved
ResponseItem::ContextCompactionin replacement history. A later model request could replay that history into/responses, producing the API wire enum error:Invalid value: context_compactionWhat Changed
model_api_safe_response_item, for API-safeResponseItemnormalization.Prompt::get_formatted_input()and remote compaction replacement-history processing.context_compactionitems tocompactionbefore model/API use.context_compactionitems from model/API-bound history because they are UI lifecycle markers; the UI path usesTurnItem::ContextCompaction.Validation
just fmtjust test -p codex-core formatted_input_normalizes_context_compaction_for_responses_api process_compacted_history_normalizes_context_compaction_itemsjust test -p codex-corewas attempted. The new compaction tests passed, but the full run failed in unrelated sandbox/environment categories:target/debug/test_stdio_serverfor MCP stdio testssandbox-exec: sandbox_apply: Operation not permittedjust fix -p codex-coreAdversarial Review
Prompt::get_formatted_input()now normalizes API-bound input, and the regression test asserts serialized JSON contains"type":"compaction"and notcontext_compaction.TurnItem::ContextCompactionremains unchanged, so app-server v2 clients still receive the canonical UI compaction item.ContextCompaction { encrypted_content: None }carries no model-visible encrypted compaction payload. It is a UI lifecycle marker, so omitting it from model/API history avoids sending an unsupported enum without losing model history.context_compactionresponse items are normalized at the model request boundary, and new remote replacement histories are cleaned before persistence.ResponseItemvariants instead of using a wildcard arm, so new variants require an explicit review decision.