From 6daa4911e7671941ff8a14f7c64faa51ac5f7d82 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 14 Feb 2026 00:28:12 +0000 Subject: [PATCH] perf(subagents): speed announce retry polling and trim duplicate e2e coverage --- .../subagent-announce.format.e2e.test.ts | 58 +------------------ src/agents/subagent-announce.ts | 3 +- 2 files changed, 4 insertions(+), 57 deletions(-) diff --git a/src/agents/subagent-announce.format.e2e.test.ts b/src/agents/subagent-announce.format.e2e.test.ts index b1a0f6dd1..882e85a76 100644 --- a/src/agents/subagent-announce.format.e2e.test.ts +++ b/src/agents/subagent-announce.format.e2e.test.ts @@ -292,7 +292,7 @@ describe("subagent announce formatting", () => { lastChannel: "whatsapp", lastTo: "+1555", queueMode: "collect", - queueDebounceMs: 80, + queueDebounceMs: 0, }, }; @@ -327,7 +327,7 @@ describe("subagent announce formatting", () => { }), ]); - await new Promise((r) => setTimeout(r, 120)); + await expect.poll(() => agentSpy.mock.calls.length).toBe(2); expect(agentSpy).toHaveBeenCalledTimes(2); const accountIds = agentSpy.mock.calls.map( (call) => (call?.[0] as { params?: { accountId?: string } })?.params?.accountId, @@ -513,58 +513,4 @@ describe("subagent announce formatting", () => { expect(call?.params?.channel).toBe("bluebubbles"); expect(call?.params?.to).toBe("bluebubbles:chat_guid:123"); }); - - it("splits collect-mode announces when accountId differs", async () => { - const { runSubagentAnnounceFlow } = await import("./subagent-announce.js"); - embeddedRunMock.isEmbeddedPiRunActive.mockReturnValue(true); - embeddedRunMock.isEmbeddedPiRunStreaming.mockReturnValue(false); - sessionStore = { - "agent:main:main": { - sessionId: "session-789", - lastChannel: "whatsapp", - lastTo: "+1555", - queueMode: "collect", - queueDebounceMs: 0, - }, - }; - - await runSubagentAnnounceFlow({ - childSessionKey: "agent:main:subagent:test", - childRunId: "run-a", - requesterSessionKey: "main", - requesterOrigin: { accountId: "acct-a" }, - requesterDisplayKey: "main", - task: "do thing", - timeoutMs: 1000, - cleanup: "keep", - waitForCompletion: false, - startedAt: 10, - endedAt: 20, - outcome: { status: "ok" }, - }); - - await runSubagentAnnounceFlow({ - childSessionKey: "agent:main:subagent:test", - childRunId: "run-b", - requesterSessionKey: "main", - requesterOrigin: { accountId: "acct-b" }, - requesterDisplayKey: "main", - task: "do thing", - timeoutMs: 1000, - cleanup: "keep", - waitForCompletion: false, - startedAt: 10, - endedAt: 20, - outcome: { status: "ok" }, - }); - - await expect.poll(() => agentSpy.mock.calls.length).toBe(2); - - const accountIds = agentSpy.mock.calls.map( - (call) => (call[0] as { params?: Record }).params?.accountId, - ); - expect(accountIds).toContain("acct-a"); - expect(accountIds).toContain("acct-b"); - expect(agentSpy).toHaveBeenCalledTimes(2); - }); }); diff --git a/src/agents/subagent-announce.ts b/src/agents/subagent-announce.ts index 2bca43901..a3093c7b9 100644 --- a/src/agents/subagent-announce.ts +++ b/src/agents/subagent-announce.ts @@ -298,6 +298,7 @@ async function readLatestAssistantReplyWithRetry(params: { initialReply?: string; maxWaitMs: number; }): Promise { + const RETRY_INTERVAL_MS = 100; let reply = params.initialReply?.trim() ? params.initialReply : undefined; if (reply) { return reply; @@ -305,7 +306,7 @@ async function readLatestAssistantReplyWithRetry(params: { const deadline = Date.now() + Math.max(0, Math.min(params.maxWaitMs, 15_000)); while (Date.now() < deadline) { - await new Promise((resolve) => setTimeout(resolve, 300)); + await new Promise((resolve) => setTimeout(resolve, RETRY_INTERVAL_MS)); const latest = await readLatestAssistantReply({ sessionKey: params.sessionKey }); if (latest?.trim()) { return latest;