Repository navigation
[PR] fix(storage): DB open self-check no longer blocks startup — large-DB background check + verdict cache (#4609) | fix(storage): 开库自检不再阻塞启动——大库后台查 + 判定缓存(#4609) - #4852
Conversation
PRAGMA quick_check walks every B-tree page of every table, so a 14 GB index.db costs ~260 s of single-core scan on EVERY open — and because open() runs it before listen, the native lane's 60 s spawn budget kills the child mid-scan, the host falls back to direct (no compression) for its whole lifetime, and every restart repeats the scan (#4609). Two halves, #4175's premise (a corrupt file must never be migrated against) preserved wherever it is cheap: - verdict cache: index.db.chk.json records the last outcome keyed by (schema version, index.db stat, -wal stat). An unchanged file set skips the rescan; any write or a schema upgrade invalidates the key; a hot -wal left by a killed process changes the key by construction — exactly the risky boots that deserve a rescan. A clean close of a verified store refreshes the key onto the post-checkpoint stats, so the normal restart path is rescan-free. - size gate: stores at or below 512 MiB keep the synchronous pre-migration check (a couple of seconds at most). Larger stores check post-open on a second read-only connection in a worker thread (WAL allows concurrent readers; the main handle has already run recovery), so open() returns in milliseconds. A background failure is recorded loudly, cached, and makes the NEXT open throw StorageIntegrityError so the existing #4175 quarantine-and-reopen-fresh machinery runs. BILI_STORAGE_QUICK_CHECK=0 keeps its meaning: no check, no cache IO. Quarantine now moves the .chk.json sidecar along with the db set.
…the dist-external gate (#4852) The WORKER_SOURCE template literal is bundled VERBATIM into dist/, where scripts/check-dist-external.mjs text-scans for quoted require("…") forms. The literal require("node:sqlite") inside the worker source tripped the gate in dist/index.js, dist/agent/pi-native.js and dist/agent/opencode-native.js — node:sqlite is NOT listed in module.builtinModules (still experimental), so the checker's builtin exemption never applied. Route the specifier through a named const (SQLITE_SPEC) — the checker's documented sanctioned "opaque specifier" path — mirroring 8b70e91 for src/storage/quick-check-worker.ts. Runtime behavior unchanged: same worker_threads Worker, read-only DatabaseSync, PRAGMA quick_check, postMessage verdict.
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.6275-pr.4852.dda5292This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr4852.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…scans (#4852) The quick_check verdict cache was named index.db.chk.json — the sessions directory's first non-envelope .json. The dsh persona e2e walker treats every .json there as a session envelope and RETURNED from the whole scan when one had no payload.id, so the raw-conversation-key assertions went blind ('the raw conversation key persisted a session' failed on both #2241 and #2791). Rename the sidecar to index.db.chk (non-.json; the sessions tree stays envelope-only) and harden the walker to skip stray files instead of aborting. Also demote four integrity-check exports the unused-exports gate flagged (INTEGRITY_SYNC_THRESHOLD_BYTES, IntegrityCache, IntegrityMode, effectiveSyncThreshold) to module-internal. Verified locally: tsc, unused-exports gate, dist-external build, storage-integrity-cache 6/6, storage-durability 5/5, and the two dsh persona lanes now pass (#2241, #2791).
(ai: vllm-qwen/qwen3.8-27b) 先给结论:这 11 项 CI 失败根因只有两个,都在本 PR 新增的 八问:
收工判定:本车道不再 push、不开新 issue(无需要 owner 拍板的设计决策项)。请等待 / 触发 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.858-master.96b7e43 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Conflict resolution notes: - store.ts constructor: keep master's signature (dbPath last param, ranxianglei#4852 integrity work); ranxianglei#4628's extra path param drops in favour of this.dbPath. - gc() zero-ref sweep: keep ranxianglei#4800's index-driven batched collection (collectZeroRefContent, fixed 2000-row batches) instead of ranxianglei#4628's rowid-IN-subquery adaptive batches — with idx_content_refcount present, candidate selection is an index range scan and per-batch TRUNCATE checkpoints bound WAL growth. ranxianglei#4612's test asserts the actual log format. - live-files.mjs: union of both sides' entries.
这是啥问题
0.1.205 起(#4175),
UnifiedStore.open()在listen 之前无条件跑PRAGMA quick_check,耗时 O(库大小):14 GB 库要 260 秒。native 车道 spawn 代理的预算是硬常量 60 秒 → 子进程还在扫库就被杀 → 插件判定 bootstrap 失败 → 宿主整个生命周期直连(不压缩),大会话带原始历史出网撞上游 400。每次重启重复同样的扫描(判定从不缓存),260 秒里零日志,和"卡死"无法区分。根本原因
自检本身没错,错在位置:O(库大小)的工作被放在了启动关键路径上,且判定结果从不缓存。60 秒预算是宿主侧常量,扫描时间无上界,调哪边都不可能收敛——唯一正确的修法是别让 listen 等自检。
改动(两半,#4175 的"坏文件不得迁移"前提在便宜场景原样保留)
1. 判定缓存
index.db.chk.jsonStorageIntegrityError→ 复用 Storage Reliability Trio: open-time self-check (quick_check) + online backup (VACUUM INTO) + second-process probe on the | 存储可靠性三件套:开库自检 quick_check + 在线备份 VACUUM INTO + 同库第二进程探测 #4175 现成的隔离+重开机制(包括后台查发现失败后下次开库自动隔离)2. 尺寸门限 512 MiB
/__bili/status)+缓存;启动即打一行"background quick_check started"日志(不再黑箱)隔离联动:quarantine 时
.chk.json随 db/-wal/-shm 一起改名走,新库从干净缓存开始。逃生门:
BILI_STORAGE_QUICK_CHECK=0语义不变(不查、不碰缓存)。诚实交代的取舍
大库升级后的首次开库,迁移会跑在"未验证"的文件上(#4175 前提的让步)——V8 迁移本身流式可续、JSON envelopes 永远是恢复源,窗口有界且可见(日志+runtime-status)。
验证
tests/storage-integrity-cache.test.ts6 用例:同步查写缓存+重开跳过、stat 变化强制重查、缓存失败抛类型错误(不重扫)、超阈值走后台不阻塞 open、env=0 全跳过、坏小库照旧同步抛错 → 6/6storage-durability5/5、launcher-site-overlay31/31 绿;storage-engine-proofs8/12(4 个失败为 master 既有红,stash 复核确认与本改动无关)tsc --noEmit干净关联:#4609(P1)、#4175(自检来源)、#4677(大库迁移教训:关键路径上的 O(库) 工作)