fix: normalize compacted Responses user inputs before session reuse#2925
Merged
fix: normalize compacted Responses user inputs before session reuse#2925
Conversation
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.
This pull request fixes replay safety for compacted Responses user messages in
OpenAIResponsesCompactionSession.When
responses.compact()returns userinput_imageorinput_filecontent with null alternatives such asfile_id: null, the SDK was previously storing that shape back into session history unchanged. That left the nextresponses.createcall dependent on server tolerance for contract-invalid null combinations and also meant a normalization failure could clear the underlying session before replacement succeeded.This change normalizes compacted user image and file inputs into replay-safe shapes before they are written back to the session, keeping only valid source fields such as
image_url,file_id,file_url, orfile_dataas appropriate. It also defers clearing the underlying session until normalization succeeds so malformed compacted output does not erase existing history. The update includes regression coverage for compacted image normalization, compacted file normalization, and the failure path that preserves prior session items.see also: openai/openai-agents-js#1181