Skip to content

Prevent recurring native module ABI failures - #2575

Merged
SawyerHood merged 2 commits into
mainfrom
bb/investigate-recurring-issue-cause-thr_wwbjzitc62
Aug 27, 2026
Merged

Prevent recurring native module ABI failures#2575
SawyerHood merged 2 commits into
mainfrom
bb/investigate-recurring-issue-cause-thr_wwbjzitc62

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Node 22 and Node 24 could use the same better_sqlite3.node inode through pnpm hard links. The prior fix detached the file only after verification found an ABI mismatch. A valid ABI 137 file could therefore stay shared. A later Node 22 install changed that inode to ABI 127. The managed Node 24 server then failed each restart because the launcher checked native modules only before supervision began.

What changed

  • Detach a hard-linked native binary before verification, even when its ABI is correct.
  • Add a server preflight hook to the managed process launcher.
  • Run each native preflight in a fresh Node process before each source-server start and restart.
  • Give each preflight a separate process group, so shutdown can stop a blocked download or source build.
  • Add tests for a matching shared binary, a replaced binary, and a blocked repair process tree.
  • This change does not alter a wire contract, a CLI command, or a configuration surface.

How you verified

  • pnpm exec turbo run test --filter=@bb/scripts --force passed 123 tests.
  • pnpm exec turbo run test --filter=bb-app --force passed 73 tests.
  • pnpm exec turbo run typecheck --filter=@bb/scripts --filter=bb-app --force passed.
  • pnpm exec turbo run test --filter=@bb/scripts --force -- --run test/start-bb.test.mjs passed four focused tests.
  • A real Turbo prerequisite detached the worktree binary. The main and worktree binaries now each have one link.

Fixes: no linked issue.

AGENT GENERATED

@SawyerHood

Copy link
Copy Markdown
Collaborator Author

@slopcop review

@bb-slop-cop

bb-slop-cop Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

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

Comment thread scripts/ensure-native-modules.mjs
Comment thread scripts/start-bb.mjs Outdated

@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 change protects bb when two Node versions share one native database file. It separates hard links before checks. It also repeats the repair before each managed server start.

I found two restart lifecycle problems.

  1. P1: The repeated check can use a cached add-on. The launcher keeps the first better-sqlite3 module in memory. A later install can replace the disk file. The launcher then tests the cached module, while the new server loads the bad file. This result can restore the restart loop. Use a fresh child process for every initial check.

  2. P2: A repair can block shutdown. The repair uses synchronous child processes for downloads and source builds. These calls block the launcher signal handler. After 15 seconds, bb stop can kill the launcher and leave child processes alive. Use the existing asynchronous process-group helper.

The security review found no issue. The architecture review found no duplicate repair path. The callback also keeps repository repair policy outside the published launcher, which is the correct boundary.

The focused tests passed: 73 bb-app tests and 121 scripts tests. Both package typechecks passed. The worktree passed git diff --check.

I started the dev server from this branch. The health endpoint responded successfully. Doobie loaded the Settings page without HTTP error responses or browser errors.

The repair idea is sound, but the restart path still has these two failure cases. I left line comments with the details.

@SawyerHood

Copy link
Copy Markdown
Collaborator Author

@slopcop review

@bb-slop-cop

bb-slop-cop Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

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

@SawyerHood
SawyerHood merged commit 307f1fd into main Aug 27, 2026
15 checks passed
@SawyerHood
SawyerHood deleted the bb/investigate-recurring-issue-cause-thr_wwbjzitc62 branch August 27, 2026 19:56
Comment thread scripts/start-bb.mjs
} = {}) {
// Each check needs a fresh module cache. The process group also lets the
// launcher stop a blocked download or source build during shutdown.
const result = await runBuildProcess({

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 — Bound repeated native repair attempts

If this preflight fails during a supervised restart, restartManagedProcess retries it every second without a limit. Each attempt can repeat a prebuilt download and a full node-gyp rebuild. A persistent network or compiler failure can consume CPU and network resources until the user stops bb. Please stop after a repair failure, or add a bounded retry count with a longer delay.

@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 pull request protects each checkout from shared native binaries. It verifies native modules in a fresh process before every managed server start.

Finding

I found one P2 resource issue. A persistent repair failure enters the existing one-second restart loop. Every attempt can repeat a prebuilt download and a full source build. This can use CPU and network resources until the user stops bb. See the inline comment for the requested change.

Other review areas

  • Security: I found no new security issue.
  • Quality: The change has clear boundaries and focused tests.
  • Architecture: The repository has one repair implementation. I found no duplicate repair logic.
  • Refactor: A small helper could combine three process-result checks. I do not require that change.
  • Performance: The successful preflight has low overhead. The unlimited failure loop is the only performance issue.

Checks

  • The bb-app suite passed 73 tests.
  • The @bb/scripts suite passed 123 tests.
  • Both package type checks passed through Turbo.
  • git diff --check origin/main...HEAD passed.
  • The production-like worktree start reached ready state.
  • A forced server exit produced a new server process.
  • Doobie loaded the optimized app with HTTP 200 after the restart.

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