Skip to content

fix: coerce nested agent params to prevent spawn_agents validation failures#652

Closed
1337Xcode wants to merge 2 commits into
CodebuffAI:mainfrom
1337Xcode:main
Closed

fix: coerce nested agent params to prevent spawn_agents validation failures#652
1337Xcode wants to merge 2 commits into
CodebuffAI:mainfrom
1337Xcode:main

Conversation

@1337Xcode
Copy link
Copy Markdown

What it fixes: spawn_agents was rejecting valid inputs when the LLM emitted nested agent.params as a JSON string during batched spawns.

How it works: Adds a coerceToObject z.preprocess step that JSON-parses stringified objects before validation, mirroring the existing array coercion. Wired into the Zod input schemas for both spawn_agents and the inline spawn tool.

Files changed: utils.ts, spawn-agents.ts, spawn-agent-inline.ts, coerce-to-array.test.ts, tool-validation-error.test.ts

Fixes #635

Copilot AI review requested due to automatic review settings May 12, 2026 06:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes validation failures when spawning agents in batches by coercing nested agent.params values that the LLM sometimes emits as a JSON string. It adds a narrow JSON-object coercion step and wires it into the Zod input schemas for both spawn_agents and spawn_agent_inline, with accompanying tests.

Changes:

  • Added coerceToObject to JSON-parse stringified object inputs (while leaving malformed values to fail validation).
  • Updated spawn_agents and spawn_agent_inline Zod schemas to preprocess params via coerceToObject.
  • Added/updated tests to cover coerceToObject and spawn_agents stringified params handling.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/agent-runtime/src/tests/tool-validation-error.test.ts Adds a regression test for spawn_agents stringified params and refactors message-content extraction logic.
common/src/tools/params/utils.ts Introduces coerceToObject for narrowly parsing stringified JSON objects.
common/src/tools/params/tool/spawn-agents.ts Applies coerceToObject preprocessing to each agent entry’s params schema.
common/src/tools/params/tool/spawn-agent-inline.ts Applies coerceToObject preprocessing to inline spawn params.
common/src/tools/params/tests/coerce-to-array.test.ts Adds unit tests for coerceToObject behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +159 to +163
{
agent_type: 'basher',
prompt: 'Run tests',
params: '{"command":"bun test"}',
},
@jahooma
Copy link
Copy Markdown
Contributor

jahooma commented May 12, 2026

Thank you! Forking this with some tweaks here: #658

@jahooma jahooma closed this May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spawning Multiple Agents Routinely Fails

3 participants