Repository navigation
Conversation
ymichael
force-pushed
the
bb/class-fix-flaky-tests-via-shared-fixtures-and-ni-thr_ye9fgrdqrq
branch
from
November 17, 2026 21:02
12bffdc to
e7db1a5
Compare
Add @bb/test-helpers/child-processes (child-process tracker, process lifeline, descendant pipe), expose it to forkable plugins as experimental_ exports of @get-bb/plugin-sdk/testing, move every PID-based test check and the per-package diagnostics-channel trackers onto it, and add a CI rule that rejects signal-0 probes, PID liveness helpers and PID inequality assertions in test code. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… in tests Parse call arguments with balanced brackets, catch kill -0, liveness helpers named Exists, /proc/<pid> reads, ps -p existence probes, PID equality and not.toContain assertions, and process.kill on any PID but the test process's own or its parent's. Move the remaining sites onto ChildProcess handles, lifelines, killProcessGroup, stopVerifiedProcess, start-time identity loops in shell, and a new signalDescendantProcesses owner for listed descendants. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/class-fix-flaky-tests-via-shared-fixtures-and-ni-thr_ye9fgrdqrq
branch
from
November 18, 2026 00:24
e7db1a5 to
90a64b9
Compare
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/class-fix-flaky-tests-via-shared-fixtures-and-ni-thr_ye9fgrdqrq
branch
November 18, 2026 04:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
Tests decided whether a process was alive, or had restarted, from its PID. The operating system reuses PIDs, and Windows does so quickly. So a test can be failed by an unrelated process that later takes the number:
process.kill(pid, 0);expect(newPid).not.toBe(oldPid).The fixes were per file. Each one patched its own checks, and three of them copied the same diagnostics-channel tracker into their own package. Nothing stopped the next test from writing the pattern again.
runtime.process-lifecycle.test.tsandplugin-host-manager.test.tsare on their sixth fix. Background: the C16 section of the ui-label verification report.Related failure modes came with it:
What changed
Guard.
scripts/check-test-process-identity.mjsruns in CI'splanjob, next to the provider-literal ratchet. It has no dependencies and uses no Turbo cache, so it covers every package, including the ~40 that have nolintscript. It parses call arguments with balanced brackets, so nested forms likeisAlive(Number(readFileSync(pidFile)))are caught. In test code (*.test.*,test/,tests/,testing/, fixtures, test-support,@bb/test-helpers) it rejects:signal-zero-probe:kill(x, 0)and shellkill -0;pid-liveness-helper:…Alive(/…Running(/…Exists(given a PID or PID file, or passed as a callback over PIDs;pid-os-probe:/proc/<pid>reads andps -p <pid>existence probes;pid-identity-assertion:.not.toBe/toEqual/toContainon a PID, andexpect(a.pid === b.pid);pid-signal:process.kill(<remembered pid>, signal), including group signals. A failed spawn'schild.pid ?? 0would signal the runner's whole process group.What stays allowed:
process.pidandprocess.ppid;pscalls that read a start time (lstart,etime) to compare a recorded identity;child-processes.ts,process-sweep.ts).There is no allowlist. Each message names the replacement.
packages/scripts/test/test-process-identity.test.mjspins the rule with 52 cases kept as JSON data, so the rule passes on itself. They include the verbatim checks past fixes removed and each form an independent review found missing.One owner:
@bb/test-helpers/child-processes.trackChildProcesses()is Verify fixture child lifetimes without probing retired PIDs #7681's diagnostics-channel tracker, made shared. It offerschildren,running(),waitForExit(),waitForClose(),killRunning()anddispose().createProcessLifeline()is a local socket (a named pipe on Windows) for descendants the test does not spawn itself.holdSource(label, onHeld?).onHeldruns once the hold is registered, for scripts that block next.holder.exitedandalive()follow the connection.holder.kill()signals only while the connection is open, so a reused PID is never signalled.close()reaps the holders still connected.createDescendantPipe()is a POSIX FIFO for shell descendants that must start instantly, such assleep 60 > "$pipe" &racing a 300 ms production timeout.openedandclosedfollow the inherited write end.Plugin SDK, additive and backward compatible.
@get-bb/plugin-sdk/testinggainsexperimental_trackChildProcesses,experimental_createProcessLifelineandexperimental_createDescendantPipe, plus theirExperimental*types. They are thin wrappers over the same module, so forkable plugins use core's path. Nothing existing changed.docs/api_to_audit.md,plugins/plugin-api-docs/src/surfaces.tsand the plugin-authoringtesting.md. Repository guidance is indocs/debugging-and-qa.md("Observing Processes in Tests").Migration. Every finding on main (163 in 42 files) moved onto the owner:
process-tree,portable-process,exec-portable-file;config(verified-process-stop);test-helpersprocess-sweep: liveness after SIGTERM now re-lists processes and matches PID plus args, and only those still listed get SIGKILL;frp-clientfixture and its two callers;bridge,shutdown, andfake-acp-agent.mjs, which now runs a hold instead of writing a PID file;environment-lifecycle-script,runtime-manager,connect-next, and the server-move fixture plus activation and service tests;install-machine-script;log-viewer;start-bb;tests/integration/global-setup.tsandfake/recovery/reconnect-open-work;shared.ts,standalone-restart-command,spawn-logged-process,scripts/run-root-command.mjs;install-machine-script: 13 remembered-daemon kills deleted, since the file'safterEachpath sweep already owns them. Its fakelaunchctl bootoutwaits on a recordedps -o lstart=instead ofkill -0.desktop bb-process: the grandchild reports its own/proc/self/statgroup and holds a lifeline; it no longer reads/proc/<pid>.process-utils oom-scoreandagent-runtimeOOM: children report their own/proc/self/oom_score_adj.bb-app app-update-run-command: trackerkillRunning()instead of a remembered-PID set.plugin-sdk kill-processes:child.kill(); thechild.pid ?? 0path is gone.bb-app managed-process,cli broken-pipee2e, server-move fixture:killProcessGroup({ child }).bridge(4 readyFile kills), Codex archived-rebuild, integration reconnect: trackedChildProcess.kill().agent-runtimelive recorder:signalDescendantProcesses(), a new sweep owner that signals selected descendants of the test process straight from a fresh listing.tests/qakillProcessand integrationglobal-setup:readProcessIdentity()plusstopVerifiedProcess()from@bb/config.tests/qabuildDaemonRestartCommand: waits on a recordedlstartin shell.Processes that cannot hold a handle are confirmed by identity, never by bare PID:
lsoforpsstart time;sleep, byreadProcessIdentity.plugin-host-manager.test.tskeeps #7683's self-reportedbootId, which already satisfies the rule.Past fixes this root cause produced
expect(replacementProvider.child.pid).not.toBe(exitedPid)×3pid-identity-assertionrejects itisProcessGroupAlive(prepared.pid), Windows PID reusepid-liveness-helperrejects it; the fixture now hands out the ownedChildProcessprocessIsAlive(child.pid)lifeline.close()/killRunning()reap holders and tracked childrenawait holder.exitedwaitForClose(), lifeline/pipeexited/closedkill(pid, 0); added 3 tracker copieswaitForClose()Patches this deletes:
test-supportandparity.test.ts;isAlive,processIsAlive,isPidAlive,isProcessRunning,alive, …);sleep 200 msand qa's 500 ms after signalling;There are no linked issues: this class was fixed in PRs only.
How you verified
origin/main(f1c53045c94) reports 163 findings in 42 files; on this branch, 0.processExists(pid), shellkill -0,/proc/${pid},ps -p,a.pid === b.pid,.not.toContain(oldPid), remembered-PID SIGKILL,pid ?? 0);exitCode, boot id,holder.alive(),isProcessGroupAlive(child),ps -o lstart=,process.pid/process.ppid,/proc/self, a fullps -Alisting, a"parent.pid"file name).kill(pid, 0)still succeeds, butalive()is false andkill()refuses.signalDescendantProcesses).turbo run typecheck lint lint:type-aware --filter='[origin/main]': 78 tasks passed..cmdshim kill, MSYS lifecycle cancellation) and the integration suite. CI covers them.Decisions for review
Integration global setup. It now stops stale
lsofholders only after verifying their recorded identity (stopVerifiedProcess). It no longer re-lists and signals by PID.QA tooling.
cleanupStandaloneOrphansnow judges a parent alive bypsstart time against when the state was written, not by signal 0.killProcessverifies the target withstopVerifiedProcess(60 s start-time tolerance) and skips processes it cannot inspect.pscan see it.New public SDK surface. Three
experimental_testing exports with audit criteria indocs/api_to_audit.md. The patch bump means third-party plugins can opt in, and existing ones are unaffected.Failure mode. A process that never exits now fails on the test's existing timeout rather than at a separate PID-poll deadline. The failure message is less specific, in exchange for no extra budget.
🤖 Generated with Claude Code