Skip to content

fix(cli): improve better-sqlite3 postinstall rebuild for cross-platform installs - #313

Merged
diegosouzapw merged 1 commit into
cheaper-inference:mainfrom
ardaaltinors:fix/better-sqlite3-postinstall-rebuild
Mar 11, 2026
Merged

diegosouzapw merged 1 commit into
cheaper-inference:mainfrom
ardaaltinors:fix/better-sqlite3-postinstall-rebuild

Conversation

@ardaaltinors

Copy link
Copy Markdown
Contributor

Fixes #312

Summary

  • Replace unreliable process.dlopen() platform detection in scripts/postinstall.mjs with explicit process.platform/process.arch comparison against the build target (linux-x64). On macOS, dlopen can load an incompatible binary without throwing, so the postinstall script skips the rebuild entirely.
  • Fail the install (exit 1) if rebuild fails, instead of warning silently — users now see a clear error with platform-specific fix instructions during npm install, rather than discovering the issue at runtime.
  • Verify the rebuilt binary actually loads after npm rebuild.
  • Add a pre-flight binary compatibility check in bin/omniroute.mjs as a safety net before starting the server.

…rm installs (cheaper-inference#312)

Replace unreliable process.dlopen() platform detection with explicit
platform/arch comparison against the build target (linux-x64). On macOS,
dlopen can load an incompatible binary without throwing, causing the
postinstall script to skip the rebuild entirely.

- Detect platform mismatch via process.platform/arch instead of dlopen
- Fail the install (exit 1) if rebuild fails, instead of warning silently
- Verify rebuilt binary loads correctly after rebuild
- Add pre-flight binary check in CLI entry point as a safety net
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness of better-sqlite3 native module handling, particularly for cross-platform installations. It refines the post-installation rebuild process by using more reliable platform detection, introduces immediate error reporting for failed rebuilds, and adds a crucial runtime compatibility check, preventing issues that could arise from incompatible native binaries.

Highlights

  • Improved Platform Detection: Replaced process.dlopen() with explicit process.platform and process.arch checks for better-sqlite3 rebuilds in scripts/postinstall.mjs to ensure accurate cross-platform compatibility, especially for macOS where dlopen alone can be unreliable.
  • Enhanced Error Handling: Modified scripts/postinstall.mjs to exit with an error code (exit 1) if the better-sqlite3 rebuild fails, providing immediate and clear feedback to the user instead of silent warnings.
  • Post-Rebuild Verification: Implemented a check in scripts/postinstall.mjs to verify that the better-sqlite3 native binary successfully loads after a rebuild, ensuring the rebuild was effective.
  • Runtime Compatibility Check: Added a pre-flight check in bin/omniroute.mjs to ensure the better-sqlite3 native module is compatible with the current platform before the server starts, acting as a safety net.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • bin/omniroute.mjs
    • Added a pre-flight check to verify the compatibility of the better-sqlite3 native binary before starting the server, including platform-specific fix instructions for macOS.
  • scripts/postinstall.mjs
    • Replaced process.dlopen()-based platform detection with explicit process.platform and process.arch comparisons to accurately determine if a better-sqlite3 rebuild is necessary.
    • Changed rebuild failure behavior from a warning to an exit 1 error, providing clearer feedback to the user.
    • Introduced a post-rebuild verification step to ensure the newly built better-sqlite3 binary can be successfully loaded.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist 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.

Code Review

The pull request significantly improves the cross-platform compatibility and reliability of the better-sqlite3 native module by enhancing its post-installation rebuild process and adding a pre-flight compatibility check. The changes introduce more robust platform detection, ensure rebuild failures are explicitly reported, and verify the rebuilt binary's loadability, preventing silent failures and providing clearer user guidance.

Comment thread scripts/postinstall.mjs
console.warn(" You can fix this manually by running:");
console.warn(` cd ${join(ROOT, "app")} && npm rebuild better-sqlite3\n`);
// Don't fail the install — the user can fix manually
console.error(" ❌ Failed to rebuild better-sqlite3 automatically.");

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.

medium

The catch block for the execSync command currently logs a generic error message. Including the actual error.message from the execSync failure could provide more specific debugging information to the user, which would be helpful for diagnosing rebuild issues.

Suggested change
console.error(" ❌ Failed to rebuild better-sqlite3 automatically.");
console.error(" ❌ Failed to rebuild better-sqlite3 automatically." + (error.message ? ` ${error.message}` : ""));

Comment thread bin/omniroute.mjs
// ── Pre-flight: verify better-sqlite3 native binary ───────
// The published binary targets linux-x64. Check both platform match AND
// dlopen — on macOS, dlopen alone may succeed on an incompatible binary
// (false positive), so we check platform first as the primary signal.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Misleading comment - The comment states "Check both platform match AND dlopen" and "we check platform first as the primary signal", but the actual implementation (lines 208-215) only performs the dlopen check without any platform verification. Either add the platform check or update the comment to accurately describe the runtime verification behavior.

Comment thread bin/omniroute.mjs
"\x1b[31m✖ better-sqlite3 native module is incompatible with this platform.\x1b[0m"
);
console.error(` Run: cd ${APP_DIR} && npm rebuild better-sqlite3`);
if (platform() === "darwin") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Consider using process.platform instead of platform() from the os module for consistency with the rest of the codebase. The process.platform values (linux, darwin, win32) are more commonly used and directly comparable to the BUILD_PLATFORM check in postinstall.mjs.

@kilo-code-bot

kilo-code-bot Bot commented Mar 11, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
bin/omniroute.mjs 199 Misleading comment - states "Check both platform match AND dlopen" but code only does dlopen

SUGGESTION

File Line Issue
bin/omniroute.mjs 222 Use process.platform instead of platform() for consistency
Other Observations (not in diff)

The changes in scripts/postinstall.mjs are well-implemented:

  • Platform detection logic is correct (lines 36-38)
  • Error handling properly fails with exit(1) instead of warnings
  • Post-rebuild verification is a good addition

No issues found in the postinstall.mjs changes.

Files Reviewed (2 files)
  • bin/omniroute.mjs - 2 issues
  • scripts/postinstall.mjs - 0 issues

Positive aspects of this PR:

  • Adds valuable runtime pre-flight check for better-sqlite3 compatibility
  • Improves cross-platform detection with explicit platform/arch checks
  • Adds post-rebuild verification to ensure binary actually loads
  • Provides helpful error messages with platform-specific fix instructions

The issues found are minor documentation and consistency improvements. The core functionality is sound.

@diegosouzapw
diegosouzapw merged commit f7bd99f into cheaper-inference:main Mar 11, 2026
@diegosouzapw

Copy link
Copy Markdown
Collaborator

Thanks @ardaaltinors for this excellent contribution! 🎉 The improved cross-platform detection is now merged and shipped in v2.2.9. Your fix for the silent macOS ARM rebuild failure will save a lot of frustration for Apple Silicon users. We really appreciate the thorough analysis and the pre-flight check in bin/omniroute.mjs!

diegosouzapw added a commit that referenced this pull request Mar 11, 2026
fix(aliases): custom model aliases applied to routing + restored on startup (#315 #316, PR #317)
fix(cli): better-sqlite3 postinstall rebuild cross-platform macOS ARM (#312, PR #313 @ardaaltinors)
Poid-ZA pushed a commit to Poid-ZA/OmniRoute that referenced this pull request Aug 5, 2026
…-sqlite3-postinstall-rebuild

fix(cli): improve better-sqlite3 postinstall rebuild for cross-platform installs
Poid-ZA pushed a commit to Poid-ZA/OmniRoute that referenced this pull request Aug 5, 2026
fix(aliases): custom model aliases applied to routing + restored on startup (cheaper-inference#315 cheaper-inference#316, PR cheaper-inference#317)
fix(cli): better-sqlite3 postinstall rebuild cross-platform macOS ARM (cheaper-inference#312, PR cheaper-inference#313 @ardaaltinors)
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…-sqlite3-postinstall-rebuild

fix(cli): improve better-sqlite3 postinstall rebuild for cross-platform installs
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
fix(aliases): custom model aliases applied to routing + restored on startup (cheaper-inference#315 cheaper-inference#316, PR cheaper-inference#317)
fix(cli): better-sqlite3 postinstall rebuild cross-platform macOS ARM (cheaper-inference#312, PR cheaper-inference#313 @ardaaltinors)
diegosouzapw pushed a commit that referenced this pull request Oct 21, 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.

[BUG] better-sqlite3 postinstall rebuild fails silently on macOS ARM

2 participants