fix(subagents): pass group context in /subagents spawn

This commit is contained in:
Peter Steinberger
2026-02-17 03:00:01 +01:00
parent 2b3ecee7c5
commit f242246839
3 changed files with 29 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { resetSubagentRegistryForTests } from "../../agents/subagent-registry.js";
import type { SpawnSubagentResult } from "../../agents/subagent-spawn.js";
import { resetSubagentRegistryForTests } from "../../agents/subagent-registry.js";
const hoisted = vi.hoisted(() => {
const spawnSubagentDirectMock = vi.fn();
@@ -126,6 +126,28 @@ describe("/subagents spawn command", () => {
expect(spawnParams.task).toBe("do the thing");
});
it("passes group context from session entry to spawnSubagentDirect", async () => {
spawnSubagentDirectMock.mockResolvedValue(acceptedResult());
const params = buildCommandTestParams("/subagents spawn beta do the thing", baseCfg);
params.sessionEntry = {
sessionId: "session-main",
updatedAt: Date.now(),
groupId: "group-1",
groupChannel: "#group-channel",
space: "workspace-1",
};
const result = await handleSubagentsCommand(params, true);
expect(result).not.toBeNull();
expect(result?.reply?.text).toContain("Spawned subagent beta");
const [, spawnCtx] = spawnSubagentDirectMock.mock.calls[0];
expect(spawnCtx).toMatchObject({
agentGroupId: "group-1",
agentGroupChannel: "#group-channel",
agentGroupSpace: "workspace-1",
});
});
it("returns forbidden for unauthorized cross-agent spawn", async () => {
spawnSubagentDirectMock.mockResolvedValue(
forbiddenResult("agentId is not allowed for sessions_spawn (allowed: alpha)"),

View File

@@ -1,7 +1,8 @@
import crypto from "node:crypto";
import type { SubagentRunRecord } from "../../agents/subagent-registry.js";
import type { CommandHandler } from "./commands-types.js";
import { AGENT_LANE_SUBAGENT } from "../../agents/lanes.js";
import { abortEmbeddedPiRun } from "../../agents/pi-embedded.js";
import type { SubagentRunRecord } from "../../agents/subagent-registry.js";
import {
clearSubagentRunSteerRestart,
listSubagentRunsForRequester,
@@ -35,7 +36,6 @@ import {
} from "../../shared/subagents-format.js";
import { INTERNAL_MESSAGE_CHANNEL } from "../../utils/message-channel.js";
import { stopSubagentsForRequester } from "./abort.js";
import type { CommandHandler } from "./commands-types.js";
import { clearSessionQueues } from "./queue.js";
import { formatRunLabel, formatRunStatus, sortSubagentRuns } from "./subagents-utils.js";
@@ -681,6 +681,9 @@ export const handleSubagentsCommand: CommandHandler = async (params, allowTextCo
agentAccountId: params.ctx.AccountId,
agentTo: params.command.to,
agentThreadId: params.ctx.MessageThreadId,
agentGroupId: params.sessionEntry?.groupId ?? null,
agentGroupChannel: params.sessionEntry?.groupChannel ?? null,
agentGroupSpace: params.sessionEntry?.space ?? null,
},
);
if (result.status === "accepted") {