Repository navigation
Validate Pi sub-agent invocation parameters - #74370
Conversation
Co-authored-by: pelikhan <[email protected]>
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
✅ Ponytail Reviewer completed successfully! Ponytail ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft. Design Decision Gate 🏗️Outcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
Review: non-blocking concern
The parameter-shape validation is correct, but delegated tasks remain unbounded and can impose avoidable memory/runtime pressure on the child process. I left one inline comment requesting a task-size limit and regression test.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.7K
Comment /review to run again
| description: `Delegate a task to a declared agent in an isolated Pi session. Available agents: ${agents.map(agent => `${agent.name}: ${agent.description}`).join("; ")}`, | ||
| parameters: { type: "object", properties: { agent: { type: "string", enum: agents.map(agent => agent.name) }, task: { type: "string", minLength: 1 } }, required: ["agent", "task"], additionalProperties: false }, | ||
| async execute(_id, params, signal, _onUpdate, ctx) { | ||
| if (!params || typeof params !== "object" || Array.isArray(params) || typeof params.agent !== "string" || typeof params.task !== "string" || !params.task.trim()) |
There was a problem hiding this comment.
The new boundary still accepts arbitrarily large task strings and writes them directly to child stdin, so a huge invocation can consume substantial memory or keep the child busy despite this validation hardening.
💡 Bound delegated task size
Add a documented maximum task length (and a regression test) before dispatch, or otherwise enforce a resource limit at this boundary. The existing schema only has minLength, so it does not prevent oversized input.
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd and /codebase-design. The hardening is sound: the guard runs before agents.find and before any dispatch, and the task still goes to child stdin with shell: false. Three small test-coverage items remain.
📋 Key Themes & Highlights
Key Themes
- Test table gaps: the new guard has two clauses (
agenttype,tasktype) with no matching test rows. - Dispatch ordering is untested: nothing asserts that a rejected call emits no dispatch event.
- Redundant clause:
typeof params.agent !== "string"duplicates the strict===in thefind.
Positive Highlights
- ✅ Validation happens before the agent lookup, so malformed input never reaches
runPiSubagent. - ✅ Non-object and array
paramsare rejected explicitly. - ✅ The
shell: falseand stdin-only task design is unchanged and correct.
Verification
- I ran the validation logic directly with Node against 10 malformed or undeclared inputs. Each one throws the expected error.
- I could not run the Vitest suite:
npm cifailed on a sandbox TLS certificate error, so the newit.eachrow is unverified.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~3 AIC · ⌖ ~1 AIC · ⊞ 5.4K
Comment /matt to run again
| expect(registerTool).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it.each([null, [], { agent: "unknown", task: "Read." }, { agent: "reader", task: " " }])("rejects malformed or undeclared invocation parameters: %j", async params => { |
There was a problem hiding this comment.
[/tdd] The new typeof guards have no test row for a non-string task. With { agent: "reader", task: 5 } only the first clause protects the call. If that clause were removed, .trim() would throw a TypeError with a different message, and this suite would not catch it.
💡 Suggested rows
Add these two rows to the array on line 61:
{ agent: 1, task: "Read." }{ agent: "reader", task: 5 }
One row per guard clause makes the table read as a spec for the boundary.
@copilot please address this.
| const registerTool = vi.fn(); | ||
| extension({ registerTool }); | ||
| const tool = registerTool.mock.calls[0][0]; | ||
| await expect(tool.execute("id", params, undefined, undefined, { cwd: dir })).rejects.toThrow("Choose a declared Pi sub-agent"); |
There was a problem hiding this comment.
[/tdd] The test checks the rejection but not the "before dispatch" guarantee the PR description relies on. A change that moved validation after the dispatch event would still pass this test.
💡 Suggested assertion
Add after line 66:
expect(process.stdout.write).not.toHaveBeenCalled();process.stdout.write is already mocked in beforeEach, so no extra setup is needed.
@copilot please address this.
| description: `Delegate a task to a declared agent in an isolated Pi session. Available agents: ${agents.map(agent => `${agent.name}: ${agent.description}`).join("; ")}`, | ||
| parameters: { type: "object", properties: { agent: { type: "string", enum: agents.map(agent => agent.name) }, task: { type: "string", minLength: 1 } }, required: ["agent", "task"], additionalProperties: false }, | ||
| async execute(_id, params, signal, _onUpdate, ctx) { | ||
| if (!params || typeof params !== "object" || Array.isArray(params) || typeof params.agent !== "string" || typeof params.task !== "string" || !params.task.trim()) |
There was a problem hiding this comment.
Nit: typeof params.agent !== "string" is redundant. The strict === in the find on line 212 already rejects non-string values, so behavior is identical without this clause.
@copilot please address this.
There was a problem hiding this comment.
🟡 Changes recommended
The undeclared-agent error misleadingly asks for a non-empty task when a valid task is supplied and omits the declared agent names needed to correct the selection.
1 open issue
What changed in this PR
Hardens gh-aw’s Pi sub-agent delegation boundary in response to #74044 by validating invocation parameters before agent lookup and dispatch.
Changes:
- Rejects malformed parameters and blank tasks before looking up the declared agent.
- Adds regression cases for null, array, undeclared-agent, and whitespace-only-task inputs.
| File | Description |
|---|---|
actions/setup/js/pi_subagent_extension.test.cjs |
Adds invalid-invocation regression cases. |
actions/setup/js/pi_subagent_extension.cjs |
Validates parameter shape and task content before agent lookup. |
Review effort: Max (auto)
| throw new Error("Choose a declared Pi sub-agent and provide a non-empty task"); | ||
| const agent = agents.find(candidate => candidate.name === params.agent); | ||
| if (!agent || typeof params.task !== "string" || !params.task.trim()) throw new Error("Choose a declared Pi sub-agent and provide a non-empty task"); | ||
| if (!agent) throw new Error("Choose a declared Pi sub-agent and provide a non-empty task"); |
|
Note The pull request was not created — a fallback review issue was created instead due to protected file changes: #74424 PR finisher pass: merged PR finisher dispatch requested for the following outstanding work: review items 1-6 above. Sous-chef head: 3f49ac2
|
|
🎉 This pull request is included in a new release. Release: |

Security findings flagged package-validation commands and Pi sub-agent delegation as potential command injection paths. The Go commands already resolve fixed executable names and validate package names; this change hardens validation at the Pi tool boundary.
shell: false.