fix: /stop aborts subagents

This commit is contained in:
Peter Steinberger
2026-01-16 21:37:11 +00:00
parent 390bd11f33
commit a0be85c34c
11 changed files with 198 additions and 12 deletions

View File

@@ -18,6 +18,14 @@ const commandQueueMocks = vi.hoisted(() => ({
vi.mock("../../process/command-queue.js", () => commandQueueMocks);
const subagentRegistryMocks = vi.hoisted(() => ({
listSubagentRunsForRequester: vi.fn(() => []),
}));
vi.mock("../../agents/subagent-registry.js", () => ({
listSubagentRunsForRequester: subagentRegistryMocks.listSubagentRunsForRequester,
}));
describe("abort detection", () => {
it("triggerBodyNormalized extracts /stop from RawBody for abort detection", async () => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-abort-"));
@@ -137,4 +145,59 @@ describe("abort detection", () => {
expect(getFollowupQueueDepth(sessionKey)).toBe(0);
expect(commandQueueMocks.clearCommandLane).toHaveBeenCalledWith(`session:${sessionKey}`);
});
it("fast-abort stops active subagent runs for requester session", async () => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-abort-"));
const storePath = path.join(root, "sessions.json");
const cfg = { session: { store: storePath } } as ClawdbotConfig;
const sessionKey = "telegram:parent";
const childKey = "agent:main:subagent:child-1";
const sessionId = "session-parent";
const childSessionId = "session-child";
await fs.writeFile(
storePath,
JSON.stringify(
{
[sessionKey]: {
sessionId,
updatedAt: Date.now(),
},
[childKey]: {
sessionId: childSessionId,
updatedAt: Date.now(),
},
},
null,
2,
),
);
subagentRegistryMocks.listSubagentRunsForRequester.mockReturnValueOnce([
{
runId: "run-1",
childSessionKey: childKey,
requesterSessionKey: sessionKey,
requesterDisplayKey: "telegram:parent",
task: "do work",
cleanup: "keep",
createdAt: Date.now(),
},
]);
const result = await tryFastAbortFromMessage({
ctx: {
CommandBody: "/stop",
RawBody: "/stop",
SessionKey: sessionKey,
Provider: "telegram",
Surface: "telegram",
From: "telegram:parent",
To: "telegram:parent",
},
cfg,
});
expect(result.stoppedSubagents).toBe(1);
expect(commandQueueMocks.clearCommandLane).toHaveBeenCalledWith(`session:${childKey}`);
});
});