Skip to content

test(sdk): settle health-check commands before the next exec test starts - #4881

Closed
Dominion5254 wants to merge 1 commit into
masterfrom
fix/sdk-exec-lifecycle-leak
Closed

Dominion5254 wants to merge 1 commit into
masterfrom
fix/sdk-exec-lifecycle-leak

Conversation

@Dominion5254

Copy link
Copy Markdown
Member

Fixes an intermittent failure of the deadline covers a stdin callback that never arrives in projects/start-sdk/lib/test/exec.lifecycle.test.ts. It shows up as timedOutAfter: null where 10 was expected, e.g. on #4866 (job; a rerun passed).

Cause

Since #4855, HealthDaemon.term() returns without waiting for an in-flight ready.fn. The preceding test, health checks can terminate while fast commands finish, therefore ended with its 36 sub.exec calls still waiting on readFile.

The next test's subject('hung-stdin') then pointed the cp.spawn mock at its hung child, so those leftover calls spawned that same child and attached their own 25 ms kill timers to it. Whenever a leftover timer fired before the test's own 10 ms deadline, it killed the child while the test's timedOut flag was still false. That takes a stall of more than 15 ms between the two spawns, which a busy CI runner occasionally produces.

The sharing itself happened on every run since #4855: each run prints MaxListenersExceededWarning for the shared child's emitters. Runs before #4855 print none.

Change

The health test keeps the promise for its commands and awaits it after term() has settled within its own bound. The test therefore still checks that stopping doesn't wait for the check, and it once again checks that the fast commands finish.

Two alternatives were considered and rejected:

  • Passing the check's abort signal to exec: fails every time. exec spawns before it checks the signal, so leftover calls kill the next test's child immediately.
  • Resetting the spawn mock per test: doesn't help, because leftover calls read whichever mock is current when they spawn.

Test-only. No user-visible behaviour changes, so there is no changelog fragment.

Verification

All on 2cf57f322, with 0881e5430 (its parent, current master) as the baseline:

Check Baseline 0881e5430 This PR 2cf57f322
20 ms stall injected before the deadline test's exec (temporary branches) 5/5 fail with the CI signature 0/5 fail
MaxListenersExceededWarning across 30 runs of the file 30/30 runs 0/30 runs
30 runs pinned to one core with 3 busy loops 4/30 fail with the CI signature 0/30 fail
30 runs, idle 0/30 fail 0/30 fail

Where the leak started: bf3c13a23^ warns in 0 of 10 runs, bf3c13a23 (#4855) in 10 of 10.

make start-sdk-test on 2cf57f322 passes: 418/418 jest tests in 32 suites, 542/542 start-core tests, and the Node script tests, with no listener warnings. Prettier is clean.

Since #4855, HealthDaemon.term() returns without awaiting an in-flight
ready.fn. "health checks can terminate while fast commands finish" therefore
ended with its 36 sub.exec calls still waiting on readFile. They spawned
after the next test pointed the cp.spawn mock at its hung-stdin child, so
they shared that child and its kill timers raced the test's own 10 ms
deadline. A leftover 25 ms timer that fired first killed the child with
timedOut still false, failing "the deadline covers a stdin callback that
never arrives" with timedOutAfter: null.

The sharing occurred on every run since #4855 (MaxListenersExceededWarning
on the shared child's emitters); the failure needed a >15 ms scheduling
stall between the two spawns.

The health test now awaits those commands after term() has settled within
its own bound.

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at 2cf57f322. The PR merges cleanly with master; no correctness findings.

After health termination stopped waiting for in-flight checks, this fixture's commands could spawn under the next test's mock. Retaining their promise before signaling entry, then awaiting it after the separately bounded termination, drains the batch without changing the termination contract. Both waits reuse the existing 250 ms helper. Production behavior is unchanged.

Implementation diff: +0 / −0 lines in 0 files (excludes lockfiles, tests, docs, release notes, and changelog).

Verification: CI passed all 418 SDK tests, including this lifecycle file, and 542 TypeScript start-core tests. Prettier and Formatting & Lockfiles passed. The author's recorded injected-stall and loaded-run comparisons distinguish the fix from baseline. I did not run builds or tests during review.

Still pending: Build (aarch64/riscv64/x86_64), start-core Tests & Man Pages, StartWRT Tests, rpc-toolkit, visit-rs & backup-fs Tests, and Generated Bindings & MCP Catalog.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@helix-red

Copy link
Copy Markdown
Contributor

This fix is now on master. It was cherry-picked unchanged (git cherry-pick -x of 2cf57f322) into integration/registry-cache-sync via #4905 to unblock that branch's CI, and landed with #4898 (446ce7664). When master merged into the integration branch (#4926), the test also picked up #4856's per-subject spawn helper. With that helper, leftover health-check commands already reach their own test's child. This PR has nothing left to add and can be closed.

@dr-bonez dr-bonez closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants