Repository navigation
fix: synthesize assistant function_call before orphaned function results (422) - #5
Open
PetrIIvanov wants to merge 1 commit into
Open
PetrIIvanov wants to merge 1 commit into
PetrIIvanov wants to merge 1 commit into
Conversation
GigaChat requires every 'function' result in the history to be immediately
preceded by an 'assistant' message carrying a function_call. opencode can
send orphaned tool results in long sessions (after compaction, or when the
assistant produced text between tool calls), which the API rejects with 422
('every function result must have an assistant function call in history').
translateMessages now tracks whether the last appended message is an
assistant with a function_call and synthesizes a matching assistant message
when one is missing.
Author
|
Локальная проверка (Node 20, эквивалент всех шагов CI):
Воспроизведение бага: GigaChat-API возвращал Фикс в |
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.
Problem
GigaChat requires every
functionresult in the history to be immediately preceded by anassistantmessage carrying afunction_call. opencode can send orphaned tool results in long sessions — after compaction or when the assistant produced text between tool calls — which the API rejects with422 INVALID_PARAMS(every function result must have an assistant function call in history).Fix
translateMessagesinsrc/plugin/messages.tsnow tracks whether the last appended message is an assistant carrying afunction_call. When appending afunction/toolresult that is not preceded by one, the plugin synthesizes a matchingassistantmessage with an emptyfunction_callso the pair is valid.Tests
Added a unit test with an orphaned
toolresult that asserts a synthesized assistantfunction_callis inserted before thefunctionresult. All 77 tests pass.