Skip to content

fix(install): stop and status load without packages, the commands that need them fail before any change, SIGINT/TERM/HUP reach the release, and a child's death by any signal is 128 + n - #3953

Merged
devswha merged 2 commits into
mainfrom
fix/plugin-signal-and-load-faults
Nov 16, 2026

Conversation

@devswha

@devswha devswha commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

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 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 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.

…es signals on, and the launcher names the first signal and any signal's code

- scripts/plugin.ts loads no application package: the QR code, the relay offer and scripts/plugin-link.ts are imported by the commands that use them, and COMMAND_ALIASES moves to scripts/plugin-runtime.ts, so stop and status work over a checkout whose install was cut off.
- One handOn() runs the release Settings > Updates installed for link, phone-setup and an unknown command: listeners before the spawn, child?.kill, and removed on every way out (phone-setup listened for nothing before).
- runTui's signal listeners use child?.kill and are removed on every way out, the spawn that throws included.
- scripts/plugin-launch.ts: the build's signal record is the fromSource call's own and keeps the first signal; a child ended by any signal gives 128 + its number (os.constants.signals).
@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
    • Fixed the plugin’s stop and status commands so they work from checkouts with incomplete package installations.
    • Improved signal handling when commands are handed off to an installed release, including forwarding termination signals and returning appropriate exit results.
    • Fixed launcher behavior so the first received signal determines the build result and prevents subsequent build steps from running.
    • Ensured signal handlers are cleaned up after the terminal interface exits or fails to start.

The plugin changes defer selected dependencies until their commands run, forward signals during release handoff, and remove TUI signal listeners after completion. The launcher now tracks signals per call and derives child signal exit codes from platform signal numbers.

Changes: Plugin command and signal lifecycle

Layer / File(s) Summary
Command dependencies and aliases
scripts/plugin.ts, scripts/plugin-runtime.ts, scripts/plugin-link.ts, scripts/plugin.test.ts, scripts/plugin-link.test.ts
Plugin commands load QR, pairing, and link dependencies at their use sites. COMMAND_ALIASES moves to plugin-runtime.ts. Tests cover status and stop from a checkout with an empty node_modules.
Release handoff and signal forwarding
scripts/plugin.ts, scripts/plugin.test.ts
handOn starts the active release script, forwards SIGTERM and SIGHUP, and removes listeners when it finishes. Link, phone setup, and unknown-command dispatch use this helper.
TUI signal listener cleanup
scripts/plugin-tui.ts, scripts/plugin-tui.test.ts, scripts/plugin.ts
TUI signal registration returns cleanup functions. runTui removes listeners after child completion or spawn failure; tests cover registration order, signal forwarding, and cleanup.
Launcher signal state and exit codes
scripts/plugin-launch.ts, scripts/plugin-launch.test.ts, changelog.d/plugin-stop-without-packages.md
The launcher uses per-call signal state, stops later build steps after a signal, and derives child signal exit codes from platform signal numbers. Tests cover signal ordering, sequential calls, and additional terminating signals.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related PRs

  • devswha/ovis#3944: Updates signal-handler registration and cleanup in the same launcher, plugin, and TUI scripts.
Merge Risk: Minimal · up to 69ebe

This change lets stop and status run without installed application packages, forwards signals during release handoff, and fixes launcher exit codes for signals. No concrete merge-blocking defect was found, and the main concern about link codes being issued after a signal was ruled out.

Pre-merge checks: Passed 4

Check name Status Explanation
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.
Title check Passed The title is a long, comma-chained list of six separate changes (stop/status loading without packages, command failure ordering, SIGINT/TERM/HUP forwarding, and 128 + n exit codes). It is accurate to …
Description check Passed The description covers the change in detail with a numbered list of what changes, a rationale for each point, and an extensive Validation section with commands and results. It follows the template's C…
Full details: Title check

Explanation

The title is a long, comma-chained list of six separate changes (stop/status loading without packages, command failure ordering, SIGINT/TERM/HUP forwarding, and 128 + n exit codes). It is accurate to the changeset but overly long at 184 characters and 31 words, so it is not concise. It does reference real, central parts of the change, so it is not off-topic.

Full details: Description check

Explanation

The description covers the change in detail with a numbered list of what changes, a rationale for each point, and an extensive Validation section with commands and results. It follows the template's Change and Validation sections. It does not link a maintainer-agreed issue, which the template asks for only for features, and this PR is a fix. The description is long and dense, but it is mostly complete.

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 869ec34 and 69ebe4b.

Files selected for processing: 10

  • changelog.d/plugin-stop-without-packages.md
  • scripts/plugin-launch.test.ts
  • scripts/plugin-launch.ts
  • scripts/plugin-link.test.ts
  • scripts/plugin-link.ts
  • scripts/plugin-runtime.ts
  • scripts/plugin-tui.test.ts
  • scripts/plugin-tui.ts
  • scripts/plugin.test.ts
  • scripts/plugin.ts

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

…pass a SIGINT on to the release

- pair, phone-setup, phone, link and pair --approve import what they need before anything they change (a pairing code, Tailscale, a decision), so a checkout whose install was cut off fails with nothing changed.
- handOn passes a SIGINT sent to the checkout on to the release (not on Windows, where Bun would end the release outright); a Ctrl+C reaches the release twice, which it ends at or catches.
- The changelog says what the launcher reports: a child's death by any signal as 128 + its number.
@devswha devswha changed the title fix(install): stop and status load without packages, phone setup passes signals on, and the launcher names the first signal and any signal's code fix(install): stop and status load without packages, the commands that need them fail before any change, SIGINT/TERM/HUP reach the release, and a child's death by any signal is 128 + n Nov 16, 2026
@devswha
devswha merged commit 9d17bcd into main Nov 16, 2026
15 of 16 checks passed
@devswha
devswha deleted the fix/plugin-signal-and-load-faults branch November 16, 2026 08:51
@devswha

devswha commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 69249e2e3d4e as 9d17bcdd74eb on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

devswha added a commit that referenced this pull request Nov 16, 2026
…he fleet preview (#3955)

## Change

Changes what `ovis add` (also `ovis link` and `ovis login`) does under
the fleet preview, `OVIS_PREVIEW=fleet`
(`server/preview.ts`, from #3938, which this pull request builds on). No
release sets that variable. The plugin
reads it from its environment or its
settings file (`env`, `.env`), the merged settings the server it starts
gets. With it unset, `ovis add` does what
`main` does.

Under `OVIS_PREVIEW=fleet`, `ovis add` without `--approve`, in the order
a person meets it:

- If its output or its input is not a terminal, with or without
`--print`, it does not start the sign-in. It
prints one line saying that adding this PC needs a terminal and exits 1.
It lists nothing and shows no code.
  With the preview unset, `--print` behaves as before.
- The sign-in itself is unchanged.
- After the sign-in, it names the account that signed in and the
provider it used: `Signed in as Ovis account
<id> (signed in with GitHub). Press Enter to show the QR code for this
account's phone, or press Ctrl+C if that is
not your account:`. Until Enter is pressed, this PC is not listed in
that account and no code is made.
- A line that is empty, or holds only spaces, lists this PC in the
account (`This PC is listed in that account as
<name>.`). It then shows the QR code as before, on a screen of its own,
or with `--print` as lines that stay.
- Any other line, or the end of the input (Ctrl+D), prints `The QR code
was not shown, and this PC was not listed
  in that account.` with what to run again, and exits 1.
- Some lines answer nothing, and the question is asked again:
  - a line that comes less than 1.5 s after the question shows;
- the first line, where the terminal's input could not be emptied as the
question showed.
  This is the same rule the existing questions of `ovis add` use.
- Under the preview, two variables change what the command names:
- The app the server pairs with (`OVIS_RELAY_APP_URL`; its offers carry
it) replaces `app.ovis.sh` in the code
lines of `ovis add` and `ovis link --code` and in the `--approve` line.
- `OVIS_CLI_NAME`, for a wrapper that runs the plugin under another
name, replaces `ovis` in the commands
    `ovis add` says to run.

`ovis add --approve` gets neither the terminal check nor the Enter step.
Under the preview, only the app it names
changes.

With `OVIS_PREVIEW` unset (or set to a list without the word `fleet`),
nothing changes, whatever
`OVIS_RELAY_APP_URL` and `OVIS_CLI_NAME` say. The one change in
`scripts/plugin.ts` passes `OVIS_RELAY_APP_URL` on
to `link`, which reads it only under the preview.

A changelog fragment is included
(`changelog.d/add-confirm-under-fleet-preview.md`).

Five follow-ups rated low in review are in #3957.

## Validation

On this head, which holds `main` 9d17bcd: `main` was merged in after
#3953 changed the same files (two conflicts,
both in import lines: `linkSettings` now comes with `link`'s deferred
import of `scripts/plugin-link.ts`):

- `bun run typecheck`: passed.
- One run of `bun test scripts/plugin-link.test.ts
scripts/plugin.test.ts`: 213 pass, 0 fail (with `main`'s new tests
  of a checkout whose packages are not installed).
- `bun run check fast`: passed (workflow syntax, generated types and
themes, typecheck, build; unit tests 17,705
  pass, 0 fail, 54 skip).
- macOS arm64 (27.0.1), Bun 1.4.2, in a fresh clone of this pull
request's head (535de9e): the same two test
  files, 211 pass, 2 skip, 0 fail.
- `main` e5c6a8e and this branch two revisions before this head (before
the settings-file change and before
  `main` 9d17bcd was merged in), side by side
with `OVIS_PREVIEW` unset, by a reviewer that did not write it, through
the real `scripts/plugin.ts`: `add`,
`add --print`, `add --approve`, `link --code`, `status`, `help` and an
unknown command; piped and at a pty; the two
variables unset and set; `OVIS_PREVIEW` unset, empty, `fleets` and
`no-fleet`: 112 runs a side under `strace`,
against a local stand-in for the PC and an account service that refuses
connections. Output (the pty's bytes
too), exit codes, the calls to the PC and the `connect` and `execve`
calls were the same. These runs reach the
refusal, the sign-in failing, `link --code` and usage; the QR, Enter and
approve paths are compared in the
  in-process runs below.
- New tests in `scripts/plugin-link.test.ts`:
- under the preview: the refusal without a terminal (output, input,
`--print`, and a list that names `fleet`
beside another word); the account named before anything is listed, with
Enter, other lines (`no`, `y`, ` x `)
and Ctrl+D; the line that comes too soon and the first line where the
input could not be emptied; both
variables taking effect; the preview set only in the plugin's settings
file (the refusal through the real
command, the Enter step in-process through the plugin's own merge of its
settings);
- a control with the preview unset (also `""`, `fleets`, `no-fleet`),
run once with nothing set and once with
both variables set. It expects `main`'s lines: `--print` to a pipe
writes the code, no Enter step, `app.ovis.sh`
    and `ovis` in what is printed;
- one run of the real `scripts/plugin.ts add` with its output piped: the
refusal under the preview, `main`'s
    sentence without it.
- These tests fail when the preview condition is removed:
- The preview-unset controls failed with the condition removed from the
terminal check and the Enter step (on
    the first version of this branch).
- The control also failed with the condition removed from the app name
and from the command name (on this
    code).
- `main` 9d17bcd and this head, with `OVIS_PREVIEW` unset, compared
side by side by the author (the real
  `scripts/plugin.ts` also for `status`, `stop` and `help`):
- `link` was driven in-process, with the test file's fake PC, fake
account service and a fixed clock, through 14
runs: plain add, `--print` at a terminal, `--print` with the output and
with both output and input not a
terminal, output only or input only not a terminal, the account service
off (with and without `--print`),
already in an account, nobody scanning for 30 minutes, Ctrl+C while the
code shows, a device kept out by
    Enter, `link --code`, and `--approve`.
- The real `scripts/plugin.ts add` and `add --print` were run with
stdout a pipe, with the account service
    unreachable and off.
- Each was run three ways: nothing set, `OVIS_RELAY_APP_URL` set,
`OVIS_CLI_NAME` set; the real command also
with the two names set only in the settings file. The output, exit
codes, calls to the PC and calls to the
    account service were the same.

Not run: the Enter step with a person at a real terminal, or through the
real command with the preview only in
the settings file; under the preview, the QR and approve paths through
the
real command (in-process only); a real account service, relay or phone;
Windows.
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