feat: reins restart, and a stale daemon restarts itself after an upgrade - #39
Merged
Merged
Conversation
After `npm i -g @karnstack/reins@latest` the background daemon kept running the old code until someone knew to `reins kill` it. Now: - ensureDaemon restarts a live daemon whose /health version is older than the CLI. Only older: a newer daemon is left alone so two installed CLI versions can't bounce it back and forth. - `reins restart` stops the daemon, waits for its port to go quiet, spawns a fresh one and waits for previously connected browsers to reconnect. - `reins kill` now waits until the daemon has actually exited, so a command straight after it can't reach the dying process. The old service-manager `restart` (launchd/systemd) was removed in 4e7cf33; this one is for the spawn-on-demand daemon, so the help-text guard against it is dropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-ups for the restart / restart-on-upgrade work: - stopDaemon treats a rejected /shutdown as "already going"; the /health poll decides. - Stop and spawn run under a best-effort lockfile (~/.reins/daemon.lock, stale by dead pid or age, never blocks longer than 10s), and the decision is re-made once it's held. A parallel CLI can no longer /shutdown the daemon another one just started, and parallel spawns collapse into one. A daemon found under the lock counts as fresh, so callers wait for the extension to reconnect. - Auto-restart that can't stop the old daemon warns and uses it as-is instead of failing every command; explicit restart/kill still error. - "0.0.0" (unreadable package.json) never triggers a restart. - findDaemon prefers the lowest live port, the one lowerPortRival keeps. - reins restart reports each case truthfully and exits 1 when browsers that were connected don't come back within 15s. - reins doctor flags a daemon/CLI version mismatch; reins status hints when the daemon is older. Docs and changeset match what auto-restarts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Follow-ups from the review, in d98bb8c:
Checked against a real Chrome, with a daemon from a copy of the build stamped v0.4.0:
Before the "found under the lock counts as fresh" fix, 4 of those 5 failed with 244 tests pass; lint and typecheck are clean. |
doctor told users to `reins restart` on any daemon/CLI version mismatch. When the daemon is newer (a second, newer install started it), a restart from this older CLI downgrades the daemon, and the newer CLI's next command bumps it straight back up. For that direction doctor now says to upgrade this CLI or look for a second install with `which -a reins`. Versions that differ only by pre-release tag pass, matching the restart logic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
After
npm i -g @karnstack/reins@latest, the background daemon kept running the old code./healthalready reports the daemon's version, but nothing compared it with the CLI's, and there was no restart command, onlyreins killplus knowing that the daemon respawns on demand.What
reins tabsetc., pluspolicyandextension --reload) restarts a daemon older than the CLI and printsreins: daemon runs v0.4.0, CLI is v0.5.0 — restarting itto stderr.0.0.0(unreadable package.json) never triggers a restart.reins restart: stops the daemon, waits for its port to go quiet, spawns a fresh one, and waits up to 15s for previously connected browsers to come back. It exits 1 if they don't:reins kill: now waits until the daemon has actually exited. A rejected/shutdowncounts as "already stopping".~/.reins/daemon.lock, newlock.ts), and the decision is re-made once the lock is held./shutdowna daemon another command just started, and parallel spawns collapse into one.findDaemonprefers the lowest live port, which is the onelowerPortRivalkeeps.reins doctor: flags a version mismatch.run reins restart.which -a reins, since a restart from the older CLI would downgrade the daemon.reins status: shows a hint when the daemon is older than the CLI.reins allow,docs/RUNNING.md, the web command table, and a new FAQ entry ("How do I update reins?") are updated. Changeset:@karnstack/reinsminor.The old
restart(launchd/systemd service restart) was removed in 4e7cf33. This one is for the spawn-on-demand daemon, so thehelpTexttest no longer asserts thatrestartis absent.Testing
pnpm lint,pnpm typecheck, and the CLI tests pass (246). Tests cover the lock (real temp dirs, stale by dead pid and by age, timeout), ordering under the lock, a rejected/shutdown, a failed auto-restart, the0.0.0guard, each restart outcome, and the doctor check in both directions.reins restartwith a browser connected: back in about 1.3s. With nothing running, it starts a daemon.reins tabsagainst a v0.4.0 daemon: all exit 0, one restart notice, one daemon left (v0.5.0), no lockfile left over.reins tabswith no daemon running: all exit 0, one daemon.doctorsays the CLI is outdated, andreins tabsruns without downgrading the daemon.🤖 Generated with Claude Code