Skip to content

fix(storage): drop better-sqlite3 optional dep (#2823) - #2825

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-12_remove-better-sqlite3
Oct 11, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-12_remove-better-sqlite3

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Remove the better-sqlite3 optional dependency and pin the "no SQLite engine available" degrade contract with regression tests.

Why (root cause)

Fresh dsh plugin-market installs/updates of billion-context fail on pnpm ≥10 with:

[ERR_PNPM_IGNORED_BUILDS] Ignored build scripts: better-sqlite3@13.0.3

pnpm ≥10 enables a strict build-script gate (strictDepBuilds defaults true): any dependency shipping an install/build script is blocked unless explicitly allowed in the project allowlist, and an unlisted script is a hard install error. dsh's plugin manager runs pnpm non-interactively with a fixed allowlist covering only its own native deps, never third-party plugin deps — so better-sqlite3 (which needs its postinstall to fetch/build its native binding) is unlisted → hard error → dsh reports the update as failed. The deeper defect is dsh-side (an optional dep treated like a required one instead of skipped gracefully); that is tracked separately and deferred per owner.

Why removing it here is safe (compat tested)

  • Unified storage is OFF by default (legacy JSON file persistence); SQLite is only touched when a user opts into storage.unified.
  • The driver already prefers built-in node:sqlite when the native module is absent (src/storage/driver.ts).
  • When no engine is available at all, UnifiedShadow.maybeOpen degrades to legacy-only with one warn and never bricks construction (src/storage/shadow.ts) — same contract as [Bug][storage] corrupt index.db bricks SessionStore construction in shadow/full mode (violates the sidecar never-breaks-legacy policy) #2771.
  • New tests pin exactly this: UnifiedShadow.maybeOpen → null; SessionStore runs legacy-only, writes survive, and no index.db is created (tests/storage-engine-proofs.test.ts). Verified on Node 22 (where node:sqlite exists) using a test seam to force the no-engine path deterministically.
  • The opportunistic require("better-sqlite3") probe is kept, so hosts that still have the native module keep using it.

Behavior change (flagged)

  • Old: better-sqlite3 shipped as an optionalDependencies entry; hosts whose package manager allowed its build script used the native SQLite engine, everyone else already fell back to built-in node:sqlite.
  • New: better-sqlite3 is no longer declared; fresh installs always use built-in node:sqlite. Hosts that already have the native module installed keep using it via the retained probe.
  • Why: removes the dependency that trips pnpm ≥10's build-script gate and breaks dsh-market installs/updates (0.1.189更新失败,插件市场更新报错 #2823). The perf delta (native vs built-in) is negligible for the proxy's small index.db workload, and the unified store is off by default.
  • sharp is left untouched: it ships prebuilt binaries (no build-script gate trip) and was not part of the reported error.

Gates

Green on this head: typecheck, targeted storage tests (no SQLite engine | CAS refcounts | corrupt index.db → 4/4), and build (dist self-contained; probe retained). Full suite + e2e left to CI.

Release

This is the content fix. A standard-flow release v0.1.194 follows after merge (version bump only) — publishing it to npm is what resolves the reporter's update failure.

Closes #2823

… contract (#2823)

pnpm >=10's strict build-script gate (strictDepBuilds) blocks any unlisted
install script as a hard error, so dsh plugin-market installs/updates on fresh
profiles failed with [ERR_PNPM_IGNORED_BUILDS] better-sqlite3. Unified storage
is OFF by default (legacy file persistence), so dropping the optional native
engine is low-impact: the driver already prefers built-in node:sqlite when the
native module is absent, and when no engine is available at all
UnifiedShadow.maybeOpen degrades to legacy-only (one warn, never bricks).

- package.json / package-lock.json: remove better-sqlite3 (sharp stays).
- src/storage/driver.ts: add setSqliteEnginesUnavailableForTests seam so tests
  force the "no engine" path deterministically; keep the opportunistic
  require("better-sqlite3") probe for hosts that still ship it.
- tests/storage-engine-proofs.test.ts: pin the contract -- maybeOpen -> null;
  SessionStore runs legacy-only, writes survive, no index.db.
- CHANGELOG.md: [Unreleased] entry.

Gates green on this head: typecheck + targeted storage tests + build.
Closes #2823
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-12_remove-better-sqlite3 (ce1dd2f)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3131-pr.2825.767a6a4

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2825.tgz
npm install -g package

Install instructions are refreshed on each push.

…e3 dep drop (#2825 review)

The line still said 'better-sqlite3 primary, node:sqlite fallback'; after the
optional dependency was removed in this PR, fresh installs always run on the
built-in node:sqlite engine, with the native module used only opportunistically
when a host already has it. Also fixes the zh typo 兑底 -> 兜底 in the same span.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #2825 审查完成 — 代码核对通过,本地定向验证全绿,可合(CI 转绿后)

拉取分支逐行核对了 cb90ad40b(当前 master 之上的单提交,无冲突),并在该 head 上跑了定向验证。结论按八问:

1. 是什么问题
dsh plugin-market 在 pnpm ≥10 下安装/更新 billion-context 时,better-sqlite3 的 postinstall 触发 pnpm 严格构建脚本门禁(strictDepBuilds),未列入 allowlist 的脚本被当作硬错误 → 全新 profile 的安装/更新直接失败(#2823)。

2. 什么原因导致的
根因分两层:dsh 侧把 optional 依赖当 required 处理(深层缺陷,另行跟踪、owner 已定缓办);bili 侧则是不必要地把一个带构建脚本的原生模块放进 optionalDependencies——而 unified 存储默认关闭、驱动本身已有 node:sqlite 兜底,这个依赖对默认用户没有价值。本 PR 消除 bili 侧这一半。

3. 影响范围与严重程度
受影响面:所有走 pnpm ≥10 且 allowlist 不含第三方插件依赖的安装通道(实测即 dsh plugin-market)。严重度:该通道上安装/更新完全失败(不是体验问题)。其余安装通道(npm 等)此前已自动走 node:sqlite,行为不变。

4. 怎么修复的
从 package.json/lockfile 移除 better-sqlite3(连带其传递依赖 node-addon-api;sharp 不动——预构建二进制不触门禁)。保留 src/storage/driver.ts:165 的机会性 require("better-sqlite3") 探测,已有原生模块的宿主继续用原生引擎。新增测试缝 setSqliteEnginesUnavailableForTests 让测试确定性走"无任何引擎"路径,两个回归测试钉死降级契约:UnifiedShadow.maybeOpen → null;SessionStore 纯 legacy 运行、写入存活、不产生 index.db。我核对了错误传播链:缝抛出的 SqliteDriverError 经 UnifiedStore.open(src/storage/store.ts:143)进入 maybeOpen 既有 catch(src/storage/shadow.ts:68-80)→ 一条 warn + 返回 null,与 #2771 同形,构造永不 brick。

5. 是否有回归问题
审过的既有行为逐项:无意外回归。

  • 默认(legacy)路径:maybeOpen 在触碰驱动前就返回 null,未动;
  • 损坏 index.db 降级([Bug][storage] corrupt index.db bricks SessionStore construction in shadow/full mode (violates the sidecar never-breaks-legacy policy) #2771):同一 catch 路径,未动;
  • 已装原生模块的宿主:detectEngine 仍先探测 better-sqlite3,行为保持;
  • 线协议/配置面/持久化格式/kernel:均未触碰(config-surface-guard、kernel-guard、version-guard CI 已过);
  • 有意的行为变更(已在 PR 正文按规范披露):新装环境默认引擎从"better-sqlite3 优先"变为"内置 node:sqlite",性能差异对该小 index.db 负载可忽略。
  • 一处知会(非阻塞):此后 CI 的 npm ci 不再安装 better-sqlite3,tests/storage-unified.test.ts:187 的 better-sqlite3 corpus 腿将恒为 skip——openBetterSqlite3 适配器失去 CI 覆盖。可接受(unified 默认关、适配器小而冻结;挪到 devDependencies 反而可能因 dsh 是否裁剪 dev 依赖而重触 pnpm 门禁,不可取)。若日后要恢复双引擎覆盖,建议单独立项。

6. 是否破坏缓存:不涉及(不动压缩/前缀缓存/会话身份任何机制)。

7. 是否改了设计方向:不涉及。存储架构不变,只是收缩了可选引擎的声明面;"探测保留、缺失降级"的既有分层原样工作。

8. 是否引入新配置:无。唯一导出是测试缝 setSqliteEnginesUnavailableForTests(仅测试翻转、finally 复位,不进配置面)。

本地定向验证记录(PR head,Node 22,better-sqlite3 确实未装):

  • typecheck ✅;
  • tests/storage-engine-proofs.test.ts 12/12 过(含两个新增 no-engine 测试);
  • tests/storage-unified.test.ts 12 过 + 1 跳(better-sqlite3 腿按设计的 loud skip);
  • build ✅,dist 自包含,确认 bundle 内探测是 try/catch 包裹的运行时 require(非静态 import,缺模块不会炸启动);
  • 实机冒烟:干净 XDG 目录 + BILI_STORAGE_UNIFIED=full 启动构建产物 → 日志 unified FULL mode ENABLED、index.db 由内置 node:sqlite 创建、health 正常。

顺手小修(独立 commit ce1dd2f6f,已推 PR 分支):CONFIGURATION.md:1745 与 CONFIGURATION.zh-CN.md:1742 仍写"(better-sqlite3 主引擎,node:sqlite 兑底)"——与本 PR 后的事实不符,已改为"内置 node:sqlite;宿主已装的 better-sqlite3 机会性沿用(#2823 移除包依赖)",并顺手修掉同段 zh 错字「兑底」→「兜底」。CI 会在新 head 上重跑(docs-sync 双语文案一致,应绿)。

CI 状态:审查时 kernel-guard / version-guard / lock-sync / config-surface-guard / lane-guard / unused-exports / pi-subagents-guard / docs-sync / docs-coverage / e2e / real-codex persona-continuity 均已 success,其余在跑,无 failure;mergeable: true,state blocked 仅为 checks 未完(+分支保护)。

判定:内容正确、范围干净、契约钉死,CI 转绿后可合。 合并后按 PR 所述走标准流程发 v0.1.194(纯版本 bump),发布到 npm 才是对报告者更新失败的最终解决。合并由人来操作:#2825

@ranxianglei ranxianglei mentioned this pull request Oct 11, 2026
@ranxianglei
ranxianglei merged commit e0f4c0c into master Oct 11, 2026
28 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.293-master.e0f4c0c (rolling master tag).

npm install -g billion-context@0.0.293-master.e0f4c0c  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

ranxianglei pushed a commit that referenced this pull request Oct 11, 2026
…f-download (#2833)

Engine acquisition no longer depends on host install-time build-script
approval (the strictDepBuilds gate behind #2823/#2825):

- detectEngine order: built-in node:sqlite (Node >= 22.5) -> host
  better-sqlite3 require probe -> registered self-downloaded loader ->
  none (legacy-only per the #2825 contract)
- new src/storage/engine-bootstrap.ts: one-time download of the pinned
  better-sqlite3 13.0.3 npm tarball (in-tarball N-API prebuilds for all
  8 platform-arch targets, no build scripts), sha512-pinned in-repo,
  extracted via a dependency-free gunzip+ustar reader into
  <cache>/sqlite/better-sqlite3-<version>, atomic publish, 6h cooldown
  after failure, proxy-aware via the existing network.proxy chain
- storage.sqliteAutoDownload (default true) / BILI_SQLITE_AUTO_DOWNLOAD
  gate the network fetch only; a cached copy is used even when false
- wired into bili start before the first store open (bounded ~10s);
  enablement log now records engine/source for field diagnosis
ranxianglei added a commit that referenced this pull request Oct 13, 2026
…tter-sqlite3

The #2845 suite assumed better-sqlite3 is absent from node_modules (true
on fresh CI npm ci since #2825, false on dev machines that installed it
earlier): when present, the host branch opens with source "host" —
equally valid proof the branch was taken. Accept either outcome.
ranxianglei added a commit that referenced this pull request Oct 13, 2026
resolveStorageMode now lands on 'shadow' when neither storage.unified nor
BILI_STORAGE_UNIFIED is set: the JSON envelope stays the sole source of
truth (zero behavior change) while every session write is mirrored into
index.db with digest reconciliation — fleet-wide parity telemetry before
the full-mode default flip. Explicit legacy opts out; garbage still
degrades to legacy; engine-less lanes stay legacy-only (#2825 contract).

The test corpus runs on an explicit legacy baseline
(tests/preload-storage-baseline.mjs wired into npm test and
scripts/run-ci-tests.mjs) so the 600-suite wire/e2e corpus keeps its
legacy dir-shape assumptions; the storage family pins and overrides its
own modes, the resolveStorageMode matrices pin the new default, and the
web-sessions stamp test now asserts shadow for absent-everywhere.
@ranxianglei
ranxianglei deleted the 2026-10-12_remove-better-sqlite3 branch October 15, 2026 05:33
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.

0.1.189更新失败,插件市场更新报错

1 participant