fix(ci): resolve three intermittent test flakes across runtime-host, runtime, and cli - #1776
Merged
Conversation
…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.
This was referenced Aug 6, 2026
Open
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The CI
testjob flaked intermittently on three unrelated suites. Each root cause was captured from the failed job logs:runtime-host steering (
execution-host.test.js) — submit fails withMessage 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 spurioussession_busy. Regression test simulates the race by pulling/acking the queued steering from inside a delayed preflight.runtime shell-run-manager —
preserves cancellation when timeout fires during POSIX process discoveryexpectedcancelledbut gottimed_out.armTimeoutpinslifecycleCausetotimeoutimmediately; a later cancellation was ignored becauserequestTerminationreturned the existing termination. A cancel that arrives before the kill is applied now upgrades the cause tocancel.cli pi-tui-runner —
forces signal exit/reports and forces fatal exit when outer cleanup never settlesexpected graceful exit (143/1) but gotSIGKILL. The probe's 5s kill timer started at spawn, while the process exit grace (PROCESS_EXIT_GRACE_MS=3000) starts afterREADY; slow CI startup ate the budget. The kill timer now resets when the probe reports READY.ci-test-plan —
runtime-bootstrap.test.ts(packages/cli) executes real sandboxed shell tools, but the bubblewrap + user-namespace install only ran whenpackages/runtimechanged; 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-coordinator26/26 incl. new regression test — confirmed it fails when retry is disabled, passes with the fix.shell-run-manager51/51,pi-tui-runner205/205,ci-test-plan4/4.packages/runtimesuite 2839 pass / 0 fail;runtime-host445/446 (one pre-existing concurrent UDS timeout, passes alone).npm run format:checkandnpm run lintclean.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.