refactor(agents): unify subagent announce delivery pipeline

Co-authored-by: Smith Labs <SmithLabsLLC@users.noreply.github.com>
Co-authored-by: Do Cao Hieu <docaohieu2808@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-02-26 00:30:19 +00:00
parent aedf62ac7e
commit 4258a3307f
14 changed files with 623 additions and 132 deletions

View File

@@ -155,4 +155,43 @@ describe("announce loop guard (#18264)", () => {
const stored = runs.find((run) => run.runId === entry.runId);
expect(stored?.cleanupCompletedAt).toBeDefined();
});
test("announce rejection resets cleanupHandled so retries can resume", async () => {
announceFn.mockReset();
announceFn.mockRejectedValueOnce(new Error("announce failed"));
registry.resetSubagentRegistryForTests();
const now = Date.now();
const runId = "test-announce-rejection";
loadSubagentRegistryFromDisk.mockReturnValue(
new Map([
[
runId,
{
runId,
childSessionKey: "agent:main:subagent:child-1",
requesterSessionKey: "agent:main:main",
requesterDisplayKey: "agent:main:main",
task: "rejection test",
cleanup: "keep" as const,
createdAt: now - 30_000,
startedAt: now - 20_000,
endedAt: now - 10_000,
cleanupHandled: false,
},
],
]),
);
registry.initSubagentRegistry();
await Promise.resolve();
await Promise.resolve();
const runs = registry.listSubagentRunsForRequester("agent:main:main");
const stored = runs.find((run) => run.runId === runId);
expect(stored?.cleanupHandled).toBe(false);
expect(stored?.cleanupCompletedAt).toBeUndefined();
expect(stored?.announceRetryCount).toBe(1);
expect(stored?.lastAnnounceRetryAt).toBeTypeOf("number");
});
});