perf(test): shrink subagent announce fast-mode settle waits

This commit is contained in:
Peter Steinberger
2026-02-22 09:27:44 +00:00
parent 267d2193bf
commit 35d5bd4e07
2 changed files with 14 additions and 33 deletions

View File

@@ -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);

View File

@@ -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)),
});
}