Skip to content

fix(test): flaky Windows-only failure in subagent-announce.format.test.ts #31298

@ktamas77

Description

@ktamas77

Summary

src/agents/subagent-announce.format.test.ts — test "waits for updated synthesized output before announcing nested subagent completion" fails intermittently on Windows CI (shard 1/2 or 2/2).

Root Cause

FAST_TEST_MODE is evaluated at module load time (line 46 of subagent-announce.ts):

const FAST_TEST_MODE = process.env.OPENCLAW_TEST_FAST === "1";

But the test sets vi.stubEnv("OPENCLAW_TEST_FAST", "1") in beforeEach (line 161), which runs after beforeAll where the module is imported (line 148). If OPENCLAW_TEST_FAST is not already set in the environment when the module loads, FAST_TEST_MODE is false for the entire test run.

With FAST_TEST_MODE = false:

  • RETRY_INTERVAL_MS = 100ms (not 8ms)
  • minReplyChangeWaitMs = 250ms (not 20ms)
  • The test passes timeoutMs: 100, so maxWaitMs = max(250, min(100, 2000)) = 250ms

The poll loop has ~250ms budget with 100ms sleeps. On Windows, setTimeout(100) routinely overshoots to 115–150ms due to the default timer resolution (~15.6ms). This gives only 1–2 iterations — not enough to reach the 3rd chatHistory mock call that returns "Final synthesized answer.".

On Linux CI, OPENCLAW_TEST_FAST=1 is typically set in the environment already, so the module-level const captures true and the test passes.

Evidence

Suggested Fix

Set OPENCLAW_TEST_FAST=1 in the environment before importing the module, so the module-level const picks it up. For example, move the env stub into beforeAll before the dynamic import:

beforeAll(async () => {
  process.env.OPENCLAW_TEST_FAST = "1";
  ({ runSubagentAnnounceFlow } = await import("./subagent-announce.js"));
  // ...
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions