fix(home): always converge backpass and acpx to the latest npm release on rebuild #19

Merged
hermes merged 4 commits from fm/dotfiles-backpass-latest into main 2026-11-11 13:15:57 -05:00
Owner

Policy

Before: backpass and acpx were installed only when their binary was missing, so a rebuild never changed their version and the installed backpass had fallen 16 releases behind (0.1.28 against 0.1.44).

After: every rebuild reads each package's installed version and the registry's latest, and installs only when they differ, so a current copy costs no install and a stale one always converges.

Behaviour offline and while a package is running

  • Registry unreachable: each package prints cannot read the latest version from the npm registry (offline?) - keeping the installed copy, rebuild continues and the switch carries on with exit 0. An install that fails prints install of <version> failed - keeping the installed copy, rebuild continues and the switch also carries on.
  • A backpass or acpx process is running: the install still happens. The switch adds one informational line: <pkg>: a running process keeps the code it already loaded - <latest> takes effect at its next start. No deferral, no skip.
  • Versions already match: <pkg>: already at <version> and no install command runs.

Change

home.activation.backpass in home.nix gains one shared converge_npm_global function, called once for backpass and once for acpx. Each call reads the installed version from npm ls -g --depth=0, reads the published version with npm view <pkg> version (15s fetch timeout, one retry), installs <pkg>@<latest> only when the two differ, and then checks pgrep -f /opt/homebrew/bin/<pkg> purely to print the running-process notice.

Every optional step returns 0, so set -e never aborts the switch and later activation blocks still run. The existing PATH fix and the Homebrew-npm missing guard are unchanged, and Homebrew's npm stays the only npm used. No flake input and no nix package was added.

Proof

The script under test was not retyped. nix eval --raw .#darwinConfigurations.lt-mbp.config.home-manager.users.laptran.home.activation.backpass.data printed the activation string and diff confirmed it byte-identical to the extracted script the runs below used:

IDENTICAL: extracted script == nix-evaluated activation string

How the versions were simulated. The real global prefix was left untouched. Each run pointed npm's own global prefix at a sandbox directory (npm_config_prefix=$SANDBOX), so npm ls -g and npm install -g wrote there instead of /opt/homebrew. The registry side was the real npm registry (backpass 0.1.44, acpx 0.22.0 at proof time). The "installed" side was seeded by writing package.json files carrying this machine's current versions (0.1.28 and 0.19.3). Each run appended echo "LATER BLOCK RAN" after the script to prove set -e did not abort later steps, and runs marked "trace" used bash -x to show whether an install command executed.

1. Installed version behind the registry: install runs, even with a live process

A long-running dummy matching each pattern was added on top of the real ones: /usr/bin/perl -e 'sleep 45' /opt/homebrew/bin/backpass (same for acpx). pgrep -fl showed them alongside genuine backpass and acpx sessions then running on the machine.

===== CASE 4: dummy long-running processes matching each pattern =====
9624 /usr/bin/perl -e sleep 45 /opt/homebrew/bin/backpass
87545 node /opt/homebrew/bin/backpass --analysis-agent opencode --analysis-model ...
9625 /usr/bin/perl -e sleep 45 /opt/homebrew/bin/acpx
58057 node /opt/homebrew/bin/acpx --cwd /Users/laptran/Documents/firstmate ...
backpass: updating 0.1.28 -> 0.1.44
changed 1 package in 141ms
backpass: installed 0.1.44
backpass: a running process keeps the code it already loaded - 0.1.44 takes effect at its next start
acpx: updating 0.19.3 -> 0.22.0
changed 42 packages in 1s
acpx: installed 0.22.0
acpx: a running process keeps the code it already loaded - 0.22.0 takes effect at its next start
LATER BLOCK RAN
exit=0

2. Installed version already matches: no install call

-- stdout:
backpass: already at 0.1.44
acpx: already at 0.22.0
LATER BLOCK RAN
script exit=0
-- install commands:
(none)
-- version decisions:
+ installed=0.1.44
+ latest=0.1.44
+ installed=0.22.0
+ latest=0.22.0

3. Registry unreachable: warning, exit 0, no install

Sandbox reset to stale, registry pointed at a closed port (npm_config_registry=http://127.0.0.1:9/):

===== CASE 3: registry unreachable =====
backpass: cannot read the latest version from the npm registry (offline?) - keeping the installed copy, rebuild continues
acpx: cannot read the latest version from the npm registry (offline?) - keeping the installed copy, rebuild continues
LATER BLOCK RAN
exit=0

4. Install fails: warning, exit 0

Earlier in this work, with a read-only sandbox prefix so the install could not write:

backpass: updating 0.1.28 -> 0.1.44
backpass: install of 0.1.44 failed - keeping the installed copy, rebuild continues
acpx: updating 0.19.3 -> 0.22.0
acpx: install of 0.22.0 failed - keeping the installed copy, rebuild continues
LATER BLOCK RAN

Why the pgrep patterns use the global bin path

A shebang script launched through a symlink keeps the invoked path in argv. Verified locally with a node script and a symlink:

$ ps -Ao pid,command | grep backpass
32011 node /private/.../bin/backpass --some-arg
$ pgrep -f "node_modules/backpass/bin/backpass.js"   # source path
(no match)
$ pgrep -f "bin/backpass"                            # invoked path
32011

That is why the notice matches /opt/homebrew/bin/backpass and /opt/homebrew/bin/acpx, and why pgrep -fl above lists the real sessions by those paths.

Found by the pipeline and fixed

  • backpass-guard-always (ask-user): the first draft skipped a package while a process was running, which contradicted "always pulls the latest". Fixed: install always runs, and a running process only gets the informational notice.
  • pgrep-pattern-dead (auto-fix): the first notice built on source-path patterns could never match a real launch. Fixed to the invoked global-bin paths, and verified independently as shown above.
  • The document step corrected the stale home.activation.securityAuditSkill comment that still said the skill skips "like backpass"; it now says "unlike backpass which tracks the latest release".

acpx is under the same policy per the follow-up instruction, so the earlier open question about it is answered by this change rather than left as a note.

## Policy **Before:** `backpass` and `acpx` were installed only when their binary was missing, so a rebuild never changed their version and the installed `backpass` had fallen 16 releases behind (0.1.28 against 0.1.44). **After:** every rebuild reads each package's installed version and the registry's latest, and installs only when they differ, so a current copy costs no install and a stale one always converges. ## Behaviour offline and while a package is running - **Registry unreachable:** each package prints `cannot read the latest version from the npm registry (offline?) - keeping the installed copy, rebuild continues` and the switch carries on with exit 0. An install that fails prints `install of <version> failed - keeping the installed copy, rebuild continues` and the switch also carries on. - **A `backpass` or `acpx` process is running:** the install still happens. The switch adds one informational line: `<pkg>: a running process keeps the code it already loaded - <latest> takes effect at its next start`. No deferral, no skip. - **Versions already match:** `<pkg>: already at <version>` and no install command runs. ## Change `home.activation.backpass` in `home.nix` gains one shared `converge_npm_global` function, called once for `backpass` and once for `acpx`. Each call reads the installed version from `npm ls -g --depth=0`, reads the published version with `npm view <pkg> version` (15s fetch timeout, one retry), installs `<pkg>@<latest>` only when the two differ, and then checks `pgrep -f /opt/homebrew/bin/<pkg>` purely to print the running-process notice. Every optional step returns 0, so `set -e` never aborts the switch and later activation blocks still run. The existing PATH fix and the Homebrew-npm missing guard are unchanged, and Homebrew's npm stays the only npm used. No flake input and no nix package was added. ## Proof The script under test was not retyped. `nix eval --raw .#darwinConfigurations.lt-mbp.config.home-manager.users.laptran.home.activation.backpass.data` printed the activation string and `diff` confirmed it byte-identical to the extracted script the runs below used: ``` IDENTICAL: extracted script == nix-evaluated activation string ``` **How the versions were simulated.** The real global prefix was left untouched. Each run pointed npm's own global prefix at a sandbox directory (`npm_config_prefix=$SANDBOX`), so `npm ls -g` and `npm install -g` wrote there instead of `/opt/homebrew`. The registry side was the real npm registry (`backpass` 0.1.44, `acpx` 0.22.0 at proof time). The "installed" side was seeded by writing `package.json` files carrying this machine's current versions (0.1.28 and 0.19.3). Each run appended `echo "LATER BLOCK RAN"` after the script to prove `set -e` did not abort later steps, and runs marked "trace" used `bash -x` to show whether an install command executed. ### 1. Installed version behind the registry: install runs, even with a live process A long-running dummy matching each pattern was added on top of the real ones: `/usr/bin/perl -e 'sleep 45' /opt/homebrew/bin/backpass` (same for `acpx`). `pgrep -fl` showed them alongside genuine `backpass` and `acpx` sessions then running on the machine. ``` ===== CASE 4: dummy long-running processes matching each pattern ===== 9624 /usr/bin/perl -e sleep 45 /opt/homebrew/bin/backpass 87545 node /opt/homebrew/bin/backpass --analysis-agent opencode --analysis-model ... 9625 /usr/bin/perl -e sleep 45 /opt/homebrew/bin/acpx 58057 node /opt/homebrew/bin/acpx --cwd /Users/laptran/Documents/firstmate ... backpass: updating 0.1.28 -> 0.1.44 changed 1 package in 141ms backpass: installed 0.1.44 backpass: a running process keeps the code it already loaded - 0.1.44 takes effect at its next start acpx: updating 0.19.3 -> 0.22.0 changed 42 packages in 1s acpx: installed 0.22.0 acpx: a running process keeps the code it already loaded - 0.22.0 takes effect at its next start LATER BLOCK RAN exit=0 ``` ### 2. Installed version already matches: no install call ``` -- stdout: backpass: already at 0.1.44 acpx: already at 0.22.0 LATER BLOCK RAN script exit=0 -- install commands: (none) -- version decisions: + installed=0.1.44 + latest=0.1.44 + installed=0.22.0 + latest=0.22.0 ``` ### 3. Registry unreachable: warning, exit 0, no install Sandbox reset to stale, registry pointed at a closed port (`npm_config_registry=http://127.0.0.1:9/`): ``` ===== CASE 3: registry unreachable ===== backpass: cannot read the latest version from the npm registry (offline?) - keeping the installed copy, rebuild continues acpx: cannot read the latest version from the npm registry (offline?) - keeping the installed copy, rebuild continues LATER BLOCK RAN exit=0 ``` ### 4. Install fails: warning, exit 0 Earlier in this work, with a read-only sandbox prefix so the install could not write: ``` backpass: updating 0.1.28 -> 0.1.44 backpass: install of 0.1.44 failed - keeping the installed copy, rebuild continues acpx: updating 0.19.3 -> 0.22.0 acpx: install of 0.22.0 failed - keeping the installed copy, rebuild continues LATER BLOCK RAN ``` ### Why the `pgrep` patterns use the global bin path A shebang script launched through a symlink keeps the invoked path in argv. Verified locally with a node script and a symlink: ``` $ ps -Ao pid,command | grep backpass 32011 node /private/.../bin/backpass --some-arg $ pgrep -f "node_modules/backpass/bin/backpass.js" # source path (no match) $ pgrep -f "bin/backpass" # invoked path 32011 ``` That is why the notice matches `/opt/homebrew/bin/backpass` and `/opt/homebrew/bin/acpx`, and why `pgrep -fl` above lists the real sessions by those paths. ## Found by the pipeline and fixed - `backpass-guard-always` (ask-user): the first draft skipped a package while a process was running, which contradicted "always pulls the latest". Fixed: install always runs, and a running process only gets the informational notice. - `pgrep-pattern-dead` (auto-fix): the first notice built on source-path patterns could never match a real launch. Fixed to the invoked global-bin paths, and verified independently as shown above. - The document step corrected the stale `home.activation.securityAuditSkill` comment that still said the skill skips "like backpass"; it now says "unlike backpass which tracks the latest release". `acpx` is under the same policy per the follow-up instruction, so the earlier open question about it is answered by this change rather than left as a note.
hermes added 4 commits 2026-11-11 13:12:05 -05:00
Both npm globals were installed only when the binary was missing, so a
rebuild never moved them and the installed copies drifted behind the
registry. Read the installed version and the registry's latest instead,
and install only when they differ.

The running-process guard skips a package while one of its own processes
is alive, the registry lookup and the install warn and continue on
failure so the switch never aborts, and one shared function serves both
packages.
hermes merged commit 8b3aa7ef3b into main 2026-11-11 13:15:57 -05:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: transnet/dotfiles#19