fix(delegate): normalize tasks-as-string in delegate_task for batch mode#21957
fix(delegate): normalize tasks-as-string in delegate_task for batch mode#21957liuhao1024 wants to merge 3 commits into
Conversation
…INSTALL_TIMEOUT Increase the default npm install timeout for WhatsApp bridge from 60s to 300s (5 minutes) to accommodate slower systems like Unraid NAS. Make it configurable via WHATSAPP_NPM_INSTALL_TIMEOUT environment variable for users who need even longer timeouts. Closes NousResearch#14980
- Add 'path', 'old_string', 'new_string', and 'patch' to required list - Update description to clarify mode-specific parameter requirements - This addresses issue where LLMs would omit these parameters because they were not marked as required in the schema, even though they are required depending on the mode Fixes NousResearch#15524
Some open-weight models (e.g. Qwen3.6-27B-FP8) emit the 'tasks' array as a JSON-encoded string instead of a native list. The generic coerce_tool_args in model_tools.py handles the common case, but when the string contains complex nested escaping, json.loads() may fail there. Add a normalization step at the top of delegate_task() that attempts to parse a string 'tasks' parameter as JSON before the batch-mode logic. Returns a clear error if parsing fails. Fixes NousResearch#21933
|
Closing as superseded by #22436, which fixed #21933 via salvage of #21966 (@Bartok9). Both your PRs targeted the same root cause and reached This PR mixed in unrelated changes — the WhatsApp Thanks for the diagnosis and the upstream issue analysis — happy to take the WhatsApp timeout change as a separate focused PR if you'd like to refile it. |
Summary
delegate_taskbatch mode silently fails when open-weight models (e.g. Qwen3.6-27B-FP8) emit thetasksarray as a JSON-encoded string instead of a native list. The agent retries 4-5 times before falling back to single-task mode, making batch delegation unusable.Root Cause
The generic
coerce_tool_args()inmodel_tools.pyattempts to parse string→array via_coerce_json(), but when the JSON string contains complex nested escaping (common with open-weight models),json.loads()fails silently. The string passes through unmodified, anddelegate_task()seesisinstance(tasks, list) == False, falling through to the error path.Fix
Add a normalization step at the top of
delegate_task()that attempts to parse a stringtasksparameter as JSON before the batch-mode logic. Returns a clear error message if parsing fails.Files changed:
tools/delegate_tool.py(+18 lines),tests/tools/test_delegate_tool.py(new, 124 lines)Regression Coverage
test_tasks_as_json_string_is_parsed— JSON-encoded array string is correctly parsedtest_tasks_as_invalid_string_returns_error— unparseable string returns clear errortest_tasks_as_native_list_still_works— native list passes through unchangedtest_tasks_as_none_with_goal_works— single-task mode unaffectedtest_tasks_empty_list_returns_error— empty list still returns errortest_tasks_string_with_nested_objects— complex nested JSON string parses correctlyTesting
All 6 new tests pass:
Fixes [Bug]: delegate_task batch mode fails silently when model emits tasks as JSON string #21933