fix(tools): normalize JSON-encoded tool args from local LLMs#536
Open
JessicaMulein wants to merge 7 commits into
Open
fix(tools): normalize JSON-encoded tool args from local LLMs#536JessicaMulein wants to merge 7 commits into
JessicaMulein wants to merge 7 commits into
Conversation
Mirror ReadRange format_output ToolError handling; fall back to plain task text when brace-prefixed strings are not JSON. Tighten tests and fix import order for pre-commit. Co-authored-by: Cursor <cursoragent@cursor.com>
Match CI pre-commit (black --line-length 100 --preview). Mirror ReadRange Invalid Tool JSON handling in UpdateTodoList.format_output; add tests for mixed JSON-string task rows and malformed tool arguments. Co-authored-by: Cursor <cursoragent@cursor.com>
Some models emit tool array args as one string per character (e.g. UpdateTodoList tasks). Rejoin and parse before normalize_task_items / ReadRange show ops. Co-authored-by: Cursor <cursoragent@cursor.com>
- normalize_search_operations for char-split and bare pattern strings - _repair_local_model_json_text / _try_parse_json_value for ReadRange show and other double-encoded arrays (literal newline after ':') - Tests: test_grep.py, test_get_lines.py, test_update_todo_list.py Co-authored-by: Cursor <cursoragent@cursor.com>
DeepSeek and similar models emit {…}{}{…} tool args; merge into one
object before dispatch instead of triplicate ls/Git/Grep calls. Fix Grep
format_output tool_footer TypeError on parse errors. Tests in
test_tool_arguments.py.
Co-authored-by: Cursor <cursoragent@cursor.com>
dwash96
pushed a commit
that referenced
this pull request
May 31, 2026
Open
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
Local / Ollama models sometimes pass tool parameters as JSON strings instead of native arrays/objects (e.g.
showforReadRange,tasksforUpdateTodoList). That caused tool failures or opaqueToolErrors during headless and desktop-hosted runs.This PR adds shared coercion helpers and uses them in
ReadRangeandUpdateTodoListso we accept:Changes
cecli/tools/utils/helpers.py:normalize_json_array(),coerce_dict_item()with clearToolErrormessagescecli/tools/read_range.py:normalize_show_ops()before path resolutioncecli/tools/update_todo_list.py:normalize_task_items()for agent todo synctests/tools/test_get_lines.py(stringshowJSON), newtests/tools/test_update_todo_list.pyMotivation
BrightVision dogfood (Vision HTTP + local Qwen/Llama) hit this in E2E and real sessions: the model emitted
"show": "[{...}]"or stringified task rows. Interactive cecli may see it less often; headless tool loops see it regularly.Test plan
pytest tests/tools/test_get_lines.py tests/tools/test_update_todo_list.pyReadRange/UpdateTodoListwhere the model double-encodes JSON argsNotes
ToolError.