Skip to content

Node 22: plugin tests report cancelled results and exit 1 when awaited work depends on unref'd timers #3436

Done

Description

@Birfy

On Node 22, test/features.test.js in runtime/flybot-workspace-web can end with tests cancelled and exit code 1 while fail is 0. The smallest reliable reproduction is a single awaited test: runtime() resolves once the DS-Bot wrapper attaches, and times out otherwise (test/features.test.js:156) reports cancelledByParent on Node 22 and passes on Node 24, on both the unpatched parent content and the head this was found on.

This is test-harness behaviour, not a product defect: no plugin code is involved beyond the modules the tests import.

Environment

  • repo state: PR Isolate the plugin test suite from host secrets #3435 head 8f70ad5932b837a7402a453f69a36584073c9fdd, tree 93a2fb2da2c93adfe58df4ae7f6165519c15d590, parent 1a981717 (main at the time of writing). The targeted reproduction below is identical on the unpatched parent content (tree b43a727d) on both hosts, so the PR under test is not the trigger.
  • node v22.23.5 (aarch64) versus node v24.22.3 (aarch64), two separate hosts, both aarch64.
  • TMPDIR on real disk; /tmp on this host is a 64 MB tmpfs and fills up.

Reproduction (Node 22 only)

From runtime/flybot-workspace-web:

node --test --test-name-pattern='runtime\(\) resolves' test/features.test.js

Node 22 (v22.23.5):

not ok 1 - runtime() resolves once the DS-Bot wrapper attaches, and times out otherwise
  location: 'test/features.test.js:156:1'
  failureType: 'cancelledByParent'
  code: 'ERR_TEST_FAILURE'
  error: 'Promise resolution is still pending but the event loop has already resolved'
# tests 1
# pass 0
# fail 0
# cancelled 1

Exit code 1. Node 24 on the same command: 1 test / 1 pass / 0 cancelled, exit 0. The sibling test is collateral, not a second hang — run it alone (--test-name-pattern='dispatch passes payload') and it passes on Node 22.

Counts

  • whole directory, node --test --test-concurrency=2 test/*.test.js: Node 22 # tests 497 # pass 493 # fail 0 # cancelled 4, exit 1; Node 24 497 / 497 pass / 0 fail / 0 cancelled, exit 0.
  • node --test test/features.test.js: Node 22 # tests 6 # pass 4 # fail 0 # cancelled 2, exit 1, cancelled TAP 5 and 6 (eight runs on one host, seven on the other, always the same two); Node 24 6 / 6 pass, exit 0.

In the whole-directory Node 22 run the four cancelled tests are:

TAP location name
176 test/features.test.js:156 runtime() resolves once the DS-Bot wrapper attaches, and times out otherwise
177 test/features.test.js:168 dispatch passes payload and call context, maps thrown codes
233 test/memory-extras.test.js:356 automatic group capture has its own cursor and can be paused during extraction
234 test/memory-extras.test.js:412 cross-workspace recall searches approved pages and actions using live membership

TAP 177 reports duration_ms: 0, i.e. that test never ran. Every cancelled entry carries failureType: 'cancelledByParent', code: 'ERR_TEST_FAILURE', error: 'Promise resolution is still pending but the event loop has already resolved', stack process.emit (node:events:519:28).

A cancelled test takes the rest of its file with it, so the set reported for a whole file is a consequence of where the cascade started, not a list of independent hangs. An earlier full-file run in a directory that no longer exists reported TAP 3–6 (including the synchronous duplicate and malformed endpoints are refused, which cannot hang on its own); that variant has not reproduced since, which is why the targeted command above is the one to use.

Cause (short)

Both unref calls are correct in production — a server always has a listening socket, and neither a pending wrapper nor a scheduled memory scan should keep the process alive. What breaks is the test-side assumption that those timers still fire while the test's event loop has nothing ref'd left.

  1. runtime() rejection timer, src/host.js:26-34: test/features.test.js:155 does detachRuntime() then await assert.rejects(runtime({ timeoutMs: 20 }), /not attached/). The timer that would reject after 20 ms is unrefed at src/host.js:28, so the loop may drain before it fires and the promise never settles.
  2. Memory capture scan schedule, features/memory/capture.js:198: the same shape. The two cancelled memory-extras tests await extracting, which resolves only after that scan runs, and race it against delay(6000, null, {ref: false}) — also unref'd, so nothing holds the loop.

Fix direction

Test-side keep-alive around each await, production timers unchanged; the alternative is to state which Node version this directory supports so that cancelled > 0, fail 0 is not mistaken for failed assertions. The keep-alives are the smaller change and leave production timers alone.

Why it matters

npm test in this directory exits 1 on a Node 22 runner in a run that reports fail 0, so the exit code stops being a signal of assertion failures. Today that is latent: of the 11 workflows at 1a981717, exactly one references runtime/flybot-workspace-web — flybot-runtime-image.yml, which runs npm test there on Node 24 only (:24 node-version, :32-33 working directory and npm test). No job runs this suite on Node 22, so these cancellations do not affect any current CI conclusion; they will as soon as Node 22 coverage is added.

Expected

The four tests named above pass on Node 22 instead of being cancelled, and cancelled > 0 stops being produced by those two files. The exit code then reflects assertions rather than a drained event loop.

Details follow in the two comments below: the A/B evidence per site, and the exact test-side patch with its before/after table — plus a second cancellation cluster in test/social-templates.test.js with a different cause, which keeps this from claiming a green directory.


Evidence collected locally, not from CI. Node 22 and Node 24 runs used the same checkout and the same TMPDIR; the whole-directory runs used --test-concurrency=2 (higher concurrency on this host hits thread-creation failures unrelated to this report).

Activity

  1. added
    agent-ready
    on Nov 29, 2026
  2. Birfy commented on Nov 29, 2026

    @Birfy
    CollaboratorAuthor

    A/B evidence per site (details for the report above)

    All runs on one scratch copy of the content, one variable at a time, Node 22, same shell, same TMPDIR. The copy was verified byte-identical to the tree under test (git add -Af then write-tree = the tree id in the report).

    Site 1 — runtime() rejection timer (src/host.js:26-34). test/features.test.js:155 starts with detachRuntime() and then await assert.rejects(runtime({ timeoutMs: 20 }), /not attached/). The timer that would reject after 20 ms is unrefed at src/host.js:28, so the loop may drain before it fires; the promise then never settles and the runner cancels the test.

    export function runtime({ timeoutMs = 15_000 } = {}) {
      if (attached) return Promise.resolve(attached)
      return new Promise((resolve, reject) => {
        const timer = setTimeout(() => { waiters.delete(done); reject(...) }, timeoutMs)
        timer.unref?.()
        const done = (value) => { clearTimeout(timer); resolve(value) }
        waiters.add(done)
      })
    }
    variant result
    head content as is 1 test / 1 cancelled, exit 1
    timer.unref?.() removed at src/host.js:28 1 test / 1 pass, exit 0; whole file 6 / 6 pass
    production unchanged, keep-alive timer around that await inside the test 1 test / 1 pass; whole file 6 / 6 pass

    Site 2 — memory capture scan schedule (features/memory/capture.js:198). schedule() arms setTimeout(...) for the next capture scan and calls timer.unref?.() on it. The two cancelled tests in test/memory-extras.test.js (:356 and :412) await extracting, which resolves after that scan runs, and race it against delay(6000, null, {ref: false}) — also unref'd, so nothing holds the loop.

    variant result (node --test test/memory-extras.test.js)
    head content as is 11 tests / 9 pass / 0 fail / 2 cancelled, exit 1
    timer.unref?.() removed at features/memory/capture.js:198 11 / 11 pass / 0 fail / 0 cancelled, exit 0
    production unchanged, keep-alive timer around the Promise.race in the test 11 / 11 pass, exit 0

    Not the cause: the in-test race timer at test/features.test.js:64 (Chat waited for an unrelated feature); that 3000 ms guard never fires and removing its .unref() changes nothing.

    Controls — this is a cascade, and it is not the change under test:

    • The dispatch passes payload test is green on its own and cancelled only behind its sibling: --test-name-pattern='dispatch passes payload' on Node 22 gives 1 test / 1 pass / 0 cancelled.
    • The latch test (native Chat serves the migrated owner directory while unrelated features initialize, test/features.test.js:78) is green both alone and inside the whole-directory run; when it appeared cancelled in one older full-file observation, it was collateral as well.
    • Same content, same results on a second independent host: identical on parent tree b43a727d and on head tree 93a2fb2d.
    • Repeatable, not a flake: 8 of 8 runs on one host and 7 of 7 on the other reported the same two, so this is deterministic; do not report it as "sometimes 2, sometimes 4".
    • Reverting the three env injections this suite gained in the change under test, one at a time and then all three, left the full-file result byte-identical to the unmodified copy run from the same directory (same counts, same TAP numbers), so the change under test is not the trigger.

    One correction to an earlier draft of this report: it claimed the unref at src/host.js:28 was ruled out. That earlier A/B edited a copy that was not the one being executed, so it measured nothing. The tables above supersede it.

  3. Birfy commented on Nov 29, 2026

    @Birfy
    CollaboratorAuthor

    Suggested fix (test-side, both sites), and a second cancellation cluster

    Keep the loop alive while asserting, and leave the production timers as they are:

    // test/features.test.js
    detachRuntime()
    const keepAlive = setTimeout(() => {}, 1000)
    try {
      await assert.rejects(runtime({ timeoutMs: 20 }), /not attached/)
    } finally {
      clearTimeout(keepAlive)
    }
    // test/memory-extras.test.js, at both cancelled tests
    const keepAlive = setTimeout(() => {}, 6000)
    try {
      await Promise.race([extracting, delay(6000, null, {ref: false}).then(...)])
    } finally {
      clearTimeout(keepAlive)
    }

    Both edits applied to a scratch copy of 1a981717 (tree b43a727d, verified byte-identical: git add -Af then write-tree = b43a727d), production files untouched, same shell, same TMPDIR, Node 22:

    command without the keep-alives with them
    node --test --test-name-pattern='runtime\\(\\) resolves' test/features.test.js 1 test / 1 cancelled, exit 1 1 / 1 pass, exit 0
    node --test test/memory-extras.test.js 11 / 9 pass / 2 cancelled, exit 1 11 / 11 pass, exit 0
    node --test --test-concurrency=2 test/*.test.js 497 / 470 pass / 17 fail / 10 cancelled, exit 1 497 / 474 pass / 17 fail / 6 cancelled, exit 1

    The whole-directory line is the strict A/B: exactly four results move from cancelled to pass (#176 #177 #233 #234), the fail count does not change, and the remaining 6 cancellations are a different cluster (below). Absolute whole-directory counts are not stable across shells on this content because 1a981717 still lets the suite inherit host environment variables — that is what #3434 addresses, not this report. A ready-to-apply test-only patch for the two sites (2 files, +15/−2, git apply --check clean on a fresh main copy) exists locally and can be attached as a PR if this issue is taken.

    A second cancellation cluster (same signature, different cause)

    test/social-templates.test.js reports 6 cancelledByParent results (#442–#447) under the same conditions on 1a981717, but they are not an unref'd-timer problem and the two keep-alives above do not touch them. On Node 22:

    condition result for that file
    whole directory, host environment as it happens to be 6 cancelled
    file alone, FLYBOT_WORKSPACE_ROUTING_INSTANCE_ID set 8 / 8 pass
    file alone, that variable absent 8 / 1 pass / 1 fail / 6 cancelled

    The first failure there is an assertion, not a cancellation: agents/v1 failed: {"code":"flybot-workspace/not-found","message":"Unknown FlyBot endpoint agents/v1"} — the agents feature did not load, and the six following tests are cancelled because the fixture promise from that test never settles. Node 24 with the same environment fails the same test with 500 where 201 is expected. So on this content the cancellation set depends on the hosting environment, which is why the same command can report 4, 6 or 10 cancellations on different machines without any assertion changing.

    Scope

    This report claims the four named results only. On 1a981717 the whole directory still reports 6 cancellations from test/social-templates.test.js in some environments, and 17 assertion failures that come from host environment variables leaking into the suite (#3434). It does not claim a green directory.

  4. added
    agent-working
    on Nov 29, 2026
  5. Birfy commented on Nov 29, 2026

    @Birfy
    CollaboratorAuthor

    Claimed. Branch: dev/3436-node22-plugin-test-keepalive, cut from main at e6aeae4e2bae52d13e721506a41e598a222655ea (tree 93a2fb2d). Scope is the two test-side keep-alive hunks only (test/features.test.js, test/memory-extras.test.js); src/host.js and features/memory/capture.js are left untouched, and no assertion changes. Refs #3434.

  6. Birfy commented on Nov 29, 2026

    @Birfy
    CollaboratorAuthor

    PR: #3437, head fd392ab5b756b597d1110fb03567c93d3524cb7a, cut from main at e6aeae4e (tree 93a2fb2d), 2 files +15/-2. The two test files on that head are byte-identical to the local A/B copies (sha256 5e0baaa8... and 4ea16a22...). Exact-head verification is QA Engineer's call, not asserted here. Refs #3434.

  7. Birfy commented on Nov 29, 2026

    @Birfy
    CollaboratorAuthor

    Done: #3437 merged as ee8ae6df3e3ee10af8cad63e5e7e078db4fc9bd8 (tree dffcaed5782aedb4f710695d9d06af9bd5d2e93e, single parent e6aeae4e).

    What shipped: two test-side keep-alive handles in runtime/flybot-workspace-web/test/features.test.js and test/memory-extras.test.js, so awaited work that depends on unref'd timers keeps the process alive. Production code is unchanged: the PR tree reconstructs byte-for-byte from e6aeae4e plus those two blobs, and both unref calls stay as they are.

    Verification (all bound to the merged content, tree dffcaed5):

    • Pre-merge exact head fd392ab5b756b597d1110fb03567c93d3524cb7a: local A/B on Node v22.23.5 moved the four cancelled results to pass (#176, #177, #233, #234) and the whole test/*.test.js directory from 497 / 493 pass / 0 fail / 4 cancelled / exit 1 to 497 / 497 / 0 / 0 / exit 0.
    • Post-merge recheck on the new main content (commit ee8ae6df, reconstructed tree dffcaed5): node --test --test-concurrency=2 test/*.test.js in runtime/flybot-workspace-web gives 497 / 497 pass / 0 fail / 0 cancelled / exit 0 on Node v22.23.5.
    • CI on the merge commit: 33/33 check runs completed with success.

    Not claimed: these are local single-host readings plus the recorded CI results, not acceptance; absolute counts differ between hosts, so only the cancelled-to-pass delta is treated as evidence.

    Related #3437. Refs #3434.

  8. removed
    agent-working
    on Nov 29, 2026
  9. removed
    agent-ready
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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