fix(kosong): sanitize malformed history tool calls - #2196
Closed
he-yufeng wants to merge 1 commit into
Closed
Conversation
Author
|
Closing this during backlog cleanup. There has been no human maintainer signal, the repository is no longer an active target for new work, and keeping many stale small PRs open makes the queue noisy. Happy to reopen or refresh it if maintainers want this specific change. |
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 #2165.
Historical tool calls can contain malformed
function.argumentsafter a model emits invalid JSON. OpenAI-compatible backends then reject the next request while replaying the session history, so the conversation keeps failing on every turn.This keeps the fix at the provider boundary:
strict=False{}The same helper is used by OpenAI Responses, OpenAI Legacy, Anthropic, and Google GenAI conversions.
Tests
python -m uv run pytest packages\kosong\tests -qpython -m uv run pytest packages\kosong\tests\test_tool_call_argument_sanitizing.py -qpython -m uv run ruff check packages\kosong\src\kosong\contrib\chat_provider\common.py packages\kosong\src\kosong\contrib\chat_provider\openai_responses.py packages\kosong\src\kosong\contrib\chat_provider\openai_legacy.py packages\kosong\src\kosong\contrib\chat_provider\anthropic.py packages\kosong\src\kosong\contrib\chat_provider\google_genai.py packages\kosong\tests\test_tool_call_argument_sanitizing.pypython -m uv run ruff format packages\kosong\src\kosong\contrib\chat_provider\common.py packages\kosong\src\kosong\contrib\chat_provider\openai_responses.py packages\kosong\src\kosong\contrib\chat_provider\openai_legacy.py packages\kosong\src\kosong\contrib\chat_provider\anthropic.py packages\kosong\src\kosong\contrib\chat_provider\google_genai.py packages\kosong\tests\test_tool_call_argument_sanitizing.py --checkpython -m uv run pyright packages\kosong\src\kosong\contrib\chat_provider\common.py packages\kosong\src\kosong\contrib\chat_provider\openai_responses.py packages\kosong\src\kosong\contrib\chat_provider\openai_legacy.py packages\kosong\src\kosong\contrib\chat_provider\anthropic.py packages\kosong\src\kosong\contrib\chat_provider\google_genai.py packages\kosong\tests\test_tool_call_argument_sanitizing.pypython -m py_compile packages\kosong\src\kosong\contrib\chat_provider\common.py packages\kosong\src\kosong\contrib\chat_provider\openai_responses.py packages\kosong\src\kosong\contrib\chat_provider\openai_legacy.py packages\kosong\src\kosong\contrib\chat_provider\anthropic.py packages\kosong\src\kosong\contrib\chat_provider\google_genai.py packages\kosong\tests\test_tool_call_argument_sanitizing.py; git diff --check