Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(agent-runtime): accept job plus multi-id TaskWait selectors
koeriaaef5adac4001
diff --git a/packages/agent-runtime/src/background-job-tools.test.ts b/packages/agent-runtime/src/background-job-tools.test.tsindex 606e71cb6..d9035b058 100644--- a/packages/agent-runtime/src/background-job-tools.test.ts+++ b/packages/agent-runtime/src/background-job-tools.test.ts@@ -71,13 +71,32 @@ describe("session job controls", () => {},);- it.each([["other"], ["delegate", "other"], "delegate", null].map(delegationIds => ({ delegationIds })))(- "rejects conflicting or malformed delegation selectors (%j) before dispatch",+ it.each([["other"], ["delegate", "other"]].map(delegationIds => ({ delegationIds })))(+ "falls through to multi-target delegation selectors when job conflicts (%j)",+ async ({ delegationIds }) => {+ const { wait, stop, dispatch, delegates } = fixture();+ const params = {+ job: { kind: "delegation", id: "delegate" }, delegationIds,+ mode: "any", minCompleted: 2, timeoutSeconds: 180,+ };+ const signal = new AbortController().signal;+ const update = vi.fn();+ const waitResult = await wait.execute("wait", params, signal, update);+ expect(waitResult.content).toEqual([{ type: "text", text: "delegate report" }]);+ expect(delegates.wait.execute).toHaveBeenCalledWith("wait", params, signal, update);+ await stop.execute("stop", params, signal, update);+ expect(delegates.stop.execute).toHaveBeenCalledWith("stop", params, signal, update);+ expect(dispatch).not.toHaveBeenCalled();+ },+ );++ it.each(["delegate", null, ["delegate", null], [42]].map(delegationIds => ({ delegationIds })))(+ "rejects malformed delegation selectors (%j) with an actionable error",async ({ delegationIds }) => {const { wait, stop, dispatch, delegates } = fixture();const params = { job: { kind: "delegation", id: "delegate" }, delegationIds };- await expect(wait.execute("wait", params)).rejects.toThrow("omit delegationIds or pass only job.id");- await expect(stop.execute("stop", params)).rejects.toThrow("omit delegationIds or pass only job.id");+ await expect(wait.execute("wait", params)).rejects.toThrow("delegationIds must be an array of delegation ids");+ await expect(stop.execute("stop", params)).rejects.toThrow("delegationIds must be an array of delegation ids");expect(delegates.wait.execute).not.toHaveBeenCalled();expect(delegates.stop.execute).not.toHaveBeenCalled();expect(dispatch).not.toHaveBeenCalled();diff --git a/packages/agent-runtime/src/background-job-tools.ts b/packages/agent-runtime/src/background-job-tools.tsindex 42e2b5f91..3b54b8b90 100644--- a/packages/agent-runtime/src/background-job-tools.ts+++ b/packages/agent-runtime/src/background-job-tools.ts@@ -13,7 +13,7 @@ import type { RuntimeHost } from "./host-client.js";const jobSchema = Type.Object({kind: Type.Union([Type.Literal("bash"), Type.Literal("delegation")]),id: Type.String({ minLength: 1 }),-}, { additionalProperties: false, description: "An explicit job returned by Bash, Task or TaskList. For delegation jobs, omit delegationIds or pass an empty array or only this job's id; mode and minCompleted are ignored. For Bash jobs, omit delegationIds or pass an empty array; mode may be omitted, all or any, and minCompleted may be omitted or 1." });+}, { additionalProperties: false, description: "An explicit job returned by Bash or Task. For delegation jobs, a delegationIds array that selects other subagents takes precedence over job.id and uses the multi-target wait; an omitted/empty delegationIds or an array of only this job's id targets just this job and ignores mode and minCompleted. For Bash jobs, omit delegationIds or pass an empty array; mode may be omitted, all or any, and minCompleted may be omitted or 1." });function record(value: unknown): value is Record<string, unknown> {return typeof value === "object" && value !== null && !Array.isArray(value);@@ -27,9 +27,16 @@ function target(params: unknown): JobReference | undefined {throw new Error("job must contain a kind (bash or delegation) and a nonempty id");}if (job.kind === "delegation") {- if (params.delegationIds !== undefined && (!Array.isArray(params.delegationIds) ||- params.delegationIds.some(id => id !== job.id))) {- throw new Error("A delegation job targets one subagent: omit delegationIds or pass only job.id. To select multiple subagents, omit job and use delegationIds.");+ if (params.delegationIds !== undefined) {+ if (!Array.isArray(params.delegationIds) ||+ params.delegationIds.some(id => typeof id !== "string")) {+ throw new Error("delegationIds must be an array of delegation ids. To select subagents, drop the job field and retry with delegationIds: [...]; to target this one job, omit delegationIds.");+ }+ // Strict Responses-style models send the job returned by Task next to+ // every id they want to collect. The multi-target path already honors+ // delegationIds, so treat that conflict as "no job" rather than+ // rejecting an input the delegate can handle (#2188 residual, #2487).+ if (params.delegationIds.some(id => id !== job.id)) return undefined;}} else if ((params.delegationIds !== undefined && (!Array.isArray(params.delegationIds) || params.delegationIds.length !== 0)) ||diff --git a/packages/agent-runtime/src/runtime.test.ts b/packages/agent-runtime/src/runtime.test.tsindex 809863766..d83c3caac 100644--- a/packages/agent-runtime/src/runtime.test.ts+++ b/packages/agent-runtime/src/runtime.test.ts@@ -11443,6 +11443,10 @@ describe("DesktopAgentRuntime subagents", () => {);expect(listed.details.resumable).toEqual([]);expect(listed.content[0].text).not.toContain("Reusable subagent sessions");+ // TaskList must not advertise the `job` shape that made strict models+ // resend a job next to a multi-id TaskWait (#2487).+ expect(listed.content[0].text).toContain(`delegationIds=["${delegationId}"]`);+ expect(listed.content[0].text).not.toContain("job=");subagentRuns.deferred = false;await runtime.dispose();diff --git a/packages/agent-runtime/src/runtime.ts b/packages/agent-runtime/src/runtime.tsindex 2fb1fe01a..c6ea8fea1 100644--- a/packages/agent-runtime/src/runtime.ts+++ b/packages/agent-runtime/src/runtime.ts@@ -6139,7 +6139,7 @@ Do not invent objections or turn speculative risks into blockers. Stop when thedelegations.length === 0? "No subagents have been started in this session.": delegations- .map((record) => `- ${formatDelegationHeartbeat(record)}; job=${JSON.stringify({ kind: "delegation", id: record.delegationId })}`)+ .map((record) => `- ${formatDelegationHeartbeat(record)}; delegationIds=${JSON.stringify([record.delegationId])}`).join("\n"),this.delegationChains.resumableBlock({ runningDelegationIds }),]