Skip to content

fix(storage): close the SQLite handle when UnifiedStore.open fails on a corrupt index (#2771 follow-up) - #2788

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-11_corrupt-open-handle
Oct 11, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-11_corrupt-open-handle

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Problem

test (windows-latest, 22/24) is red on master and currently blocks the release PR #2767 — one failure:

✖ storage engine: corrupt index.db degrades to legacy-only instead of bricking construction (#2771)
  Error: EPERM, Permission denied: \\?\C:\...\Temp\bili-engproof-corrupt-* (rmSync → rmrf)

(The other three Windows failures from #2772 were fixed by #2781's first commit; this one landed after that PR was merged, so it never reached master.)

Root cause — a product bug, not test hygiene

UnifiedStore.open (src/storage/store.ts) opens the Database handle, then throws on the first pragma/migrate statement (SqliteError: file is not a database) without closing the handle — better-sqlite3 only reads the header on first statement execution, so the constructor had succeeded. Consequences:

Fix

Tests

  • storage-engine-proofs 10/10, tsc --noEmit clean
  • storage family re-run green (review-fixes 4, unified 13, replicas 4, corpus 9, export-jsonl 4)
  • windows-latest matrix (this PR) — this is the fix for the currently-red lane

Unblocks #2767 (release v0.1.193).


prepared by an agent under the local git identity (ranxianglei), human merge required

… a corrupt index

#2771 made a corrupt index.db degrade to legacy-only with the advice
"delete the file to reset the index" — but open() leaked the handle it
had just created (pragma/migrate throws after the Database constructor
succeeds, since better-sqlite3 only reads the header on first statement
execution). On Windows you cannot delete a file a live process holds
open, so the documented recovery path was impossible, and the leaked fd
also kept EPERM-failing the engine-proof tmpdir cleanup.

- UnifiedStore.open: wrap pragma+migrate in try/catch, db.close(), rethrow
- engine-proof corrupt-index test: pin the contract with a portable
  renameSync(dir) guard — POSIX tolerates open handles (always passes),
  Windows refuses to move a directory containing an open file
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_corrupt-open-handle (9365fb2)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3061-pr.2788.1bc7232

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-pr2788.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei merged commit e7b94a2 into master Oct 11, 2026
14 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.283-master.e7b94a2 (rolling master tag).

npm install -g billion-context@0.0.283-master.e7b94a2  # 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.

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