Skip to content

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

Merged
devswha merged 2 commits into
mainfrom
fix/launcher-signal-handlers-before-spawn
Nov 16, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/launcher-signal-handlers-before-spawn

Conversation

@devswha

@devswha devswha commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Change

What was wrong. run() in scripts/plugin-launch.ts spawned its child and only then called process.on for 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 the try whose finally removes 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 before Bun.spawn returned runs once child is 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, and fromSource went 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-level stopped), and fromSource checks 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 before run() 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 exited resolved and the handlers were removed, calls child.kill on a dead child. On Bun 1.4.2 that returns without throwing (checked: kill after await child.exited), and the existing try/catch stays around it. Between exited resolving and the finally only 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… and Bun.spawn in scripts/):

Where Verdict
scripts/plugin-launch.ts run() Same order. Fixed here.
scripts/plugin.ts runPlugin, a command handed on to the release Settings → Updates installed Same order (spawn, then SIGTERM/SIGHUP). Fixed here, the way linkCommand already does it.
scripts/plugin-tui.ts runTui (ovis tui) Same order (spawn, then SIGTERM/SIGHUP through options.on; SIGINT was already first). Fixed here.
scripts/plugin.ts linkCommand Already listens before the release starts (#3808).
scripts/plugin.ts phoneSetup, handing on to the release Passes no signal on at all: a SIGTERM to it ends it and leaves the release's phone-setup running. Not the same order, a separate fault; left as it is.
scripts/ci-tests.ts (unit workers) Handlers are installed before the first file starts; they pass the signal to the files' process groups. Fine. Its serial and integration paths pass nothing on: their files share its process group.
scripts/check.ts Handlers (around line 1283) are installed before its first step runs. Fine.
server/managed.ts (outside scripts/, the same shape) Handlers before the first spawn. Fine.
Every other Bun.spawn in scripts/ (benches, regressions, QA harnesses, gh/git/docker/ffmpeg calls) Passes no signal on to a long-lived child; cleanup handlers only. Not this pattern.

Every place that runs children one after another through run() (run() is called only in scripts/plugin-launch.ts):

Where After a SIGTERM or SIGHUP
fromSource("install"): bun install, bun run build, the Rust PTY host step The only sequence. A step the signal reached ends by it (non-zero: the loop returns it); a step it reached only after the step had ended returns 0, and the recorded signal now stops the loop (143/129). Fixed here.
main's build(), around fromSource("install") Returns that code before it reads git's commit again or stamps the build, so the stamp stays started: the build is not marked finished.
fromSource(<command>) (one plugin.ts command) and main's last line (the release's binary) One child each: the launcher exits as that child did.
Between two run() calls (main reading git, writing the stamp, installServer fetching) No listener is installed there: the signal ends the launcher by default (143/129) with no child running, as at main.

Faults that remain (older than this PR, not changed here):

  • A child ended by a signal other than SIGHUP, SIGINT or SIGTERM gives 128, not 128 + its number: SIGKILL gives 128 (137 expected), SIGQUIT 128 (131).
  • scripts/plugin.ts phoneSetup, 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 against exited), so a launcher that hangs fails its test and still reaches the finally that 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's sleep 0.05 loop is the child idling).

  • The SIGTERM sent while the child runs (the case main had, kept as its own): the child writes its pid, says up on the stdout it shares with the launcher, and loops; once the test reads up it signals the launcher, which must exit 3 as the child did, with the child gone. No poll: it waits for the line.
  • A SIGTERM / SIGHUP that comes the instant the child starts (two cases): the launcher script records whether Bun.spawn has been called and, through process.on("newListener") (it runs inside process.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 no kill -0).
  • No further build step after a SIGTERM / SIGHUP that found its step already ended (two cases): the real main(["install"]) under OVIS_FROM_SOURCE=1 (so build() and fromSource), with a Bun.spawn wrapper in the launcher script that replaces only the build steps: just before the first step starts, it sends the launcher the signal, starts true and holds until that step has ended (ps says 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, which build() reads, runs as it is.

All five are skipped on win32 as before: herdr runs scripts/plugin.ps1 there and no SIGTERM or SIGHUP reaches a launcher.

No new test covers the plugin.ts and plugin-tui.ts reorderings: they are the same two-line move, relying on the same Bun behaviour the tests above show for run().

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 test run 20 times in a row; the test file of this head; scripts/plugin-launch.ts swapped in from the named commit):

  • At main a81ec59, -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.
  • At cab9f19 (the first commit alone), -t "starts no further build step": 20 of 20 runs fail, both cases every time: { code: 0, secondStep: true }.
  • At this head, bun test scripts/plugin-launch.test.ts (the whole file, 44 tests): 20 of 20 pass.
  • The first commit's own runs, for reference: its whole file passed 20 of 20, and 20 of 20 inside a heavy slot of 2 cores with 8 yes processes on its cpus.
  • Neither test's held state leaves a process behind: the finally kills the launcher and the child by pid (checked with pgrep -af on the scratch path after the runs).

The reviewers' race, unforced (scratch; the signal is sent from a Bun.spawn wrapper just before the first build step true starts, with no hold; 60 runs per signal per head, launcher pinned by taskset): 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 reached true before 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 before run() 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:

  • Windows VM (Windows 11): a fresh %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 3944 PASS 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 also scripts/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 fast on 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).
  • Bun behaviour the fix relies on, checked in a scratch script: a SIGTERM the process sent itself, followed by 200 ms of synchronous code, reached its listener only after that code ended; child.kill("SIGTERM") after await child.exited returned without throwing.

Skipped: macOS (the tests are not skipped there; not run on a Mac for this PR). The pr-check.ps1 run 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 the plugin.ts and plugin-tui.ts reorderings.

The changelog: changelog.d/launcher-signal-while-child-starts.md is new, and one sentence of changelog.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.

…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.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • SIGTERM and SIGHUP received while a command, terminal client, or update process is starting are now forwarded to that process, preventing it from being left running after the launcher exits.
    • Launches built from a different version—or from a different commit when available—show a notice identifying the versions and the rebuild command.

The launcher, TUI, and fallback release dispatcher now register SIGTERM and SIGHUP handlers before spawning child processes. Tests cover both signals during startup. Changelog entries document startup signal forwarding and build notices.

Changes: Startup signal forwarding

Layer / File(s) Summary
Register signal handlers before spawning
scripts/plugin-launch.ts, scripts/plugin-tui.ts, scripts/plugin.ts, scripts/plugin-launch.test.ts, changelog.d/launcher-signal-while-child-starts.md
The three launcher paths register SIGTERM and SIGHUP handlers before spawning. Tests cover both signals during startup. The changelog describes the behavior.

Build notice changelog

Layer / File(s) Summary
Document build notices
changelog.d/plugin-launch-build-check.md
The changelog describes startup notices for builds from another version or commit, including the condition for showing the notice.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to cab9f

This change makes the launcher forward SIGTERM and SIGHUP to a command that is still starting, instead of exiting and leaving that command running. No concrete defect remains after review, and the changelog entries match the code. It is low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the launcher registers SIGTERM and SIGHUP handlers before it starts its child, so a signal in that window no longer leaves the child running. It is specific and matche…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the template's two sections, Change and Validation. The Change section explains the bug (handlers registered after spawn), the fix, the affected call sites, remaining faults, a…
Full details: Title check

Explanation

The title names the main change: the launcher registers SIGTERM and SIGHUP handlers before it starts its child, so a signal in that window no longer leaves the child running. It is specific and matches the changeset. The title is long (142 characters), but the content is accurate.

Full details: Description check

Explanation

The description follows the template's two sections, Change and Validation. The Change section explains the bug (handlers registered after spawn), the fix, the affected call sites, remaining faults, and the new tests. The Validation section lists the Linux and Windows test runs, the check fast run, the Bun behaviour checks, and what was skipped (macOS, the pr-check Windows steps, and new tests for the plugin.ts and plugin-tui.ts reorderings). The description is long and dense, but it covers the required content. It does not link a maintainer-agreed issue for the change. The template asks for that only for features; this is a bug fix, so the omission is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a81ec59 and cab9f19.

Files selected for processing: 6

  • changelog.d/launcher-signal-while-child-starts.md
  • changelog.d/plugin-launch-build-check.md
  • scripts/plugin-launch.test.ts
  • scripts/plugin-launch.ts
  • scripts/plugin-tui.ts
  • scripts/plugin.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@devswha

devswha commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

Windows VM (Windows 11, ssh winvm, in its desktop session), head cab9f19:

  • pr-check.ps1 -Pr 3944 (this PR's Windows CI steps, in a fresh %TEMP% clone): PR-CHECK PASS. windows-install.test.ps1, preflight, bun install --frozen-lockfile, bun run build, bun test of the Windows set (51 tests across 5 files, 1 skip, exit 0), windows-terminal-browser-qa.ts; clone removed.
  • bun test scripts/plugin-launch.test.ts (the whole file; it is not in that Windows set), in a fresh %TEMP% clone of this branch at the same head: 39 pass, 2 skip, exit 0. The two skipped are the new signal tests (it.skipIf(process.platform === "win32"), as the test they replace was: herdr runs scripts/plugin.ps1 there and no SIGTERM or SIGHUP reaches a launcher). Clone removed.

…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.
@devswha
devswha merged commit fccc9c4 into main Nov 16, 2026
16 checks passed
@devswha

devswha commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 6e60ede02865 as fccc9c48cf58 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

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.
Two reviewers, two rounds. The first head lost a stop request in one order of events (a signal just before a short build step that exits 0: the next build step started, where main stopped): both reviewers reproduced it; now the received signal is recorded and checked between build steps (60 of 60 pinned runs exit 143 and no later step starts), while a single command still exits as its child did (a child that traps TERM and exits 5 gives 5).
The new tests hit the window on purpose, with a hook and bounded waits, not by timing; each fails against the launcher it guards against. scripts/plugin.ts and scripts/plugin-tui.ts get the same reordering. The earlier changelog fragment's unclear sentence is reworded here.
Reviewers ran scripts/plugin-launch.test.ts (44 pass) and the signal tests three times; Windows was read, not run.

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.

@devswha
devswha deleted the fix/launcher-signal-handlers-before-spawn branch November 16, 2026 06:14
devswha added a commit that referenced this pull request Nov 16, 2026
…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.
devswha added a commit that referenced this pull request Nov 16, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant