Skip to content

test(cli): waitFor's fixed 250 ms wall-clock deadline makes 373 TUI assertions flaky under CI load #2221

Closed

Description

@Astro-Han

What happened

CI failed on PR #2208, a documentation-only change whose diff touches nothing but two files under docs/eval/. The failing job was test_workspaces, in the [cli] workspace:

✖ marks an inherited running Bash card detached after rewind (262.565832ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
  false !== true
      at waitFor (packages/cli/dist/__tests__/tui-terminal-mock.js:115:12)
      at TestContext.<anonymous> (packages/cli/dist/__tests__/pi-tui-runner.test.js:4385:9)

Re-running the same job on the same commit passed with no other change. main was green at the time.

Root cause

waitFor polls a predicate against a hard-coded 250 ms wall-clock budget:

export async function waitFor(predicate: () => boolean): Promise<void> {
  const deadline = Date.now() + 250;
  while (Date.now() < deadline) {
    if (predicate()) return;
    await delay(5);
  }
  assert.equal(predicate(), true);
}

The reported test duration was 262.6 ms — the assertion fired essentially the moment the budget expired, not because the predicate was ever going to be false. The budget is a fixed wall-clock number, so it does not scale with a loaded runner, and the failure mode when it expires is an opaque false !== true rather than a description of what was being waited on.

waitFor is a shared helper with 373 call sites across pi-tui-runner.test.ts, cli-goal-continuation.test.ts, runtime-bootstrap.test.ts, and slash-command-completion.test.ts. Any of them can fail this way; this issue reports the one that happened to lose the race.

Why it matters

The failure is indistinguishable from a real regression at the point of reading CI: a docs-only PR showed a red test_workspaces, and telling the two apart required pulling the job log and re-running. That cost is paid by every PR that hits it.

Suggested direction

Not prescribing a fix, but the constraints seem to be:

  • The budget should scale with the environment rather than being a fixed 250 ms — an env-var override honoured in CI, or a multiplier, would remove the load sensitivity without slowing local runs.
  • The expiry assertion should name what it was waiting for. waitFor currently receives only a predicate, so it has nothing to report; taking a description argument would turn false !== true into an actionable message across all 373 call sites.

Repro

Not deterministically reproducible by design — it is a load-dependent race. Observed on test_workspaces in run 30986889078; the re-run of the same job on the same commit passed.

Activity

  1. Astro-Han commented on Aug 5, 2026

    @Astro-Han
    ContributorAuthor

    Same root cause, second workspace: packages/headless

    Hit this on PR #2227, a renderer-only change (7 files, all under packages/ui; zero headless files touched). The failing job was test_headless, not test_workspaces:

    ✖ does not report deadline settlement after normal completion already claimed the terminal state (3138ms)
    

    harbor-cell.test.ts:1285 passes a fixed settleAfterMs: 1_000 and then asserts result.settledByDeadline === false — i.e. it asserts that normal completion wins a race against a 1 s wall-clock budget. The run took 3138 ms, so on a loaded runner the deadline latched first and the assertion reported the opposite of what it was written to check. Re-running the same job on the same commit passed with no other change.

    This is not waitFor, so it is not fixed by whatever replaces the 250 ms budget in tui-terminal-mock.ts — but it is the same defect shape: a test encodes a fixed wall-clock number as if it were a logical ordering guarantee. Worth noting here so a fix scopes to the pattern rather than to the one helper.

    Two other data points that make the pattern worth a sweep rather than a point fix:

    Suggested scope: audit for fixed millisecond budgets that gate an assertion about ordering, and make the ordering explicit (deterministic clock, injected settle signal, or a barrier) instead of widening the number.

  2. Benjamin-eecs commented on Aug 6, 2026

    @Benjamin-eecs
    Contributor

    Taking this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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