Skip to content

Commit c792a16

Browse files
authored
fix(agents): allow uncategorized hidden and ACP spawns (#131736)
1 parent 789e811 commit c792a16

3 files changed

Lines changed: 67 additions & 21 deletions

File tree

‎docs/tools/subagents.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ In `prefer` mode, hidden sub-agents are for internal legwork that the user does
252252
Create a persistent dashboard session for work the user will watch or return to, or when they ask for a thread. Visible spawns support only `runtime: "subagent"` and always keep the created session.
253253
</ParamField>
254254
<ParamField path="category" type="string">
255-
Optional sidebar category for a visible session. Omit it or pass an empty string to leave the session ungrouped. Requires `visible: true`.
255+
Optional sidebar category for a visible session. Omitted, empty, and whitespace-only values mean no category and are also accepted for hidden or ACP runs. A nonempty category requires `visible: true`.
256256
</ParamField>
257257
<ParamField path="worktree" type="boolean" default="false">
258258
Provision a managed git worktree for the new dashboard session. Requires `visible: true`.
@@ -271,7 +271,9 @@ their latest assistant turn back to the requester; external delivery stays with
271271
the parent/requester agent.
272272
</Warning>
273273

274-
With `visible: true`, `category`, `model`, `cwd`, and a same-agent `context: "fork"` are supported. Use this durable mode for coding, multi-step work, or results the user may revisit, steer, or keep; it appears in the sidebar when the web UI is available and still works without it. Pass `category` to place the new session in that sidebar group atomically; omission and an empty string leave it ungrouped. A sandboxed target restricts `cwd` to that agent's workspace. Non-admin callers may use `cwd` only inside a configured agent workspace. Omit `cwd` to use the target agent workspace; for another repository, ask the operator to start the session from a registered project. Do not replace a rejected persistent spawn with the synchronous `openclaw agent` CLI, whose command deadline defaults to 600 seconds. Thread binding, `mode`, thinking overrides, `lightContext`, `attachments`, and `attachAs` are unavailable on this path because visible sessions are persistent dashboard sessions created through `sessions.create`. The new dashboard child inherits the requester's effective tool-policy ceiling before its first turn. Session listing and addressing obey `tools.sessions.visibility`; the default `tree` scope covers the current session and its own spawn subtree, while the main session can reach every same-agent session unless `self` or the sandbox spawned-only clamp applies. See [Session tools](/concepts/session-tool#visibility) and [Managed worktrees](/concepts/managed-worktrees).
274+
With `visible: true`, `category`, `model`, `cwd`, and a same-agent `context: "fork"` are supported. Use this durable mode for coding, multi-step work, or results the user may revisit, steer, or keep; it appears in the sidebar when the web UI is available and still works without it. Pass `category` to place the new session in that sidebar group atomically; omitted or blank values leave it ungrouped. A sandboxed target restricts `cwd` to that agent's workspace. Non-admin callers may use `cwd` only inside a configured agent workspace. Omit `cwd` to use the target agent workspace; for another repository, ask the operator to start the session from a registered project. Do not replace a rejected persistent spawn with the synchronous `openclaw agent` CLI, whose command deadline defaults to 600 seconds. Thread binding, `mode`, thinking overrides, `lightContext`, `attachments`, and `attachAs` are unavailable on this path because visible sessions are persistent dashboard sessions created through `sessions.create`. The new dashboard child inherits the requester's effective tool-policy ceiling before its first turn. Session listing and addressing obey `tools.sessions.visibility`; the default `tree` scope covers the current session and its own spawn subtree, while the main session can reach every same-agent session unless `self` or the sandbox spawned-only clamp applies. See [Session tools](/concepts/session-tool#visibility) and [Managed worktrees](/concepts/managed-worktrees).
275+
276+
If a call fails with `Parameters require visible=true`, omit the named category or worktree options to keep the hidden or ACP runtime. To create a visible session instead, use `visible: true` with `runtime: "subagent"` and omit `mode`, `thread`, `thinking`, `lightContext`, `attachments`, `attachAs`, swarm options, and the ACP-only `streamTo` and `resumeSessionId`. Worktree names and base refs also require `worktree: true`. Adding `visible: true` alone does not make an ACP call compatible.
275277

276278
A visible spawn is attributed to the requesting agent: the new session's creator and initial owner is that agent, shown with its configured identity name and avatar in the sidebar. The accepted result doubles as a receipt with `childSessionKey`, `runId`, a Control UI `sessionUrl` (omitted when the Control UI is disabled), and an `owner` record. When acknowledging the spawn in a channel, put the session URL on the first line and `Owner: <label>` on the second so the user can open the session and see who is responsible. Owners can be reassigned later; see [Multi-user mode](/concepts/multi-user#agent-spawned-sessions).
277279

‎src/agents/tools/sessions-spawn-tool.test.ts‎

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ describe("sessions_spawn tool", () => {
679679
},
680680
);
681681

682-
it.each([{ category: undefined }, { category: "" }])(
682+
it.each([{ category: undefined }, { category: "" }, { category: " \t\n " }])(
683683
"keeps a visible session ungrouped when category is $category",
684684
async ({ category }) => {
685685
const callGateway = vi.fn(async () => ({
@@ -849,22 +849,67 @@ describe("sessions_spawn tool", () => {
849849
});
850850
});
851851

852-
it("requires visible sessions for worktree options", async () => {
853-
const tool = createSessionsSpawnTool({ agentSessionKey: "agent:main:main" });
852+
describe.each([
853+
{
854+
runtime: "subagent",
855+
spawn: hoisted.spawnSubagentDirectMock,
856+
other: hoisted.spawnAcpDirectMock,
857+
},
858+
{ runtime: "acp", spawn: hoisted.spawnAcpDirectMock, other: hoisted.spawnSubagentDirectMock },
859+
])("$runtime category preflight", ({ runtime, spawn, other }) => {
860+
beforeEach(() => registerAcpBackendForTest());
854861

855-
await expect(
856-
tool.execute("hidden-worktree", { task: "inspect", worktree: true }),
857-
).rejects.toThrow("Parameters require visible=true: worktree");
858-
expect(hoisted.spawnSubagentDirectMock).not.toHaveBeenCalled();
859-
});
862+
it.each([undefined, "", " \t\n "])("dispatches once with category %j", async (category) => {
863+
const callGateway = vi.fn();
864+
const tool = createSessionsSpawnTool({ agentSessionKey: "agent:main:main", callGateway });
865+
const request = {
866+
task: "inspect",
867+
runtime,
868+
model: "openai/gpt-5.6-luna",
869+
thinking: "ultra",
870+
sandbox: "require",
871+
mode: "run",
872+
};
860873

861-
it.each(["Projects", ""])("rejects category %j without visible mode", async (category) => {
862-
const tool = createSessionsSpawnTool({ agentSessionKey: "agent:main:main" });
874+
const result = await tool.execute("hidden-category", {
875+
...request,
876+
visible: false,
877+
...(category !== undefined ? { category } : {}),
878+
});
863879

864-
await expect(tool.execute("hidden-category", { task: "inspect", category })).rejects.toThrow(
865-
"Parameters require visible=true: category",
866-
);
867-
expect(hoisted.spawnSubagentDirectMock).not.toHaveBeenCalled();
880+
expect(result.details).toMatchObject({ status: "accepted", runId: `run-${runtime}` });
881+
expect(spawn).toHaveBeenCalledOnce();
882+
const { runtime: _runtime, ...forwarded } = request;
883+
expect(spawn).toHaveBeenCalledWith(expect.objectContaining(forwarded), expect.any(Object));
884+
expect(other).not.toHaveBeenCalled();
885+
expect(callGateway).not.toHaveBeenCalled();
886+
expect(hoisted.inProcessCreationMock).not.toHaveBeenCalled();
887+
});
888+
889+
it.each([
890+
{ category: "Projects" },
891+
{ worktree: true },
892+
{ worktreeName: "repair" },
893+
{ worktreeBaseRef: "main" },
894+
])("rejects visible-only options %j with actionable recovery", async (options) => {
895+
const callGateway = vi.fn();
896+
const tool = createSessionsSpawnTool({ agentSessionKey: "agent:main:main", callGateway });
897+
898+
await expect(
899+
tool.execute("hidden-visible-options", {
900+
task: "inspect",
901+
runtime,
902+
mode: "run",
903+
...options,
904+
}),
905+
).rejects.toThrow(
906+
`Parameters require visible=true: ${Object.keys(options).join(", ")}. ` +
907+
'Omit these options for hidden subagent or ACP runs. For a visible session, use visible=true with runtime="subagent"; omit mode, thread, thinking, lightContext, attachments, attachAs, swarm options, and ACP-only streamTo/resumeSessionId. Worktree names/base refs also require worktree=true.',
908+
);
909+
expect(spawn).not.toHaveBeenCalled();
910+
expect(other).not.toHaveBeenCalled();
911+
expect(callGateway).not.toHaveBeenCalled();
912+
});
868913
});
869914

870915
it("applies a per-run timeout to visible dashboard sessions", async () => {

‎src/agents/tools/sessions-spawn-visible.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,10 @@ export async function maybeSpawnVisibleSession(params: {
111111
const worktree = params.raw.worktree === true;
112112
const worktreeName = readToolStringParam(params.raw, "worktreeName");
113113
const worktreeBaseRef = readToolStringParam(params.raw, "worktreeBaseRef");
114-
const categoryProvided = Object.hasOwn(params.raw, "category");
115-
const requestedCategory = readToolStringParam(params.raw, "category", { allowEmpty: true });
114+
const category = readToolStringParam(params.raw, "category");
116115
if (params.raw.visible !== true) {
117116
const visibleOnlyParams = [
118-
["category", categoryProvided ? requestedCategory : undefined],
117+
["category", category],
119118
["worktree", worktree],
120119
["worktreeName", worktreeName],
121120
["worktreeBaseRef", worktreeBaseRef],
@@ -125,7 +124,8 @@ export async function maybeSpawnVisibleSession(params: {
125124
.map(([name]) => name);
126125
if (providedVisibleOnlyParams.length > 0) {
127126
throw new ToolInputError(
128-
`Parameters require visible=true: ${providedVisibleOnlyParams.join(", ")}`,
127+
`Parameters require visible=true: ${providedVisibleOnlyParams.join(", ")}. ` +
128+
'Omit these options for hidden subagent or ACP runs. For a visible session, use visible=true with runtime="subagent"; omit mode, thread, thinking, lightContext, attachments, attachAs, swarm options, and ACP-only streamTo/resumeSessionId. Worktree names/base refs also require worktree=true.',
129129
);
130130
}
131131
return undefined;
@@ -207,7 +207,6 @@ export async function maybeSpawnVisibleSession(params: {
207207
sessionKey: requesterKey,
208208
agentId: params.options?.requesterAgentIdOverride,
209209
});
210-
const category = normalizeOptionalString(requestedCategory);
211210
const requireAgentId =
212211
resolveAgentConfig(cfg, requesterAgentId)?.subagents?.requireAgentId ??
213212
cfg.agents?.defaults?.subagents?.requireAgentId ??

0 commit comments

Comments
 (0)