Skip to content

fix(ci): resolve three intermittent test flakes across runtime-host, runtime, and cli - #1776

Merged
Astro-Han merged 2 commits into
mainfrom
fix/ci-flaky-tests
Aug 1, 2026
Merged

fix(ci): resolve three intermittent test flakes across runtime-host, runtime, and cli#1776
Astro-Han merged 2 commits into
mainfrom
fix/ci-flaky-tests

Conversation

@Astro-Han

Copy link
Copy Markdown
Contributor

Summary

The CI test job flaked intermittently on three unrelated suites. Each root cause was captured from the failed job logs:

  1. runtime-host steering (execution-host.test.js) — submit fails with Message queue changed during admission (session_busy). A running Turn consumes steering out of the queue outside the admission lock (#pull/#ack/#nack), so a submit's preflight snapshot can go stale while it awaits and the final admission check fails. Submit now re-runs admission (up to 4 times) when the queue changed, instead of surfacing a spurious session_busy. Regression test simulates the race by pulling/acking the queued steering from inside a delayed preflight.

  2. runtime shell-run-managerpreserves cancellation when timeout fires during POSIX process discovery expected cancelled but got timed_out. armTimeout pins lifecycleCause to timeout immediately; a later cancellation was ignored because requestTermination returned the existing termination. A cancel that arrives before the kill is applied now upgrades the cause to cancel.

  3. cli pi-tui-runnerforces signal exit / reports and forces fatal exit when outer cleanup never settles expected graceful exit (143/1) but got SIGKILL. The probe's 5s kill timer started at spawn, while the process exit grace (PROCESS_EXIT_GRACE_MS=3000) starts after READY; slow CI startup ate the budget. The kill timer now resets when the probe reports READY.

  4. ci-test-planruntime-bootstrap.test.ts (packages/cli) executes real sandboxed shell tools, but the bubblewrap + user-namespace install only ran when packages/runtime changed; editing the cli workspace ran it without a sandbox → sandbox required but unavailable. The plan now also flags the sandbox when that test file changes.

Verification

  • message-coordinator 26/26 incl. new regression test — confirmed it fails when retry is disabled, passes with the fix.
  • shell-run-manager 51/51, pi-tui-runner 205/205, ci-test-plan 4/4.
  • packages/runtime suite 2839 pass / 0 fail; runtime-host 445/446 (one pre-existing concurrent UDS timeout, passes alone).
  • npm run format:check and npm run lint clean.

The original flakes are CI-scheduling dependent and could not be reproduced locally (same as the previous steering fix); the fixes follow the captured error chains, and the regression test pins the runtime-host race deterministically.

…runtime, and cli

Three flaky suites kept the CI test job red intermittently:

1. runtime-host steering (execution-host.test.js) — 'Message queue changed
   during admission' session_busy. A running Turn consumes steering out of the
   queue outside the admission lock (#pull/#ack/#nack), so a submit's preflight
   snapshot can go stale while it awaits and the final admission check fails.
   Submit now re-runs admission (up to 4 times) when the queue changed instead
   of surfacing a spurious session_busy. Regression test simulates the race by
   pulling/acking the queued steering from inside a delayed preflight.

2. runtime shell-run-manager — 'preserves cancellation when timeout fires
   during POSIX process discovery' expected cancelled but got timed_out.
   armTimeout pins lifecycleCause to 'timeout' immediately; a later
   cancellation was ignored because requestTermination returned the existing
   termination. A cancel that arrives before the kill is applied now upgrades
   the cause to 'cancel'.

3. cli pi-tui-runner — 'forces signal exit / reports and forces fatal exit
   when outer cleanup never settles' expected graceful exit (143/1) but got
   SIGKILL. The 5s kill timer started at spawn, while the process exit grace
   (PROCESS_EXIT_GRACE_MS=3000) starts after READY; slow CI startup ate the
   budget. The kill timer now resets when the probe reports READY.

4. ci-test-plan — runtime-bootstrap.test.ts (packages/cli) executes real
   sandboxed shell tools but only triggered the bubblewrap install when
   packages/runtime changed; editing the cli workspace ran it without a
   sandbox and it failed with 'sandbox required but unavailable'. The plan
   now also flags the sandbox when that test file changes.

Verification: message-coordinator 26/26 incl. new regression test (fails with
retry disabled), shell-run-manager 51/51, pi-tui-runner 205/205, ci-test-plan
4/4; runtime suite 2839 pass / 0 fail; runtime-host 445/446 (one pre-existing
concurrent UDS timeout, passes alone).
The Host stderr diagnostic added in #1760 (full nested AggregateError chain
via util.inspect depth: null) is flagged by the check-console audit; it is
error-metadata only and was the tool that made the steering flake
diagnosable. Allow the file with a one-line reason.
@Astro-Han
Astro-Han merged commit 3a12eed into main Aug 1, 2026
12 checks passed
Astro-Han pushed a commit that referenced this pull request Aug 12, 2026
…) (#2611)

The `keeps the first committed lifecycle cause across Stop and timeout
races` test intermittently reported `timed_out` where `cancelled` was
expected (CI run 31258873738). Root cause is not a broken contract — it
is the test betting on wall-clock for commit ordering.

In PTY mode, `stopBackgroundTask` runs `beginStopTermination` inside
`collector.mutateAtCut()`, which serializes against the PTY flush. Under
CI load, Stop can be delayed past the `timeoutMs` boundary; once the
timeout has fired and set `live.termination` (or killed the process),
`stopBackgroundTask` returns at its first guard without re-arbitrating
(`if (live.driverExit)` / `if (live.termination)`), so the run is
reported `timed_out`. Note the PR #1776 cancel-override at
`requestTermination` is not reachable from `stopBackgroundTask` — Stop
never calls `requestTermination`; it either starts its own termination
or joins an existing one. That override only serves the run abort and
session/runtime shutdown paths.

Fix: add a `scheduleTimeout` seam (twin of the existing `scheduleFlush`)
so tests can drive timeout timing deterministically. No arbitration
logic changes; production behavior is unchanged (defaults to real
`setTimeout`).

The flaky two-scenario test is rewritten into three deterministic
scenarios, each pinning one arrival ordering and covering a distinct
`stopBackgroundTask` branch:
  1. Stop commits first            -> cancelled  (applied: true)
  2. timeout kills, then Stop      -> timed_out  (driverExit branch)
  3. timeout commits, process live -> timed_out  (termination branch)

All original assertions (status and operation) are kept verbatim.

Verification:
  - format:check / lint / typecheck / build: clean
  - shell-run-manager.test.js: 58/58 pass
  - rewritten scenarios looped 200x locally: 0 failures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant