From 35d5bd4e07489f33f62374d43607fd76a0812ad7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 22 Feb 2026 09:27:44 +0000 Subject: [PATCH] perf(test): shrink subagent announce fast-mode settle waits --- .../subagent-announce.format.e2e.test.ts | 35 +++---------------- src/agents/subagent-announce.ts | 12 +++++-- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/agents/subagent-announce.format.e2e.test.ts b/src/agents/subagent-announce.format.e2e.test.ts index 446000274..e93c97389 100644 --- a/src/agents/subagent-announce.format.e2e.test.ts +++ b/src/agents/subagent-announce.format.e2e.test.ts @@ -929,26 +929,16 @@ describe("subagent announce formatting", () => { childRunId: "run-1", requesterSessionKey: "main", requesterDisplayKey: "main", + ...defaultOutcomeAnnounce, task: "first task", - timeoutMs: 1000, - cleanup: "keep", - waitForCompletion: false, - startedAt: 10, - endedAt: 20, - outcome: { status: "ok" }, }); await runSubagentAnnounceFlow({ childSessionKey: "agent:main:subagent:worker", childRunId: "run-2", requesterSessionKey: "main", requesterDisplayKey: "main", + ...defaultOutcomeAnnounce, task: "second task", - timeoutMs: 1000, - cleanup: "keep", - waitForCompletion: false, - startedAt: 10, - endedAt: 20, - outcome: { status: "ok" }, }); } finally { nowSpy.mockRestore(); @@ -1482,13 +1472,8 @@ describe("subagent announce formatting", () => { childRunId: "run-leaf-missing-fallback", requesterSessionKey: "agent:main:subagent:orchestrator", requesterDisplayKey: "agent:main:subagent:orchestrator", - task: "do thing", - timeoutMs: 1000, + ...defaultOutcomeAnnounce, cleanup: "delete", - waitForCompletion: false, - startedAt: 10, - endedAt: 20, - outcome: { status: "ok" }, }); expect(didAnnounce).toBe(false); @@ -1529,13 +1514,8 @@ describe("subagent announce formatting", () => { childRunId: testCase.childRunId, requesterSessionKey: "agent:main:main", requesterDisplayKey: "main", + ...defaultOutcomeAnnounce, task: testCase.task, - timeoutMs: 1000, - cleanup: "keep", - waitForCompletion: false, - startedAt: 10, - endedAt: 20, - outcome: { status: "ok" }, ...(testCase.expectsCompletionMessage ? { expectsCompletionMessage: true } : {}), }); @@ -1657,13 +1637,8 @@ describe("subagent announce formatting", () => { childRunId: testCase.childRunId, requesterSessionKey: testCase.requesterSessionKey, requesterDisplayKey: testCase.requesterDisplayKey, + ...defaultOutcomeAnnounce, task: "QA task", - timeoutMs: 1000, - cleanup: "keep", - waitForCompletion: false, - startedAt: 10, - endedAt: 20, - outcome: { status: "ok" }, }); expect(didAnnounce, testCase.name).toBe(true); diff --git a/src/agents/subagent-announce.ts b/src/agents/subagent-announce.ts index f38a79cf9..54729fc9e 100644 --- a/src/agents/subagent-announce.ts +++ b/src/agents/subagent-announce.ts @@ -38,6 +38,8 @@ import type { SpawnSubagentMode } from "./subagent-spawn.js"; import { readLatestAssistantReply } from "./tools/agent-step.js"; import { sanitizeTextContent, extractAssistantText } from "./tools/sessions-helpers.js"; +const FAST_TEST_MODE = process.env.OPENCLAW_TEST_FAST === "1"; + type ToolResultMessage = { role?: unknown; content?: unknown; @@ -294,7 +296,8 @@ async function buildCompactAnnounceStatsLine(params: { const agentId = resolveAgentIdFromSessionKey(params.sessionKey); const storePath = resolveStorePath(cfg.session?.store, { agentId }); let entry = loadSessionStore(storePath)[params.sessionKey]; - for (let attempt = 0; attempt < 3; attempt += 1) { + const tokenWaitAttempts = FAST_TEST_MODE ? 1 : 3; + for (let attempt = 0; attempt < tokenWaitAttempts; attempt += 1) { const hasTokenData = typeof entry?.inputTokens === "number" || typeof entry?.outputTokens === "number" || @@ -302,7 +305,9 @@ async function buildCompactAnnounceStatsLine(params: { if (hasTokenData) { break; } - await new Promise((resolve) => setTimeout(resolve, 150)); + if (!FAST_TEST_MODE) { + await new Promise((resolve) => setTimeout(resolve, 150)); + } entry = loadSessionStore(storePath)[params.sessionKey]; } @@ -1037,10 +1042,11 @@ export async function runSubagentAnnounceFlow(params: { } if (requesterDepth >= 1 && reply?.trim()) { + const minReplyChangeWaitMs = FAST_TEST_MODE ? 120 : 250; reply = await waitForSubagentOutputChange({ sessionKey: params.childSessionKey, baselineReply: reply, - maxWaitMs: Math.max(250, Math.min(params.timeoutMs, 2_000)), + maxWaitMs: Math.max(minReplyChangeWaitMs, Math.min(params.timeoutMs, 2_000)), }); }