From 169d0e0de671fcccb454ec76f0595d8500b5a6bc Mon Sep 17 00:00:00 2001 From: awork Date: Mon, 19 Oct 2026 06:59:18 +0800 Subject: [PATCH 1/4] fix: hash-free lite fold anchors for past-cap tool cores (#3752) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The MAX_ANCHORS=16384 seed-loop cap (#2334) dropped every covered id past the window entirely, leaving the positional scan as their only recovery channel — and that scan dies after MAX_RESYNC_GAPS accumulated breaks. On long sessions with weeks of genuine drift, the 0.1.200->0.1.201 identity re-key (#3658) therefore mass-unfolded thousands of folded messages per session in both directions (upgrade and downgrade). Past-cap tool cores now persist a hash-free lite anchor ({r,c,t,b}): Pass 1's toolCallId channel consumes exactly those fields, so they re-anchor at any session length with zero added hashing and no new misattribution surface (claim discipline unchanged). Non-tool past-cap cores keep the positional-only status quo; the full-anchor cap and the #2334 zero-work steady-state contract are untouched (lite anchors reuse verbatim). FoldAnchor.n becomes optional (norm-keyed passes skip absent n); the seed loop continues past the cap for tool cores instead of breaking. Regression tests pin mint shape, the channel (via the reconciler's own counter), and the pre-fix-ledger convergence replay; all red without the fix, green with it. --- src/fold-reconcile.ts | 71 +++++-- tests/issue3752-lite-anchors.test.ts | 267 +++++++++++++++++++++++++++ 2 files changed, 324 insertions(+), 14 deletions(-) create mode 100644 tests/issue3752-lite-anchors.test.ts diff --git a/src/fold-reconcile.ts b/src/fold-reconcile.ts index bb6d2ed930..b207da8695 100644 --- a/src/fold-reconcile.ts +++ b/src/fold-reconcile.ts @@ -273,8 +273,10 @@ function resetFoldDriftState(session: Session): void { /** Per-covered-id anchor recorded from the last pass in which the id was seen. * Stored in session.metadata.foldAnchors (persisted, free-form field). */ export interface FoldAnchor { - /** sha256-16 of role\0contentType\0toolName\0toolCallId\0normalizedText. */ - n: string; + /** sha256-16 of role\0contentType\0toolName\0toolCallId\0normalizedText. + * Absent on #3752 lite anchors (minted beyond the MAX_ANCHORS window, + * hash-free by construction) — every norm-keyed pass skips them. */ + n?: string; /** #2396: sha256-16 of role\0contentType\0toolName\0normalizedText (no * toolCallId) — set alongside `t`; pairs a missing id with an inbound * twin whose only difference is a rewritten toolCallId. Anchors @@ -678,6 +680,21 @@ function anchorFrom(message: CoreMessage, ctx?: TurnCtx): FoldAnchor { return anchor; } +// #3752: hash-free anchor for tool cores minted beyond the MAX_ANCHORS window. +// The window exists to bound per-pass hashing (#2334), but ids past it lost +// EVERY channel except the positional scan, which dies after MAX_RESYNC_GAPS +// accumulated breaks — so on long sessions a bili-side identity re-key left +// thousands of tool cores unrecoverable (the #3752 incident). Pass 1 consumes +// exactly {t, r}; {c, b} keep the drift classifier and length guards honest. +function liteToolAnchorFrom(message: CoreMessage): FoldAnchor { + return { + r: message.role, + c: message.contentType, + t: message.toolCallId as string, + b: message.text?.length ?? 0, + }; +} + interface BlockLike { blockId?: string; active?: boolean; @@ -965,7 +982,7 @@ export function planReconciliation( for (const oldId of missingMiddle) { if (plan.claims.has(oldId)) continue; const anchor = anchors[oldId]; - if (anchor === undefined) continue; + if (anchor === undefined || anchor.n === undefined) continue; const g = normGroups.get(anchor.n); if (g === undefined) continue; if (g.anchors.length >= g.ids.length) continue; @@ -1097,9 +1114,10 @@ export function planReconciliation( for (const oldId of missingMiddle) { if (plan.claims.has(oldId)) continue; const anchor = anchors[oldId]; - if (anchor === undefined || anchor.t !== undefined) continue; + if (anchor === undefined || anchor.t !== undefined || anchor.n === undefined) continue; + const normKey = anchor.n; const take = (map: Map): string | undefined => { - const bucket = map.get(anchor.n); + const bucket = map.get(normKey); if (bucket === undefined) return undefined; const usable = bucket.filter((id) => { const c = candById.get(id); @@ -1124,7 +1142,7 @@ export function planReconciliation( for (const oldId of missingMiddle) { if (plan.claims.has(oldId)) continue; const anchor = anchors[oldId]; - if (anchor === undefined || anchor.t !== undefined) continue; + if (anchor === undefined || anchor.t !== undefined || anchor.n === undefined) continue; const bucket = byNorm.get(anchor.n); if (bucket === undefined) byNorm.set(anchor.n, [oldId]); else bucket.push(oldId); @@ -1546,19 +1564,31 @@ export function reconcileFoldCoverage(session: Session, msgs: CoreMessage[], opt // form computed a full normalization + sha256 for every covered id and // discarded the overflow — and the discarded ids had no stored anchor // to reuse, so EVERY subsequent pass recomputed and dropped them again - // (a 20k-id session paid 3616 wasted hashes per request). Breaking at - // the cap keeps exactly the old survivor set (first MAX_ANCHORS in + // (a 20k-id session paid 3616 wasted hashes per request). Capping at + // MAX_ANCHORS keeps exactly the old survivor set (first MAX_ANCHORS in // covered order — the deletion loop removed precisely the tail) and the - // key order; ids past the cap still get no anchor, as before. - if (anchorCount >= MAX_ANCHORS) break; + // key order. + // #3752: ids PAST the cap no longer fall out entirely — tool cores get + // a hash-free lite anchor ({r, c, t, b}) so Pass 1's toolCallId channel + // reaches them at any session length. Before this, the positional scan + // was their only path, and it dies after MAX_RESYNC_GAPS accumulated + // breaks — on long sessions with weeks of genuine drift that turned + // bili's own identity re-key (#3658) into a mass unfold (the incident + // that opened #3752). Non-tool cores past the cap keep the old status + // quo (positional-only): their channels need text hashes, exactly the + // cost the window bounds. const claimed = plan.claims.get(id); if (claimed !== undefined) { for (const nid of new Set(claimed)) { if (nextAnchors[nid] !== undefined) continue; const message = byId.get(nid); if (message === undefined) continue; - nextAnchors[nid] = anchorFrom(message, turnCtxFor(message)); - anchorCount++; + if (anchorCount < MAX_ANCHORS) { + nextAnchors[nid] = anchorFrom(message, turnCtxFor(message)); + anchorCount++; + } else if (message.toolCallId !== undefined && message.toolCallId !== "") { + nextAnchors[nid] = liteToolAnchorFrom(message); + } } continue; } @@ -1569,6 +1599,15 @@ export function reconcileFoldCoverage(session: Session, msgs: CoreMessage[], opt // rounds near-free on 8K-message histories). const prior = anchors[id]; if (prior !== undefined) { + if (anchorCount >= MAX_ANCHORS) { + // Reuse verbatim, no backfill: past the window the stored + // anchor (full or lite) already carries everything any + // reachable channel needs, and backfilling would pay hashes + // for nothing (#2334 steady-state contract, extended to the + // tail). + nextAnchors[id] = prior; + continue; + } // #2396: anchors persisted before the no-toolCallId norm existed // lack `m`; backfill it while the bytes are still on the wire — // one extra normalization per such anchor, once (same-id means @@ -1605,8 +1644,12 @@ export function reconcileFoldCoverage(session: Session, msgs: CoreMessage[], opt } const message = byId.get(id); if (message !== undefined) { - nextAnchors[id] = anchorFrom(message, turnCtxFor(message)); - anchorCount++; + if (anchorCount < MAX_ANCHORS) { + nextAnchors[id] = anchorFrom(message, turnCtxFor(message)); + anchorCount++; + } else if (message.toolCallId !== undefined && message.toolCallId !== "") { + nextAnchors[id] = liteToolAnchorFrom(message); + } } } const nextOrder = plan.newOrder.slice(-MAX_ORDER); diff --git a/tests/issue3752-lite-anchors.test.ts b/tests/issue3752-lite-anchors.test.ts new file mode 100644 index 0000000000..160b362ef0 --- /dev/null +++ b/tests/issue3752-lite-anchors.test.ts @@ -0,0 +1,267 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { createInitialState, type CoreMessage } from "acp-kernel"; +import type { Session } from "../src/session.ts"; +import { + reconcileFoldCoverage, + normalizedIdentity, + positionalFingerprint, + type FoldAnchor, +} from "../src/fold-reconcile.ts"; + +// #3752 — the 0.1.200→0.1.201 identity re-key mass-unfolded long sessions +// because covered ids beyond the MAX_ANCHORS=16384 window lost EVERY channel +// except the positional scan, which dies after MAX_RESYNC_GAPS accumulated +// breaks. Weeks of genuine drift guarantee >8 breaks on a 15K-core session, +// so the window's tool cores became unrecoverable in both directions +// (upgrade AND downgrade). The fix mints hash-free LITE anchors ({r,c,t,b}) +// for tool cores beyond the window: Pass 1's toolCallId channel consumes +// exactly those fields, so tool cores re-anchor at any session length. +// +// Pinned properties: +// 1. the seed loop mints lite anchors past the cap — ONLY for tool cores +// (non-tool cores keep the old positional-only status quo) and WITHOUT +// touching the full-anchor cap (#2334 contract); +// 2. when the positional scan has died in the past-cap region, Pass 1 +// claims the past-cap tool cores THROUGH THE toolCallId CHANNEL (asserted +// on the reconciler's own counter, not just on outcomes), pairing each +// new id with the protocol tool id it actually carries (no cross-pairing); +// 3. the incident trajectory converges: a true pre-fix ledger + a re-keyed, +// drift-riddled resend may lose dead-middle cores once (honest — no +// bytes on the wire under the old ids to pair from), the refold +// re-covers the new ids, and from the next pass on the ledger is +// complete and the session sits in drift-free steady state. + +const CAP = 16384; // mirrors MAX_ANCHORS in src/fold-reconcile.ts +const TURNS = 5700; // 3 cores/turn → 17100 covered, past the cap +type Kind = "user" | "call" | "result"; + +interface FixtureMsg extends CoreMessage { + kind: Kind; + turn: number; + toolCallId?: string; +} + +function makeSession(): Session { + return { + id: `test-${Math.random().toString(36).slice(2)}`, + meta: {}, + stats: { requests: 0, tokensSaved: 0, inputTokens: 0, cachedTokens: 0, outputTokens: 0, cacheSamples: 0, lastInputTokens: 0, compressCreditTokens: 0, contextTokens: 0, retrieveCalls: 0, retrieveHits: 0, retrieveMisses: 0, storedBytes: 0, storeBytesSaved: 0, rangeRestores: 0 }, + metadata: {}, + state: createInitialState(), + createdAt: Date.now(), + lastSeen: Date.now(), + blockContents: new Map(), + inFlight: 0, + persisted: false, + pendingRetrievals: [], + }; +} + +// One long OpenCode-style history: each turn = user text + assistant +// tool-call + tool-result. Tool ids embed the turn so every toolCallId is +// conversation-unique (protocol guarantee) while core ids stay synthetic. +function buildBase(): FixtureMsg[] { + const out: FixtureMsg[] = []; + for (let t = 0; t < TURNS; t++) { + out.push({ + id: `u_${t}`, kind: "user", turn: t, + role: "user", contentType: "text", + text: `request ${t} ${"x".repeat(120)}`, + }); + out.push({ + id: `tc_${t}`, kind: "call", turn: t, toolCallId: `tu_${t}`, + role: "assistant", contentType: "tool-call", toolName: "bash", + text: `{"command":"step ${t}","cwd":"/w"}`, + }); + out.push({ + id: `tr_${t}`, kind: "result", turn: t, toolCallId: `tu_${t}`, + role: "tool", contentType: "tool-result", + text: `output of step ${t} ${"y".repeat(120)}`, + }); + } + return out; +} + +const isTool = (m: FixtureMsg): boolean => m.kind !== "user"; + +// The resent generation: bili's own re-key (every tool core re-minted — same +// bytes, new ids, exactly what #3658 does to this lane) PLUS genuine host-side +// drift concentrated in the TAIL: the last `mutateTail` user messages edited +// (new bytes, new ids). All edits land strictly inside the past-cap region +// (turn ≥ TURNS-240 → index ≥ 16500), so the head scan runs clean to the cap +// boundary and then dies at the first break (consecutive edits leave no +// 3-run resync window), and the tail scan dies after 8 gaps near the very end +// — the entire past-cap middle is positional-dead and only an anchor channel +// can claim it. +function buildResent(base: FixtureMsg[], mutateTail: number): { msgs: CoreMessage[]; mutatedUserIds: string[] } { + const mutatedUserIds: string[] = []; + const cut = TURNS - mutateTail; + const msgs: CoreMessage[] = base.map((m) => { + if (isTool(m)) return { ...m, id: `${m.id}_remint` }; + if (m.turn >= cut) { + const nm = { ...m, id: `${m.id}_e`, text: `request ${m.turn} REWRITTEN BY HOST ${"z".repeat(116)}` }; + mutatedUserIds.push(nm.id as string); + return nm; + } + return m; + }); + return { msgs, mutatedUserIds }; +} + +function fullAnchor(m: CoreMessage): FoldAnchor { + return { n: normalizedIdentity(m), r: m.role, c: m.contentType, b: (m.text ?? "").length }; +} + +function liteAnchor(m: FixtureMsg): FoldAnchor { + return { r: m.role, c: m.contentType, t: m.toolCallId, b: (m.text ?? "").length }; +} + +function installBlock(session: Session, ids: string[]): void { + session.state.blocks = [{ + blockId: "b0", runId: "r0", tier: 1, summary: "fold", directMessageIds: ids, + effectiveMessageIds: ids, directBlockIds: [], compressedTokens: 1000, createdAt: Date.now(), + survivedCount: 0, generation: "young", active: true, + }]; +} + +function installLedger(session: Session, base: FixtureMsg[], anchors: Record): void { + const ids = base.map((m) => m.id as string); + installBlock(session, ids); + session.metadata = { + foldAnchors: anchors, + foldAnchorOrder: [...ids], + foldPositions: { ids: [...ids], canon: base.map((m) => positionalFingerprint(m)) }, + }; +} + +function toolClaimCount(logs: string[]): number { + for (const line of logs) { + const m = /(\d+) by toolCallId/.exec(line); + if (m !== null) return Number(m[1]); + } + return -1; +} + +test("#3752: seed loop mints hash-free lite anchors for past-cap tool cores only", () => { + const session = makeSession(); + const base = buildBase(); + installLedger(session, base, {}); + + reconcileFoldCoverage(session, base, { mode: "repair" }); + + const anchors = session.metadata["foldAnchors"] as Record; + const full = Object.values(anchors).filter((a) => a.n !== undefined); + // The expensive-anchor cap holds exactly as before (#2334 contract)… + assert.equal(full.length, CAP, "full anchors must stay capped at MAX_ANCHORS"); + // …but past-cap TOOL cores now persist hash-free lite anchors… + const pastCapTools = base.filter((m, i) => i >= CAP && isTool(m)); + for (const m of pastCapTools) { + const a = anchors[m.id as string]; + assert.ok(a !== undefined, `past-cap tool core ${m.id} must get a lite anchor`); + assert.equal(a.n, undefined, "lite anchors carry no norm hash"); + assert.equal(a.m, undefined, "lite anchors carry no twin norm"); + assert.equal(a.sh, undefined, "lite anchors carry no simhash"); + assert.equal(a.wh, undefined, "lite anchors carry no wordbag"); + assert.equal(a.t, m.toolCallId, "lite anchors keep the protocol tool id (Pass 1's key)"); + assert.equal(a.r, m.role); + assert.equal(a.c, m.contentType); + assert.equal(a.b, (m.text ?? "").length); + } + // …while past-cap NON-tool cores keep the old status quo (no anchor). + const pastCapNonTools = base.filter((m, i) => i >= CAP && !isTool(m)); + for (const m of pastCapNonTools) { + assert.equal(anchors[m.id as string], undefined, `past-cap non-tool core ${m.id} must stay anchor-less`); + } + assert.equal(Object.keys(anchors).length, CAP + pastCapTools.length); +}); + +test("#3752: past-cap tool cores are claimed through the toolCallId channel when position is dead", () => { + const session = makeSession(); + const base = buildBase(); + const { msgs: resent, mutatedUserIds } = buildResent(base, 240); + // Ledger as a RUNNING FIXED build persists it: full anchors under the + // cap, hash-free lite anchors for past-cap tool cores, nothing else. + const anchors: Record = {}; + base.forEach((m, i) => { + if (i < CAP) anchors[m.id as string] = fullAnchor(m); + else if (isTool(m)) anchors[m.id as string] = liteAnchor(m); + }); + installLedger(session, base, anchors); + + const logs: string[] = []; + reconcileFoldCoverage(session, resent, { mode: "repair", log: (level, msg) => { logs.push(`${level}: ${msg}`); } }); + + // The reconciler's own accounting proves the channel: some past-cap tool + // cores were claimed BY TOOLCALLID (position died before the cap region + // could be reached from either flank). + assert.ok(toolClaimCount(logs) > 0, `expected a positive toolCallId claim count in the drift log, got: ${logs.join(" | ")}`); + + const nextAnchors = session.metadata["foldAnchors"] as Record; + // Every re-minted tool core — including EVERY one past the cap — must be + // claimed (byTool through the dead region, byPos in the surviving flanks). + // A claimed id seeds its anchor under the NEW id this pass. + let pastCapClaimed = 0; + base.forEach((m, i) => { + if (!isTool(m)) return; + const newId = `${m.id}_remint`; + const a = nextAnchors[newId]; + assert.ok(a !== undefined, `re-minted tool core ${newId} must have been claimed`); + assert.equal(a.t, m.toolCallId, `anchor under ${newId} must carry its own tool id (no cross-pairing)`); + assert.equal(a.r, m.role); + if (i >= CAP) pastCapClaimed++; + }); + assert.ok(pastCapClaimed > 0, "fixture must exercise past-cap tool cores"); + // Full-anchor discipline survives the churn pass unchanged. + assert.ok(Object.values(nextAnchors).filter((a) => a.n !== undefined).length <= CAP); + // The host edits never leak into the tool channel: no anchor seeded under + // a mutated USER id carries a tool id. + for (const id of mutatedUserIds) { + const a = nextAnchors[id]; + if (a !== undefined) assert.equal(a.t, undefined, `mutated user cell ${id} must not gain a tool id`); + } +}); + +test("#3752: incident trajectory — true pre-fix ledger converges to a complete ledger in one refold", () => { + const session = makeSession(); + const base = buildBase(); + const { msgs: resent } = buildResent(base, 240); + const resentIds = resent.map((m) => m.id as string); + // PRE-FIX ledger: exactly what a 0.1.200 build persisted — full anchors + // for the first CAP ids, NOTHING beyond (the break-at-cap survivor set). + const anchors: Record = {}; + base.forEach((m, i) => { if (i < CAP) anchors[m.id as string] = fullAnchor(m); }); + installLedger(session, base, anchors); + + // Pass 1 — the first request after the upgrade. Dead-region cores may + // lose once (honest loss: no bytes on the wire under the old ids); the + // pass must stay consistent regardless. + reconcileFoldCoverage(session, resent, { mode: "repair" }); + assert.notEqual(session.metadata["foldDriftEscalated"], true, "one partial pass must not latch destruction"); + + // The proxy's preflight re-folds the unfolded content: coverage now + // follows the CURRENT ids (applyRanges semantics — same bytes, new ids). + installBlock(session, resentIds); + + // Pass 2 — every covered id is on the wire: the seed loop mints a + // COMPLETE ledger, full under the cap, lite for past-cap tool cores. + reconcileFoldCoverage(session, resent, { mode: "repair" }); + const after2 = session.metadata["foldAnchors"] as Record; + const pastCapTools = base.filter((m, i) => i >= CAP && isTool(m)); + for (const m of pastCapTools) { + const a = after2[`${m.id}_remint`]; + assert.ok(a !== undefined, `post-refold past-cap tool core ${m.id} must be anchored`); + assert.equal(a.n, undefined, "minted past the cap → lite shape"); + assert.equal(a.t, m.toolCallId); + } + const fullAfter2 = Object.values(after2).filter((a) => a.n !== undefined).length; + assert.ok(fullAfter2 > 0 && fullAfter2 <= CAP, "cap intact after the refold"); + + // Pass 3 — steady state: the ledger is frozen (pure reuse) and no drift + // state accrues. The session is drift-proof for tool cores at this length. + const keysBefore = Object.keys(after2).sort().join("\n"); + reconcileFoldCoverage(session, resent, { mode: "repair" }); + const after3 = session.metadata["foldAnchors"] as Record; + assert.equal(Object.keys(after3).sort().join("\n"), keysBefore, "steady-state pass must neither add nor drop anchors"); + assert.notEqual(session.metadata["foldDriftEscalated"], true, "converged session must not carry the destruction latch"); +}); From fca804df5cf2ae4545664fa23cdab4abf3a5e5a5 Mon Sep 17 00:00:00 2001 From: awork Date: Mon, 19 Oct 2026 10:38:06 +0800 Subject: [PATCH 2/4] docs: changelog entry for #3752 + correct #3642 upgrade-cost wording --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60b22f8433..52981f273a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,11 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag - **Fork 子会话不再因前缀漂移永久 409(#3741,owner 决策:门降 advisory)**:dsh/客户端 fork 出的子会话,其首个请求如果与继承的有序前缀不匹配(升级换代重排消息 id、宿主改写 body 等),过去直接 409 且被拒请求不计数——重试永远撞同一扇门,子会话确定性卡死、无任何自愈或清除路径。现在改为**照常收养**:session-id 绑定本来就是真正的唤醒路由,折叠覆盖差异由 reconcile(#3641 order-over-hash)兜底修复;漂移首请求付出一次性未折叠 token 峰,正确性无损。每次收养打一条带分类的 warn(reason 沿用 #3743 诊断:id-drift / hash-drift-under-same-id / prefix-longer-than-incoming 等),`publicForkPrefix` 在漂移时保持 false,side-lane 降级启发照常发言。测试:三种漂移形态全部 200+转发+父会话不动+恰一条 warn(one-shot:首请求后 stats.requests>0 绕过检查)。 - **快照渲染:proxy 车道的出站前缀改由服务端正史渲染,存量会话对内核升级免疫(#3756,根治 #3752/#3751)。** 折叠覆盖此前锚定在"客户端本轮重发的字节"上——消息 id 由内容哈希现算,身份函数一变(协议切换 #3640、#3642 的一次性 re-key、dsh 图片 offload #3588、宿主自查点)覆盖名单就与历史失联:轻则整段历史因 MAX_ANCHORS=16384 封顶失锚(#3752),重则图片族 `_N` 后缀全体位移重铸、每轮 fold 断缓存(#3751)。新引擎 `src/server/snapshot-render.ts`(灰度开关 `BILI_ROLLOUT_SNAPSHOT_RENDER`,默认 0%):当会话有活跃折叠块且统一存储可读时,prepare 层的出站消息序列 = 服务端快照行前缀(覆盖区由块的 seq/signature 覆盖集自拥抑制 + `acp_summary_*` 锚原位重渲,身份跟随块而非客户端字节)+ 客户端尾巴(分歧点 join 之上逐字保留,rewind 裁剪不复活)。链回溯用 id 快路径 + 内容签名兜底(#3658 canonical 种子同构,升级后同内容仍可链上);任何环节失步整轮降级回 legacy 路径,零行为面风险。验收:身份函数原地翻盐后出站前缀逐字节不变(老病当场钉死)、协议中途切换会话不分叉、客户端任意删/checkpoint 覆盖区不复活(一轮采用滞后,模块头有注释)、稳态轮轮前缀字节稳。观测闩 `metadata.snapshotRenderTurns`;kernel 加 `__setMessageIdSaltForTests` 测试缝(kernel 0.0.134,仅测试可达,生产零调用)。 +- **Fold anchors no longer cliff at the 16k window: past-cap tool cores keep a hash-free lite anchor, so bili-side identity re-keys stop mass-unfolding long sessions (#3752).** The seed loop capped EXPENSIVE (hash-carrying) anchors at `MAX_ANCHORS` = 16384 and dropped everything past the window entirely (#2334) — but ids past the cap thereby lost every recovery channel except the positional scan, which dies after 8 accumulated fingerprint breaks. On a session with weeks of genuine drift the whole tail region is positional-dead, so any id re-mint (the 0.1.200→0.1.201 canonical-identity re-key #3658) left thousands of folded messages unrecoverable per session — field incident #3752: every active session mass-unfolded on upgrade (one Anthropic session 125K→998K input tokens in one turn, cache hit 2%), and the downgrade re-churned identically. Past-cap TOOL cores now persist a hash-free **lite anchor** (`{r, c, t, b}` — role, content class, protocol tool id, text length): Pass 1's toolCallId channel consumes exactly those fields, so they re-anchor at any session length with zero added hashing and no new misattribution surface (claim discipline unchanged: unique unclaimed candidate per (toolCallId, role)). Non-tool past-cap cores keep the positional-only status quo (their channels need text hashes — exactly what the window bounds), the full-anchor cap itself is untouched (#2334 contract), and steady-state passes stay zero-work (lite anchors reuse verbatim). The first transition pass after a re-key is unchanged — dead-region cores may unfold ONCE (no bytes on the wire under the old ids to pair from); convergence lands on the next fold, from which the session is drift-proof for tool cores at that length. Additive persistence only: new entries in the existing `foldAnchors` metadata record, old builds reading them degrade gracefully (their Pass 1 already consumes `{t, r}`; norm-keyed passes skip the absent `n`). Regression tests: `tests/issue3752-lite-anchors.test.ts` (mint shape, channel proof via the reconciler's own counter, pre-fix-ledger convergence replay; red without the fix). + - **Automatic upgrades now stagger across a window instead of landing within minutes; a public policy file controls the window fleet-wide (#3619).** Every bili instance that discovers a new version draws ONE random moment inside a delay window (built-in default **15 min – 48 h**), persists it, and upgrades when it arrives — restarts never re-roll. Before this, a release hit every auto-updating install within ~15–30 minutes, leaving no time to stop a bad one mid-rollout (#3401/#3600/#3394 were all shipped-too-fast incidents). The window and the emergency controls live in `auto-update-policy.json` in this repo, fetched anonymously (plain GET + ETag, zero telemetry, fail-open — an unreachable or malformed file falls back to local defaults): `hold` freezes automatic upgrades fleet-wide, `blocked` skips listed versions, `pinned` sets an upgrade ceiling, and per-version `overrides` tune the window (`{ "range": ">=0.1.200", "maxDelay": "1h" }`). Delay fields take human-readable durations — `"15m"`, `"2d"`, `"1d12h"` (units s/m/h/d/w, combinable; plain numbers still mean raw ms); malformed values are ignored with a warning, never guessed. The file steers timing/skip/pin only — it can never control what gets installed (no URLs, no commands; target versions must exist in the npm packument). Exits: manual `bili update` bypasses `hold`/stagger (still respects `blocked`/`pinned`), `update.staggerMinDelayMs: 0` + `update.staggerMaxDelayMs: 0` (or the `BILI_UPDATE_STAGGER_*_MS` twins) restore legacy immediate upgrades on one machine, `ACP_AUTO_UPDATE=0` disables auto-updates entirely. The update-driven e2e suites pin stagger 0/0 + an unroutable policy URL — they test periodic-update mechanics, not rollout timing. - **openai wire: non-array content tolerance (kernel 0.0.133, #3658 follow-up)** — the #3642 per-part rewrite iterated `messages[].content` and threw `TypeError: m.content is not iterable` on clients that emit a lone content-part object instead of an array (#2824 corpus caught it). Non-array non-string content now degrades to the legacy empty-text core (byte-compatible ids and bytes with the pre-#3642 codec) instead of throwing. Also regenerates the storage-render chat goldens for the documented one-time canonical re-key (tool-pair ids), and inverts the retired reconcile-off id-churn control into an absorption canary: with reconcile OFF, tool_call id rewrites + argument re-serialization must not disturb fold coverage (canonical ids absorb them by construction). -- **protocol-stable core identity: the same logical conversation now yields byte-identical core message ids in all four dialects (#3642).** Wire codecs previously baked dialect accidents into message identity: anthropic used `"[image]"` as image text while openai deliberately kept `""` ("switching the seed would move every pre-existing shape"), tool-call ids embedded the provider's `toolCallId` bytes, raw JSON tool arguments hashed verbatim (key order = new id), and responses' empty-text reasoning cells seeded from the provider's volatile `item.id`. Switch protocols mid-session (opencode #3640: `/chat/completions` → `/v1/messages`) and ~20-68% of ids churned, tripping the fold-destroyed misdiagnosis #3641 just class-fixed. Identity now derives from a canonical form shared by all four codecs: a new `kernel/src/wire/identity.ts` (canonicalToolArgs: JSON args parsed → recursive key sort → compact stringify, verbatim for non-JSON; canonicalOpaqueSeed: provider `item.id`/`status` stripped; image marker `[image]` everywhere), the `toolCallId` slot retired from the seed (cluster suffixes disambiguate same-shape calls, deleting one sibling is local damage), and granularity normalized to one core per content part (anthropic's existing shape — its lanes take zero granularity re-keying, though tool-call/tool-result cores still re-seed since the `toolCallId` slot is retired; openai/responses/google split runs, with accumulators re-merging on rebuild so the wire stays byte-stable). The kernel first-user pin now spans the opening message's whole core run, so a multimodal opening message keeps its image bytes through folds (#781/#2607). Cross-protocol golden: text/tool/bash conversation → identical id arrays in all four dialects; canonical key-sort makes `{"file","line"}` == `{"line","file"}`. Image cells are now stamped `imagePart: true` at parse time (never text-compared — tag injection rewrites markers mid-render, which previously made image cores render as text and lose the real bytes, #767 billing fallout). Upgrade cost is one re-key of stored ids for openai/responses/google lanes; the #3641 reconcile tiers (word-bag claims, k-th image family pairing, toolCallId channel, epoch gate) absorb it without re-folding. +- **protocol-stable core identity: the same logical conversation now yields byte-identical core message ids in all four dialects (#3642).** Wire codecs previously baked dialect accidents into message identity: anthropic used `"[image]"` as image text while openai deliberately kept `""` ("switching the seed would move every pre-existing shape"), tool-call ids embedded the provider's `toolCallId` bytes, raw JSON tool arguments hashed verbatim (key order = new id), and responses' empty-text reasoning cells seeded from the provider's volatile `item.id`. Switch protocols mid-session (opencode #3640: `/chat/completions` → `/v1/messages`) and ~20-68% of ids churned, tripping the fold-destroyed misdiagnosis #3641 just class-fixed. Identity now derives from a canonical form shared by all four codecs: a new `kernel/src/wire/identity.ts` (canonicalToolArgs: JSON args parsed → recursive key sort → compact stringify, verbatim for non-JSON; canonicalOpaqueSeed: provider `item.id`/`status` stripped; image marker `[image]` everywhere), the `toolCallId` slot retired from the seed (cluster suffixes disambiguate same-shape calls, deleting one sibling is local damage), and granularity normalized to one core per content part (anthropic's existing shape — its lanes take zero granularity re-keying, though tool-call/tool-result cores still re-seed since the `toolCallId` slot is retired; openai/responses/google split runs, with accumulators re-merging on rebuild so the wire stays byte-stable). The kernel first-user pin now spans the opening message's whole core run, so a multimodal opening message keeps its image bytes through folds (#781/#2607). Cross-protocol golden: text/tool/bash conversation → identical id arrays in all four dialects; canonical key-sort makes `{"file","line"}` == `{"line","file"}`. Image cells are now stamped `imagePart: true` at parse time (never text-compared — tag injection rewrites markers mid-render, which previously made image cores render as text and lose the real bytes, #767 billing fallout). Upgrade cost is one re-key of stored ids on **all** lanes — tool-call/tool-result cores everywhere (the retired `toolCallId` slot re-seeds them regardless of dialect), plus image/reasoning/opaque cores and run-split granularity on openai/responses/google; the #3641 reconcile tiers (word-bag claims, k-th image family pairing, toolCallId channel, epoch gate) absorb it without re-folding for ids inside the anchor window — the beyond-window residual is #3752, fixed by the lite-anchor entry below. *(Wording corrected post-release: the original sentence said "openai/responses/google lanes", contradicting this entry's own statement that anthropic tool cores re-seed — the 0.1.200→0.1.201 field incident #3752 confirmed the Anthropic lane was affected.)* - **fold anchoring doctrine: order over hash — protocol switches, image offload, and host-side truncation stop being read as destruction (#3641, fixes #3588, fixes #3640).** Three real-world defect classes all shared one root: the fold's identity model keyed coverage to content hashes, so any transformation that re-mints ids without removing content (dsh's image-offload component rewriting image cells into placeholder text, opencode switching a mid-session request from `/chat/completions` to `/v1/messages`, or a host that compacts/truncates history itself) made every covered id look *destroyed*. Consequences: 7× false "compression substrate appears destroyed" escalations on healthy sessions (#3588), 298-id churn with unanchored summary blocks landing AFTER the user's newest question — the model answered five rounds of stale summaries instead of the question (#3640) — and the #2193 collapse streak on sanctioned host compaction. The reconcile pass now carries a shape tier (loose word-evidence pairing for prose cells, a flanked k-th discipline for evidence-less image cells), a residual census classifying unmatched ids as *transformed* (near-duplicate evidence exists), *absent* (content truly off the wire with the surviving wire a suffix-continuation of the episode baseline), or *drift* (nothing matches anywhere); only the third accrues the collapse streak, and a wire-frozen episode witness guarantees a foreign conversation can never quietly become the baseline mid-episode. Unresolved summary anchors clamp ahead of the newest user turn instead of at the array tail (the #3640 "stale summary after the question" shape), and a genuine total collapse now latches `foldEpochConfirmPending` and PAUSES folding (verbatim passthrough — nothing is deleted, the snapshot is kept) until the histories realign or the user confirms a new epoch, instead of escalating on a misdiagnosis. Single genuine edits below the mass bar still report drift honestly; the #1729/#2193 escalation itself stays (its error text now names the epoch gate). From 491f16bca4e034d8cca661dac676762222a528a1 Mon Sep 17 00:00:00 2001 From: awork Date: Tue, 20 Oct 2026 03:54:15 +0800 Subject: [PATCH 3/4] fix: drop over-export on internal-only maskUrlForPublish Merging master into this branch pulled in #3811, which added maskUrlForPublish to src/log-mask.ts. It is called only by maskUrlsForPublish in the same file; #3811's external consumer (src/web/diagnostics.ts) imports the wrapper, never this helper. The unused-exports gate therefore classifies it INTERNAL_ONLY. Drop the leading export per the gate's prescription. Behavior-neutral: the internal caller is unaffected and no dist export surface changes. --- src/log-mask.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/log-mask.ts b/src/log-mask.ts index ac2440b279..d34a619b1b 100644 --- a/src/log-mask.ts +++ b/src/log-mask.ts @@ -118,7 +118,7 @@ export function maskUrlsInText(text: string): string { * preference must not weaken the publish boundary (same stance as * redactSecretsInText, which is never gated by the switch). Userinfo, query * and hash are dropped exactly as in maskUrlForLog; the path is kept. */ -export function maskUrlForPublish(url: string): string { +function maskUrlForPublish(url: string): string { let u: URL; try { u = new URL(url); From 31e19c29848a64773d18127626de1890c4d86ad2 Mon Sep 17 00:00:00 2001 From: awork Date: Tue, 20 Oct 2026 03:54:15 +0800 Subject: [PATCH 4/4] docs: regenerate config reference (collapse merged duplicate rows) The master merge left two duplicated config-table rows in CONFIGURATION.md / CONFIGURATION.zh-CN.md: a stale 'storage.unified defaults to shadow' row alongside the current '#3818 flip -> full' row, and an older 'storage.sqliteAutoDownload' row lacking the #3788 retry-cooldown sentence alongside the current one. Re-running the single-source generator (tools/gen-config-docs.mjs) collapses each key to its current seed row. Retained rows carry the newest semantics; no knob is lost. Satisfies the docs-sync drift guard. --- CONFIGURATION.md | 2 -- CONFIGURATION.zh-CN.md | 2 -- 2 files changed, 4 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 749ce78afe..9c6eb99fc9 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -174,8 +174,6 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed | `persist.epermAlertRepeatMs` | number | 0 (no repeats) | BILI_PERSIST_EPERM_ALERT_REPEAT_MS | Repeat interval for the EPERM alert; 0 logs it once. | | `storage` | object | {} (all defaults) | — | Unified SQLite storage sidecar settings (#2671). | | `storage.unified` | legacy\|shadow\|full | unset (full) | BILI_STORAGE_UNIFIED | Tiered storage-migration switch (#2671): shadow = unified SQLite double-write dry-run with digest reconciliation; full = drop-in read path (unified-first loads with organic import, legacy fallback). Absent everywhere now defaults to FULL (#3818 flip - the shadow dry-run reconciled cleanly since #2815, so the index is the load path; JSON envelopes keep being written, and legacy remains the one-line escape hatch). File tier is strict legacy/shadow/full; the env tier also accepts 1/true (=shadow) and unified (=full) and wins over the file. Resolved once per lane boot - hot edits need a restart. Encryption (BILI_ENCRYPTION_KEY) hard-blocks the sidecar. | -| `storage.sqliteAutoDownload` | boolean | true | BILI_SQLITE_AUTO_DOWNLOAD | Gate for the one-time SQLite engine self-download (#2833): when no engine is available in-process (no built-in node:sqlite, no host-installed better-sqlite3) and the unified sidecar is wanted on this platform, bili downloads the pinned better-sqlite3 prebuilt tarball from the npm registry once (~11 MB, sha512-verified) into the cache dir and reuses it on every later start. Engine resolution order: built-in node:sqlite (Node >= 22.5) -> host-provided better-sqlite3 -> cached self-download -> self-download (gated by this switch) -> none (legacy-only, the #2825 degrade contract). The switch gates only the network fetch - a cached copy is used even when it is false; unsupported platforms never download. The tarball download walks a builtin mirror list (#3338): the configured registry (BILI_UPDATE_REGISTRY / update.registry) is tried first, then https://registry.npmjs.org, then https://registry.npmmirror.com - the first mirror that yields a sha512-verified tarball wins; a Node < 22.5 with no engine gets an explicit Node upgrade hint in the degrade reason (#3385). | -| `storage.unified` | legacy\|shadow\|full | unset (shadow) | BILI_STORAGE_UNIFIED | Tiered storage-migration switch (#2671): shadow = unified SQLite double-write dry-run with digest reconciliation; full = drop-in read path (unified-first loads with organic import, legacy fallback). Absent everywhere now defaults to shadow (JSON stays the sole source of truth; the index is digest-reconciled telemetry - set legacy to opt out). File tier is strict legacy/shadow/full; the env tier also accepts 1/true (=shadow) and unified (=full) and wins over the file. Resolved once per lane boot - hot edits need a restart. Encryption (BILI_ENCRYPTION_KEY) hard-blocks the sidecar. | | `storage.sqliteAutoDownload` | boolean | true | BILI_SQLITE_AUTO_DOWNLOAD | Gate for the one-time SQLite engine self-download (#2833): when no engine is available in-process (no built-in node:sqlite, no host-installed better-sqlite3) and the unified sidecar is wanted on this platform, bili downloads the pinned better-sqlite3 prebuilt tarball from the npm registry once (~11 MB, sha512-verified) into the cache dir and reuses it on every later start. Engine resolution order: built-in node:sqlite (Node >= 22.5) -> host-provided better-sqlite3 -> cached self-download -> self-download (gated by this switch) -> none (legacy-only, the #2825 degrade contract). The switch gates only the network fetch - a cached copy is used even when it is false; unsupported platforms never download. The tarball download walks a builtin mirror list (#3338): the configured registry (BILI_UPDATE_REGISTRY / update.registry) is tried first, then https://registry.npmjs.org, then https://registry.npmmirror.com - the first mirror that yields a sha512-verified tarball wins; a Node < 22.5 with no engine gets an explicit Node upgrade hint in the degrade reason (#3385). A failed download arms a 6-hour retry cooldown persisted as a marker file under the cache dir (billion-context/sqlite/.bootstrap-failed.json); the storage diagnostics blob shows the marker's absolute expiry time and path - delete that file and restart bili to force an immediate retry instead of waiting out the whole window (#3788). | | `storage.jsonWriter` | on\|off | on | BILI_STORAGE_JSON_WRITER | Phase 3 envelope switch (#2960): off stops writing the legacy JSON session envelope while storage.unified is full - the SQLite index becomes the only persistent copy (reads are already unified-first; boot enumerates the index union, so index-only sessions load normally). Only honored in effective-full mode: under shadow/legacy (or with encryption active) the request is ignored with a one-time warning because the JSON file remains the sole source of truth. Env tier 0/false/off = off and 1/true/on = on wins over the strict file spellings. Fail-safe: if the sidecar disables itself mid-run, envelope writes resume on the next save. Rollback: unset the knob - writing resumes, index-only sessions keep loading via the boot union, and replicas/restore re-materialize portable JSON envelopes. Downgrading the binary (or losing the SQLite engine) makes index-only sessions invisible to v0.1.196 and older until a >=v0.1.197 binary runs again - the data stays intact in index.db, it is just not read by the older code. The per-session content-store sidecar keeps being written either way. A jsonWriter=off lane must be the SOLE writer of its sessions directory: an off lane reads unified-first and never falls back to the file, so any peer instance running legacy/shadow against the same directory diverges silently (its JSON copy stops receiving updates, and the off lane never sees the peer's writes). | | `storage.walJournalSizeLimitBytes` | number | 8388608 | BILI_STORAGE_WAL_JOURNAL_SIZE_LIMIT_BYTES | WAL reclamation cap for index.db-wal (#3250), in bytes: every completed checkpoint truncates the WAL file back to this size, bounding disk use and crash-recovery replay in long-lived processes. NOT a per-session data quota - data lands in index.db as it is written and the WAL only stages frames between checkpoints, so session count/size does not scale this; a large burst can overshoot temporarily until the next completed checkpoint truncates back. Higher = rarer truncate IO but more steady disk use and a longer crash-replay tail. Env tier (positive integer) wins over the file tier; a garbage or non-positive env value falls through to the file/default tier instead of failing boot. Applied when the store opens at lane boot - hot edits need a restart. The effective value appears on the unified-enable log line and in the storage diagnostics blob. | diff --git a/CONFIGURATION.zh-CN.md b/CONFIGURATION.zh-CN.md index 27fdfbd8df..1976631346 100644 --- a/CONFIGURATION.zh-CN.md +++ b/CONFIGURATION.zh-CN.md @@ -174,8 +174,6 @@ | `persist.epermAlertRepeatMs` | number | 0 (no repeats) | BILI_PERSIST_EPERM_ALERT_REPEAT_MS | EPERM 告警的重复间隔;0 只记录一次。 | | `storage` | object | {} (all defaults) | — | 统一 SQLite 存储边车设置(#2671)。 | | `storage.unified` | legacy\|shadow\|full | unset (full) | BILI_STORAGE_UNIFIED | 分层存储迁移开关(#2671):shadow = 统一 SQLite 双写干跑 + digest 对账;full = 平替读路径(unified-first 加载 + 有机导入 + legacy 兜底)。两处均未设置时默认 full(#3818 翻转 —— shadow 干跑自 #2815 起对账一直干净,索引因此成为默认加载路径;JSON 信封照写,legacy 仍是一行逃生口)。文件层只接受 legacy/shadow/full;环境变量层还接受 1/true(=shadow)与 unified(=full)并优先于文件。每个 lane 启动时解析一次 —— 热改动需重启生效。加密(BILI_ENCRYPTION_KEY)会硬阻断边车。 | -| `storage.sqliteAutoDownload` | boolean | true | BILI_SQLITE_AUTO_DOWNLOAD | SQLite 引擎一次性自下载的闸门(#2833):进程内没有可用引擎(无内置 node:sqlite、宿主未装 better-sqlite3)且本平台希望启用统一边车时,bili 从 npm registry 一次性下载钉死的 better-sqlite3 预编译 tarball(约 11 MB,sha512 校验)到缓存目录,之后每次启动复用。引擎解析顺序:内置 node:sqlite(Node >= 22.5)-> 宿主机已装的 better-sqlite3 -> 缓存的自下载副本 -> 自下载(本开关控制)-> 无引擎(仅 legacy,即 #2825 降级契约)。开关只控制网络下载 —— 为 false 时缓存副本仍会使用;不支持的平台永不下载。 tarball 下载内置镜像列表兜底(#3338):先试配置的 registry(BILI_UPDATE_REGISTRY / update.registry),再试 https://registry.npmjs.org、https://registry.npmmirror.com —— 第一个通过 sha512 校验的镜像生效;Node < 22.5 且无引擎时,降级原因会给出明确的 Node 升级提示(#3385)。 | -| `storage.unified` | legacy\|shadow\|full | unset (shadow) | BILI_STORAGE_UNIFIED | 分层存储迁移开关(#2671):shadow = 统一 SQLite 双写干跑 + digest 对账;full = 平替读路径(unified-first 加载 + 有机导入 + legacy 兜底)。两处均未设置时默认 shadow(JSON 仍是唯一事实源,索引只做对账遥测 —— 设 legacy 可退出)。文件层只接受 legacy/shadow/full;环境变量层还接受 1/true(=shadow)与 unified(=full)并优先于文件。每个 lane 启动时解析一次 —— 热改动需重启生效。加密(BILI_ENCRYPTION_KEY)会硬阻断边车。 | | `storage.sqliteAutoDownload` | boolean | true | BILI_SQLITE_AUTO_DOWNLOAD | SQLite 引擎一次性自下载的闸门(#2833):进程内没有可用引擎(无内置 node:sqlite、宿主未装 better-sqlite3)且本平台希望启用统一边车时,bili 从 npm registry 一次性下载钉死的 better-sqlite3 预编译 tarball(约 11 MB,sha512 校验)到缓存目录,之后每次启动复用。引擎解析顺序:内置 node:sqlite(Node >= 22.5)-> 宿主机已装的 better-sqlite3 -> 缓存的自下载副本 -> 自下载(本开关控制)-> 无引擎(仅 legacy,即 #2825 降级契约)。开关只控制网络下载 —— 为 false 时缓存副本仍会使用;不支持的平台永不下载。 tarball 下载内置镜像列表兜底(#3338):先试配置的 registry(BILI_UPDATE_REGISTRY / update.registry),再试 https://registry.npmjs.org、https://registry.npmmirror.com —— 第一个通过 sha512 校验的镜像生效;Node < 22.5 且无引擎时,降级原因会给出明确的 Node 升级提示(#3385)。下载失败会置一个 6 小时的重试冷却,以标记文件形式持久化在缓存目录下(billion-context/sqlite/.bootstrap-failed.json);storage 诊断块会显示该标记的绝对到期时间与路径 —— 删除该文件并重启 bili 即可强制立即重试,不必等完整个冷却窗口(#3788)。 | | `storage.jsonWriter` | on\|off | on | BILI_STORAGE_JSON_WRITER | Phase 3 信封开关(#2960):off 时若 storage.unified 为 full 则不再写 legacy JSON 会话信封 —— SQLite 索引成为唯一持久化副本(读路径本就 unified-first;boot 枚举索引并集,纯索引会话可正常加载)。仅在有效 full 模式下生效:shadow/legacy(或加密激活)下请求会被忽略并警告一次,因为 JSON 文件仍是唯一事实源。环境变量层 0/false/off = off、1/true/on = on,优先于严格拼写的文件层。失败安全:若边车运行中自禁用,下次保存即恢复信封写入。回滚:去掉该开关 —— 写入恢复,纯索引会话经 boot 并集继续可加载,replicas/restore 可重新物化可移植的 JSON 信封。降级二进制(或丢失 SQLite 引擎)会让纯索引会话在 v0.1.196 及更早版本上不可见,直到重新运行 >=v0.1.197 —— 数据在 index.db 中完好无损,只是旧代码不读它。每会话的 content-store 边车无论开关如何都照写。jsonWriter=off 的 lane 必须是其会话目录的唯一写者:off lane 读路径 unified-first、永不回退到文件,因此同一目录上跑 legacy/shadow 的对等实例会静默分叉(它的 JSON 副本收不到更新,off lane 也看不到对等实例的写入)。 | | `storage.walJournalSizeLimitBytes` | number | 8388608 | BILI_STORAGE_WAL_JOURNAL_SIZE_LIMIT_BYTES | index.db-wal 的 WAL 回收上限(#3250),单位字节:每次完成的 checkpoint 把 WAL 文件截回该大小,约束长驻进程的磁盘占用与崩溃恢复重放。不是每会话数据配额 —— 数据写入时就已落进 index.db,WAL 只是两次 checkpoint 之间的帧暂存区,会话数量/大小不会放大它;大 burst 可能暂时超出,直到下一次完成的 checkpoint 截回。调大 = truncate IO 更稀疏,但稳态磁盘占用更多、崩溃恢复重放尾更长。环境变量层(正整数)优先于配置文件层;env 值非法或非正数时静默落到文件/默认层,boot 不崩。lane 启动、store open 时生效 —— 热改动需重启。实际取值会出现在 unified-enable 日志行与 storage 诊断块中。 |