mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 17:01:53 +03:00
perf(subagents): speed announce retry polling and trim duplicate e2e coverage
This commit is contained in:
@@ -292,7 +292,7 @@ describe("subagent announce formatting", () => {
|
|||||||
lastChannel: "whatsapp",
|
lastChannel: "whatsapp",
|
||||||
lastTo: "+1555",
|
lastTo: "+1555",
|
||||||
queueMode: "collect",
|
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);
|
expect(agentSpy).toHaveBeenCalledTimes(2);
|
||||||
const accountIds = agentSpy.mock.calls.map(
|
const accountIds = agentSpy.mock.calls.map(
|
||||||
(call) => (call?.[0] as { params?: { accountId?: string } })?.params?.accountId,
|
(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?.channel).toBe("bluebubbles");
|
||||||
expect(call?.params?.to).toBe("bluebubbles:chat_guid:123");
|
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<string, unknown> }).params?.accountId,
|
|
||||||
);
|
|
||||||
expect(accountIds).toContain("acct-a");
|
|
||||||
expect(accountIds).toContain("acct-b");
|
|
||||||
expect(agentSpy).toHaveBeenCalledTimes(2);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -298,6 +298,7 @@ async function readLatestAssistantReplyWithRetry(params: {
|
|||||||
initialReply?: string;
|
initialReply?: string;
|
||||||
maxWaitMs: number;
|
maxWaitMs: number;
|
||||||
}): Promise<string | undefined> {
|
}): Promise<string | undefined> {
|
||||||
|
const RETRY_INTERVAL_MS = 100;
|
||||||
let reply = params.initialReply?.trim() ? params.initialReply : undefined;
|
let reply = params.initialReply?.trim() ? params.initialReply : undefined;
|
||||||
if (reply) {
|
if (reply) {
|
||||||
return reply;
|
return reply;
|
||||||
@@ -305,7 +306,7 @@ async function readLatestAssistantReplyWithRetry(params: {
|
|||||||
|
|
||||||
const deadline = Date.now() + Math.max(0, Math.min(params.maxWaitMs, 15_000));
|
const deadline = Date.now() + Math.max(0, Math.min(params.maxWaitMs, 15_000));
|
||||||
while (Date.now() < deadline) {
|
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 });
|
const latest = await readLatestAssistantReply({ sessionKey: params.sessionKey });
|
||||||
if (latest?.trim()) {
|
if (latest?.trim()) {
|
||||||
return latest;
|
return latest;
|
||||||
|
|||||||
Reference in New Issue
Block a user