Skip to content

flaky(runtime-host): lifecycle tests intermittently fail process-exit and settlement checks #5009

Closed

Description

@sunrioa

Summary

Four Runtime Host lifecycle tests fail intermittently on a clean main checkout, including during serial focused repetitions.

The failures concern Host process exit after launcher termination, clean settlement of a successor Candidate, and process exit after managed activation reaches true idle.

The same revision can pass a focused run and fail a later run without source changes.

Environment

  • Commit: 8b3655a1710a4c52b09759249d8c2dbb57284a7a (main at the start of testing)
  • OS: macOS 26.5.2, arm64
  • Node.js: v24.19.0
  • Installation and build: npm 11.19.0
  • Test commands were launched through the local npm 11.17.0 or directly through Node, as shown below
  • Fresh detached worktree; Git status remained clean after testing
  • A Node preload redirected os.userInfo().homedir to a disposable account directory
  • Normal local network conditions
  • npm ci: passed
  • Complete npm run build: passed

Reproduction

After installation and build, run the complete Runtime Host suite:

npm --workspace @maka/runtime-host run test:dist

Repeat the lifecycle tests serially, from the repository root:

node --test \
  --test-concurrency=1 \
  --test-name-pattern='^(?:owned Host exits promptly after its first connection closes|an authority-supervised Candidate exits if its launch owner is killed|an invocation-owned detached Host retires after launcher natural exit|an invocation-owned detached Host retires after launcher crash|a launcher-owned detached Host exits when its launcher is killed|an exited owned Candidate permits one real successor in the same election)$' \
  packages/runtime-host/dist/__tests__/host-kernel.test.js \
  packages/runtime-host/dist/__tests__/owned-candidate.test.js

The six-test selection above was repeated five times, with no skipped tests. In the recorded runs, the working directory was packages/runtime-host, with the equivalent dist/__tests__/... file arguments.

After observing a managed-activation failure in the complete suite, repeat that test separately:

node --test \
  --test-concurrency=1 \
  --test-name-pattern='^two real managed activations converge on one Host and exit at true idle$' \
  packages/runtime-host/dist/__tests__/managed-activation.test.js

This single-test selection was also repeated five times.

Account-isolation preload used for the recorded runs

The following preload was passed through NODE_OPTIONS=--import=/absolute/path/to/isolate.mjs. The disposable account directory was created before testing. HOME was not changed. Replace the example path below with an existing disposable directory when reproducing.

import os from 'node:os';
import { syncBuiltinESMExports } from 'node:module';
const userInfo = os.userInfo;
os.userInfo = (...args) => ({
  ...userInfo(...args),
  homedir: '/absolute/path/to/disposable-account',
});
syncBuiltinESMExports();

Results

Test Focused results
a launcher-owned detached Host exits when its launcher is killed 4 passed / 1 failed
an invocation-owned detached Host retires after launcher crash 4 passed / 1 failed
an exited owned Candidate permits one real successor in the same election 3 passed / 2 failed
two real managed activations converge on one Host and exit at true idle 4 passed / 1 failed

The other three tests in the six-test selection passed all five rounds.

For the six-test selection, rounds 1, 4, and 5 passed completely. Round 2 failed the invocation-crash and successor-settlement cases. Round 3 failed the launcher-killed and successor-settlement cases. In the separate managed-activation repetitions, round 4 failed and the other four rounds passed.

The complete Runtime Host suite reported 1,808 passed, 1 failed, and 12 skipped. Its failure was the managed-activation test, which subsequently also failed in a focused run.

Launcher-related failures

The client connection had already closed, but waitForProcessExit still observed the Host PID after its five-second timeout:

Error: process <pid> did not exit

Successor settlement failure

The connection and two-launch assertions passed. The following assertion then failed because settlement returned false:

assert.equal(await attempts[1]?.settle(5_000), true);
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
false !== true

Managed-activation failure

The local and remote client connections had closed. The test then failed while waiting for the Host process to exit:

await waitUntil(() => !processExists(first.pid), 5_000);
Error: condition did not become true

The same assertion failed in both the complete suite and the focused repetition. Both stacks point to dist/__tests__/managed-activation.test.js:145 through waitUntil.

Impact

These intermittent failures reduce the reliability of Runtime Host regression checks.

Because focused serial repetitions also fail, the observations are not limited to full-suite concurrent execution.

The results do not establish permanent process leaks or a shared root cause across all four tests.

Suggested investigation

  • Distinguish client connection closure, Host shutdown completion, and actual process exit.
  • Determine what remains active when the process-exit budget expires.
  • Identify why successor settlement returns false.
  • Check whether the tests need explicit lifecycle synchronization.
  • Preserve the ownership and process-exit assertions, and verify changes through repeated runs rather than relying only on retries or longer timeouts.

Expected outcome

The tests reliably observe the required process exit and clean settlement, without intermittent lifecycle-timing failures.

Activity

  1. sunrioa commented on Sep 8, 2026

    @sunrioa
    ContributorAuthor

    take

  2. added
    bug
    on Sep 17, 2026
  3. sunrioa commented on Sep 24, 2026

    @sunrioa
    ContributorAuthor

    Still reproduces on current main. Measured against the commit this issue reports, on one machine in one sitting, so the two sides are comparable.

    Both sides ran the six-test focused selection from the issue body, six serial rounds each, on Node v24.19.0, with three busy loops occupying cores to compress the timing.

    Revision Rounds with a failure Failed executions
    8b3655a17 (the commit above) 4 of 6 4 of 36
    17fa03647 (current main) 3 of 6 4 of 36

    Which tests failed, by round:

    • 8b3655a17 — successor settlement; launcher-killed; invocation-crash; launcher-killed
    • 17fa03647 — invocation-natural-exit; invocation-natural-exit and invocation-crash together; successor settlement

    The signatures are the two this issue already records, in the same proportion on each side: Error: process <pid> did not exit three times, and the settle(5_000) assertion once.

    It does not reproduce on Linux. On GitHub-hosted ubuntu-24.04 runners, each of the five tests named here ran 56 times as part of the full @maka/runtime-host suite without failing once — 32 executions on an otherwise idle runner, 15 under CPU contention on two of four cores, and 9 directly after the workspace test batch ci.yml schedules immediately before this suite. That is consistent with CI staying green while the failure is routine on macOS, and it narrows where to look.

    Environment for the macOS side: macOS 26.5.2, arm64, 10 cores, Node v24.19.0, npm 11.17.0, a fresh detached worktree per revision, and the account-isolation preload from the issue body.

  4. sunrioa commented on Sep 24, 2026

    @sunrioa
    ContributorAuthor

    Correction to my earlier comment: the macOS framing there points the wrong way. The variable is how long the startup models.dev fetch stays in its TLS handshake relative to the Host's lifetime in the test, not the platform — models.dev answers a hosted runner in about a hundred milliseconds and this machine in 1.49 s. #5043 fixes it, and a stalled-server control there takes all four tests named above from 12 of 12 failing to 12 of 12 passing.

  5. added a commit that references this issue on Sep 27, 2026
    9f4e026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions