Skip to content

Probe native add-ons for real after install and self-update - #1816

Closed
SawyerHood wants to merge 1 commit into
mainfrom
bb/draft-pr-for-1120-fresh-install-silently-breaks-thr_mhgd5dvwux
Closed

SawyerHood wants to merge 1 commit into
mainfrom
bb/draft-pr-for-1120-fresh-install-silently-breaks-thr_mhgd5dvwux

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Follow-up to #1805 (issue #1120). It addresses the three correctness findings from the SlopCop review on that PR, which merged before the fixes landed.

What was wrong

  1. The installer health check only did require("better-sqlite3"). That loads JavaScript only; the native binding loads in the Database constructor. With npm 12 and only the better-sqlite3 script blocked, npm and the probe both returned 0, and bb still failed at startup with Could not locate the bindings file.
  2. The daemon self-updater had no native health check. ignore-scripts=true in an npmrc overrides --allow-scripts, npm returns 0, and the daemon reported updated and restarted into a package with missing bindings.
  3. The ignore-scripts recovery commands in the README omitted --allow-scripts, so on npm 12 they still produced a broken install.

What changed

  • apps/server/src/assets/install-machine.sh: the probe opens and closes an in-memory better-sqlite3 database, then requires node-pty (which loads pty.node at module load).
  • apps/host-daemon/src/protocol-self-update.ts: after npm install -g, the updater runs npm root -g [--prefix ...], then runs the same probe in a node child process against <root>/bb-app. If it fails, installTarball throws with a message that names the add-ons and the npm_config_allow_scripts=... npm_config_ignore_scripts=false fix, so handleProtocolMismatch returns failed and keeps the current daemon running. SelfUpdateProcessRunner now returns { stdout }.
  • apps/server/test/app/install-machine-script.test.ts: the fake npm keeps the add-on JavaScript and models the native output as build/Release/*.node files that the fake modules load like the real ones. FAKE_NPM_SKIP_NATIVE_MODULES names the modules whose native output is missing. Three cases: both, only better-sqlite3, only node-pty.
  • apps/host-daemon/src/protocol-self-update.test.ts: asserts the npm root -g and probe calls, and that a probe failure yields failed with the loud error.
  • README.md: the ignore-scripts recovery commands set both controls (npm_config_ignore_scripts=false npx --allow-scripts=... bb-app@latest, and the npm install -g form).

Not done: the "single policy manifest" note. The list lives in shell (installer) and TypeScript (daemon) with no shared build step between them; a manifest would need a generation step, which is more than this follow-up. Both sites carry a keep-in-sync comment.

How I verified

  • Before the probe change, with only better-sqlite3's native output missing, the installer test fails loudly when npm skipped the install scripts for better-sqlite3 failed (installer exit 0). After: all 19 installer tests pass.
  • pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/host-daemon → pass.
  • pnpm exec turbo run test --filter=@bb/host-daemon → 585 passed (includes the two new self-updater tests).
  • pnpm exec turbo run test --filter=@bb/server → 1726 passed, 1 failed: internal-skill-trees.test.ts expects file mode 420 and gets 436 (local umask); unrelated and green in CI.

Refs #1120

AGENT GENERATED: by Claude Opus 5

Address the SlopCop review on #1805:

- The installer probe now opens and closes an in-memory better-sqlite3
  database. A plain require loads only JavaScript; the binding loads in
  the Database constructor. node-pty loads pty.node at module load.
- The daemon self-updater runs the same probe (via `npm root -g` and a
  node child process) after `npm install -g` and throws before it
  reports "updated", so ignore-scripts=true cannot swap a working daemon
  for a broken package silently. The process runner now returns stdout.
- The fake npm in the installer test keeps the add-on JavaScript and
  omits only the native output, per module, so the test covers "only
  better-sqlite3 blocked".
- The README ignore-scripts recovery commands also pass --allow-scripts.

Co-Authored-By: Claude <[email protected]>
@bb-slop-cop

bb-slop-cop Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am the SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior.

},
{ env },
);
await verifyInstalledNativeModules(prefixArgs, runProcess, env);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — High: the failed probe leaves a broken package on disk.

npm install -g has already replaced the package in the service prefix before this probe runs. If the probe fails, the updater returns failed, but it does not restore the prior package. The current Node process can stay alive with cached modules. However, the next service restart uses the broken on-disk install and can enter a restart loop. Please install into a staging prefix and promote it after the probe passes, or restore the prior package before this path returns.

const root = process.argv[1];
const Database = require(root + "/node_modules/better-sqlite3");
new Database(":memory:").close();
require(root + "/node_modules/node-pty");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — Medium: the probe omits one native add-on from its own policy list.

BB_APP_NATIVE_MODULES includes @parcel/watcher, but this probe loads only SQLite and PTY. @parcel/watcher loads its native binding during require, so a missing watcher binary can pass this check. The new daemon can then start with a watcher child that fails repeatedly. Please require root + "/node_modules/@parcel/watcher" here and in the shell probe. Add a test that omits only its native output.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

Plain-English summary: This PR tests real native module loads after an install or self-update. It also fixes npm recovery commands.

I found two correctness problems.

  1. High: A failed post-install probe leaves the broken package in the service prefix. The current process survives, but a later restart can fail.
  2. Medium: The policy lists @parcel/watcher, but both probes omit it. A broken watcher can pass the probe and fail after restart.

I left inline comments with the exact failure paths and fixes.

Two small maintenance issues also remain. The probe policy now exists in shell, TypeScript, and the native repair script. A shared probe script would prevent drift. The published packages/bb-app/README.md also lacks the new ignore-scripts recovery command.

The security review found no injection or unsafe path use. The performance review found no material cost or tight retry loop.

Validation passed at the exact head SHA:

  • Host-daemon typecheck and server typecheck.
  • Host-daemon self-update test: 14 tests.
  • Machine installer test: 19 tests, including three blocked-native cases.
  • All current GitHub CI checks.

No web route changed. A browser test cannot exercise these host-local install paths. The shell installer test covers the applicable end-to-end path.

I posted a comment-only review. I did not approve or request changes.

@SawyerHood SawyerHood closed this Aug 18, 2026
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