Skip to content

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

Go

fix(subagent): clear run records immediately after successful announcement

yushena3f5a21561c6
diff --git a/src/agent/subagent/registry.test.ts b/src/agent/subagent/registry.test.ts
index 9d0fe93104..2169564b23 100644
--- a/src/agent/subagent/registry.test.ts
+++ b/src/agent/subagent/registry.test.ts
@@ -1,4 +1,4 @@
-import { describe, it, expect, beforeEach } from "vitest";
+import { describe, it, expect, beforeEach, vi } from "vitest";
import {
registerSubagentRun,
listSubagentRuns,
@@ -244,3 +244,33 @@ describe("subagent registry — coalescing", () => {
expect(record?.findingsCaptured).toBe(true);
});
});
+
+describe("subagent registry — post-announce cleanup", () => {
+ it("removes runs from registry after successful announcement", async () => {
+ // Mock runCoalescedAnnounceFlow to succeed
+ const announceModule = await import("./announce.js");
+ const spy = vi.spyOn(announceModule, "runCoalescedAnnounceFlow").mockReturnValue(true);
+
+ // Register two runs for the same parent — both end immediately (no Hub)
+ registerSubagentRun({
+ runId: "run-a",
+ childSessionId: "child-a",
+ requesterSessionId: "parent-1",
+ task: "Task A",
+ });
+ registerSubagentRun({
+ runId: "run-b",
+ childSessionId: "child-b",
+ requesterSessionId: "parent-1",
+ task: "Task B",
+ });
+
+ // Both runs should have been announced and removed from registry
+ expect(spy).toHaveBeenCalled();
+ expect(getSubagentRun("run-a")).toBeUndefined();
+ expect(getSubagentRun("run-b")).toBeUndefined();
+ expect(listSubagentRuns("parent-1")).toHaveLength(0);
+
+ spy.mockRestore();
+ });
+});
diff --git a/src/agent/subagent/registry.ts b/src/agent/subagent/registry.ts
index 0dbfa971aa..0f03002aa6 100644
--- a/src/agent/subagent/registry.ts
+++ b/src/agent/subagent/registry.ts
@@ -289,10 +289,13 @@ function checkAndAnnounce(requesterSessionId: string): void {
for (const r of pending) {
r.announced = true;
r.cleanupHandled = true;
- r.archiveAtMs = Date.now() + DEFAULT_ARCHIVE_AFTER_MS;
- r.cleanupCompletedAt = Date.now();
+ // Remove from registry immediately — findings already delivered to parent
+ subagentRuns.delete(r.runId);
}
persist();
+ if (subagentRuns.size === 0) {
+ stopSweeper();
+ }
} else {
console.warn(
`[SubagentRegistry] Coalesced announce failed for requester ${requesterSessionId}`,