Preserve tool-call atomicity when popping context records and add tests#2
Merged
CompilError-bts merged 2 commits intomasterfrom Mar 31, 2026
Merged
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.
Motivation
tool_callsand subsequenttoolmessages.pop_recordrobust for cases with leading orphantoolmessages and multi-call assistant messages.Description
Provider.pop_recordto remove the earliest non-system "unit" (a single message or an assistant+tool(s) group) while preserving assistanttool_callsand their followingtoolmessages as an atomic unit._has_tool_callsand_next_unit_boundsto detect units and compute removal bounds, and limited total removed items to keep behavior close to the previous strategy.tests/test_openai_source.pyby adding async tests forpop_recordbehavior:test_pop_record_removes_assistant_tool_calls_with_following_tools_atomically,test_pop_record_removes_leading_orphan_tool_messages,test_pop_record_normal_messages_no_regression,test_pop_record_assistant_with_multiple_tool_calls, andtest_pop_record_only_system_messages.Pathcomparisons and constructed afile://localhostURI usingurlparse/urlunparseto avoid platform-dependent formatting.Testing
tests/test_openai_source.pywithpytest, including the newpop_recordunit tests, and the updated file-URI tests; all tests passed.test_pop_record_normal_messages_no_regression, which succeeded.Codex Task