Skip to content

fix(delegate): accept JSON string batch tasks#21966

Closed
Bartok9 wants to merge 2 commits into
NousResearch:mainfrom
Bartok9:fix/21933-delegate-string-tasks
Closed

fix(delegate): accept JSON string batch tasks#21966
Bartok9 wants to merge 2 commits into
NousResearch:mainfrom
Bartok9:fix/21933-delegate-string-tasks

Conversation

@Bartok9

@Bartok9 Bartok9 commented May 8, 2026

Copy link
Copy Markdown
Contributor

Problem

Closes #21933.

Open-weight models can emit delegate_task batch tasks as a JSON-encoded array string instead of a native array. When that reaches the delegate boundary unchanged or as a bad single list item, batch delegation fails with a confusing generic error or an attribute error instead of running the requested subtasks.

Root cause

delegate_task only treated native lists as batch mode and assumed every list item was a task object. It did not recover the common tasks='[{...}]' model-output shape, and it did not validate list element types before calling .get().

Fix

Parse string-shaped tasks as a JSON array at the delegate boundary, preserve native list behavior, and return clear structured tool errors for malformed JSON, non-array JSON, or non-object list entries.

Testing

  • python3 -m py_compile tools/delegate_tool.py tests/tools/test_delegate.py: clean
  • python3 -m pytest -o addopts='' tests/tools/test_delegate.py::TestDelegateTask::test_batch_mode_accepts_json_string_tasks tests/tools/test_delegate.py::TestDelegateTask::test_batch_mode_rejects_non_object_tasks tests/tools/test_delegate.py::TestDelegateTask::test_batch_mode_rejects_malformed_json_string_tasks -q: 3 passed
  • git diff --check: clean

Made with Cursor

Bartok9 and others added 2 commits May 8, 2026 12:30
Recover delegate_task batch inputs when open-weight models emit tasks as a JSON-encoded array string, and return clear errors for malformed task lists.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Bartok9

Bartok9 commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

The test CI failure is pre-existing on main — verified at main SHA 1997b3ba. Not introduced by this PR.

@Bartok9

Bartok9 commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

The test CI failure is pre-existing on main — verified at main SHA 524cbabd. Not introduced by this PR.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tools Tool registry, model_tools, toolsets tool/delegate Subagent delegation labels May 9, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing with #22092 and #21957 — all three fix the same delegate_task batch JSON string issue (#21933).

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Merged via #22436 — your commit was cherry-picked with original authorship preserved (326ca754a on main). Thanks for the clean fix!

Both your PR and #21957 targeted the same code path; we picked yours as the salvage base because it had focused tests, returned structured errors for malformed/non-array JSON, and added per-element type validation. The companion commit (7330183d0) salvages diagnostic logging from #22092 by @uzunkuyruk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P2 Medium — degraded but workaround exists tool/delegate Subagent delegation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: delegate_task batch mode fails silently when model emits tasks as JSON string

3 participants