Repository navigation
Description
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, tree93a2fb2da2c93adfe58df4ae7f6165519c15d590, parent1a981717(main at the time of writing). The targeted reproduction below is identical on the unpatched parent content (treeb43a727d) on both hosts, so the PR under test is not the trigger. node v22.23.5(aarch64) versusnode v24.22.3(aarch64), two separate hosts, bothaarch64.TMPDIRon real disk;/tmpon 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 24497 / 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 246 / 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.
runtime()rejection timer,src/host.js:26-34:test/features.test.js:155doesdetachRuntime()thenawait assert.rejects(runtime({ timeoutMs: 20 }), /not attached/). The timer that would reject after 20 ms isunrefed atsrc/host.js:28, so the loop may drain before it fires and the promise never settles.- Memory capture scan schedule,
features/memory/capture.js:198: the same shape. The two cancelledmemory-extrastests awaitextracting, which resolves only after that scan runs, and race it againstdelay(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
Birfy commentedon Nov 29, 2026
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 -Afthenwrite-tree= the tree id in the report).Site 1 —
runtime()rejection timer (src/host.js:26-34).test/features.test.js:155starts withdetachRuntime()and thenawait assert.rejects(runtime({ timeoutMs: 20 }), /not attached/). The timer that would reject after 20 ms isunrefed atsrc/host.js:28, so the loop may drain before it fires; the promise then never settles and the runner cancels the test.timer.unref?.()removed atsrc/host.js:286 / 6 passawaitinside the test6 / 6 passSite 2 — memory capture scan schedule (
features/memory/capture.js:198).schedule()armssetTimeout(...)for the next capture scan and callstimer.unref?.()on it. The two cancelled tests intest/memory-extras.test.js(:356and:412) awaitextracting, which resolves after that scan runs, and race it againstdelay(6000, null, {ref: false})— also unref'd, so nothing holds the loop.node --test test/memory-extras.test.js)11 tests / 9 pass / 0 fail / 2 cancelled, exit 1timer.unref?.()removed atfeatures/memory/capture.js:19811 / 11 pass / 0 fail / 0 cancelled, exit 0Promise.racein the test11 / 11 pass, exit 0Not 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:
dispatch passes payloadtest is green on its own and cancelled only behind its sibling:--test-name-pattern='dispatch passes payload'on Node 22 gives1 test / 1 pass / 0 cancelled.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.b43a727dand on head tree93a2fb2d.envinjections 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
unrefatsrc/host.js:28was 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.Birfy commentedon Nov 29, 2026
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:
Both edits applied to a scratch copy of
1a981717(treeb43a727d, verified byte-identical:git add -Afthenwrite-tree=b43a727d), production files untouched, same shell, sameTMPDIR, Node 22:node --test --test-name-pattern='runtime\\(\\) resolves' test/features.test.js1 test / 1 cancelled, exit 11 / 1 pass, exit 0node --test test/memory-extras.test.js11 / 9 pass / 2 cancelled, exit 111 / 11 pass, exit 0node --test --test-concurrency=2 test/*.test.js497 / 470 pass / 17 fail / 10 cancelled, exit 1497 / 474 pass / 17 fail / 6 cancelled, exit 1The 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 because1a981717still 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 --checkclean on a freshmaincopy) 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.jsreports 6cancelledByParentresults (#442–#447) under the same conditions on1a981717, but they are not an unref'd-timer problem and the two keep-alives above do not touch them. On Node 22:FLYBOT_WORKSPACE_ROUTING_INSTANCE_IDset8 / 8 pass8 / 1 pass / 1 fail / 6 cancelledThe first failure there is an assertion, not a cancellation:
agents/v1 failed: {"code":"flybot-workspace/not-found","message":"Unknown FlyBot endpoint agents/v1"}— theagentsfeature 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 with500where201is 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
1a981717the whole directory still reports 6 cancellations fromtest/social-templates.test.jsin some environments, and 17 assertion failures that come from host environment variables leaking into the suite (#3434). It does not claim a green directory.Birfy commentedon Nov 29, 2026
Claimed. Branch:
dev/3436-node22-plugin-test-keepalive, cut frommainate6aeae4e2bae52d13e721506a41e598a222655ea(tree93a2fb2d). Scope is the two test-side keep-alive hunks only (test/features.test.js,test/memory-extras.test.js);src/host.jsandfeatures/memory/capture.jsare left untouched, and no assertion changes. Refs #3434.Birfy commentedon Nov 29, 2026
PR: #3437, head
fd392ab5b756b597d1110fb03567c93d3524cb7a, cut frommainate6aeae4e(tree93a2fb2d), 2 files +15/-2. The two test files on that head are byte-identical to the local A/B copies (sha2565e0baaa8...and4ea16a22...). Exact-head verification is QA Engineer's call, not asserted here. Refs #3434.Birfy commentedon Nov 29, 2026
Done: #3437 merged as
ee8ae6df3e3ee10af8cad63e5e7e078db4fc9bd8(treedffcaed5782aedb4f710695d9d06af9bd5d2e93e, single parente6aeae4e).What shipped: two test-side keep-alive handles in
runtime/flybot-workspace-web/test/features.test.jsandtest/memory-extras.test.js, so awaited work that depends onunref'd timers keeps the process alive. Production code is unchanged: the PR tree reconstructs byte-for-byte frome6aeae4eplus those two blobs, and bothunrefcalls stay as they are.Verification (all bound to the merged content, tree
dffcaed5):fd392ab5b756b597d1110fb03567c93d3524cb7a: local A/B on Nodev22.23.5moved the four cancelled results to pass (#176,#177,#233,#234) and the wholetest/*.test.jsdirectory from497 / 493 pass / 0 fail / 4 cancelled / exit 1to497 / 497 / 0 / 0 / exit 0.maincontent (commitee8ae6df, reconstructed treedffcaed5):node --test --test-concurrency=2 test/*.test.jsinruntime/flybot-workspace-webgives497 / 497 pass / 0 fail / 0 cancelled / exit 0on Nodev22.23.5.completedwithsuccess.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.