Repository navigation
fix: GC the CCR content-store companions (#1180) - #1189
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1189Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1189.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Picking up the review for this PR. Plan: fetch the branch, verify it's on current master, audit the diff line-by-line against the existing GC behavior (#1082) and the CCR content-store contract (#1097), run the full pre-flight (typecheck / test / build) on the head, and report a mergeability verdict with the required regression checklist. Will follow up here. |
Session-file GC (#1082) ignored the per-session CCR content stores added by #1097: walkSessionFiles picked up <hash>.content-store.json but viewFromParsed rejected it (no savedAt field), so it was counted unreadable and kept forever — and when a session file WAS deleted its sibling store was never unlinked, orphaning potentially large lossless payload files with no code path to clean them. - co-delete the companion when its session file is deleted - sweep orphaned companions (session file already gone) once past the age gate; the reference check matches the shared hash stem across namespaces (meta fill-once can migrate _unknown/ -> namespaced without cleaning the old path), so a live store is never false-orphaned across that move - fold the store footprint (unique-content chars / 4) into the maxTokens gate: a tiny session carrying a huge store no longer slips under the size ceiling - unreadable/foreign companion next to an otherwise-eligible session keeps both files (never guess at unreadable data) - per-file audit lines for companion deletions (path + size), plus a companionsRemoved counter in GcResult (removed stays session files) - docs: companion lifecycle noted in README + CONFIGURATION, en/zh
…ace duplicate (#1180) Meta fill-once (session.ts getSession) migrates a session _unknown/<h>.json -> ns/host_<h>.json without cleaning the old path (kernel StateStore writes never delete the previous relPath), and saveContentStore only rewrites when dirty. A moved CCR session whose store was not re-saved since the move therefore still reads its LIVE store from the stale duplicate's sibling (loadContentStore probes _unknown/ when the namespaced store is absent, stopping at the first existing candidate). The co-delete pairing is strictly same-directory, so sweeping the aged duplicate would unlink live lossless payload bytes. Guard: skip the companion unlink when another surviving session file shares the hash stem and has no store of its own. The bytes then stay referenced until that twin itself is swept, after which the orphan pass collects them. When the twin owns its own (shadowing) store the flat sibling is dead bytes and co-deletion proceeds as before. Adds 3 regression tests: duplicate + fresh twin without own store (store kept); duplicate + twin with own store (dead copy co-deleted, live one kept); both copies eligible (whole session incl. lone store swept, order-independent).
86c5e01 to
333135c
Compare
[bot] 🏷 PR review — #1189 "fix: GC the CCR content-store companions" Pre-flight (on rebased head)Base was 3 commits behind master (#1187 native-fetch-guard); I rebased onto current master ( Diff cleanlinessClean. 6 files, every line serves the purpose: Regression audit — existing behaviors on touched paths
Problem found & fixed directly on the branch (commit
|
… foreign-companion audit log (#1180)
|
复核完成(人工 + 独立 reviewer 双轨),两个 SHOULD-FIX 已修并推回( 修复 1 — 估算器混用: 修复 2 — 孪生守卫 inode 探测改为形状探测: 顺带:外族/不可识别伴生文件的永久保留现在有审计日志(#1082 精神:每个保留决定可追溯)。 复核确认(review 裁定无阻塞):两个根因属实;删除安全通过对抗审计——年龄门分层正确、无 stat→rm 间 await(无 TOCTOU)、24-hex stem 无碰撞、不跟随符号链接、Windows basename 后缀判断保守。 可合并。 |
[bot] 🏷 复核验证完成 — 独立验证(不是转述,是逐条查证)修复 1(估算器混用)— 成立且必要。 我追了完整链条: 修复 2(形状探测)— 你抓到了我守卫里的真实角落。 我之前只验证了「malformed JSON → return null 不穿透」,漏了 顺带审计日志 — 已确认:外族/不可识别伴生文件导致的双保留现在逐条留痕,符合 #1082「每个保留决定可追溯」精神。 增量行为审查(本轮 diff = a3ec90f + 7321d7d)
无 wire/schema/persistence/kernel 触碰;删除安全性(年龄分层、无 stat→rm 间 await、stem 唯一性、不跟符号链接)与上轮对抗审计结论一致。 我补的提交
|
What
Session-file GC (#1082) ignored the per-session CCR content stores added by #1097:
walkSessionFilesaccepts any*.json, so<hash>.content-store.jsonentered the sweep, butviewFromParsedrequires a top-levelsavedAt, which the store envelope{version, byHash, byRef}lacks → countedunreadable, kept forever.rm'd the session file; the sibling store was never unlinked, orphaning potentially large lossless payload files with no code path to clean them.Changes (
src/session-gc.ts+ tests + docs).content-store.json(deterministic sibling percontentStoreRelPathFor) is unlinked too.session.ts) can migrate a session_unknown/→ namespaced without cleaning the old path, so sibling-only matching would false-orphan live store bytes across that move.totalChars) is folded into theBILI_SESSION_GC_MAX_TOKENSgate, so a tiny session carrying a huge store cannot slip under the ceiling.GcResultgainscompanionsRemoved(removedstays "session files").Deliberately NOT done: treating "has content-store entries" like
everCompressed(would permanently exempt CCR sessions from GC — the population with the biggest files — contradicting the lossless-bytes argument of the issue).Behavior changes (flagged per owner policy)
All behind the existing opt-in
BILI_SESSION_GC(default off):MAX_AGE_DAYSrawInputTokens/contextTokensbefore comparing toMAX_TOKENS+ N content store file(s)when some areNo wire/message-shape, config-schema, persistence-format, or acp-kernel changes.
Tests
8 new cases in
tests/session-gc.test.ts: stale CCR session → both files removed; live session + aged companion → untouched; cross-namespace companion still referenced (no false-orphan); orphan sweep (aged removed, fresh kept); tiny session + huge store → ineligible while its store-less twin is deleted; unreadable companion → both kept; plus unit tests forcontentStoreTokensand the folded size gate.Pre-flight on rebased head (master
03dd9c78): typecheck clean · full suite 2359 pass / 0 fail / 2 skipped (pre-existing e2e gates) · build success.Fixes #1180