Skip to content

flaky(runtime-host): owned Host lifecycle tests intermittently fail to observe process exit #4776

Closed

Description

@sunrioa

Summary

Two owned Runtime Host lifecycle tests fail intermittently on a clean current main checkout, including during focused repetitions. Both tests assert that an owned process exits after its controlling lifetime ends.

The failures are nondeterministic: the same exact revision can pass, then fail on a later run without any source or environment change.

Environment

  • Commit: 4ed6255f2998eff93414491cb14305f3bca0884b (main)
  • OS: macOS 26.5.2, arm64
  • Node.js: v24.19.0
  • npm: 11.17.0
  • Fresh detached worktree with a clean Git status
  • npm ci: passed
  • npm run build --workspace @maka/runtime-host: passed

Reproduction

Run the complete Runtime Host suite repeatedly:

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

Then repeat the affected tests directly:

node --test \
  --test-name-pattern="an authority-supervised Candidate exits" \
  packages/runtime-host/dist/__tests__/host-kernel.test.js

node --test \
  --test-name-pattern="owned Host exits promptly after its first connection closes" \
  packages/runtime-host/dist/__tests__/owned-candidate.test.js

A serial full-suite control was also run with:

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

Results

Test mode Result
Default-concurrency complete Runtime Host suite 2 passed / 3 failed across 5 runs
Focused authority-supervised Candidate exit test 8 passed / 2 failed across 10 runs
Focused owned Host first-disconnect exit test 9 passed / 1 failed across 10 runs
Serial complete Runtime Host suite 3 passed / 0 failed across 3 runs

The complete suite contains 1,687 tests: a green run reports 1,675 passed, 12 skipped, and 0 failed.

The default-concurrency failures moved between runs:

  • Runs 2–4 failed an authority-supervised Candidate exits if its launch owner is killed.
  • Runs 3–4 also failed owned Host exits promptly after its first connection closes.

The focused Candidate failure reports:

Error: process <pid> did not exit

The focused owned Host failure reaches its exit assertion with:

AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
false !== true

No process launched from the test worktree remained after the runs completed.

Impact

Unrelated pull requests can receive a blocking red Runtime Host result without modifying Runtime Host code. Because focused repetitions can also fail, this is not solely a full-suite concurrency artifact, although concurrent suite load appears to increase its frequency.

Related work

The current reproduction also covers the authority-supervised Candidate owner-death boundary, for which no matching Issue or PR was found.

Suggested investigation

  • Determine whether the owned processes actually remain alive or whether the tests observe lifecycle state before settlement.
  • Replace wall-clock timing assumptions with explicit lifecycle synchronization where practical.
  • Preserve the existing ownership and process-exit assertions; avoid resolving the flake only through retries or weaker assertions.
  • Verify any fix with repeated focused, default-concurrency, and serial suite runs.

Expected outcome

The affected tests deterministically observe the required process exit, and complete Runtime Host runs no longer fail because of scheduler-dependent lifecycle settlement.

AI assistance: OpenAI Codex assisted with reproduction, test triage, duplicate searching, and drafting this issue. The evidence and issue text were reviewed by me.

Activity

  1. UncertaintyDeterminesYou4ndMe commented on Sep 4, 2026

    @UncertaintyDeterminesYou4ndMe
    Contributor

    I looked into this and closed my PR (#4784) to keep review load down while the project is slimming. Leaving the findings here so they are not lost.

    • The launch-owner test gates its exit budget on connected.connection.closed, which is the Client's own transport: the Client aborts it after a 2 s unanswered liveness probe, so it resolves while a busy Host is still running. The owner-loss close is also only armed after composition startup and recovery settle (launchOwnerGuard.bind runs after startExecutionRuntimeHostCandidate resolves), and retryConnect connects while the Host is still recovering, so the SIGKILL lands mid-startup.
    • The owned-exit test bounds the whole shutdown at 5 s while the kernel allows itself shutdownGraceMs (10 s); settle then SIGKILLs and reports an unclean exit.
    • Neither test failed here in 42 focused and 19 full-suite runs; stalling the Host's main thread during startup and stalling composition close reproduce both reported errors exactly. Details and the proposed test-side fix are in test(runtime-host): assert owned Host exit against the kernel's shutdown contract #4784.
    • The test that does flake on this machine is a different one, filed as flaky(runtime-host): WorkHub delegation races the automatic Session title through the candidate-set identity #4785.
  2. ggbdpq commented on Sep 4, 2026

    @ggbdpq
    Contributor

    take

  3. sunrioa commented on Sep 7, 2026

    @sunrioa
    ContributorAuthor

    Additional evidence that may be useful for #4814:

    While investigating the failures encountered during validation of #4994, I reproduced the authority-supervised Candidate exit failure on main at f4abd4918 (macOS, Node 24.19.0, Undici 8.10.1), with lifecycle and socket instrumentation.

    In this occurrence, composition recovery and shutdown had already completed. host.closed resolved, but the process remained alive for more than five seconds with an active TLS connection to models.dev, initiated by the startup model-metadata refresh. The process was in state S, not a zombie, when the test timed out and killed it.

    The observed path is:

    • Shutdown aborts the metadata fetch and awaits transport.close().
    • The underlying Undici dispatcher destruction completes while the TLS handshake is still pending.
    • The pending socket remains alive after host.closed, keeping the Node process running.

    I also reproduced the transport behavior without external networking: a local TCP server accepts a connection but never completes the TLS handshake. After aborting the fetch, transport.close() resolved at approximately 112 ms, while the client TLSSocket was still not destroyed at 5,614 ms.

    The other two lifecycle tests also showed a similar post-close TLS wait, but passed in this instrumented run. I therefore cannot attribute every historical failure to this path.

    This appears distinct from the startup synchronization and shutdown-budget issues addressed by #4814. I have not tested its latest head, so this is not a claim that the PR still fails. It may be worth tracking the pending-connection cleanup separately: a longer process-exit budget can accommodate this delay without verifying that transport shutdown actually releases the socket.

  4. sunrioa commented on Sep 8, 2026

    @sunrioa
    ContributorAuthor

    Additional validation: #4814 and main

    I completed local validation of #4814 at a0c4dbaa on macOS arm64 with Node.js 24.19.0. The results below also include earlier and recent control runs on unmodified main.

    Both tests directly changed by #4814 passed

    Each of the following tests passed all 10 focused repetitions. Both also passed in two complete Runtime Host runs:

    • an authority-supervised Candidate exits if its launch owner is killed
    • owned Host exits promptly after its first connection closes

    Problems observed on both #4814 and main

    Test or observation #4814 result Main result
    an invocation-owned detached Host retires after launcher natural exit Failed in both complete Host runs with process ... did not exit. f4abd4918: failed in 1 of 5 focused rounds.
    an exited owned Candidate permits one real successor in the same election Failed in the first complete Host run and passed in the second. The failure was at the second Candidate's settle(5000) assertion. e60e85d77: failed in 3 of 5 focused rounds.
    A pending TLS socket remains alive after transport.close() returns. Reproduced with the local minimal experiment. Previously verified in an instrumented main run and a local minimal experiment; see the diagnostic comment.
    archived-only history boots into a usable new task Failed in the complete E2E run, then failed in all three focused repetitions. 5a1514c1d: all three focused repetitions failed with the same error.

    These problems occur on both #4814 and main, but I have not established whether they share a root cause.

    Failure observed on #4814 without a main failure control

    an invocation-owned detached Host retires after launcher crash

    This failed in the complete two-file run and both complete Host runs on #4814, with process ... did not exit. I do not yet have a corresponding main failure control, so whether it also fails on main remains unverified.

    Failure observed on main, but not in this #4814 validation

    a launcher-owned detached Host exits when its launcher is killed

    This previously failed in 2 of 5 focused rounds on main e60e85d77. It did not fail in this #4814 validation.

    TLS experiment details

    I reran the local transport experiment using the current #4814 build: a loopback TCP server accepts a connection but does not complete the TLS handshake; the experiment then aborts the fetch and awaits transport.close().

    • At approximately 118 ms, transport.close() returned while the client's TLSSocket.destroyed was still false.
    • At approximately 5.6 seconds, that socket was still not destroyed.
    • The diagnostic then explicitly cleaned up its own experimental connection.

    The experiment requires no external network access. It checks whether the client socket has closed, rather than whether the entire diagnostic process has exited.

    In short, the close function returned before the connection actually closed. This run only confirmed that the socket was still alive at approximately 5.6 seconds. It did not establish whether the socket would outlive #4814's new waiting deadlines, or whether this issue causes all the other Host exit failures.

    Archive E2E failure

    The archive-startup test failed at apps/desktop/e2e/new-task-reload.spec.ts:34 while calling sessions:archive:

    RuntimeHostOperationError: Session <id> has a live derived effect
    

    The complete Electron E2E run on #4814 reported 36 passed and 1 failed. All three subsequent focused repetitions of this test failed with the same error.

    I then installed dependencies and rebuilt in a fresh, unmodified main checkout at 5a1514c1d. The target test file was identical to the version on #4814. With one worker, three repetitions, and zero retries, all three runs failed with the same error. The checkout remained clean afterward.

    This appears different from the issue recorded in #4785: here, the archive request is rejected because the Session still has a live derived effect; #4785 describes a race between WorkHub delegation and automatic Session titles. The test corresponding to #4785 passed in both complete Host runs in this validation, so this archive failure may need separate tracking.

    Complete run results

    Validation Result
    The two exit tests directly changed by #4814, 10 repetitions each 20 passed, 0 failed
    Complete host-kernel and owned-candidate files 90 passed, 1 failed
    First complete Runtime Host suite 1,793 passed, 12 skipped, 3 failed
    Second complete Runtime Host suite 1,794 passed, 12 skipped, 2 failed
    Complete Electron E2E suite 36 passed, 1 failed

    Build, lint, formatting, typechecking, all 562 script tests, browser semantic smoke, alignment checks, Storybook rendering, CLI packaging and offline installation smoke, and the production dependency audit all passed.

    These are local observations from the same Mac, not independent cross-machine reproductions.

    AI assistance: OpenAI Codex assisted with executing the validation, organizing the evidence, and drafting this comment. I reviewed the content.

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

Metadata

Metadata

Assignees

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