fix(tools): lenient UpdateTodoList tasks JSON in normalize_json_array#13
fix(tools): lenient UpdateTodoList tasks JSON in normalize_json_array#13JessicaMulein wants to merge 1 commit into
Conversation
|
Static Code Review 📊 🛑 3 quality checks failed!
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Review Summary by QodoFix lenient UpdateTodoList tasks JSON parsing for local models
WalkthroughsDescription• Add lenient JSON parser for UpdateTodoList tasks with unescaped inner quotes • Handle local model glued JSON objects in tool arguments • Wire lenient repair through normalize_json_array before raising errors • Add test coverage for unescaped task array parsing Diagramflowchart LR
A["Local Model Output<br/>Glued/Unescaped JSON"] -->|"normalize_json_array"| B["try_parse_lenient_task_array"]
B -->|"Regex Pattern Match"| C["Parsed Task Array"]
B -->|"Fallback"| D["Standard json.loads"]
C --> E["UpdateTodoList Success"]
D --> E
File Changes1. cecli/helpers/responses.py
|
Code Review by Qodo
1. Partial task array accepted
|
| rows = [ | ||
| {"done": m.group(1).lower() == "true", "task": m.group(2).replace('\\"', '"')} | ||
| for m in pattern.finditer(raw) | ||
| ] | ||
| return rows if rows else None |
There was a problem hiding this comment.
1. Partial task array accepted 🐞 Bug ☼ Reliability
try_parse_lenient_task_array returns any regex matches without verifying the full array was parsed, so malformed inputs can be partially accepted and silently drop tasks. This can cause UpdateTodoList to write an incomplete todo list without surfacing an error.
Agent Prompt
### Issue description
The lenient task parser builds `rows` from `pattern.finditer(raw)` and returns them as long as there’s at least one match. It does not validate that the remaining text is only brackets/commas/whitespace, so garbage between/after objects is ignored and tasks can be dropped silently.
### Issue Context
This function is invoked as a recovery path before raising `ToolError`, so returning partial results turns what should be a hard failure into a silent data-loss behavior.
### Fix Focus Areas
- After collecting matches, validate that the input contains *only*:
- the matched objects
- commas
- surrounding `[` `]`
- whitespace
If anything else remains, return `None` (so the caller raises a ToolError).
- Add a test that includes trailing/embedded garbage and asserts an error is raised (no partial success).
### Fix Focus Areas (code pointers)
- cecli/helpers/responses.py[522-530]
- cecli/tools/utils/helpers.py[360-393]
- tests/tools/test_tool_arguments.py[248-259]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Local models emit glued tool args and unescaped inner quotes on tasks arrays.
Add try_parse_lenient_task_array and wire it through normalize_json_array so
UpdateTodoList survives qwen-style { "tasks": "[{...}]" }{ "path": "..." }.
Co-authored-by: Cursor <cursoragent@cursor.com>
05c829b to
d05a4bb
Compare
|
Superseded by upstream PR to cecli-dev/cecli (branch rebased on upstream/main). |
|
Upstream PR opened: cecli-dev#550 |
Summary
try_parse_lenient_task_arrayfor local-model UpdateTodoListtasksargs with unescaped inner JSON quotesnormalize_json_arraybefore raisingToolError[{"done": true, "task": "..."}, ...]array stringsContext
BrightVision dogfood on qwen3.6 hit
Invalid tasks parameter JSONwhen the model glued{ "tasks": "[{...}]" }{ "path": "..." }. UI-side JSON tree rendering is separate (BrightVision head); this fixes tool execution in cecli.Test plan
pytest tests/tools/test_tool_arguments.py::test_normalize_json_array_lenient_unescaped_tasks -qpytest tests/tools/test_update_todo_list.py -qMade with Cursor
PR Summary by Typo
Overview
This PR addresses an issue where
UpdateTodoListtasks JSON might contain unescaped inner quotes, causing parsing failures. It introduces a more lenient parsing mechanism to correctly handle these malformed JSON strings, particularly from models like local Qwen.Key Changes
try_parse_lenient_task_arrayincecli/helpers/responses.pyto robustly parseUpdateTodoListtasks with unescaped inner JSON quotes.normalize_json_arrayincecli/tools/utils/helpers.pyto utilize this new lenient parser when standard JSON parsing fails fortasksparameters, and to handle nestedtasksobjects.test_normalize_json_array_lenient_unescaped_tasksto validate the improved parsing logic.Work Breakdown
To turn off PR summary, please visit Notification settings.