Repository navigation
feat: SQLite engine self-bootstrap — builtin -> host -> cached -> self-download (#2833) - #2845
Conversation
…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
… notes, changelog (#2833)
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3150-pr.2845.cf24a59This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2845.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…unpassable
assert.equal from node:assert/strict is strictEqual: comparing the fake
driver's get() result against a fresh { ok: true } literal always fails on
reference equality, so the test could never pass. Use deepEqual to assert
the actual value (the point: the registered self-downloaded loader drives a
real open through the driver).
Review fix for PR #2845 (found by local run of the suite: 20/21 with this
line failing).
downloadAndInstall published via fsp.rename(tmpDir, finalDir) only. When a stale/partial final dir already exists (killed run, local tampering), the rename fails ENOTEMPTY over the non-empty dir, so every retry re-downloads and fails at publish, re-arming the 6h cooldown indefinitely — contradicting the documented 'corrupt cache dir is skipped' contract. Before publishing: a usable existing dir means a concurrent process already published the same pinned artifact (treat as success); an unusable one is removed and replaced. Adds the hermetic regression test (stale dir -> downloaded, complete cache, no cooldown marker). Review fix for PR #2845.
…xports gate OpenedDatabase (driver.ts) and EngineBootstrapSpec/DEFAULT_ENGINE_SPEC/ BootstrapStatus/EnsureSqliteEngineOptions (engine-bootstrap.ts) have no references outside their declaring files and tsup emits no d.ts, so the exports are pure surface bloat. Unexport them; behavior unchanged. Review fix for PR #2845 (CI unused-exports job).
…blocks The PR hand-edited the generated param-ref/env-map blocks instead of adding a seed entry, which broke docs-sync/docs-coverage/config-surface-guard. Add the seed to website/config-reference/process.yaml and regenerate (also fixes the env-map row ordering the generator sorts by name). Sync the static zh long-form BILI_STORAGE_UNIFIED entry to the new engine-resolution wording. Review fix for PR #2845.
[bot] 🏷 Review complete — 4 review-fix commits pushed to the branch ( What I verified (not just the diff)
What I fixed (labeled commits on the branch)
Residuals (assessed, not blocking)
结构化八问
判定:CI 在新 head( |
[bot] 🏷 CI 全绿确认 — head 四个 review-fix commit(断言修复、stale-cache-dir 自愈、internal-only 导出收敛、文档种子+再生成+zh 同步)均已随 CI 验证。可以合并了:#2845 (合并请人工执行) |
Closes #2833 (thorough fix for the #2823 build-blocked failure domain; #2825 was the stopgap).
Mechanism
#2823: under pnpm >=10
strictDepBuilds, any native dependency needing install-time build scripts that is not on the host's allowlist hard-fails the whole install (ERR_PNPM_IGNORED_BUILDS-> dsh reports build-blocked). #2825 removed better-sqlite3 from optionalDependencies and pinned the no-engine legacy-only degrade contract. This PR lands the owner-approved thorough fix: engine acquisition never depends on host install-time build-script approval, via runtime self-bootstrapping.Resolution order (per request, sticky per process)
node:sqlitewhen the runtime provides it (Node >= 22.5); zero native deps, never touches the gate;require("better-sqlite3")probe (hosts that already ship it keep using it);<cache>/billion-context/sqlite/better-sqlite3-13.0.3/;network.proxychain;Failure is fail-safe at every step: download error arms a 6h cooldown marker, then legacy-only; corrupt cache dir is logged and skipped (no re-download loop); unsupported platform never downloads. Bounded startup block: wired into
bili startbefore the first store open, single 10s fetch timeout, once per machine lifetime.Config surface
New key
storage.sqliteAutoDownload(boolean, defaulttrue) + env overrideBILI_SQLITE_AUTO_DOWNLOAD— documented in CONFIGURATION.md en/zh.false; disabling only prevents new downloads. All other resolution steps are unaffected by the switch.true; existing installs are unaffected (they either have a builtin/host engine or were already legacy-only).Behavior changes (old -> new)
storage.sqliteAutoDownload: false.bili startmay block up to ~10s once on first-ever bootstrap (only on machines that reach step 4); subsequent starts are a local cache hit. After a failed attempt, a 6h cooldown applies and startup proceeds immediately in legacy-only mode.engine/source(e.g.[engine:better-sqlite3/self-downloaded]) for field diagnosis — additive log detail only.No change to: wire protocol, persistence format/version (index.db schema untouched; #2771 corrupt-index degrade, CAS refcounting, dual-domain affinity all preserved), nudge cadence, kernel, updater.
Tests & pre-flight
tests/storage-engine-bootstrap.test.ts(21 tests): loopback mock registry, isolated XDG cache, fake pinned tarball fixtures — resolution order x5, bootstrap flows (happy path/cache-hit/sha-mismatch-quarantine/cooldown-expiry/offline/disabled-knob/legacy-short-circuit/builtin/host/unsupported-platform/concurrent-dedup) x10, extractor security (non-gzip, missing-prebuilt, path traversal, symlink rejection) x4, knob matrix, platform key sanity.off += size + pad512(size)).tests/e2e/e2e-sqlite-bootstrap.test.ts(gatedACP_TEST_SQLITE_BOOTSTRAP=1, outside the default glob): verified locally end-to-end against the live registry on linux-x64 — download, sha verify, load, DDL/DML/rollback proof, full UnifiedStore schema migration over the self-downloaded binding.Ref: #2823 (bug), #2825 (stopgap + contract), #2833 (this design).