Skip to content

[PR] fix: web overview rides the persist store singleton instead of opening a second SessionStore - #5002

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-28_web-single-store
Oct 30, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-28_web-single-store

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #4990

What & why

GET /__bili/overview (and the other web read surfaces) kept their own lazily constructed SessionStore (getDiskStore() in src/web/sessions-data.ts). In unified storage modes the SessionStore constructor re-runs the full open-time path — integrity check, lockfile write, migration pass, WAL checkpoint — on the live main thread. A healthy pi-native proxy therefore stalled ~20s on its FIRST overview request with a ~900MiB database (measured 19,910ms synchronous quick_check on v0.1.208).

The engine already owns a shared store instance (persist.getStore(), constructed at boot, same dir/config/mode). This fix makes every web read site ride that singleton: one store per process, no second open, no duplicated integrity check / migration / checkpoint on the overview path.

Changes

Behavior change (disclosed)

Applies ONLY when persistence is disabled (BILI_PERSIST=0 or persist.enabled: false):

before after
overview/detail source web's own locally-enabled store → index rows authoritative in unified modes disabled engine store → legacy JSON file walk
envelope-bearing sessions listed listed (unchanged)
row-only sessions (JSON twin gone) listed from the index NOT listed anymore

Persistence-enabled paths (the default): zero behavior change — same dir, same config, same mode; the web surface was read-only already and simply stops opening a second connection.

Complements #4852 (merged, post-v0.1.208): the verdict cache made the FIRST open cheap; this removes the SECOND open entirely (it previously still paid connection + lockfile rewrite + migration pass + WAL checkpoint).

Related: #4609, #4643 (open-time integrity check cost family).

Verification

  • Local targeted runs (full suite is remote CI's job): new regression test 2/2; affected suites green — web-sessions 28/28, issue3199-overview-cold-scan 3/3, web-blocks-tree 12/12, billing-web 7/7, web-storage-fallback 2/2.
  • npm run typecheck green on the pushed head.

The web module (GET /__bili/overview and friends) kept its own lazily
constructed SessionStore. In unified storage modes that constructor re-runs
the full open-time path - integrity check, lockfile, migration pass, WAL
checkpoint - on the live main thread, so a healthy proxy stalled ~20s on
its first overview request with a ~900MiB database (v0.1.208).

- sessions-data.ts: drop the private diskStore/getDiskStore; every call
  site now rides persist.getStore() (the instance the engine already
  opened at boot)
- persist.ts: add _resetStoreForTest() (close + drop the singleton) so the
  web test reset keeps its re-resolve-env contract without owning a second
  store
- _resetDiskCacheForTest() funnels through _resetStoreForTest()
- tests/issue4990-web-single-store.test.ts: regression test covering both
  gate directions (rides the engine instance, no second open; disabled-
  store file-walk degradation). Verified to fail on pre-fix source.

Behavior change (BILI_PERSIST=0 / persist.enabled=false only): overview
and session detail previously used a locally enabled store, which listed
row-only sessions from the index in unified modes. They now ride the
disabled engine store and fall back to the legacy JSON file walk -
envelope-bearing sessions are still listed, row-only sessions are not.
Persistence-enabled paths have zero behavior change.

Related: #4609, #4643 (open-time integrity check cost family)
@ranxianglei ranxianglei changed the title fix: web overview rides the persist store singleton instead of opening a second SessionStore [PR] fix: web overview rides the persist store singleton instead of opening a second SessionStore Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-28_web-single-store (8b0db75)

Latest build — install this exact version

npm install -g billion-context@0.0.6887-pr.5002.163545e

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

Recent builds (commit → version)

commit version build
8b0db75 billion-context@0.0.6887-pr.5002.163545e build
9eacff0 billion-context@0.0.6552-pr.5002.62be92a build
c9ac406 billion-context@0.0.6540-pr.5002.ba6792b build

Download artifact

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

Install instructions are refreshed on each push.

ci-check added 2 commits October 28, 2026 03:35
…sidecar harness (#4990)

The harness injects a disabled SessionStore pointing at <run>/sessions via
_setStoreForTest but never created that dir. Before #4990 the web read
surface ignored the singleton (it built its own store on the default layout,
which the harness did create), so this stayed hidden. Now the web rides
getStore(), walks the injected dir, hits ENOENT, and stays loud per the
#1937 pristine gate (data root holds a non-infra 'sessions' entry) ->
/__bili/sessions 500s -> the sessionIds() helper crashed on .map of
undefined. Two test shards' worth of red across ubuntu/windows.

- create <run>/sessions so the injected state is production-plausible
  (in production the engine store's dir is created by the open path or is
  the pristine default layout; a custom dir beside a non-pristine data
  root cannot occur outside injection)
- sessionIds() now asserts the list shape and dumps the body instead of
  dying with an opaque TypeError when the endpoint errors

Server behavior unchanged: the #1937 loudness contract for suspicious
missing dirs is intact.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.922-master.7553b41 (rolling master tag).

npm install -g billion-context@0.0.922-master.7553b41  # 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 to Zhishulo/billion-context that referenced this pull request Oct 31, 2026
…i#4942)

Resolution notes:
- src/persist.ts single hunk: both sides inserted functions at the same
  spot. Kept ours' restoreBlockContents extraction (from the ranxianglei#5198 era) as
  its own function, dropped theirs' duplicate 'function buildSession' line
  (ours' refactored version below it already calls restoreBlockContents),
  and kept theirs' new export recordToLegacyView immediately above
  buildSession. The legacyLoad wiring (persist.ts:512) came through
  auto-merge intact.
- src/web/sessions-data.ts: took d-4987's async load shape mapped onto the
  current process singleton: 'await getStore().loadAsync(id)' (the
  branch-local getDiskStore() local is obsolete since ranxianglei#5002 unified the
  store).
- store.ts/sessions-data.ts auto-merge verified by full tsc parse.
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][web/storage] First overview creates a second SessionStore; v0.1.208 repeats a 19.91s synchronous integrity check

1 participant