Repository navigation
fix(install): the launcher listens for SIGTERM and SIGHUP before it starts its command, so one in between no longer leaves the command running - #3944
Conversation
…tarts its command run() in scripts/plugin-launch.ts spawned its child and only then installed its SIGTERM/SIGHUP/SIGINT handlers. A signal in between ended the launcher by default (143), was never passed on, and left the child running. The handlers now come first; Bun runs a signal listener from the event loop, so one for a signal that came before the spawn returned runs once the child is set. scripts/plugin.ts (a command handed on to the installed release) and scripts/plugin-tui.ts (ovis tui) had the same order and get the same fix. The test holds the launcher where it starts listening, if it has spawned the child by then, until the child has signalled it: it fails on main every time and asserts the child is gone afterwards. Also rewords one sentence of changelog.d/plugin-launch-build-check.md, as the merge pass asked.
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
|
Windows VM (Windows 11,
|
…ound its step already ended With the launcher listening before it spawns, a signal that comes just before a short step starts can be dispatched after that step has exited 0: it is passed on to nothing, run() returns 0, and fromSource started the next step. The handler now records the signal, and fromSource stops after the step with 128 + its number (143, 129). run() itself still exits as its child did. Tests: the lost stop, held so that the first step has ended before the signal can be passed on (fails at cab9f19 every time); the SIGTERM sent while the child runs, kept as its own case, without a poll; every wait for the launcher bounded, so a hang still reaches the cleanup.
Merge passMerged head
Merge pass note for #3944 at 6e60ede (fix(install): the launcher listens for SIGTERM and SIGHUP before it starts its command). A real window on main since #3800: the launcher started its command first and installed its signal handlers on the lines after, so a SIGTERM or SIGHUP that reached it in between killed the launcher and left the command running. Seen once in CI and reproduced by the author and in review: on main, with the launcher pinned to one cpu, 2 to 5 of 100 runs died with 143 and left the child; at this head 0 of 400 runs left a child, and an early signal is forwarded exactly once. Left for the author's next change, both small: with two different signals the record keeps the last, so the exit code can name the second; a child killed by SIGKILL gives 128, not 137, as on main. |
…se is out of reach, and prints its build command quoted for any path (#3950) Follow-up to #3940 (merge a81ec59) and #3944 (fccc9c4), in `install.ps1` and `scripts/windows-install.test.ps1`, plus a changelog fragment. Nothing in `scripts/plugin*.ts`. ## 1. The repair with the release out of reach: what it did, and the fix Since #3940 the launcher's `stop` reaches the checkout's own `scripts/plugin.ts` when no checked binary can be had, also when the release cannot be reached. install.ps1's repair (a branch rerun with `OVIS_REF` whose checkout is not built from its own sources) sends its stop through the launcher whenever a release binary is kept in `.ovis\server\bin`. So in one state the repair now stops a running server where it used to refuse. That state: the kept binary is one the launcher does not run without the release (another version's, or this version's failing its check), the release cannot be reached, and the packages load the stop. Run in the Windows VM with the test file's stand-ins (herdr, bun, the release) and real git, at main (fccc9c4): - **(a) Step by step.** The launcher's `stop` goes to the sources and stops the server, and its record is removed. install.ps1 has already removed the from-source marker before the stop. It then runs `OVIS_FROM_SOURCE=1 bun <launcher> install`. That build writes the stamp `started` and the marker, then runs `bun install`. - **(b) The build fails offline.** The user is told: `bun failed (exit 1) building the installed branch, and Ovis is stopped. Fix the error above, then run this again with OVIS_REF=feat/windows-install to build it and start Ovis.` The marker is taken back, and the stamp stays `started`. Nothing that is printed starts Ovis again while the release is out of reach: - Herdr's start runs the launcher without a marker, which asks the release. Run for real in the VM, it gives `Ovis: could not install the server of v0.5.4: Unable to connect. Is the computer able to access the url?`, exit 1, and nothing is started. - With a kept binary of this version that fails its check, the message even adds `Until then, herdr plugin action invoke devswha.ovis.start-windows starts the release's binary this checkout ran before.` That start fails in the same way. - Once the release is back, a branch's start meets the `started` stamp and is refused until the rebuild succeeds. - **(c) The old build.** Its files are not removed: real `bun install` with the registry out of reach exits 1 and leaves `node_modules` as it was (`is-number unchanged: True`), and `vite` runs only after `bun install` succeeds. But it is no longer usable through herdr. The marker that sent herdr's start to it is gone, and the stamp says `started`. So a user is left with a stopped Ovis and no working way back until the release can be reached. Before #3940 the launcher's stop exited 1 in this state, and the repair refused with nothing stopped. **The fix: do not stop in that state. The rule: the repair asks the release first whenever the launcher's stop or herdr's later start would have to ask it, that is, whenever the checkout keeps no release binary the launcher runs without the release.** Concretely, before the repair touches anything (the marker included), unless a kept binary passes \`$keptRuns\`, it asks the release for \`v<version>/ovis-server.json\` with \`Save-ReleaseFile\`. \`$keptRuns\` passes for a binary of this version whose executable has the SHA-256 its manifest names, with its client. If the request throws (out of reach, or failing), the repair refuses before anything is stopped or changed, for example: \`The release of version 1.2.3 could not be reached (could not download https://127.0.0.1:1/v1.2.3/ovis-server.json (...)), and this checkout keeps no release binary: Ovis would be stopped for the build, and if the build failed too, herdr could not start it again until the release can be reached. So the branch was not built, and nothing was stopped or changed by this run. Run this again once the release can be reached.\` With a kept binary that does not pass, the reason names that binary's folder instead. When the old id's server was stopped for the move, the refusal says so, with its start (\`$unchanged\`, as the other refusals since #3929). A 404 (a branch's version has no release) is no reason to refuse: the stop and the start go to the sources, as before #3940. What the rule does not tell apart: sources git cannot tie to a release (changes in \`server/\` or \`shared/\` not committed), whose stop and start do not ask the release, are refused offline too. That is on the safe side, since nothing is stopped there either. A kept binary whose hash passes but whose signature no longer verifies is taken as one the launcher runs, because install.ps1 does not check that signature (see the start hint below). Why this and not restarting the old build after a failed one: restarting means starting a server from install.ps1 outside herdr's start, over a build the launcher has already marked \`started\`. Not stopping keeps the server, its marker and its stamp exactly as they were, which is what the user had before #3940. **The start hint after a failed build no longer promises.** install.ps1 checks the kept binary's version, SHA-256 and client, but not its manifest's signature, which the launcher also checks. The launcher has no dry check that says whether it would run the kept binary without the release, and this PR does not invent one. So where \`$keptRuns\` passes, the hint now reads: \`Until then, herdr plugin action invoke devswha.ovis.start-windows may start the release's binary this checkout keeps, if the launcher still accepts it (its signature, which this installer does not check, included).\` It is no longer \`starts the release's binary this checkout ran before\`. On main the hint was given for any kept binary of this version with an executable and a client, a failing hash included. ### States touched Run in the VM with the test file's stand-ins, at main (869ec34), at the first head 2835843 and at this head. Each row has a recorded running server, packages that load the stop, the marker of this version and a finished stamp of an earlier commit. The build fails unless the row says it succeeds. | state (repair) | before #3940 | main | 2835843 | this head | |---|---|---|---|---| | **no kept binary, release out of reach, build failing** | stop to the sources, build, fails: Ovis stopped (the same as main) | launcher \`stop,install 1\`; server record gone, marker gone, stamp \`started\`: \`bun failed (exit 1) building the installed branch, and Ovis is stopped. Fix the error above, then run this again with OVIS_REF=feat/windows-install to build it and start Ovis.\` herdr's start cannot start it offline | the same as main | **refused before the stop**; launcher not called; server record, marker and stamp \`1.2.3 <commit>\` as they were | | **no kept binary, release out of reach, build succeeding** | stop, build, start | \`stop,install 1\`; built, herdr's start invoked (\`herdr start: True\`) | the same as main | **refused before the stop**, as above (the installer cannot know the build would succeed offline) | | **the same with the old id installed (its server stopped for the move), build failing** | stop, build, fails | \`stop,install 1\`, "...and Ovis is stopped... The server of the old id was stopped for the move as well: herdr plugin action invoke devswha.herdr-web-ui.start-windows starts it again." | the same as main | refused before this checkout's stop; the message ends "So the branch was not built, and nothing of the installed plugin was changed by this run, but the server of the old id was stopped for the move: herdr plugin action invoke devswha.herdr-web-ui.start-windows starts it again." | | kept binary of another version, release out of reach | refused (stop exit 1), nothing stopped | stops, builds; a failed build leaves Ovis stopped, unstartable offline | refused before the stop | refused before the stop | | kept binary of this version failing its hash, release out of reach | refused, nothing stopped | the same as above, plus a start hint that does not work | refused before the stop | refused before the stop | | either of these, or no kept binary, release out of reach, packages that do not load the stop | stop fails or cannot run; refused ("remove that folder"), or built where nothing ran | the same | refused before the stop (kept binary only) | refused before the stop; the marker is kept | | kept binary that passes \`$keptRuns\`, release out of reach, failed build | stop through the binary, build | the same, with "starts the release's binary" | the same | the same, with "may start ..., if the launcher still accepts it" | | release in reach (a 404 included), any kept binary or none | stop, build | the same | the same | the same; the release is asked once first | | any state refused before the repair (another ref, git failing or distrusting, no commit, GitHub out of reach for a branch) | unchanged | unchanged | unchanged | unchanged (the probe comes after those refusals) | ## 2. Quoting in printed commands The rebuild command after a build during which the version moved put the launcher's path in single quotes without doubling an apostrophe. Pasted for `C:\Users\John O'Brien\...` into Windows PowerShell 5.1 (VM), main's line `$env:OVIS_FROM_SOURCE = '1'; bun 'C:\...\John O'Brien\herdr plugin\scripts\plugin-launch.ts' install` ran nothing: the string never closes. This PR's line, `... bun 'C:\...\John O''Brien\herdr plugin\scripts\plugin-launch.ts' install`, pasted the same way, ran `C:\...\John O'Brien\herdr plugin\scripts\plugin-launch.ts install with OVIS_FROM_SOURCE=1`. That run used a stand-in launcher that prints its argv and environment. `Get-BuildCommand` quotes it as `Get-TrustCommand` does. A new case parses its line with PowerShell's parser for paths with a space, with an apostrophe, and with two apostrophes. It requires `OVIS_FROM_SOURCE` set to `1` and `bun <path> install`, with the path as one argument. Every other command install.ps1 prints: | command | verdict | |---|---| | build command in the "git could not read the commit" refusal (`bun '$launcherScript' install`) | same fault: fixed (`Get-BuildCommand`) | | `Get-CimInstance Win32_Process \| Where-Object CommandLine -like '*<root>*'` after a failed build | same fault: apostrophes now doubled, and since the second head the path is passed through `[WildcardPattern]::Escape` first, so brackets in a folder name are not taken as a wildcard (a case runs the repair from `[x] it's a plugin`: at 2835843 the printed pattern `'*...\[x] it''s a plugin*'` does not match that folder; at this head it does, and does not match `x it's a plugin`) | | `git config --global --add safe.directory '<folder>'` | already right (`Get-TrustCommand`) | | `Get-CimInstance Win32_Process -Filter 'ProcessId=<id>'`, `Stop-Process -Id <id>` | a number, no path: fine | | `herdr plugin action invoke <id>.start-windows` / `stop-windows`, `herdr plugin log list` | no path: fine | | `$env:OVIS_FROM_SOURCE = '1'; herdr plugin install devswha/ovis --ref <ref> --yes` | not a path; a ref is printed bare (git refs have no spaces). Left | | `ssh -L <port>:127.0.0.1:<port> <this-pc>` | no path: fine | ## 3. The message as steps The message for a build during which the checkout's version moved now ends `To build it, stop Ovis, build it, then start it:` followed by three lines, one command each. The commands are the stop action, the build command and the start action, as the trust command is printed on a line of its own. The test reads the three lines and parses the middle one. ## Validation This head was run in the Windows VM: Windows 11, Windows PowerShell 5.1, a fresh clone of main 869ec34 under \`%TEMP%\` with this head's files copied in, in the desktop session with \`CI=true\` and \`HERDR_TEST_MODE=unit\` as the job runs it. The command was \`powershell -NoProfile -ExecutionPolicy Bypass -File scripts/windows-install.test.ps1\`: - unpadded (PATH 335 characters): every PASS line, exit 0 (69 s); - PATH padded to 2700 characters: every PASS line, exit 0 (70 s). Counting copy (Assert counts instead of throwing): | install.ps1 | test file | pass | fail | |---|---|---|---| | 2835843 | its own | 247 | 3 | | 2835843 | this head's | 248 | 7 | | this head | this head's | 252 | 3 | In every run, the 3 are the gh ordering negative control's intended failures, which throw in the real file and are caught there. At 2835843 with this head's test, the 4 others fail: the three no-kept-binary rows above, and the bracket hint. At main with this head's test, those fail too, together with the first head's cases, and the run ends at the missing \`Get-BuildCommand\`. Also from the first head, still true: real \`bun install\` with the registry out of reach exits 1 and leaves \`node_modules\` as it was; the real launcher's \`start\` in the state main leaves exits 1 with nothing started; the printed build command pasted into Windows PowerShell 5.1 runs for a path with an apostrophe, where main's line runs nothing. \`bun run check fast\` (through heavy-run.sh) on this tree (main 869ec34 + this PR): exit 0, `unit: 17643 pass, 0 fail, 54 skip in 973 files`, typecheck, build, workflow syntax and generated files ok. (Main has moved to e5c6a8e since; its two commits touch none of these files.). Not run: - a real Ovis server stopped or started by the repair (forbidden on this PC; the stand-ins cover it); - the real launcher's \`stop\`, which this PR does not change; - macOS and Linux, where nothing changes.
…t need them fail before any change, SIGINT/TERM/HUP reach the release, and a child's death by any signal is 128 + n (#3953) The small signal and load faults the reviews of #3940 and #3944 left in the plugin scripts. Nothing in `install.ps1` or `install.sh`. ## What changes 1. **Handlers that touch a child that was never set** (`scripts/plugin-tui.ts`, `scripts/plugin.ts`). Since #3944 the SIGTERM/SIGHUP listeners are added before the spawn. They called `child.kill` without a guard, so when the spawn threw, a later signal hit an unset `child`: a `TypeError` in `runTui`, or a `ReferenceError` (the `const` before its declaration) in `plugin.ts`. Both now call `child?.kill(signal)` and take their listeners off on every way out, the throwing one included. In `plugin.ts` the three places that hand a command on to the release Settings → Updates installed (`link`, `phone-setup`, an unknown command) now share one `handOn()`. `runTui`'s injected `on` returns the function that takes the handler off again. 2. **The first signal names the exit code** (`scripts/plugin-launch.ts`). The build records the signal with `??=`, so a SIGTERM followed by a SIGHUP during a step that then ends with 0 gives 143, not 129. 3. **Each build keeps its own signal record** (`scripts/plugin-launch.ts`). I chose to pass the record explicitly rather than reset it in each `main()`. The record now belongs to the `fromSource` call that runs the build steps, and `run()` fills it through a parameter. No module-level state is left, so a signal an earlier `run()` or `main()` in the same process was sent cannot stop a later build. A later `start` never read the record anyway: its one child gets the signal itself. Resetting in `main()` would still leave a stray `run()` call writing module state that the next caller sees. The CLI cannot reach this (one command per process), so it is covered by a unit test. 4. **Any signal maps to 128 + n** (`scripts/plugin-launch.ts`). `run()`'s table knew only HUP, INT and TERM, so a child killed by SIGKILL gave 128. It now uses `os.constants.signals` and gives 137 for SIGKILL and 131 for SIGQUIT. 5. **`stop` and `status` load without application packages** (`scripts/plugin.ts`). Loading `plugin.ts` pulled in `qrcode-generator` directly, and through `shared/relay-offer.ts` and `scripts/plugin-link.ts` it also loaded `@noble/*`, `tweetnacl`, `base64-js` and `jsonc-parser`. A `node_modules` folder that exists but lacks them turns Bun's auto-install off, so `stop` failed with `Cannot find package 'qrcode-generator'` and a server running from that checkout could not be stopped through herdr. The QR code, `decodeOffer` and `plugin-link.ts` are now imported in the commands that use them. `COMMAND_ALIASES` moves to `scripts/plugin-runtime.ts`, which loads no packages; `plugin.ts` still names it, so install.sh's `grep COMMAND_ALIASES` still matches. `plugin-link.ts` keeps its static import of `qrcode-generator`: that file needs the relay's and the account's packages at load anyway, and `plugin.ts` now loads it only for `link` and `pair --approve`. 6. **The launcher's stop/status fallback.** Not changed. After point 5, `scripts/plugin.ts stop` and `status` load with no packages at all (the test below runs them with an empty `node_modules`), so no case is left where the fallback cannot load the sources. 7. **`phoneSetup`** handed on to the release with no signal handling at all. A run on main with a stand-in release showed the result: a SIGTERM or SIGHUP sent to the plugin process ended it (143 / 129), and the release's phone-setup kept running in the pane with nobody waiting for it. It holds the pane's terminal and is the one process that must be told, so it now follows the same rule as `link`, through `handOn()`. ## Second push (69249e2), on the merge pass's review of 69ebe4b **A. Packages load before a command changes anything.** At 69ebe4b the deferred imports came after the first change. With the QR package missing, `pair` and `phone-setup` asked the app for a pairing code, which replaces the one another device may be using, and `phone` ran `tailscale serve`; each then failed at the import. Every command that needs a package now loads it first: | command | first thing it changes | where the import now sits | |---|---|---| | `pair` | `POST /api/devices/pair/start` (a new pairing code) | `pairingParts()` (QR code + relay offer), at the top of `pair`, before `health()` | | `phone-setup` (the checkout's own) | the same, through `pair` | `pairingParts()` right after the hand-on check, before its first line, passed to `pair` (so it is not reported as "Could not read phone setup") | | `phone` | `tailscale serve --yes …` (publishes the app) | `qrDrawer()`, the first line of `phone` | | `link` / `add` / `login` | the account sign-in requests in `plugin-link.ts` `link()` | `import("./plugin-link.ts")` right after the hand-on check, before `health()` | | `pair --approve` | `POST /api/relay/pairing` (a decision) | `import("./plugin-link.ts")`, the first line of `approvePairings` | A run in a copy with an empty `node_modules` and a stand-in app and `tailscale`. At 69ebe4b, `pair` sent `POST /api/devices/pair/start` and failed at the import; `phone-setup` sent the same and said "Could not read phone setup"; `phone` ran `serve --yes --bg --https=443 …`. `link` and `pair --approve` already changed nothing. Here, all five fail with `Cannot find package 'qrcode-generator'`: no request that changes anything, and no `serve`. The test is `plugin.test.ts` "the commands that need a package fail before they change anything…", POSIX only (its stand-in `tailscale` is a shell script). **B. SIGINT is passed on to the release (`handOn`).** At 69ebe4b a SIGINT sent to the checkout alone hit an empty handler: the release got nothing, and the checkout waited. Now `handOn` passes it on like TERM and HUP, except on Windows: there Bun ends a child outright for any signal it is sent, without the release's own Ctrl+C cleanup, and a Ctrl+C reaches every process of the console anyway. I settled the double delivery by a run, with a stand-in release that counts its SIGINTs and ends 0.5 s after the first: | SIGINT | 69ebe4b | here | |---|---|---| | to the whole group (a Ctrl+C) | the release got 1, everything exits 6 | the release got 2, everything exits 6 | | to the checkout alone | the release got 0; the checkout was still waiting after 4 s | the release got 1, everything exits 6 | So a Ctrl+C now reaches the release twice. That is harmless for every release this hands on to: `link`'s `halt` returns at once on a second signal (`if (stop.signal.aborted) return`, written for exactly that), and `phone-setup` has no SIGINT handler, so it ends at the first. Tests: - "`<command>`: … passes it a SIGINT and exits as it did" for `link`, `phone-setup` and an unknown command. They fail at 69ebe4b (10 s timeout, the checkout waiting). - "`<command>`: ends with the release on a Ctrl+C, which reaches both through their process group". **C. Wording.** I chose the smaller truthful one: the launcher still passes on only TERM and HUP (a QUIT sent to it alone ends it and leaves its child, as on main). The title and the changelog fragment now say only what changed: how the launcher reports a child's death by any signal (128 + n, 137 for SIGKILL). The fragment also names the SIGINT of B and the "nothing changed" of A. Not changed (outside the three points): Codex's LOW at plugin-launch.ts:73. A build step that ends non-zero by the second of two signals returns its own code (129) rather than the first signal's (143). ## Validation All runs were on Linux (Bun 1.4.2) with `TMPDIR=$HOME/.cache/ovis-tmp/...`. Each case that touches the plugin used a scratch state, config and app-state directory and a quiet port above 20000 (`quietPort`). Nothing ran the real plugin `start` or `stop` against the default state directory. **Second push, on 69249e2** (its base is still 869ec34: main's two newer commits touch no file of this PR, and in what plugin.ts imports only `server/owner-guard.ts`, with no new import. GitHub's run tests the merge with main.) - `bun run check fast` through the heavy-slot wrapper passed: workflow syntax, generated types and themes, typecheck, build, and 17665 unit tests passed, 0 failed, 54 skipped. - Each touched test file 20 times in a row: `plugin-launch` 20/20, `plugin-tui` 20/20, `plugin` 20/20, `plugin-link` 19/20. The one failure (run 17) was the existing test "never takes a line typed for a request that went away as the answer to the next one shown in the same look", which timed out at 5.8 s against its 5 s limit while the host's load average was 88. That test exercises `link()` in-process; this PR's only change to `plugin-link.ts` is the removed `COMMAND_ALIASES` constant, and the test file's only change is that import. - Native Windows, once: identical to the first push. `plugin-launch` 39 pass / 8 skip, `plugin-link` 131 / 3 skip, `plugin-runtime` 2, `phone-setup` 3. `plugin-tui` and `plugin` fail the same 9 and 27 tests by name as main. The new SIGINT and missing-package cases are POSIX only and skipped there. - The run on 69ebe4b ended with all 15 checks green and no review thread. **First push, on 69ebe4b** - `bun run check fast` through the heavy-slot wrapper on the head 69ebe4b (rebased on 869ec34). It passed: workflow syntax, generated types and themes, typecheck, build, and 17658 unit tests passed, 0 failed, 54 skipped. - Each touched test file 20 times in a row on that head with `HERDR_TEST_MODE=unit bun test ./scripts/<file>`: - `plugin-launch.test.ts`: 20/20 - `plugin-tui.test.ts`: 20/20 - `plugin.test.ts`: 20/20 - `plugin-link.test.ts`: 20/20 - Native Windows, once, in the Windows 11 VM: the touched files plus `plugin-runtime.test.ts` and `phone-setup.test.ts`, on 7f7a4f43 (the same change before the rebase onto 869ec34), from a bundle clone. The POSIX-signal cases are skipped on Windows (`it.skipIf(win32)`). - Passed: `plugin-launch` 39 pass / 8 skip, `plugin-link` 131 pass / 3 skip, `plugin-runtime` 2 pass, `phone-setup` 3 pass. - `plugin-tui` (7 pass, 1 skip, 9 fail) and `plugin` (25 pass, 13 skip, 27 fail) fail on Windows on main too. I ran them on main's commit fccc9c4 in the same VM, and the failing tests are the same 9 and 27 by name. Neither file is in CI's Windows set. The new `runTui` spawn-throws case and the empty-`node_modules` case pass on Windows. **Before and after.** Each new regression case was run against main's sources (main's scripts with the new test files) and fails there: | point | test | on main | here | |---|---|---|---| | 1 | `plugin-tui.test.ts` "stops listening when the program cannot be started…" | listeners never removed; the SIGTERM handler throws | removed, no throw | | 1 | `plugin.test.ts` "link / a-later-command: stops listening when the release cannot be started…" | the process ends with an exit code, not by the SIGTERM (`signal: null`) | ends by SIGTERM | | 2 | `plugin-launch.test.ts` "names the first of two signals…" | 129 | 143 | | 3 | `plugin-launch.test.ts` "does not stop a build at a signal an earlier run in the same process was sent" | `{first: 143, code: 143, steps: 1}` | `{first: 143, code: 0, steps: 3}` | | 4 | `plugin-launch.test.ts` "exits with 128 + the platform's number…" | SIGKILL → 128 | 137 (SIGQUIT 131, SIGTERM 143) | | 5 | `plugin.test.ts` "load and answer with an empty node_modules…" | exit 1, `Cannot find package 'qrcode-generator'` | `status` → `down http://127.0.0.1:<port>`, `stop` → `Ovis is not running`, both 0 | | 7 | `plugin.test.ts` "phone-setup: listens before the release starts, passes it a SIGTERM / SIGHUP…" | `spawn 0 0` (no listener), exit 143 / 129, release left running | `spawn 1 1`, exit 3 / 4 (the release's own), none left | The tests showing that link, an unknown command and `runTui` listen before the spawn (`spawn 1 1`, and the order SIGINT, SIGTERM, SIGHUP, then spawn) pass on main too: since #3944 that order is right there. They add the coverage the #3944 review asked for. After the runs, `pgrep -af` on my scratch path found only `sleep 7200` restore leases that `server/pc-install.ts` leaves on purpose for its two-hour cleanup, started by `check fast`'s unit tests. I ended them, and `pgrep` then found nothing. Neither VM run left one: each Windows run's leftover shell came from the existing `stop > returns only once the server's process group is gone` case, which fails on Windows on main too. I ended it, and both clones were removed. **Not run:** `bun run check full`, the integration suite, the browser jobs and macOS. GitHub's run on this head covers them.
Change
What was wrong.
run()inscripts/plugin-launch.tsspawned its child and only then calledprocess.onfor SIGTERM, SIGHUP and SIGINT. The child is another process and can run ahead: when the launcher is descheduled between the two, the child is up before the handlers are, a SIGTERM in that gap ends the launcher by default (exit 143), is never passed on, and the child keeps running. It failed once in CI: "Fast checks" on #3935 (run 43804808022, job 133093602653),the launcher's child > gets the SIGTERM sent to the launcher, and the launcher exits as the child did:Expected 3, Received 143.The fix.
run()installs its handlers first and spawns inside thetrywhosefinallyremoves them (so a spawn that throws leaves no handler behind either). A signal that comes before the child exists is not lost: Bun runs a signal listener from the event loop, never in the middle of synchronous code, so a listener for a signal that came beforeBun.spawnreturned runs oncechildis set, and passes the signal on (checked on Bun 1.4.2: a SIGTERM sent to the process itself from synchronous code reached its listener only after that code ended). SIGINT keeps its meaning: the launcher ignores it and the terminal delivers it to the child.A stop that reaches a step already ended (second commit). Listening first has one order of its own, found in the merge pass's review: a SIGTERM that comes just before a short step starts can be dispatched only after that step has exited 0. It is passed on to nothing,
run()returns 0, andfromSourcewent on to start the next build step: at main the same signal ended the launcher (143) before the next step. The handler now records the signal (a module-levelstopped), andfromSourcechecks it after each step and before the next: if a SIGTERM or SIGHUP came, it stops there with 128 + its number (143, 129).run()itself still gives the child's own code, so a child that traps TERM and exits 5 still makes the launcher exit 5. Whether the signal comes before the step starts or after it has ended (and beforerun()returns), the recorded signal stops the build. Both orders were checked in scratch, 20 of 20 each: 143, and no further step.The other end: a signal whose listener runs after the child has exited, before
exitedresolved and the handlers were removed, callschild.killon a dead child. On Bun 1.4.2 that returns without throwing (checked:killafterawait child.exited), and the existingtry/catchstays around it. Betweenexitedresolving and thefinallyonly microtasks run, so no listener runs there. No test shows this case: which of the two event-loop callbacks comes first cannot be forced from outside.The other places that start a child and pass signals on (
process.on("SIG…andBun.spawninscripts/):scripts/plugin-launch.tsrun()scripts/plugin.tsrunPlugin, a command handed on to the release Settings → Updates installedlinkCommandalready does it.scripts/plugin-tui.tsrunTui(ovis tui)options.on; SIGINT was already first). Fixed here.scripts/plugin.tslinkCommandscripts/plugin.tsphoneSetup, handing on to the releasescripts/ci-tests.ts(unit workers)scripts/check.tsserver/managed.ts(outsidescripts/, the same shape)Bun.spawninscripts/(benches, regressions, QA harnesses,gh/git/docker/ffmpegcalls)Every place that runs children one after another through
run()(run()is called only inscripts/plugin-launch.ts):fromSource("install"):bun install,bun run build, the Rust PTY host stepmain'sbuild(), aroundfromSource("install")started: the build is not marked finished.fromSource(<command>)(oneplugin.tscommand) andmain's last line (the release's binary)run()calls (mainreading git, writing the stamp,installServerfetching)Faults that remain (older than this PR, not changed here):
scripts/plugin.tsphoneSetup, handing on to the release, passes no signal on (see the table above).Tests (
scripts/plugin-launch.test.ts, "the launcher's child"), five cases, each waiting for the launcher with a 10 s bound (a rejecting timer raced againstexited), so a launcher that hangs fails its test and still reaches thefinallythat kills it and the child by pid. Stderr goes to a file, not a pipe, which a child left running would hold open. No fixed sleep (the children'ssleep 0.05loop is the child idling).upon the stdout it shares with the launcher, and loops; once the test readsupit signals the launcher, which must exit 3 as the child did, with the child gone. No poll: it waits for the line.Bun.spawnhas been called and, throughprocess.on("newListener")(it runs insideprocess.on, before the listener is attached), holds the launcher where it starts listening for the signal if it has started the child by then, until the child, whose first action is to send it that signal, has sent it. A launcher that listens after the spawn is ended there (143 / 129) with the child left running; one that listens first is never held and passes the signal on. They assert exit 3 / 4 and that the child is gone (its pid answers nokill -0).main(["install"])underOVIS_FROM_SOURCE=1(sobuild()andfromSource), with aBun.spawnwrapper in the launcher script that replaces only the build steps: just before the first step starts, it sends the launcher the signal, startstrueand holds until that step has ended (pssays zombie, or it is gone), so the signal can only be passed on to a step already over; a later step records that it started. They assert exit 143 / 129 and no second step. Git, whichbuild()reads, runs as it is.All five are skipped on win32 as before: herdr runs
scripts/plugin.ps1there and no SIGTERM or SIGHUP reaches a launcher.No new test covers the
plugin.tsandplugin-tui.tsreorderings: they are the same two-line move, relying on the same Bun behaviour the tests above show forrun().Validation
All on Linux x86_64, Bun 1.4.2, on main a81ec59 (after #3940). Head 6e60ede: cab9f19 (handlers before the spawn) and 6e60ede (the build stops at a recorded signal; the tests below).
The tests, before and after (each
bun testrun 20 times in a row; the test file of this head;scripts/plugin-launch.tsswapped in from the named commit):-t "the launcher's child": 20 of 20 runs fail, on exactly the two start-instant cases every time:{ code: 143, childLeft: true }(SIGTERM) and{ code: 129, childLeft: true }(SIGHUP). The case of a SIGTERM while the child runs passes at main, as it should. So do the build-step cases, since main's launcher is ended by default before the next step.-t "starts no further build step": 20 of 20 runs fail, both cases every time:{ code: 0, secondStep: true }.bun test scripts/plugin-launch.test.ts(the whole file, 44 tests): 20 of 20 pass.yesprocesses on its cpus.finallykills the launcher and the child by pid (checked withpgrep -afon the scratch path after the runs).The reviewers' race, unforced (scratch; the signal is sent from a
Bun.spawnwrapper just before the first build steptruestarts, with no hold; 60 runs per signal per head, launcher pinned bytaskset): at cab9f19 and at this head, pinned to cpu 62 (an idle cpu of a heavy slot) and to cpu 0: all 60 exited 143 (SIGTERM) / 129 (SIGHUP), and no second step started. On this PC the forwarded signal reachedtruebefore it exited every time, so the race never lost the stop at cab9f19 here; the merge pass's reviewers saw it 13 and 10 times in 60. The held test above shows it every time. Also in scratch, 20 runs each: the signal sent just before the first step starts, or just after it has ended and beforerun()returns, both with the step over before the event loop runs: 20 of 20 exit 143 with no second step, in both orders.The rest:
%TEMP%clone of the branch at cab9f19 with the second commit applied (git apply, before it was pushed):bun test scripts/plugin-launch.test.ts: 39 pass, 5 skip (the five signal cases, win32), 0 fail. Clone and patch removed. For cab9f19:pr-check.ps1 -Pr 3944PASS and the whole file 39 pass, 2 skip (see the comment).bun test scripts/conventions.test.ts scripts/changelog-fold.test.ts: 32 pass. For cab9f19 alsoscripts/plugin-tui.test.ts(15),scripts/plugin.test.ts(55),scripts/plugin-link.test.ts(134): 0 fail. The second commit does not touch those files.bun run check faston this head's tree (in a heavy slot): exit 0. Workflow syntax (actionlint), generated types and themes, typecheck, build, unit tests (17616 pass, 0 fail, 54 skip in 972 files).child.kill("SIGTERM")afterawait child.exitedreturned without throwing.Skipped: macOS (the tests are not skipped there; not run on a Mac for this PR). The
pr-check.ps1run of the Windows CI steps was not repeated for the second commit, which touches no Windows path; GitHub's "Native Windows install" job runs on it. No new test for theplugin.tsandplugin-tui.tsreorderings.The changelog:
changelog.d/launcher-signal-while-child-starts.mdis new, and one sentence ofchangelog.d/plugin-launch-build-check.md(from #3940) is reworded, as the merge pass asked: "In that case" could be read as pointing at the "unless" before it.