fix: keep tool call message pairs when trimming context#1
Merged
CompilError-bts merged 3 commits intomasterfrom Mar 31, 2026
Merged
fix: keep tool call message pairs when trimming context#1CompilError-bts merged 3 commits intomasterfrom
CompilError-bts merged 3 commits intomasterfrom
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
toolmessages at the front ofcontextwhich can cause invalid requests during retry after context-length errors (issue [Bug]上下文管理截断时未保持 tool_calls 与 tool 消息的配对完整性,导致 400 报错 AstrBotDevs/AstrBot#7225).Description
AbstractProvider.pop_recordwith atomic-unit removal that treats anassistantmessage containingtool_callsplus its followingtoolmessages as one unit.toolmessages by removing contiguous leadingtoolmessages as a unit._has_tool_calls,_first_non_system_index,_pop_earliest_unit) and loop until at least two non-system records worth of content have been removed or no more removable units exist.tests/test_openai_source.pyto cover atomic removal ofassistant(tool_calls)+toolpairs and cleanup of leading orphantoolmessages.Testing
ruff format .andruff check .and both succeeded.pytest tests/test_openai_source.py -k "pop_record"but the run failed in this environment due to a missing test dependency (pytest_asyncio) and so the test execution could not complete.Codex Task