Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(tools): auto-create group when custom groupId is provided

Jiayuan Zhang691e33e71ed1
diff --git a/packages/core/src/agent/tools/sessions-spawn.test.ts b/packages/core/src/agent/tools/sessions-spawn.test.ts
index 9eaff1a75d..0a0d80a9ad 100644
--- a/packages/core/src/agent/tools/sessions-spawn.test.ts
+++ b/packages/core/src/agent/tools/sessions-spawn.test.ts
@@ -1,7 +1,11 @@
-import { describe, it, expect } from "vitest";
+import { describe, it, expect, beforeEach } from "vitest";
import { createSessionsSpawnTool } from "./sessions-spawn.js";
+import { getSubagentGroup, resetSubagentRegistryForTests } from "../subagent/registry.js";
describe("sessions_spawn tool", () => {
+ beforeEach(() => {
+ resetSubagentRegistryForTests();
+ });
it("has correct name and description", () => {
const tool = createSessionsSpawnTool({ isSubagent: false, sessionId: "test-session" });
expect(tool.name).toBe("sessions_spawn");
@@ -24,6 +28,23 @@ describe("sessions_spawn tool", () => {
expect(firstContent.text).toContain("not allowed");
});
+ it("auto-creates group when custom groupId is provided", async () => {
+ const tool = createSessionsSpawnTool({ isSubagent: false, sessionId: "parent-session" });
+
+ // Should not error — the group is auto-created
+ await tool.execute(
+ "call-group",
+ { task: "research topic", label: "Research", groupId: "my-custom-group" } as any,
+ new AbortController().signal,
+ );
+
+ // Verify group was created in the registry
+ const group = getSubagentGroup("my-custom-group");
+ expect(group).toBeDefined();
+ expect(group!.groupId).toBe("my-custom-group");
+ expect(group!.label).toBe("Group: Research");
+ });
+
it("fails gracefully when Hub is not initialized", async () => {
const tool = createSessionsSpawnTool({ isSubagent: false, sessionId: "parent-session" });
diff --git a/packages/core/src/agent/tools/sessions-spawn.ts b/packages/core/src/agent/tools/sessions-spawn.ts
index 63e615bb11..030fbe2755 100644
--- a/packages/core/src/agent/tools/sessions-spawn.ts
+++ b/packages/core/src/agent/tools/sessions-spawn.ts
@@ -126,19 +126,20 @@ export function createSessionsSpawnTool(
const runId = uuidv7();
const childSessionId = uuidv7();
- // Validate groupId if provided
+ // Auto-create group when groupId is provided but doesn't exist yet,
+ // or when `next` is provided without a groupId.
if (groupId) {
const existingGroup = getSubagentGroup(groupId);
if (!existingGroup) {
- return {
- content: [{ type: "text", text: `Error: group not found: ${groupId}. Use the groupId returned by a previous sessions_spawn call.` }],
- details: { status: "error", error: `group not found: ${groupId}` },
- };
+ // LLM provided a custom groupId — auto-create the group
+ createSubagentGroup({
+ groupId,
+ requesterSessionId,
+ label: label ? `Group: ${label}` : undefined,
+ next,
+ });
}
- }
-
- // Auto-create group when `next` is provided without an existing groupId
- if (!groupId && next) {
+ } else if (next) {
groupId = uuidv7();
createSubagentGroup({
groupId,