fix(opencode): repair malformed JSON in tool call arguments#23067
Open
ahamza360 wants to merge 2 commits intoanomalyco:devfrom
Open
fix(opencode): repair malformed JSON in tool call arguments#23067ahamza360 wants to merge 2 commits intoanomalyco:devfrom
ahamza360 wants to merge 2 commits intoanomalyco:devfrom
Conversation
6 tasks
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on the search results, I found two potentially related PRs:
These PRs may have addressed related JSON/tool call argument issues. You should verify if they already implement similar repair logic or if this PR provides additional improvements over the previous truncation handling. |
- Add strategy to handle duplicated/overlapping JSON objects - Add pattern matching for specific malformed JSON cases - Insert missing commas that might cause parsing issues - Improve logging for repair attempts
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.
Issue for this PR
Closes #23065
Type of change
What does this PR do?
This PR fixes the recurring JSON parsing errors that occur when LLMs generate malformed/truncated JSON for tool call arguments.
Problem:
LLMs occasionally generate malformed/truncated JSON for tool call arguments, resulting in "JSON parsing failed" errors.
Solution:
Enhanced the
experimental_repairToolCallcallback inpackages/opencode/src/session/llm.tswith improved JSON repair logic that:"value→"value"){ "key": "value"→{ "key": "value" })This makes opencode more robust when dealing with imperfect LLM JSON output.
How did you verify your code works?
Checklist