From 6ef17e8de92068f7a66c68ef265a7888bc4fc8db Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 21:33:22 +0800 Subject: [PATCH 01/17] fix(#2929): fold claim window covers the post-fold cold tail A degenerate head fold (81-100% coverage) rewrote the whole prefix, but the claim window only consumed the FIRST sample after it - the proxy re-request. The client's echo re-bill ~25-66s later carried no foldSeq, fell into the unattributed ttlRepay residual, and tripped cache-seam with "no fold attribution". Every one of #2929's seven seams was exactly this shape. Mirror the #1847 switch discipline for folds: - kernel buildCacheReport: a fold claims its first sample unconditionally, then COLD continuations (hit < FOLD_CLAIM_WARM_HIT_PCT=85) up to FOLD_CLAIM_COLD_ROUNDS=4; a warm line retires every open window. - cache-ledger recordCacheSample: same state machine on the sparse LedgerFold.claims/retired fields (legacy persisted ledgers keep the first-claim behavior). - web trajectory chart: cause heuristic mirrors the window (foldSeq-first, fold-between-times fallback for pre-#2929 ledgers). - i18n: the residual bucket is honestly "unattributed" (upstream TTL/eviction/unknown), not "TTL expiry"; seam tip mentions post-fold echo re-bills. kernel 0.0.119 -> 0.0.120. --- kernel/package.json | 2 +- kernel/src/cache-report.ts | 44 ++++++++- kernel/src/index.ts | 2 + kernel/tests/cache-report.test.ts | 69 +++++++++++++ src/cache-ledger.ts | 61 ++++++++++-- src/web/client.ts | 13 ++- src/web/i18n.ts | 24 ++--- tests/cache-ledger.test.ts | 17 +++- tests/issue2929-fold-claim-window.test.ts | 113 ++++++++++++++++++++++ 9 files changed, 313 insertions(+), 32 deletions(-) create mode 100644 tests/issue2929-fold-claim-window.test.ts diff --git a/kernel/package.json b/kernel/package.json index 4ea152f765..e85bec6008 100644 --- a/kernel/package.json +++ b/kernel/package.json @@ -1,6 +1,6 @@ { "name": "acp-kernel", - "version": "0.0.119", + "version": "0.0.120", "description": "Framework-agnostic context-compression engine (model-driven, 3-tier LSM). Pure core: no host dependency.", "license": "MIT", "author": "ranxianglei", diff --git a/kernel/src/cache-report.ts b/kernel/src/cache-report.ts index 47c46a55d0..97e062ca3a 100644 --- a/kernel/src/cache-report.ts +++ b/kernel/src/cache-report.ts @@ -63,6 +63,17 @@ export interface PriceProfile { q?: number; } +/** #2929: a fold claims not only its first following sample but the whole + * post-fold COLD TAIL — until a warm line proves the provider re-cached or + * this many samples have elapsed (#1847 switch discipline, mirrored for + * folds). Rationale: the first post-fold request (the proxy's re-request) + * is attributed today, but the client-echo re-bill 25–66s later carried no + * fold stamp and fell into the unattributed TTL residual, tripping the + * cache-seam detector with "no fold attribution". Warm hit that retires + * the window (same threshold as the host's WARM_HIT_PCT). */ +export const FOLD_CLAIM_WARM_HIT_PCT = 85; +export const FOLD_CLAIM_COLD_ROUNDS = 4; + export interface SampleDecomposition { missed: number; newContent: number; @@ -331,24 +342,49 @@ export function buildCacheReport( type Dec = SampleDecomposition & { foldSeq: number | null }; const decs: Dec[] = []; + // #2929: per-fold cold-tail claim state. A fold claims its FIRST following + // sample unconditionally (the materialization re-bill), then keeps claiming + // subsequent cold samples until a warm line (>= FOLD_CLAIM_WARM_HIT_PCT) + // proves re-cache or it has claimed FOLD_CLAIM_COLD_ROUNDS samples. A warm + // sample is never claimed as a continuation (it proves the damage is over). + const foldClaims: number[] = folds.map(() => 0); + const foldRetired: boolean[] = folds.map(() => false); for (let i = 0; i < samples.length; i++) { const s = samples[i]!; const prev = i > 0 ? samples[i - 1]! : null; - const prevAt = prev ? prev.at : Number.NEGATIVE_INFINITY; + const warm = s.input > 0 && hitPct(s.input, s.cached) >= FOLD_CLAIM_WARM_HIT_PCT; const pending: FoldEvent[] = []; + const pendingIdx: number[] = []; let pendingBase = 0; for (let j = 0; j < folds.length; j++) { const fj = folds[j]!; - if (fj.at <= prevAt) continue; if (fj.at > s.at) break; - if (pending.length === 0) pendingBase = j; - pending.push(fj); + if (foldRetired[j]) continue; + // First claim is unconditional; a warm continuation proves re-cache and + // is not the fold's damage anymore. + if (foldClaims[j] === 0 || !warm) { + if (pending.length === 0) pendingBase = j; + pending.push(fj); + pendingIdx.push(j); + } } const d = decomposeSample(prev, s, pending); decs.push({ ...d, foldSeq: d.foldIndex !== null ? pendingBase + d.foldIndex + 1 : null, }); + for (const j of pendingIdx) { + foldClaims[j] = foldClaims[j]! + 1; + if (foldClaims[j]! >= FOLD_CLAIM_COLD_ROUNDS) foldRetired[j] = true; + } + // A warm line retires EVERY open window — claimed or not this sample + // (#1847 discipline: it proves the provider re-cached, so a later cold + // blip is a new, unrelated event and must not be swallowed). + if (warm) { + for (let j = 0; j < folds.length; j++) { + if (folds[j]!.at <= s.at) foldRetired[j] = true; + } + } } const totals: CacheTotals = { diff --git a/kernel/src/index.ts b/kernel/src/index.ts index eed5390fb5..7474e13930 100644 --- a/kernel/src/index.ts +++ b/kernel/src/index.ts @@ -130,6 +130,8 @@ export { buildCacheReport, computeFoldEconomics, decomposeSample, + FOLD_CLAIM_COLD_ROUNDS, + FOLD_CLAIM_WARM_HIT_PCT, formatCacheReport, summarizeFoldEconomics, } from "./cache-report.js"; diff --git a/kernel/tests/cache-report.test.ts b/kernel/tests/cache-report.test.ts index 49b250c46e..0dacf7fdc4 100644 --- a/kernel/tests/cache-report.test.ts +++ b/kernel/tests/cache-report.test.ts @@ -4,6 +4,7 @@ import { buildCacheReport, computeFoldEconomics, decomposeSample, + FOLD_CLAIM_COLD_ROUNDS, formatCacheReport, type CacheSample, type FoldEvent, @@ -541,3 +542,71 @@ test("formatCacheReport summary lists every fold when few, with TTL spike idle g assert.match(text, /#1 .*S=20\.0K.* → (NOT PAID BACK|PAID BACK|\?)/); assert.ok(!text.includes("more folds omitted")); }); + +test("#2929 fold cold-tail claim: the client-echo re-bill is fold-owned until a warm line retires", () => { + // Degenerate head fold (X=3K): proxy re-request (s2) is claimed today, the + // client echo (s3) and the cold recovery tail (s4) must ALSO carry foldSeq — + // before #2929 s3/s4 fell into the unattributed ttlRepay residual and tripped + // the cache-seam detector. A warm line (s5) retires the window; a later cold + // blip (s6, real provider eviction) is NOT swallowed by the old fold. + const samples = [ + sample(0, 100_000, 99_000), // warm baseline + sample(1, 51_000, 5_000), // proxy re-request after fold: 9.8% + sample(2, 55_000, 5_100), // client echo re-bill: 9.3% + sample(3, 60_000, 42_000), // recovery: 70% (still < 85 warm line) + sample(4, 65_000, 60_000), // warm: 92% — retires the claim window + sample(5, 66_000, 30_000), // unrelated later cold blip: 45% + ]; + const folds: FoldEvent[] = [ + { at: T0 + 0.5 * min, tokensCompressed: 50_000, firstFoldStartTokens: 3_000, viewBefore: 100_000, viewAfter: 50_500 }, + ]; + const r = buildCacheReport(samples, folds); + const [, s2, s3, s4, s5, s6] = r.lines; + assert.equal(s2!.foldSeq, 1, "re-request claimed (first claim, unconditional)"); + assert.equal(s2!.compRepay, 46_000); + assert.equal(s3!.foldSeq, 1, "client-echo re-bill claimed (#2929)"); + assert.equal(s3!.compRepay, 45_900); + assert.equal(s3!.ttlRepay, 0, "echo residual no longer lands in the unattributed bucket"); + assert.equal(s4!.foldSeq, 1, "cold recovery tail claimed"); + assert.equal(s4!.compRepay, 13_000); + assert.equal(s5!.foldSeq, null, "warm line is never claimed as a continuation"); + assert.equal(s5!.compRepay, 0); + assert.equal(s6!.foldSeq, null, "window closed — later cold blip is NOT the fold's"); + assert.equal(s6!.ttlRepay, 35_000, "blip falls to the unattributed residual"); + assert.equal(r.totals.ttlRepay, 36_000, "1K baseline residual + the 35K post-window blip"); + assert.equal(r.folds[0]!.T, 46_000 + 45_900 + 13_000, "fold economics absorb the full cold tail"); +}); + +test("#2929 fold cold-tail claim: FOLD_CLAIM_COLD_ROUNDS bounds the window without a warm line", () => { + const samples = [ + sample(0, 100_000, 99_000), + sample(1, 51_000, 5_000), + sample(2, 52_000, 5_100), + sample(3, 53_000, 5_200), + sample(4, 54_000, 5_300), + sample(5, 55_000, 5_400), // 5th post-fold sample: window exhausted + ]; + const folds: FoldEvent[] = [ + { at: T0 + 0.5 * min, tokensCompressed: 50_000, firstFoldStartTokens: 3_000, viewBefore: 100_000, viewAfter: 50_500 }, + ]; + const r = buildCacheReport(samples, folds); + const claimCount = r.lines.filter((l) => l.foldSeq === 1).length; + assert.equal(claimCount, FOLD_CLAIM_COLD_ROUNDS, "exactly the bound — never an open-ended claim"); + assert.equal(r.lines[5]!.foldSeq, null); + assert.ok(r.lines[5]!.ttlRepay > 0, "post-window residual is unattributed again"); +}); + +test("#2929 fold cold-tail claim: a warm FIRST post-fold sample claims once and retires", () => { + const samples = [ + sample(0, 100_000, 99_000), + sample(1, 51_000, 50_000), // 98% warm immediately after a tiny fold + sample(2, 52_000, 20_000), // later cold blip must not be swallowed + ]; + const folds: FoldEvent[] = [ + { at: T0 + 0.5 * min, tokensCompressed: 5_000, firstFoldStartTokens: 3_000, viewBefore: 100_000, viewAfter: 95_500 }, + ]; + const r = buildCacheReport(samples, folds); + assert.equal(r.lines[1]!.foldSeq, 1, "first claim is unconditional even on a warm line"); + assert.equal(r.lines[2]!.foldSeq, null, "retired by the warm first sample"); + assert.ok(r.lines[2]!.ttlRepay > 0); +}); diff --git a/src/cache-ledger.ts b/src/cache-ledger.ts index 3c966b112a..227c00f0b2 100644 --- a/src/cache-ledger.ts +++ b/src/cache-ledger.ts @@ -2,6 +2,8 @@ import { createHash, randomUUID } from "node:crypto"; import { computeFoldEconomics, decomposeSample, + FOLD_CLAIM_COLD_ROUNDS, + FOLD_CLAIM_WARM_HIT_PCT, formatCacheReport, summarizeFoldEconomics, type CacheReport, @@ -54,6 +56,14 @@ interface LedgerFold { at: number; S: number; sigma: number; + /** #2929: samples this fold has claimed under the cold-tail window + * (first claim unconditional, then cold continuations until warm or + * FOLD_CLAIM_COLD_ROUNDS). Sparse: absent on ledgers persisted before + * #2929 — treated as 0 claims, which reproduces the first-claim path. */ + claims?: number; + /** #2929: claim window closed (warm line proved re-cache, or the cold-round + * bound elapsed). Sparse: absent = open. */ + retired?: boolean; X?: number; V?: number; Vp?: number; @@ -738,10 +748,28 @@ export function recordCacheSample( const led = getCacheLedger(session); detectNewFolds(session, led); const prevLine = led.lines[led.lines.length - 1]; + // #1536: unknown-cache samples still need a prev/cur pair so the fold chain + // stays consistent, but decompose with cached=0 then QUARANTINE every derived + // bucket (line missed/nc/cr/tr forced to 0 + excluded from agg below). + const known = s.cached !== null; + const effCached: number = s.cached ?? 0; // Same window as buildCacheReport: a fold counts once its timestamp has // elapsed (f.at <= s.at), never earlier — keeps incremental and batch math // identical under clock skew between block.createdAt and settle time. - const pendRefs = led.folds.filter((f) => f.seq > led.consumedFoldSeq && f.at <= s.at); + // #2929: the window is now the fold's COLD TAIL (mirror of the kernel's + // buildCacheReport): the first following sample is claimed + // unconditionally, then cold continuations are claimed until a warm line + // (>= FOLD_CLAIM_WARM_HIT_PCT) proves re-cache or FOLD_CLAIM_COLD_ROUNDS + // samples have elapsed. Before this, the first measurable sample consumed + // the fold, so the client-echo re-bill ~25–66s later carried no fold stamp, + // fell into the unattributed ttlRepay residual, and tripped the seam + // detector with "no fold attribution" (#2929's seven seams were exactly + // this shape, 25–66s after a degenerate head fold). + const warmLine = + known && s.input > 0 && (effCached / s.input) * 100 >= FOLD_CLAIM_WARM_HIT_PCT; + const pendRefs = led.folds.filter( + (f) => f.at <= s.at && !f.retired && ((f.claims ?? 0) === 0 || !warmLine), + ); const pending: FoldEvent[] = pendRefs.map((f) => ({ at: f.at, tokensCompressed: f.S, @@ -750,11 +778,6 @@ export function recordCacheSample( viewBefore: f.V, viewAfter: f.Vp, })); - // #1536: unknown-cache samples still need a prev/cur pair so the fold chain - // stays consistent, but decompose with cached=0 then QUARANTINE every derived - // bucket (line missed/nc/cr/tr forced to 0 + excluded from agg below). - const known = s.cached !== null; - const effCached: number = s.cached ?? 0; const rawDec = decomposeSample( prevLine ? { at: prevLine.at, input: prevLine.input, cached: prevLine.cached } : null, { at: s.at, input: s.input, cached: effCached }, @@ -773,12 +796,30 @@ export function recordCacheSample( : rawDec; let foldSeq: number | null = null; if (known && dec.foldIndex !== null) foldSeq = pendRefs[dec.foldIndex]?.seq ?? null; - // Advance the fold-consume cursor only for measurable samples: an unknown + // Advance the claim window only for measurable samples: an unknown // sample must not eat a fold, or its compRepay would never reach a fold owner. + // #2929: each claimed sample bumps the fold's claim count; warm line or + // the FOLD_CLAIM_COLD_ROUNDS bound retires it (consumedFoldSeq stays the + // high-water mark of RETIRED folds for schema compat). if (known && pendRefs.length > 0) { - let hi = 0; - for (const f of pendRefs) hi = Math.max(hi, f.seq); - led.consumedFoldSeq = Math.max(led.consumedFoldSeq, hi); + for (const f of pendRefs) { + f.claims = (f.claims ?? 0) + 1; + if (f.claims >= FOLD_CLAIM_COLD_ROUNDS) { + f.retired = true; + led.consumedFoldSeq = Math.max(led.consumedFoldSeq, f.seq); + } + } + } + // A warm line retires EVERY open window — claimed or not this sample + // (#1847 discipline): it proves the provider re-cached, so a later cold + // blip is a new, unrelated event and must not be swallowed by the fold. + if (known && warmLine) { + for (const f of led.folds) { + if (f.at <= s.at && !f.retired) { + f.retired = true; + led.consumedFoldSeq = Math.max(led.consumedFoldSeq, f.seq); + } + } } const hitPct: number | null = known && s.input > 0 ? round1((effCached / s.input) * 100) : null; // Target identity (#1535 model, generalized to model|wire|upstream in #1536): diff --git a/src/web/client.ts b/src/web/client.ts index 5c20421dd3..2192157c33 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -814,16 +814,25 @@ export const WEB_CLIENT = `(function () { area += " L" + x(lines.length - 1).toFixed(1) + "," + (PT + ih).toFixed(1) + " L" + x(0).toFixed(1) + "," + (PT + ih).toFixed(1) + " Z"; // Cache-gap causes: color each sample's un-cached band (input − cached) // by its most likely cause so gaps on the chart explain themselves. - // Heuristics use only fields every ledger era carries (at/input/cached + fold times). + // #2929: mirror the ledger's fold cold-tail window — a fold owns the + // first sample after it AND the cold continuation (hit < 85%) up to 4 + // samples, closing on the first warm line. Ledger lines carry foldSeq + // directly; the fold-between-times heuristic stays as the opener and + // for pre-#2929 ledgers whose lines have no foldSeq. const GAP_MS = 600_000; const CAUSE_COLOR = { cold: "#6e7681", comp: "#bf8700", ttl: "#8250df" }; const CAUSE_KEY = { cold: "det.cause_cold", comp: "det.cause_comp", ttl: "det.cause_ttl" }; + let foldTailClaims = 0; const causes = lines.map((l, i) => { if (i === 0) return !(l.cached || 0) ? "cold" : "new"; const p = lines[i - 1]; const missed = (l.input || 0) - (l.cached || 0); const growth = Math.max(0, (l.input || 0) - (p.input || 0)); - if ((folds || []).some((f) => (f.at || 0) >= (p.at || 0) && (f.at || 0) <= (l.at || 0)) && missed > growth + 256) return "comp"; + const warm = (l.hitPct || 0) >= 85; + const foldOwned = l.foldSeq != null || (folds || []).some((f) => (f.at || 0) >= (p.at || 0) && (f.at || 0) <= (l.at || 0)); + if (foldOwned && missed > growth + 256) { foldTailClaims = 4; return "comp"; } + if (warm) foldTailClaims = 0; + else if (foldTailClaims > 0 && missed > growth + 256) { foldTailClaims -= 1; return "comp"; } if ((l.at || 0) - (p.at || 0) > GAP_MS && missed > growth + 2048) return "ttl"; return "new"; }); diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 541c352ceb..29e53b201e 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -81,12 +81,12 @@ export const MESSAGES: Record> = { "ov.covlost_note": "其中 {n} 个折叠覆盖丢失,冻结 {x}", "det.covlost_sub": "其中 {n} 个折叠覆盖丢失(冻结 {x}):其覆盖的原始消息已离开重发历史,节省累计已停止", "ses.covlost_tip": "{n} 个折叠覆盖丢失(冻结 {x}):宿主在 bili 不知情下移除了被压缩的原始消息(如 dsh 原生压缩),对应节省已停止累计", - "ov.miss_split": "未命中构成(有账本会话):新增内容 {n} · 压缩折损 {c} · TTL过期等前缀失效 {x}", + "ov.miss_split": "未命中构成(有账本会话):新增内容 {n} · 压缩折损 {c} · 未归因前缀失效 {x}(上游TTL/淘汰/未知)", "det.hit_pct": "缓存命中率", - "ses.drop_ph": "命中率代价(占总输入的百分比,顺序:新增 / 压缩 / TTL过期)", + "ses.drop_ph": "命中率代价(占总输入的百分比,顺序:新增 / 压缩 / 未归因)", "ses.empty_hidden": "另有 {n} 个空会话已隐藏(无请求、无上下文、无账本;直接链接仍可访问)", - "det.miss_split_line": "命中率的未命中部分拆分:新增内容 {n}(−{pn}%)· 压缩折损 {c}(−{pc}%)· TTL过期等前缀失效 {x}(−{px}%)", - "det.miss_sub": "TTL过期 −{x}% · 压缩 −{c}% · 新增 −{n}%", + "det.miss_split_line": "命中率的未命中部分拆分:新增内容 {n}(−{pn}%)· 压缩折损 {c}(−{pc}%)· 未归因前缀失效 {x}(−{px}%,上游TTL/淘汰/未知)", + "det.miss_sub": "未归因 −{x}% · 压缩 −{c}% · 新增 −{n}%", "det.fold_time": "时间", "ov.global_hitpct": "全局缓存命中率", "ov.input_tokens": "输入 token", @@ -246,7 +246,7 @@ export const MESSAGES: Record> = { "det.cache_econ": "缓存经济学", "det.ce_new": "新内容", "det.ce_comp": "压缩回补", - "det.ce_ttl": "TTL 回补", + "det.ce_ttl": "未归因回补", "det.ce_residual": "残差", "det.ce_balanced": "账目平衡 ✓", "det.ce_unbalanced": "账目不平衡 ✗", @@ -255,7 +255,7 @@ export const MESSAGES: Record> = { "det.attr_provider": "▲ 上游侧失效", "det.attr_rewind": "↩ 历史回退", "det.attr_abort": "⏻ 中断相关", - "det.attr_seam_tip": "出站请求体在历史中段出现字节分叉,且无 fold/模型切换/重启归因——疑似重建缝。数值为嫌疑样本重计费的 token", + "det.attr_seam_tip": "出站请求体在历史中段出现字节分叉,且无 fold/模型切换/重启归因——疑似重建缝。数值为嫌疑样本重计费的 token。若此前几分钟内发生过折叠,多半是折叠后客户端回显的重付(#2929 后已归入压缩回补)", "det.attr_provider_tip": "上一请求的整条消息列表逐字节保留(整体一致,或前缀一致、仅尾部追加新消息;超过 512KiB 取证上限的请求以记录头稳定 + 精确消息数增长判定)却仍 miss——上游 TTL 过期/淘汰/中继节点轮换,非 bili 重建缝", "det.attr_rewind_tip": "客户端 revert/trim 使消息数下降——合法的一次性重计费(保留前缀),非缺陷", "det.attr_abort_tip": "客户端流中 abort 后 30s 内结算的 miss 样本数——重试重写重发尾部;相关性而非因果,叠加标记不计入分桶", @@ -530,12 +530,12 @@ export const MESSAGES: Record> = { "ov.covlost_note": "{n} fold(s) coverage-lost, {x} frozen", "det.covlost_sub": "{n} fold(s) coverage-lost ({x} frozen): their covered messages left the resent history — accrual stopped", "ses.covlost_tip": "{n} fold(s) coverage-lost ({x} frozen): the host removed the compressed originals outside bili's knowledge (e.g. dsh native compaction) — their savings no longer accrue", - "ov.miss_split": "missed tokens (ledgered sessions): new content {n} · compression re-read {c} · TTL expiry / other prefix invalidation {x}", + "ov.miss_split": "missed tokens (ledgered sessions): new content {n} · compression re-read {c} · unattributed prefix invalidation {x} (upstream TTL/eviction/unknown)", "det.hit_pct": "cache hit rate", - "ses.drop_ph": "hit-rate cost as a share of total input, order: new / comp / TTL expiry", + "ses.drop_ph": "hit-rate cost as a share of total input, order: new / comp / unattributed", "ses.empty_hidden": "{n} empty session(s) hidden (no requests, no context, no ledger; still reachable by direct link)", - "det.miss_split_line": "missed-token split of the hit rate: new content {n} (−{pn}%) · compression re-read {c} (−{pc}%) · TTL expiry / other prefix invalidation {x} (−{px}%)", - "det.miss_sub": "TTL expiry −{x}% · comp −{c}% · new −{n}%", + "det.miss_split_line": "missed-token split of the hit rate: new content {n} (−{pn}%) · compression re-read {c} (−{pc}%) · unattributed prefix invalidation {x} (−{px}%, upstream TTL/eviction/unknown)", + "det.miss_sub": "unattributed −{x}% · comp −{c}% · new −{n}%", "det.fold_time": "when", "ov.global_hitpct": "Global cache hit rate", "ov.input_tokens": "Input tokens", @@ -692,7 +692,7 @@ export const MESSAGES: Record> = { "det.cache_econ": "Cache economics", "det.ce_new": "New content", "det.ce_comp": "Compaction repay", - "det.ce_ttl": "TTL repay", + "det.ce_ttl": "Unattributed repay", "det.ce_residual": "Residual", "det.ce_balanced": "Ledger balanced ✓", "det.ce_unbalanced": "Ledger unbalanced ✗", @@ -701,7 +701,7 @@ export const MESSAGES: Record> = { "det.attr_provider": "▲ Provider-side miss", "det.attr_rewind": "↩ History rewound", "det.attr_abort": "⏻ Abort-correlated", - "det.attr_seam_tip": "Outbound bodies diverged mid-history with no fold/model-switch/restart attribution — suspected rebuild seam. Value = tokens re-billed on suspect samples", + "det.attr_seam_tip": "Outbound bodies diverged mid-history with no fold/model-switch/restart attribution — suspected rebuild seam. Value = tokens re-billed on suspect samples. If a fold landed minutes earlier this is usually the post-fold client-echo re-bill (fold-owned since #2929)", "det.attr_provider_tip": "The previous request's entire message list came back byte-identical (whole body, or its prefix with only tail messages appended; above the 512 KiB forensics cap, proven by the stable recorded head plus exact message-count growth) yet the upstream did not serve its cache — TTL expiry / eviction / relay node rotation. Not a bili rebuild seam", "det.attr_rewind_tip": "Client revert/trim shrank the message count — sanctioned one-time re-bill of the retained prefix, not a defect", "det.attr_abort_tip": "Missed samples settled within 30s of a client mid-stream abort — retry churn rewrites the resent tail; correlation, not causation (overlay marker, not a bucket)", diff --git a/tests/cache-ledger.test.ts b/tests/cache-ledger.test.ts index 5a833fe0e6..71736cbc96 100644 --- a/tests/cache-ledger.test.ts +++ b/tests/cache-ledger.test.ts @@ -82,11 +82,15 @@ test("incremental ledger closes the same identity as kernel batch", () => { assert.equal(inc.totals.ttlRepay, batch.totals.ttlRepay - 1000, "opener residual removed from ttl re-pay"); // Hand-computed expectations. + // #2929: the @3000 sample (28.6% — cold) is now fold b1's SECOND claim + // under the cold-tail window, so its structural excess (7000 − 4500 − + // 1000 growth = 1500) moves from the unattributed ttl bucket into + // compRepay; the batch path claims it identically. assert.equal(inc.totals.input, 30500); assert.equal(inc.totals.cached, 19000); assert.equal(inc.totals.newContent, 2500); - assert.equal(inc.totals.compRepay, 1500); - assert.equal(inc.totals.ttlRepay, 7500); + assert.equal(inc.totals.compRepay, 3000); + assert.equal(inc.totals.ttlRepay, 6000); // Line-level: the opener is no-baseline initial content. The nb flag lives // on the raw ledger line — report lines follow the kernel line shape. const rawOpener = getCacheLedger(session).lines[0]!; @@ -101,9 +105,16 @@ test("incremental ledger closes the same identity as kernel batch", () => { assert.equal(cliff.compRepay, 1500); assert.equal(cliff.ttlRepay, 3500); assert.equal(cliff.foldSeq, 1); + // #2929: the cold @3000 sample is b1's continuation claim — comp absorbs + // the structural excess instead of leaking into the unattributed bucket. + const cont = inc.lines.find((l) => l.seq === 3)!; + assert.equal(cont.newContent, 1000); + assert.equal(cont.compRepay, 1500); + assert.equal(cont.ttlRepay, 2500); + assert.equal(cont.foldSeq, 1); // Fold economics carry the measured values. const f1 = inc.folds.find((f) => f.seq === 1)!; - assert.equal(f1.T, 1500); + assert.equal(f1.T, 3000); assert.equal(f1.hPct, 16.7); assert.equal(f1.S, 5000); assert.equal(f1.sigma, 2048); diff --git a/tests/issue2929-fold-claim-window.test.ts b/tests/issue2929-fold-claim-window.test.ts new file mode 100644 index 0000000000..5db2631ead --- /dev/null +++ b/tests/issue2929-fold-claim-window.test.ts @@ -0,0 +1,113 @@ +// #2929: the fold claim window is the post-fold COLD TAIL, mirroring the +// kernel's buildCacheReport (#1847 switch discipline applied to folds). Before +// this, the first measurable sample after a fold consumed it, so the client's +// echo re-bill ~25–66s later carried no foldSeq, fell into the unattributed +// ttlRepay residual, and tripped the cache-seam detector with "no fold +// attribution" — every one of #2929's seven seams was exactly this shape. +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { noteForwardedBody, settleUsageReport, getCacheLedger } from "../src/cache-ledger.ts"; +import { FOLD_CLAIM_COLD_ROUNDS, FOLD_CLAIM_WARM_HIT_PCT } from "acp-kernel"; +import type { Session } from "../src/session.ts"; + +let seq = 0; +function makeSession(): Session { + seq += 1; + return { + id: `fold-claim-${seq}`, + metadata: {}, + stats: {}, + state: { blocks: [], messageRefs: { byRaw: {}, byRef: {} }, tokenSnapshot: {} }, + } as unknown as Session; +} + +const body = (msgs: string[]): string => JSON.stringify({ model: "m", messages: msgs.map((c) => ({ role: "user", content: c })) }); +const T0 = Date.parse("2026-10-12T10:56:00Z"); + +function settle(session: Session, at: number, input: number, cached: number): void { + settleUsageReport(session, { total: input, reportedCached: cached, output: 0, protocol: "openai", upstream: "http://u" }); +} + +/** Push a fold as a kernel block — same rig as cache-seam-detector.test.ts. */ +function fold(session: Session, at: number): void { + const st = session.state as unknown as { blocks: Array> }; + st.blocks.push({ blockId: "b1", createdAt: at, compressedTokens: 50_000, summary: "x".repeat(200), startRef: "m00002" }); +} + +test("constants exported for host/kernel parity (#2929)", () => { + assert.equal(FOLD_CLAIM_COLD_ROUNDS, 4); + assert.equal(FOLD_CLAIM_WARM_HIT_PCT, 85); +}); + +test("the client-echo re-bill is fold-owned: no seam, ttl stays clean (#2929)", () => { + const s = makeSession(); + // Healthy baseline. + noteForwardedBody(s, body(["a", "b", "c"])); + settle(s, T0, 100_000, 99_000); + // Degenerate head fold lands between requests. + fold(s, T0 + 500); + // Proxy re-request (folded view) — first claim, as before. + noteForwardedBody(s, body(["a", "SUMMARY"])); + settle(s, T0 + 1_000, 51_000, 5_000); + // Client echo re-bill 25–66s later: mid-history divergence vs the folded + // view, cold (10%), no switch/restart — the exact #2929 seam shape. + noteForwardedBody(s, body(["a", "b", "c", "d"])); + settle(s, T0 + 60_000, 55_000, 5_100); + const led = getCacheLedger(s); + const echo = led.lines[led.lines.length - 1]!; + assert.ok(echo.foldSeq !== null, "echo re-bill claimed by the fold's cold-tail window"); + assert.equal(echo.seam, undefined, "echo must NOT trip the seam detector anymore"); + assert.equal(led.agg.seamSuspects, 0); + assert.ok(echo.cr > 0 && echo.tr === 0, "residual booked as compRepay, not unattributed ttl"); + assert.ok(led.agg.cr >= echo.cr, "fold economics owner absorbs it"); +}); + +test("warm line retires the window: a later cold blip is unattributed again (#2929)", () => { + const s = makeSession(); + noteForwardedBody(s, body(["a", "b"])); + settle(s, T0, 100_000, 99_000); + fold(s, T0 + 500); + noteForwardedBody(s, body(["a", "SUMMARY"])); + settle(s, T0 + 1_000, 51_000, 5_000); // claim 1 (cold) + noteForwardedBody(s, body(["a", "SUMMARY", "d"])); + settle(s, T0 + 30_000, 55_000, 52_000); // 94.5% warm — retires every open window + noteForwardedBody(s, body(["a", "SUMMARY", "d", "e"])); + settle(s, T0 + 90_000, 60_000, 20_000); // unrelated later cold blip (33%) + const led = getCacheLedger(s); + const blip = led.lines[led.lines.length - 1]!; + assert.equal(blip.foldSeq, null, "window closed by the warm line"); + assert.ok(blip.tr > 0, "blip falls to the unattributed residual"); + assert.equal(blip.seam, undefined, "blip is byte-stable append-shaped here; and even a mid-history one would be a NEW seam worth seeing"); +}); + +test("FOLD_CLAIM_COLD_ROUNDS bounds the window without a warm line (#2929)", () => { + const s = makeSession(); + noteForwardedBody(s, body(["a", "b"])); + settle(s, T0, 100_000, 99_000); + fold(s, T0 + 500); + for (let i = 0; i < FOLD_CLAIM_COLD_ROUNDS + 2; i++) { + noteForwardedBody(s, body(["a", "SUMMARY", `t${i}`])); + settle(s, T0 + 1_000 + i * 5_000, 55_000 + i * 100, 5_100); // all cold + } + const led = getCacheLedger(s); + const claimed = led.lines.filter((l) => l.foldSeq !== null).length; + assert.equal(claimed, FOLD_CLAIM_COLD_ROUNDS, "exactly the bound"); + const tail = led.lines[led.lines.length - 1]!; + assert.equal(tail.foldSeq, null); + assert.ok(tail.tr > 0, "post-window residual is unattributed again"); +}); + +test("ledger persisted before #2929 (no claims/retired fields) still claims the first sample", () => { + const s = makeSession(); + noteForwardedBody(s, body(["a", "b"])); + settle(s, T0, 100_000, 99_000); + fold(s, T0 + 500); + noteForwardedBody(s, body(["a", "SUMMARY"])); + settle(s, T0 + 1_000, 51_000, 5_000); + const led = getCacheLedger(s); + // Sparse-field compat: the fold record now carries the new fields. + const f = led.folds[0]!; + assert.equal(f.claims, 1); + assert.notEqual(f.retired, true); + assert.ok(led.lines[led.lines.length - 1]!.foldSeq === f.seq); +}); From 993ac45b2c6bd28a4ead282f95131cf6a5bad84f Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 21:53:58 +0800 Subject: [PATCH 02/17] fix(#2934): sync root package-lock with kernel 0.0.120 bump (lock-sync gate) --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index c100cdea77..ea44ceb69b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,7 +48,7 @@ }, "kernel": { "name": "acp-kernel", - "version": "0.0.119", + "version": "0.0.120", "dev": true, "license": "MIT", "devDependencies": { From 30eecd792f1e51f466ca9ed07d4edce3352de7b6 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 21:53:58 +0800 Subject: [PATCH 03/17] fix(#2934): sync kernel/package-lock with 0.0.120 bump (pre-existing 0.0.114 drift) --- kernel/package-lock.json | 46 ++-------------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/kernel/package-lock.json b/kernel/package-lock.json index b414754c41..baab1246cd 100644 --- a/kernel/package-lock.json +++ b/kernel/package-lock.json @@ -1,12 +1,12 @@ { "name": "acp-kernel", - "version": "0.0.114", + "version": "0.0.120", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "acp-kernel", - "version": "0.0.114", + "version": "0.0.120", "license": "MIT", "devDependencies": { "@types/node": "^22.0.0", @@ -508,9 +508,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -612,9 +609,6 @@ "arm" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -629,9 +623,6 @@ "arm" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -646,9 +637,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -663,9 +651,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -680,9 +665,6 @@ "loong64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -697,9 +679,6 @@ "loong64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -714,9 +693,6 @@ "ppc64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -731,9 +707,6 @@ "ppc64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -748,9 +721,6 @@ "riscv64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -765,9 +735,6 @@ "riscv64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -782,9 +749,6 @@ "s390x" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -799,9 +763,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -816,9 +777,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ From d255f2372b4bdf17511d79ab7b9a868efaee300c Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 21:53:58 +0800 Subject: [PATCH 04/17] =?UTF-8?q?fix(#2934):=20web=20gap-cause=20heuristic?= =?UTF-8?q?=20=E2=80=94=20arm=20fold=20tail=20on=20opener=20line=20only,?= =?UTF-8?q?=20never=20re-arm=20on=20foldSeq-stamped=20lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/web/client.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index 2192157c33..450172be67 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -818,7 +818,10 @@ export const WEB_CLIENT = `(function () { // first sample after it AND the cold continuation (hit < 85%) up to 4 // samples, closing on the first warm line. Ledger lines carry foldSeq // directly; the fold-between-times heuristic stays as the opener and - // for pre-#2929 ledgers whose lines have no foldSeq. + // for pre-#2929 ledgers whose lines have no foldSeq. The tail counter + // arms ONLY on that opener path: foldSeq-stamped lines are the + // ledger's own attribution and must not re-arm, or the chart keeps + // coloring comp up to 4 lines past the ledger retiring the window. const GAP_MS = 600_000; const CAUSE_COLOR = { cold: "#6e7681", comp: "#bf8700", ttl: "#8250df" }; const CAUSE_KEY = { cold: "det.cause_cold", comp: "det.cause_comp", ttl: "det.cause_ttl" }; @@ -829,10 +832,20 @@ export const WEB_CLIENT = `(function () { const missed = (l.input || 0) - (l.cached || 0); const growth = Math.max(0, (l.input || 0) - (p.input || 0)); const warm = (l.hitPct || 0) >= 85; - const foldOwned = l.foldSeq != null || (folds || []).some((f) => (f.at || 0) >= (p.at || 0) && (f.at || 0) <= (l.at || 0)); - if (foldOwned && missed > growth + 256) { foldTailClaims = 4; return "comp"; } - if (warm) foldTailClaims = 0; - else if (foldTailClaims > 0 && missed > growth + 256) { foldTailClaims -= 1; return "comp"; } + const foldBetween = (folds || []).some((f) => (f.at || 0) >= (p.at || 0) && (f.at || 0) <= (l.at || 0)); + const foldOwned = l.foldSeq != null || foldBetween; + let tailComp = false; + if (warm) { + foldTailClaims = 0; + } else if (foldBetween && l.foldSeq == null) { + // Opener heuristic (pre-#2929 ledgers / unattributed openers): + // 3 continuation rounds after this one (FOLD_CLAIM_COLD_ROUNDS − 1). + foldTailClaims = 3; + } else if (foldTailClaims > 0 && missed > growth + 256) { + foldTailClaims -= 1; + tailComp = true; + } + if ((foldOwned || tailComp) && missed > growth + 256) return "comp"; if ((l.at || 0) - (p.at || 0) > GAP_MS && missed > growth + 2048) return "ttl"; return "new"; }); From 1dbe9fc287cb78e018126298a95665b2fc056ba6 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 21:45:50 +0800 Subject: [PATCH 05/17] fix(#2929): unify cache-bucket terminology across the web UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The same comp bucket appeared as 压缩折损/压缩/压缩后重新建缓存/压缩复付/压缩回补 and the residual bucket as 未归因前缀失效/未归因/未归因回补 across the overview, session list, detail card, miss-split line, chart tooltips and economics copy. Canonical zh terms now: 新内容 / 压缩回补 / 未归因回补(上游TTL/淘汰/未知)/ 残差; en mirrors: new / comp repay / unattributed repay / residual. Also fixes the attribution-section note, which claimed the seam/provider/ rewind/prompt/projection partitions are "not counted in TOTAL above" — they are refinements OF the unattributed repay bucket and are already included in it (abort stays an overlay counted in no bucket). --- src/web/i18n.ts | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 29e53b201e..4ee484e074 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -77,16 +77,16 @@ export const MESSAGES: Record> = { "ov.tokens_saved": "压缩节省", "ov.gross_saved": "压缩累计节省", "ov.net_saved": "净节省", - "ov.sub_repay": "已扣除压缩复付 {r} 与摘要成本 {s}", + "ov.sub_repay": "已扣除压缩回补 {r} 与摘要成本 {s}", "ov.covlost_note": "其中 {n} 个折叠覆盖丢失,冻结 {x}", "det.covlost_sub": "其中 {n} 个折叠覆盖丢失(冻结 {x}):其覆盖的原始消息已离开重发历史,节省累计已停止", "ses.covlost_tip": "{n} 个折叠覆盖丢失(冻结 {x}):宿主在 bili 不知情下移除了被压缩的原始消息(如 dsh 原生压缩),对应节省已停止累计", - "ov.miss_split": "未命中构成(有账本会话):新增内容 {n} · 压缩折损 {c} · 未归因前缀失效 {x}(上游TTL/淘汰/未知)", + "ov.miss_split": "未命中构成(有账本会话):新增内容 {n} · 压缩回补 {c} · 未归因回补 {x}(上游TTL/淘汰/未知)", "det.hit_pct": "缓存命中率", - "ses.drop_ph": "命中率代价(占总输入的百分比,顺序:新增 / 压缩 / 未归因)", + "ses.drop_ph": "命中率代价(占总输入的百分比,顺序:新增 / 压缩回补 / 未归因回补)", "ses.empty_hidden": "另有 {n} 个空会话已隐藏(无请求、无上下文、无账本;直接链接仍可访问)", - "det.miss_split_line": "命中率的未命中部分拆分:新增内容 {n}(−{pn}%)· 压缩折损 {c}(−{pc}%)· 未归因前缀失效 {x}(−{px}%,上游TTL/淘汰/未知)", - "det.miss_sub": "未归因 −{x}% · 压缩 −{c}% · 新增 −{n}%", + "det.miss_split_line": "命中率的未命中部分拆分:新增内容 {n}(−{pn}%)· 压缩回补 {c}(−{pc}%)· 未归因回补 {x}(−{px}%,上游TTL/淘汰/未知)", + "det.miss_sub": "未归因回补 −{x}% · 压缩回补 −{c}% · 新增 −{n}%", "det.fold_time": "时间", "ov.global_hitpct": "全局缓存命中率", "ov.input_tokens": "输入 token", @@ -236,13 +236,13 @@ export const MESSAGES: Record> = { "det.legend_fold": "压缩折叠点", "det.legend_window": "上下文窗口上限", "det.cause_cold": "冷启动(无历史缓存)", - "det.cause_comp": "压缩后重新建缓存", - "det.cause_ttl": "间隔过长 · 上游 TTL 过期重读", + "det.cause_comp": "压缩回补——折叠后重读重建前缀", + "det.cause_ttl": "未归因回补——疑似上游过期/淘汰(长间隔后重读)", "det.fold_short": "折叠", "ov.gross_note": "按每次折叠的节省量 × 其后每个请求累计(理论上界)", "ov.net_excl": "未含旧版本无采样会话", "det.omitted": "更早的 {n} 条采样已裁除:每个会话只保留最近 4096 条缓存采样,超出部分在写入时裁剪、不可恢复,所以曲线从最早保留的一条开始", - "ov.saved_neg_tip": "净节省为负:压缩复付(摘要复读成本)超过了理论节省——常见于折叠后很快结束的短会话,这些场景下压缩不划算", + "ov.saved_neg_tip": "净节省为负:压缩回补(摘要复读成本)超过了理论节省——常见于折叠后很快结束的短会话,这些场景下压缩不划算", "det.cache_econ": "缓存经济学", "det.ce_new": "新内容", "det.ce_comp": "压缩回补", @@ -267,7 +267,7 @@ export const MESSAGES: Record> = { "det.attr_prompt_tip": "相邻两次请求的转发投影指纹不同且原始入站内容也变了=宿主改写了系统提示词(如周期性插入/移除动态段)——下游前缀缓存全部失效;该请求稳定前缀重计费计入此桶(归因优先级 restart>model>key>prompt>projection>wire>upstream,#2350/#2867)", "det.attr_proj": "🔀 代理投影切换", "det.attr_proj_tip": "转发的 system/developer 投影变了但原始入站内容未变=代理自身切换了压缩模式/投影规则(如 self-heal 降级 plugin→proxy 把中段 developer 消息重新提升进 system)——下游前缀缓存全部失效;该请求稳定前缀重计费计入此桶(归因优先级 restart>model>key>prompt>projection>wire>upstream,#2867)", - "det.attr_note": "接缝 / 上游侧 / 回退 / 宿主改写 / 代理投影 互斥分区未解释残差的一部分,中断为叠加标记——均不含在上方 TOTAL 内,不重复计数", + "det.attr_note": "接缝 / 上游侧 / 回退 / 宿主改写 / 代理投影:互斥分区,是「未归因回补」的细化(已含在上方数字内,不重复计数);中断为叠加标记,不计入任何桶", "det.seam_events": "⚠ 缓存接缝事件 · {n}", "det.seam_events_tip": "相邻出站体的首个字节分叉位置;若可复现,请附上该时间附近的 bili.log(#1548 类问题)", "det.stab_title": "体稳定性(逐调用字节证明)", @@ -526,16 +526,16 @@ export const MESSAGES: Record> = { "ov.tokens_saved": "Saved by compression", "ov.gross_saved": "Compressed savings (cumulative)", "ov.net_saved": "Net savings", - "ov.sub_repay": "after subtracting re-pay {r} and summary cost {s}", + "ov.sub_repay": "after subtracting comp repay {r} and summary cost {s}", "ov.covlost_note": "{n} fold(s) coverage-lost, {x} frozen", "det.covlost_sub": "{n} fold(s) coverage-lost ({x} frozen): their covered messages left the resent history — accrual stopped", "ses.covlost_tip": "{n} fold(s) coverage-lost ({x} frozen): the host removed the compressed originals outside bili's knowledge (e.g. dsh native compaction) — their savings no longer accrue", - "ov.miss_split": "missed tokens (ledgered sessions): new content {n} · compression re-read {c} · unattributed prefix invalidation {x} (upstream TTL/eviction/unknown)", + "ov.miss_split": "missed tokens (ledgered sessions): new content {n} · comp repay {c} · unattributed repay {x} (upstream TTL/eviction/unknown)", "det.hit_pct": "cache hit rate", - "ses.drop_ph": "hit-rate cost as a share of total input, order: new / comp / unattributed", + "ses.drop_ph": "hit-rate cost as a share of total input, order: new / comp repay / unattributed repay", "ses.empty_hidden": "{n} empty session(s) hidden (no requests, no context, no ledger; still reachable by direct link)", - "det.miss_split_line": "missed-token split of the hit rate: new content {n} (−{pn}%) · compression re-read {c} (−{pc}%) · unattributed prefix invalidation {x} (−{px}%, upstream TTL/eviction/unknown)", - "det.miss_sub": "unattributed −{x}% · comp −{c}% · new −{n}%", + "det.miss_split_line": "missed-token split of the hit rate: new content {n} (−{pn}%) · comp repay {c} (−{pc}%) · unattributed repay {x} (−{px}%, upstream TTL/eviction/unknown)", + "det.miss_sub": "unattributed repay −{x}% · comp repay −{c}% · new −{n}%", "det.fold_time": "when", "ov.global_hitpct": "Global cache hit rate", "ov.input_tokens": "Input tokens", @@ -682,16 +682,16 @@ export const MESSAGES: Record> = { "det.legend_fold": "compression fold", "det.legend_window": "context window limit", "det.cause_cold": "cold start (no prior cache)", - "det.cause_comp": "re-caching after compaction", - "det.cause_ttl": "long gap - upstream TTL expired, re-read", + "det.cause_comp": "comp repay — prefix rebuilt after a fold", + "det.cause_ttl": "unattributed repay — likely upstream TTL/eviction after a long gap", "det.fold_short": "fold", "ov.gross_note": "sums each fold's savings across every later request (theoretical upper bound)", "ov.net_excl": "pre-tagging sessions without samples not included", "det.omitted": "earliest {n} samples were trimmed at write time: each session keeps only its most recent 4096 cache samples (unrecoverable), so the curve starts at the oldest retained sample", - "ov.saved_neg_tip": "Negative net savings: compression re-pay (summary re-read cost) exceeded the theoretical gain; typical of short sessions that ended right after folding", + "ov.saved_neg_tip": "Negative net savings: comp repay (summary re-read cost) exceeded the theoretical gain; typical of short sessions that ended right after folding", "det.cache_econ": "Cache economics", "det.ce_new": "New content", - "det.ce_comp": "Compaction repay", + "det.ce_comp": "Comp repay", "det.ce_ttl": "Unattributed repay", "det.ce_residual": "Residual", "det.ce_balanced": "Ledger balanced ✓", @@ -713,7 +713,7 @@ export const MESSAGES: Record> = { "det.attr_prompt_tip": "The forwarded-projection fingerprint differs between consecutive requests AND the canonical incoming content also changed = the host rewrote its system prompt (e.g. a periodic dynamic section) — every downstream prefix-cache entry is invalidated; the stable-prefix re-bill is charged here (attribution priority restart > model > key > prompt > projection > wire > upstream, #2350/#2867)", "det.attr_proj": "🔀 Proxy projection switch", "det.attr_proj_tip": "Forwarded system/developer projection changed while the canonical incoming content is unchanged = the proxy switched its own compression mode/projection (e.g. self-heal degrade-to-proxy re-hoists mid-history developer messages) — every downstream prefix-cache entry is invalidated; the stable-prefix re-bill is charged here (attribution priority restart > model > key > prompt > projection > wire > upstream, #2867)", - "det.attr_note": "seam / provider-side / rewound / host-rewrite / proxy-projection exclusively partition part of the unexplained residual; abort-correlated is an overlay — none of it is counted in TOTAL above", + "det.attr_note": "seam / provider-side / rewound / host-rewrite / proxy-projection: mutually exclusive refinements of \u201cunattributed repay\u201d (already included in the numbers above, not double-counted); abort-correlated is an overlay marker counted in no bucket", "det.seam_events": "⚠ Cache-seam events · {n}", "det.seam_events_tip": "First divergence between consecutive outbound bodies; if reproducible attach bili.log around this time (#1548-family)", "det.stab_title": "Body Stability (per-call byte proof)", From 0ae986be05174b0026d150915b60959ad5fbf01b Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 21:48:30 +0800 Subject: [PATCH 06/17] =?UTF-8?q?fix(#2929):=20rename=20the=20comp=20bucke?= =?UTF-8?q?t=20to=20=E6=8A=98=E5=8F=A0=E5=90=8E=E9=87=8D=E8=AF=BB=E9=87=8D?= =?UTF-8?q?=E5=BB=BA=20/=20post-fold=20re-read=20per=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/web/i18n.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 4ee484e074..facf2d9717 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -77,16 +77,16 @@ export const MESSAGES: Record> = { "ov.tokens_saved": "压缩节省", "ov.gross_saved": "压缩累计节省", "ov.net_saved": "净节省", - "ov.sub_repay": "已扣除压缩回补 {r} 与摘要成本 {s}", + "ov.sub_repay": "已扣除折叠后重读重建 {r} 与摘要成本 {s}", "ov.covlost_note": "其中 {n} 个折叠覆盖丢失,冻结 {x}", "det.covlost_sub": "其中 {n} 个折叠覆盖丢失(冻结 {x}):其覆盖的原始消息已离开重发历史,节省累计已停止", "ses.covlost_tip": "{n} 个折叠覆盖丢失(冻结 {x}):宿主在 bili 不知情下移除了被压缩的原始消息(如 dsh 原生压缩),对应节省已停止累计", - "ov.miss_split": "未命中构成(有账本会话):新增内容 {n} · 压缩回补 {c} · 未归因回补 {x}(上游TTL/淘汰/未知)", + "ov.miss_split": "未命中构成(有账本会话):新增内容 {n} · 折叠后重读重建 {c} · 未归因回补 {x}(上游TTL/淘汰/未知)", "det.hit_pct": "缓存命中率", - "ses.drop_ph": "命中率代价(占总输入的百分比,顺序:新增 / 压缩回补 / 未归因回补)", + "ses.drop_ph": "命中率代价(占总输入的百分比,顺序:新增 / 折叠后重读重建 / 未归因回补)", "ses.empty_hidden": "另有 {n} 个空会话已隐藏(无请求、无上下文、无账本;直接链接仍可访问)", - "det.miss_split_line": "命中率的未命中部分拆分:新增内容 {n}(−{pn}%)· 压缩回补 {c}(−{pc}%)· 未归因回补 {x}(−{px}%,上游TTL/淘汰/未知)", - "det.miss_sub": "未归因回补 −{x}% · 压缩回补 −{c}% · 新增 −{n}%", + "det.miss_split_line": "命中率的未命中部分拆分:新增内容 {n}(−{pn}%)· 折叠后重读重建 {c}(−{pc}%)· 未归因回补 {x}(−{px}%,上游TTL/淘汰/未知)", + "det.miss_sub": "未归因回补 −{x}% · 折叠后重读重建 −{c}% · 新增 −{n}%", "det.fold_time": "时间", "ov.global_hitpct": "全局缓存命中率", "ov.input_tokens": "输入 token", @@ -236,16 +236,16 @@ export const MESSAGES: Record> = { "det.legend_fold": "压缩折叠点", "det.legend_window": "上下文窗口上限", "det.cause_cold": "冷启动(无历史缓存)", - "det.cause_comp": "压缩回补——折叠后重读重建前缀", + "det.cause_comp": "折叠后重读重建", "det.cause_ttl": "未归因回补——疑似上游过期/淘汰(长间隔后重读)", "det.fold_short": "折叠", "ov.gross_note": "按每次折叠的节省量 × 其后每个请求累计(理论上界)", "ov.net_excl": "未含旧版本无采样会话", "det.omitted": "更早的 {n} 条采样已裁除:每个会话只保留最近 4096 条缓存采样,超出部分在写入时裁剪、不可恢复,所以曲线从最早保留的一条开始", - "ov.saved_neg_tip": "净节省为负:压缩回补(摘要复读成本)超过了理论节省——常见于折叠后很快结束的短会话,这些场景下压缩不划算", + "ov.saved_neg_tip": "净节省为负:折叠后重读重建(摘要复读成本)超过了理论节省——常见于折叠后很快结束的短会话,这些场景下压缩不划算", "det.cache_econ": "缓存经济学", "det.ce_new": "新内容", - "det.ce_comp": "压缩回补", + "det.ce_comp": "折叠后重读重建", "det.ce_ttl": "未归因回补", "det.ce_residual": "残差", "det.ce_balanced": "账目平衡 ✓", @@ -255,7 +255,7 @@ export const MESSAGES: Record> = { "det.attr_provider": "▲ 上游侧失效", "det.attr_rewind": "↩ 历史回退", "det.attr_abort": "⏻ 中断相关", - "det.attr_seam_tip": "出站请求体在历史中段出现字节分叉,且无 fold/模型切换/重启归因——疑似重建缝。数值为嫌疑样本重计费的 token。若此前几分钟内发生过折叠,多半是折叠后客户端回显的重付(#2929 后已归入压缩回补)", + "det.attr_seam_tip": "出站请求体在历史中段出现字节分叉,且无 fold/模型切换/重启归因——疑似重建缝。数值为嫌疑样本重计费的 token。若此前几分钟内发生过折叠,多半是折叠后客户端回显的重付(#2929 后已归入折叠后重读重建)", "det.attr_provider_tip": "上一请求的整条消息列表逐字节保留(整体一致,或前缀一致、仅尾部追加新消息;超过 512KiB 取证上限的请求以记录头稳定 + 精确消息数增长判定)却仍 miss——上游 TTL 过期/淘汰/中继节点轮换,非 bili 重建缝", "det.attr_rewind_tip": "客户端 revert/trim 使消息数下降——合法的一次性重计费(保留前缀),非缺陷", "det.attr_abort_tip": "客户端流中 abort 后 30s 内结算的 miss 样本数——重试重写重发尾部;相关性而非因果,叠加标记不计入分桶", @@ -526,16 +526,16 @@ export const MESSAGES: Record> = { "ov.tokens_saved": "Saved by compression", "ov.gross_saved": "Compressed savings (cumulative)", "ov.net_saved": "Net savings", - "ov.sub_repay": "after subtracting comp repay {r} and summary cost {s}", + "ov.sub_repay": "after subtracting post-fold re-read {r} and summary cost {s}", "ov.covlost_note": "{n} fold(s) coverage-lost, {x} frozen", "det.covlost_sub": "{n} fold(s) coverage-lost ({x} frozen): their covered messages left the resent history — accrual stopped", "ses.covlost_tip": "{n} fold(s) coverage-lost ({x} frozen): the host removed the compressed originals outside bili's knowledge (e.g. dsh native compaction) — their savings no longer accrue", - "ov.miss_split": "missed tokens (ledgered sessions): new content {n} · comp repay {c} · unattributed repay {x} (upstream TTL/eviction/unknown)", + "ov.miss_split": "missed tokens (ledgered sessions): new content {n} · post-fold re-read {c} · unattributed repay {x} (upstream TTL/eviction/unknown)", "det.hit_pct": "cache hit rate", - "ses.drop_ph": "hit-rate cost as a share of total input, order: new / comp repay / unattributed repay", + "ses.drop_ph": "hit-rate cost as a share of total input, order: new / post-fold re-read / unattributed repay", "ses.empty_hidden": "{n} empty session(s) hidden (no requests, no context, no ledger; still reachable by direct link)", - "det.miss_split_line": "missed-token split of the hit rate: new content {n} (−{pn}%) · comp repay {c} (−{pc}%) · unattributed repay {x} (−{px}%, upstream TTL/eviction/unknown)", - "det.miss_sub": "unattributed repay −{x}% · comp repay −{c}% · new −{n}%", + "det.miss_split_line": "missed-token split of the hit rate: new content {n} (−{pn}%) · post-fold re-read {c} (−{pc}%) · unattributed repay {x} (−{px}%, upstream TTL/eviction/unknown)", + "det.miss_sub": "unattributed repay −{x}% · post-fold re-read −{c}% · new −{n}%", "det.fold_time": "when", "ov.global_hitpct": "Global cache hit rate", "ov.input_tokens": "Input tokens", @@ -682,16 +682,16 @@ export const MESSAGES: Record> = { "det.legend_fold": "compression fold", "det.legend_window": "context window limit", "det.cause_cold": "cold start (no prior cache)", - "det.cause_comp": "comp repay — prefix rebuilt after a fold", + "det.cause_comp": "post-fold re-read", "det.cause_ttl": "unattributed repay — likely upstream TTL/eviction after a long gap", "det.fold_short": "fold", "ov.gross_note": "sums each fold's savings across every later request (theoretical upper bound)", "ov.net_excl": "pre-tagging sessions without samples not included", "det.omitted": "earliest {n} samples were trimmed at write time: each session keeps only its most recent 4096 cache samples (unrecoverable), so the curve starts at the oldest retained sample", - "ov.saved_neg_tip": "Negative net savings: comp repay (summary re-read cost) exceeded the theoretical gain; typical of short sessions that ended right after folding", + "ov.saved_neg_tip": "Negative net savings: post-fold re-read (summary re-read cost) exceeded the theoretical gain; typical of short sessions that ended right after folding", "det.cache_econ": "Cache economics", "det.ce_new": "New content", - "det.ce_comp": "Comp repay", + "det.ce_comp": "Post-fold re-read", "det.ce_ttl": "Unattributed repay", "det.ce_residual": "Residual", "det.ce_balanced": "Ledger balanced ✓", From aba017fe5933064b7f1fd484c102365460e0b4b6 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 22:06:54 +0800 Subject: [PATCH 07/17] =?UTF-8?q?fix(#2929):=20split=20provider-side=20mis?= =?UTF-8?q?ses=20by=20idle=20gap=20=E2=80=94=20normal=20TTL=20vs=20abnorma?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The provider-side arm (byte-stable / append-shaped miss with no fold or switch attribution) conflated two very different situations: a miss seconds after the previous request (abnormal — upstream eviction or relay rotation) and the same miss after a 20-minute idle (normal — the upstream prefix cache simply aged out). The web page labeled both "上游侧失效", which reads as a failure when it is expected cost. - cache-ledger: bookProvider() splits by idle gap (PROVIDER_TTL_GAP_MS = 10 min, mirroring the chart's GAP_MS) into agg.providerTtlMissed (normal) vs agg.providerSideMissed (abnormal); seam.providerTtl{count,missed} rides the ledger + /acp-cache report (⏱ UPSTREAM TTL EXPIRY — NORMAL section). - web: attribution card gains the ⏱ 上游 TTL 过期(正常) mini (green); ▲ 上游侧失效 re-labeled (异常) with a short-gap qualifier tip. - web: the headline hit-rate subline is the three-bucket split only — the seam/provider/rewind/abort/prompt/projection chips duplicated the 归因 · 未解释残差 card below and mixed taxonomy levels (#2929). - taxonomy rename: 折叠后重读重建 → 折叠后重建 / post-fold re-read → post-fold rebuild. - tests: gap-split case (short-gap → providerSide, long-idle → providerTtl) with a pinned Date.now (settleUsageReport stamps it internally); dead chip keys removed from both locales. --- src/cache-ledger.ts | 47 ++++++++++++++----- src/web/client.ts | 34 ++------------ src/web/i18n.ts | 56 +++++++++++------------ tests/issue2929-fold-claim-window.test.ts | 24 ++++++++++ 4 files changed, 91 insertions(+), 70 deletions(-) diff --git a/src/cache-ledger.ts b/src/cache-ledger.ts index 227c00f0b2..0c01a2559e 100644 --- a/src/cache-ledger.ts +++ b/src/cache-ledger.ts @@ -239,6 +239,11 @@ interface CacheLedger { * cache (TTL expiry / eviction / relay node rotation). Not a rebuild seam. */ providerSideMisses: number; providerSideMissed: number; + /** #2929: the provider-side arm split by idle gap — samples settled more + * than PROVIDER_TTL_GAP_MS after the previous sample are normal TTL + * expiry, not an abnormal provider failure. */ + providerTtlMisses: number; + providerTtlMissed: number; /** #1592 follow-up: misses right after the client rewound history * (revert/trim — fewer message elements than the previous request). * Sanctioned client intent; recorded so the one-time re-bill is @@ -326,6 +331,11 @@ export interface SeamEvent { const SEAM_BODY_CAP = 512 * 1024; const SEAM_EVENTS_CAP = 8; +/** Idle gap past which a byte-stable/append-shaped miss reads as NORMAL upstream + * TTL expiry rather than an abnormal provider-side failure (#2929 taxonomy: + * cold start | normal TTL expiry | abnormal provider miss). Mirrors the web + * chart's GAP_MS. */ +const PROVIDER_TTL_GAP_MS = 600_000; // #2131 reachability: full-body retention cap for per-call body-stability // forensics. Bodies above it are digest-only — SHA-256 still proves byte @@ -569,6 +579,20 @@ function detectSeam(session: Session, led: CacheLedger): void { const agg = led.agg; const cur = session.transient?.sentBody; const prev = session.transient?.settledBody; + // #2929: split the provider-side arms by idle gap — a byte-stable miss + // after a long idle is normal TTL expiry; the same miss seconds after the + // previous request is the abnormal provider-side failure. + const prevSampleAt = led.lines.length >= 2 ? led.lines[led.lines.length - 2].at : line.at; + const ttlExpired = line.at - prevSampleAt > PROVIDER_TTL_GAP_MS; + const bookProvider = (): void => { + if (ttlExpired) { + agg.providerTtlMisses += 1; + agg.providerTtlMissed += line.tr; + } else { + agg.providerSideMisses += 1; + agg.providerSideMissed += line.tr; + } + }; let f: ReturnType | undefined; if (cur !== undefined && prev !== undefined) { f = seamLcp(prev.str, cur.str); @@ -603,8 +627,7 @@ function detectSeam(session: Session, led: CacheLedger): void { // upstream simply did not serve its cache. Provider-side. Above // the cap this covers the identical-recorded-head case: anything // past SEAM_BODY_CAP is beyond recorded evidence either way. - agg.providerSideMisses += 1; - agg.providerSideMissed += line.tr; + bookProvider(); return; } // #2059: tail-append turns — the previous request's ENTIRE message list @@ -617,8 +640,7 @@ function detectSeam(session: Session, led: CacheLedger): void { // would fake the msgIndex == prevMsgs == 0 signature; prevMsgs > 0 keeps // an empty prior list out. if (!prevCapped && !curCapped && f.prevMsgs > 0 && f.msgIndex === f.prevMsgs && f.curMsgs > f.prevMsgs) { - agg.providerSideMisses += 1; - agg.providerSideMissed += line.tr; + bookProvider(); return; } if (prev.str.length < cur.str.length && f.lcpBytes >= prev.str.length - 4) { @@ -631,8 +653,7 @@ function detectSeam(session: Session, led: CacheLedger): void { // growth. Without them the pair is indistinguishable from a real // break and falls through to suspect. if (prev.msgs !== null && cur.msgs !== null && cur.msgs > prev.msgs) { - agg.providerSideMisses += 1; - agg.providerSideMissed += line.tr; + bookProvider(); return; } } @@ -670,7 +691,7 @@ export function getCacheLedger(session: Session): CacheLedger { "restartDropMissed", "attributedMissed", "unknownSamples", "unknownInput", "nbSamples", "nbInput", "seamSuspects", "seamMissed", - "providerSideMisses", "providerSideMissed", "rewinds", "rewindMissed", "abortCorrelated", + "providerSideMisses", "providerSideMissed", "providerTtlMisses", "providerTtlMissed", "rewinds", "rewindMissed", "abortCorrelated", ] as const) { if (typeof g[key] !== "number") g[key] = 0; } @@ -687,7 +708,7 @@ export function getCacheLedger(session: Session): CacheLedger { foldSeqCounter: 0, folds: [], lines: [], - agg: { requests: 0, input: 0, cached: 0, output: 0, nc: 0, cr: 0, tr: 0, switches: 0, switchMissed: 0, keySwitches: 0, keySwitchMissed: 0, promptSwitches: 0, promptSwitchMissed: 0, projSwitches: 0, projSwitchMissed: 0, wireSwitches: 0, wireSwitchMissed: 0, upstreamSwitches: 0, upstreamSwitchMissed: 0, restartDrops: 0, restartDropMissed: 0, attributedMissed: 0, unknownSamples: 0, unknownInput: 0, nbSamples: 0, nbInput: 0, seamSuspects: 0, seamMissed: 0, providerSideMisses: 0, providerSideMissed: 0, rewinds: 0, rewindMissed: 0, abortCorrelated: 0 }, + agg: { requests: 0, input: 0, cached: 0, output: 0, nc: 0, cr: 0, tr: 0, switches: 0, switchMissed: 0, keySwitches: 0, keySwitchMissed: 0, promptSwitches: 0, promptSwitchMissed: 0, projSwitches: 0, projSwitchMissed: 0, wireSwitches: 0, wireSwitchMissed: 0, upstreamSwitches: 0, upstreamSwitchMissed: 0, restartDrops: 0, restartDropMissed: 0, attributedMissed: 0, unknownSamples: 0, unknownInput: 0, nbSamples: 0, nbInput: 0, seamSuspects: 0, seamMissed: 0, providerSideMisses: 0, providerSideMissed: 0, providerTtlMisses: 0, providerTtlMissed: 0, rewinds: 0, rewindMissed: 0, abortCorrelated: 0 }, }; meta[LEDGER_KEY] = led; return led; @@ -1346,7 +1367,7 @@ interface BiliCacheReport extends CacheReport { * is booked as new content, never as a prefix re-pay. */ initialBills: { samples: number; inputTokens: number }; invalidation: InvalidationTokenBreakdown; - seam: { suspects: number; missed: number; events: SeamEvent[]; providerSide: { count: number; missed: number }; rewinds: { count: number; missed: number }; abortCorrelated: number }; + seam: { suspects: number; missed: number; events: SeamEvent[]; providerSide: { count: number; missed: number }; providerTtl: { count: number; missed: number }; rewinds: { count: number; missed: number }; abortCorrelated: number }; } export function buildSessionCacheReport(session: Session): BiliCacheReport { @@ -1525,7 +1546,7 @@ export function buildSessionCacheReport(session: Session): BiliCacheReport { initialBills: { samples: a.nbSamples, inputTokens: a.nbInput }, invalidation, stability, - seam: { suspects: a.seamSuspects, missed: a.seamMissed, events: led.seamEvents ?? [], providerSide: { count: a.providerSideMisses, missed: a.providerSideMissed }, rewinds: { count: a.rewinds, missed: a.rewindMissed }, abortCorrelated: a.abortCorrelated }, + seam: { suspects: a.seamSuspects, missed: a.seamMissed, events: led.seamEvents ?? [], providerSide: { count: a.providerSideMisses, missed: a.providerSideMissed }, providerTtl: { count: a.providerTtlMisses, missed: a.providerTtlMissed }, rewinds: { count: a.rewinds, missed: a.rewindMissed }, abortCorrelated: a.abortCorrelated }, }; } @@ -1679,9 +1700,13 @@ function formatSeam(r: BiliCacheReport): string { out.push("↩ HISTORY REWOUND (client revert/trim)"); out.push(` ${r.seam.rewinds.count} sample(s) · ${fmtTok(r.seam.rewinds.missed)} tok re-billed once for the retained prefix — sanctioned client intent, not a rebuild seam`); } + if (r.seam.providerTtl.count > 0) { + out.push("⏱ UPSTREAM TTL EXPIRY — NORMAL (long idle gap)"); + out.push(` ${r.seam.providerTtl.count} sample(s) · ${fmtTok(r.seam.providerTtl.missed)} tok — byte-stable/append-shaped misses settled more than ${Math.round(PROVIDER_TTL_GAP_MS / 60_000)} min after the previous sample: the upstream prefix cache simply aged out. Expected cost, not a failure.`); + } if (r.seam.providerSide.count > 0) { out.push("▲ PROVIDER-SIDE MISS (previous request's message list fully preserved)"); - out.push(` ${r.seam.providerSide.count} sample(s) · ${fmtTok(r.seam.providerSide.missed)} tok — the previous request's message list is preserved in this one (byte-for-byte under the 512 KiB forensics cap; above it, proven by the stable recorded head plus exact message-count growth — any difference is only the appended tail); the upstream did not serve its cache (TTL expiry / eviction / relay node rotation). Not a bili rebuild seam.`); + out.push(` ${r.seam.providerSide.count} sample(s) · ${fmtTok(r.seam.providerSide.missed)} tok — the previous request's message list is preserved in this one (byte-for-byte under the 512 KiB forensics cap; above it, proven by the stable recorded head plus exact message-count growth — any difference is only the appended tail), and the sample arrived within ${Math.round(PROVIDER_TTL_GAP_MS / 60_000)} min of the previous one, so this is an ABNORMAL provider miss (eviction / relay node rotation), not TTL ageing. Not a bili rebuild seam.`); out.push(` stateful-upstream check (#2483): if your upstream keeps a live session per conversation and validates the echoed history against its own transcript (claude-code-based relays such as magpie), bili's render tags on assistant text trip that check even though bili's own list is unchanged — set diagnostics.renderNone=true until per-route render-tags control ships; expect exactly ONE replay when flipping the flag mid-session`); } if (r.seam.abortCorrelated > 0) { diff --git a/src/web/client.ts b/src/web/client.ts index 450172be67..2c66e8c92d 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1119,37 +1119,12 @@ export const WEB_CLIENT = `(function () { mini(parts, t("ov.cached_tokens"), d.cachedTokens ? fmtW(d.cachedTokens) : null); const mt = d.ledger && d.ledger.totals; const missArgs = mt && mt.input > 0 ? { n: fmtW(mt.newContent || 0), c: fmtW(mt.compRepay || 0), x: fmtW(mt.ttlRepay || 0), pn: (((mt.newContent || 0) / mt.input) * 100).toFixed(1), pc: (((mt.compRepay || 0) / mt.input) * 100).toFixed(1), px: (((mt.ttlRepay || 0) / mt.input) * 100).toFixed(1) } : null; - // #1609/#1606: surface the attribution buckets (seam / provider-side / rewound / - // abort-correlated) in the headline hit-rate subline — nonzero-only, same colors - // as the 归因·未解释残差 card lower on this page. - const lsRaw = d.ledger && typeof d.ledger.seam === "object" ? d.ledger.seam : null; + // #2929: the headline hit-rate subline stays the three-bucket split only — + // the attribution chips (seam / provider / TTL / rewind / abort / prompt / + // projection) used to be appended here too, duplicating the 归因·未解释残差 + // card lower on the page and mixing taxonomy levels in one line. let hitSub = ""; if (missArgs) hitSub += t("det.miss_sub", { x: missArgs.px, c: missArgs.pc, n: missArgs.pn }); - const attrChips = []; - if (lsRaw) { - const seamSm = Number(lsRaw.missed) || 0, seamSn = Number(lsRaw.suspects) || 0; - if (seamSm > 0 || seamSn > 0) attrChips.push('' + escapeHtml(t("det.attr_seam")) + " " + fmtW(seamSm) + (seamSn > 0 ? " ×" + seamSn : "") + ""); - const provM = (lsRaw.providerSide && Number(lsRaw.providerSide.missed)) || 0, provN = (lsRaw.providerSide && Number(lsRaw.providerSide.count)) || 0; - if (provM > 0 || provN > 0) attrChips.push('' + escapeHtml(t("det.attr_provider")) + " " + fmtW(provM) + (provN > 0 ? " ×" + provN : "") + ""); - const rewM = (lsRaw.rewinds && Number(lsRaw.rewinds.missed)) || 0, rewN = (lsRaw.rewinds && Number(lsRaw.rewinds.count)) || 0; - if (rewM > 0 || rewN > 0) attrChips.push('' + escapeHtml(t("det.attr_rewind")) + " " + fmtW(rewM) + (rewN > 0 ? " ×" + rewN : "") + ""); - const abN = Number(lsRaw.abortCorrelated) || 0; - if (abN > 0) attrChips.push('' + escapeHtml(t("det.attr_abort")) + " ×" + abN + ""); - } - // #2350: host system-prompt rewrites are a named partition of the same - // residual (cause=prompt), not part of ledger.seam — read them directly. - const pswRaw = d.ledger && typeof d.ledger.promptSwitches === "object" ? d.ledger.promptSwitches : null; - if (pswRaw) { - const pM = Number(pswRaw.missedTokens) || 0, pN = Number(pswRaw.count) || 0; - if (pM > 0 || pN > 0) attrChips.push('' + escapeHtml(t("det.attr_prompt")) + " " + fmtW(pM) + (pN > 0 ? " ×" + pN : "") + ""); - } - // #2867: proxy projection/mode switches — bili's own partition of the residual. - const jswRaw = d.ledger && typeof d.ledger.projSwitches === "object" ? d.ledger.projSwitches : null; - if (jswRaw) { - const jM = Number(jswRaw.missedTokens) || 0, jN = Number(jswRaw.count) || 0; - if (jM > 0 || jN > 0) attrChips.push('' + escapeHtml(t("det.attr_proj")) + " " + fmtW(jM) + (jN > 0 ? " ×" + jN : "") + ""); - } - if (attrChips.length) hitSub += (hitSub ? " · " : "") + attrChips.join(" · "); // #2734: the ledger only covers requests since its last (re)start — a // restore/restart window drop leaves older requests invisible to hit/miss // stats. Surface the gap and the restart drops explicitly so a frozen- @@ -1335,6 +1310,7 @@ export const WEB_CLIENT = `(function () { + (seam.events.length ? '
' + seam.events.slice(0, 6).map((ev) => "#" + ev.seq + " " + (ev.at ? fmtDT(ev.at) : "") + (typeof ev.hitPct === "number" ? " " + ev.hitPct.toFixed(1) + "%" : "") + " ≥" + fmtB(ev.lcpBytes || 0) + " @m" + (ev.msgIndex != null ? ev.msgIndex : "?") + (ev.prevMsgs != null && ev.curMsgs != null ? " (" + ev.prevMsgs + "→" + ev.curMsgs + ")" : "") + "
").join("") + (seam.events.length > 6 ? "+" + (seam.events.length - 6) + " …
" : "") + "
" : "") + "" + '
' + escapeHtml(t("det.attr_provider")) + '
' + fmtW(seam.providerSide.missed) + (seam.providerSide.count > 0 ? ' ×' + seam.providerSide.count : "") + "
" + + '
' + escapeHtml(t("det.attr_ttl")) + '
' + fmtW((seam.providerTtl && seam.providerTtl.missed) || 0) + (seam.providerTtl && seam.providerTtl.count > 0 ? ' ×' + seam.providerTtl.count : "") + "
" + '
' + escapeHtml(t("det.attr_rewind")) + '
' + fmtW(seam.rewinds.missed) + (seam.rewinds.count > 0 ? ' ×' + seam.rewinds.count : "") + "
" + '
' + escapeHtml(t("det.attr_abort")) + '
' + String(seam.abortCorrelated) + "
" + "" diff --git a/src/web/i18n.ts b/src/web/i18n.ts index facf2d9717..31a422903f 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -77,16 +77,16 @@ export const MESSAGES: Record> = { "ov.tokens_saved": "压缩节省", "ov.gross_saved": "压缩累计节省", "ov.net_saved": "净节省", - "ov.sub_repay": "已扣除折叠后重读重建 {r} 与摘要成本 {s}", + "ov.sub_repay": "已扣除折叠后重建 {r} 与摘要成本 {s}", "ov.covlost_note": "其中 {n} 个折叠覆盖丢失,冻结 {x}", "det.covlost_sub": "其中 {n} 个折叠覆盖丢失(冻结 {x}):其覆盖的原始消息已离开重发历史,节省累计已停止", "ses.covlost_tip": "{n} 个折叠覆盖丢失(冻结 {x}):宿主在 bili 不知情下移除了被压缩的原始消息(如 dsh 原生压缩),对应节省已停止累计", - "ov.miss_split": "未命中构成(有账本会话):新增内容 {n} · 折叠后重读重建 {c} · 未归因回补 {x}(上游TTL/淘汰/未知)", + "ov.miss_split": "未命中构成(有账本会话):新增内容 {n} · 折叠后重建 {c} · 未归因回补 {x}(上游TTL/淘汰/未知)", "det.hit_pct": "缓存命中率", - "ses.drop_ph": "命中率代价(占总输入的百分比,顺序:新增 / 折叠后重读重建 / 未归因回补)", + "ses.drop_ph": "命中率代价(占总输入的百分比,顺序:新增 / 折叠后重建 / 未归因回补)", "ses.empty_hidden": "另有 {n} 个空会话已隐藏(无请求、无上下文、无账本;直接链接仍可访问)", - "det.miss_split_line": "命中率的未命中部分拆分:新增内容 {n}(−{pn}%)· 折叠后重读重建 {c}(−{pc}%)· 未归因回补 {x}(−{px}%,上游TTL/淘汰/未知)", - "det.miss_sub": "未归因回补 −{x}% · 折叠后重读重建 −{c}% · 新增 −{n}%", + "det.miss_split_line": "命中率的未命中部分拆分:新增内容 {n}(−{pn}%)· 折叠后重建 {c}(−{pc}%)· 未归因回补 {x}(−{px}%,上游TTL/淘汰/未知)", + "det.miss_sub": "未归因回补 −{x}% · 折叠后重建 −{c}% · 新增 −{n}%", "det.fold_time": "时间", "ov.global_hitpct": "全局缓存命中率", "ov.input_tokens": "输入 token", @@ -236,38 +236,36 @@ export const MESSAGES: Record> = { "det.legend_fold": "压缩折叠点", "det.legend_window": "上下文窗口上限", "det.cause_cold": "冷启动(无历史缓存)", - "det.cause_comp": "折叠后重读重建", + "det.cause_comp": "折叠后重建", "det.cause_ttl": "未归因回补——疑似上游过期/淘汰(长间隔后重读)", "det.fold_short": "折叠", "ov.gross_note": "按每次折叠的节省量 × 其后每个请求累计(理论上界)", "ov.net_excl": "未含旧版本无采样会话", "det.omitted": "更早的 {n} 条采样已裁除:每个会话只保留最近 4096 条缓存采样,超出部分在写入时裁剪、不可恢复,所以曲线从最早保留的一条开始", - "ov.saved_neg_tip": "净节省为负:折叠后重读重建(摘要复读成本)超过了理论节省——常见于折叠后很快结束的短会话,这些场景下压缩不划算", + "ov.saved_neg_tip": "净节省为负:折叠后重建(摘要复读成本)超过了理论节省——常见于折叠后很快结束的短会话,这些场景下压缩不划算", "det.cache_econ": "缓存经济学", "det.ce_new": "新内容", - "det.ce_comp": "折叠后重读重建", + "det.ce_comp": "折叠后重建", "det.ce_ttl": "未归因回补", "det.ce_residual": "残差", "det.ce_balanced": "账目平衡 ✓", "det.ce_unbalanced": "账目不平衡 ✗", "det.attr_title": "归因 · 未解释残差", "det.attr_seam": "⚠ 缓存接缝", - "det.attr_provider": "▲ 上游侧失效", + "det.attr_provider": "▲ 上游侧失效(异常)", + "det.attr_ttl": "⏱ 上游 TTL 过期(正常)", + "det.attr_ttl_tip": "与上一请求间隔超过 10 分钟后,字节稳定/纯追加形态仍 miss——上游前缀缓存已正常过期,属预期损耗,无需处理", "det.attr_rewind": "↩ 历史回退", "det.attr_abort": "⏻ 中断相关", - "det.attr_seam_tip": "出站请求体在历史中段出现字节分叉,且无 fold/模型切换/重启归因——疑似重建缝。数值为嫌疑样本重计费的 token。若此前几分钟内发生过折叠,多半是折叠后客户端回显的重付(#2929 后已归入折叠后重读重建)", - "det.attr_provider_tip": "上一请求的整条消息列表逐字节保留(整体一致,或前缀一致、仅尾部追加新消息;超过 512KiB 取证上限的请求以记录头稳定 + 精确消息数增长判定)却仍 miss——上游 TTL 过期/淘汰/中继节点轮换,非 bili 重建缝", + "det.attr_seam_tip": "出站请求体在历史中段出现字节分叉,且无 fold/模型切换/重启归因——疑似重建缝。数值为嫌疑样本重计费的 token。若此前几分钟内发生过折叠,多半是折叠后客户端回显的重付(#2929 后已归入折叠后重建)", + "det.attr_provider_tip": "与上一请求间隔很短,且整条消息列表逐字节保留(整体一致,或前缀一致、仅尾部追加新消息;超过 512KiB 取证上限的请求以记录头稳定 + 精确消息数增长判定)却仍 miss——异常:上游淘汰/中继节点轮换,非 bili 重建缝;长间隔的同类样本归入「上游 TTL 过期」", "det.attr_rewind_tip": "客户端 revert/trim 使消息数下降——合法的一次性重计费(保留前缀),非缺陷", "det.attr_abort_tip": "客户端流中 abort 后 30s 内结算的 miss 样本数——重试重写重发尾部;相关性而非因果,叠加标记不计入分桶", "det.attr_restart": "⟳ 重启丢窗", "det.attr_restart_tip": "bili 重启或会话恢复后,账本窗口断裂:重启后的首个请求无法与重启前样本配对,miss 按首账计费(初始内容)", "det.ledger_gap": "账本未覆盖 {n} 请求", "det.ledger_gap_tip": "命中/miss 账本只从最近一次账本(重)建立点开始记录;窗口外的请求不在统计内——多实例共享 state 目录时常见。折叠若发生在窗外,经济性折叠数也不含它", - "det.attr_prompt": "✍️ 宿主改写提示词", - "det.attr_prompt_tip": "相邻两次请求的转发投影指纹不同且原始入站内容也变了=宿主改写了系统提示词(如周期性插入/移除动态段)——下游前缀缓存全部失效;该请求稳定前缀重计费计入此桶(归因优先级 restart>model>key>prompt>projection>wire>upstream,#2350/#2867)", - "det.attr_proj": "🔀 代理投影切换", - "det.attr_proj_tip": "转发的 system/developer 投影变了但原始入站内容未变=代理自身切换了压缩模式/投影规则(如 self-heal 降级 plugin→proxy 把中段 developer 消息重新提升进 system)——下游前缀缓存全部失效;该请求稳定前缀重计费计入此桶(归因优先级 restart>model>key>prompt>projection>wire>upstream,#2867)", - "det.attr_note": "接缝 / 上游侧 / 回退 / 宿主改写 / 代理投影:互斥分区,是「未归因回补」的细化(已含在上方数字内,不重复计数);中断为叠加标记,不计入任何桶", + "det.attr_note": "接缝 / 上游侧(异常)/ 上游 TTL 过期(正常)/ 回退 / 宿主改写 / 代理投影:互斥分区,是「未归因回补」的细化(已含在上方数字内,不重复计数);中断为叠加标记,不计入任何桶", "det.seam_events": "⚠ 缓存接缝事件 · {n}", "det.seam_events_tip": "相邻出站体的首个字节分叉位置;若可复现,请附上该时间附近的 bili.log(#1548 类问题)", "det.stab_title": "体稳定性(逐调用字节证明)", @@ -526,16 +524,16 @@ export const MESSAGES: Record> = { "ov.tokens_saved": "Saved by compression", "ov.gross_saved": "Compressed savings (cumulative)", "ov.net_saved": "Net savings", - "ov.sub_repay": "after subtracting post-fold re-read {r} and summary cost {s}", + "ov.sub_repay": "after subtracting post-fold rebuild {r} and summary cost {s}", "ov.covlost_note": "{n} fold(s) coverage-lost, {x} frozen", "det.covlost_sub": "{n} fold(s) coverage-lost ({x} frozen): their covered messages left the resent history — accrual stopped", "ses.covlost_tip": "{n} fold(s) coverage-lost ({x} frozen): the host removed the compressed originals outside bili's knowledge (e.g. dsh native compaction) — their savings no longer accrue", - "ov.miss_split": "missed tokens (ledgered sessions): new content {n} · post-fold re-read {c} · unattributed repay {x} (upstream TTL/eviction/unknown)", + "ov.miss_split": "missed tokens (ledgered sessions): new content {n} · post-fold rebuild {c} · unattributed repay {x} (upstream TTL/eviction/unknown)", "det.hit_pct": "cache hit rate", - "ses.drop_ph": "hit-rate cost as a share of total input, order: new / post-fold re-read / unattributed repay", + "ses.drop_ph": "hit-rate cost as a share of total input, order: new / post-fold rebuild / unattributed repay", "ses.empty_hidden": "{n} empty session(s) hidden (no requests, no context, no ledger; still reachable by direct link)", - "det.miss_split_line": "missed-token split of the hit rate: new content {n} (−{pn}%) · post-fold re-read {c} (−{pc}%) · unattributed repay {x} (−{px}%, upstream TTL/eviction/unknown)", - "det.miss_sub": "unattributed repay −{x}% · post-fold re-read −{c}% · new −{n}%", + "det.miss_split_line": "missed-token split of the hit rate: new content {n} (−{pn}%) · post-fold rebuild {c} (−{pc}%) · unattributed repay {x} (−{px}%, upstream TTL/eviction/unknown)", + "det.miss_sub": "unattributed repay −{x}% · post-fold rebuild −{c}% · new −{n}%", "det.fold_time": "when", "ov.global_hitpct": "Global cache hit rate", "ov.input_tokens": "Input tokens", @@ -682,13 +680,13 @@ export const MESSAGES: Record> = { "det.legend_fold": "compression fold", "det.legend_window": "context window limit", "det.cause_cold": "cold start (no prior cache)", - "det.cause_comp": "post-fold re-read", + "det.cause_comp": "post-fold rebuild", "det.cause_ttl": "unattributed repay — likely upstream TTL/eviction after a long gap", "det.fold_short": "fold", "ov.gross_note": "sums each fold's savings across every later request (theoretical upper bound)", "ov.net_excl": "pre-tagging sessions without samples not included", "det.omitted": "earliest {n} samples were trimmed at write time: each session keeps only its most recent 4096 cache samples (unrecoverable), so the curve starts at the oldest retained sample", - "ov.saved_neg_tip": "Negative net savings: post-fold re-read (summary re-read cost) exceeded the theoretical gain; typical of short sessions that ended right after folding", + "ov.saved_neg_tip": "Negative net savings: post-fold rebuild (summary re-read cost) exceeded the theoretical gain; typical of short sessions that ended right after folding", "det.cache_econ": "Cache economics", "det.ce_new": "New content", "det.ce_comp": "Post-fold re-read", @@ -698,22 +696,20 @@ export const MESSAGES: Record> = { "det.ce_unbalanced": "Ledger unbalanced ✗", "det.attr_title": "Attribution · unexplained residual", "det.attr_seam": "⚠ Cache seam", - "det.attr_provider": "▲ Provider-side miss", + "det.attr_provider": "▲ Provider-side miss (abnormal)", + "det.attr_ttl": "⏱ upstream TTL expiry (normal)", + "det.attr_ttl_tip": "byte-stable / append-shaped misses settled more than 10 minutes after the previous sample — the upstream prefix cache simply aged out; expected cost, no action needed", "det.attr_rewind": "↩ History rewound", "det.attr_abort": "⏻ Abort-correlated", "det.attr_seam_tip": "Outbound bodies diverged mid-history with no fold/model-switch/restart attribution — suspected rebuild seam. Value = tokens re-billed on suspect samples. If a fold landed minutes earlier this is usually the post-fold client-echo re-bill (fold-owned since #2929)", - "det.attr_provider_tip": "The previous request's entire message list came back byte-identical (whole body, or its prefix with only tail messages appended; above the 512 KiB forensics cap, proven by the stable recorded head plus exact message-count growth) yet the upstream did not serve its cache — TTL expiry / eviction / relay node rotation. Not a bili rebuild seam", + "det.attr_provider_tip": "Arrived shortly after the previous request, whose entire message list came back byte-identical (whole body, or its prefix with only tail messages appended; above the 512 KiB forensics cap, proven by the stable recorded head plus exact message-count growth) yet the upstream did not serve its cache — abnormal: eviction / relay node rotation. Long-gap siblings are booked under upstream TTL expiry", "det.attr_rewind_tip": "Client revert/trim shrank the message count — sanctioned one-time re-bill of the retained prefix, not a defect", "det.attr_abort_tip": "Missed samples settled within 30s of a client mid-stream abort — retry churn rewrites the resent tail; correlation, not causation (overlay marker, not a bucket)", "det.attr_restart": "⟳ restart drop", "det.attr_restart_tip": "After a bili restart or session restore the ledger window breaks: the first post-restart request cannot pair with pre-restart samples, so its miss is billed as a first bill (initial content)", "det.ledger_gap": "ledger misses {n} reqs", "det.ledger_gap_tip": "The hit/miss ledger only covers requests since its last (re)build point; requests outside the window are not counted — common with multiple instances sharing a state directory. Folds inside the gap are also missing from fold economics", - "det.attr_prompt": "✍️ Host prompt rewrite", - "det.attr_prompt_tip": "The forwarded-projection fingerprint differs between consecutive requests AND the canonical incoming content also changed = the host rewrote its system prompt (e.g. a periodic dynamic section) — every downstream prefix-cache entry is invalidated; the stable-prefix re-bill is charged here (attribution priority restart > model > key > prompt > projection > wire > upstream, #2350/#2867)", - "det.attr_proj": "🔀 Proxy projection switch", - "det.attr_proj_tip": "Forwarded system/developer projection changed while the canonical incoming content is unchanged = the proxy switched its own compression mode/projection (e.g. self-heal degrade-to-proxy re-hoists mid-history developer messages) — every downstream prefix-cache entry is invalidated; the stable-prefix re-bill is charged here (attribution priority restart > model > key > prompt > projection > wire > upstream, #2867)", - "det.attr_note": "seam / provider-side / rewound / host-rewrite / proxy-projection: mutually exclusive refinements of \u201cunattributed repay\u201d (already included in the numbers above, not double-counted); abort-correlated is an overlay marker counted in no bucket", + "det.attr_note": "seam / provider-side (abnormal) / upstream TTL expiry (normal) / rewound / host-rewrite / proxy-projection: mutually exclusive refinements of \u201cunattributed repay\u201d (already included in the numbers above, not double-counted); abort-correlated is an overlay marker counted in no bucket", "det.seam_events": "⚠ Cache-seam events · {n}", "det.seam_events_tip": "First divergence between consecutive outbound bodies; if reproducible attach bili.log around this time (#1548-family)", "det.stab_title": "Body Stability (per-call byte proof)", diff --git a/tests/issue2929-fold-claim-window.test.ts b/tests/issue2929-fold-claim-window.test.ts index 5db2631ead..fc2dc08157 100644 --- a/tests/issue2929-fold-claim-window.test.ts +++ b/tests/issue2929-fold-claim-window.test.ts @@ -111,3 +111,27 @@ test("ledger persisted before #2929 (no claims/retired fields) still claims the assert.notEqual(f.retired, true); assert.ok(led.lines[led.lines.length - 1]!.foldSeq === f.seq); }); + +test("#2929 taxonomy: long-idle byte-stable miss = normal upstream TTL, short-gap = abnormal provider-side", () => { + const s = makeSession(); + const realNow = Date.now; + const at = (t: number): void => { Date.now = () => t; }; + try { + at(T0); noteForwardedBody(s, body(["a", "b"])); + settle(s, T0, 100_000, 99_000); + at(T0 + 10_000); noteForwardedBody(s, body(["a", "b"])); + settle(s, T0 + 10_000, 100_000, 40_000); // byte-stable, 10s gap, big tr → ABNORMAL provider-side + // 25 minutes later, identical body again → normal TTL expiry. + const idle = T0 + 10_000 + 25 * 60_000; + at(idle); noteForwardedBody(s, body(["a", "b"])); + settle(s, idle, 100_000, 30_000); + } finally { + Date.now = realNow; + } + const led = getCacheLedger(s); + const a = led.agg as unknown as { providerSideMisses: number; providerSideMissed: number; providerTtlMisses: number; providerTtlMissed: number }; + assert.equal(a.providerSideMisses, 1, "short-gap byte-stable miss stays abnormal"); + assert.ok(a.providerSideMissed > 0); + assert.equal(a.providerTtlMisses, 1, "long-idle byte-stable miss is re-labeled normal TTL"); + assert.ok(a.providerTtlMissed > 0); +}); From 311dc49f6609e4e0db7aae5e45d5d48a6b307af9 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 22:16:03 +0800 Subject: [PATCH 08/17] =?UTF-8?q?chore(#2929):=20refresh=20storage-render?= =?UTF-8?q?=20goldens=20=E2=80=94=20ledger=20metadata=20now=20carries=20th?= =?UTF-8?q?e=20providerTtl=20split?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/golden/storage-render/anthropic.json | 4 ++-- tests/golden/storage-render/chat.json | 4 ++-- tests/golden/storage-render/google.json | 4 ++-- tests/golden/storage-render/responses.json | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/golden/storage-render/anthropic.json b/tests/golden/storage-render/anthropic.json index 909088df9c..814862e5e1 100644 --- a/tests/golden/storage-render/anthropic.json +++ b/tests/golden/storage-render/anthropic.json @@ -80,12 +80,12 @@ "foldAt": 9, "editedAt": 12, "summaryFrom": 9, - "stateDigest": "eb8231ac9bf4cfb89a0bbebe08dae648970237dfa2608849afbb3ff86e5e6238", + "stateDigest": "dbf2e0ce4e89ca1f0582706802ec40c7574c3a93747e69dc2d6092f0471d17c6", "sectionDigests": { "state": "b8d5d5c3a1d6423b", "blockContents": "b3a9c59b22ec1a3a", "stats": "5dedce65e3559c6c", - "metadata": "63dd4b94011331dc" + "metadata": "577cf6d9b51b4984" }, "stateKeyDigests": { "blocks": "8a3021f39f1f2eb8", diff --git a/tests/golden/storage-render/chat.json b/tests/golden/storage-render/chat.json index 28d632c3f6..2190701b7d 100644 --- a/tests/golden/storage-render/chat.json +++ b/tests/golden/storage-render/chat.json @@ -80,12 +80,12 @@ "foldAt": 9, "editedAt": 12, "summaryFrom": 9, - "stateDigest": "675803ce7ea9616b2895323f54e9c20cbe1d802e221759665dccd21a747eaf5b", + "stateDigest": "384f7fd038ac18c7517c7a7d452d68a862616063d1d191133fc2e124eb5957b9", "sectionDigests": { "state": "aa312c3572a95958", "blockContents": "dd2de296a5bc6160", "stats": "88eb19a9daefcbc3", - "metadata": "b39ea710ef9d2a61" + "metadata": "0d8b8f419b38f159" }, "stateKeyDigests": { "blocks": "bdde93b0e100e13e", diff --git a/tests/golden/storage-render/google.json b/tests/golden/storage-render/google.json index 6348c3f015..6bcaff94bc 100644 --- a/tests/golden/storage-render/google.json +++ b/tests/golden/storage-render/google.json @@ -80,12 +80,12 @@ "foldAt": 9, "editedAt": 12, "summaryFrom": 9, - "stateDigest": "0daa3487b08794976d5754dc1b3a1a70d57b56a3c87e1995b6815d9c2170c8b7", + "stateDigest": "0f70a384cd9e43019336cda7c65aad47aedbb48057787e3ad4ada62b418d69e9", "sectionDigests": { "state": "3d8afb23f4d63b31", "blockContents": "4cc83a808a659f28", "stats": "c95acb7dd4c8d0b4", - "metadata": "a77709ac04d31f3e" + "metadata": "5470934a63e25925" }, "stateKeyDigests": { "blocks": "9adb53303cd4b786", diff --git a/tests/golden/storage-render/responses.json b/tests/golden/storage-render/responses.json index fc6cbe887b..3f8c437e60 100644 --- a/tests/golden/storage-render/responses.json +++ b/tests/golden/storage-render/responses.json @@ -80,12 +80,12 @@ "foldAt": 9, "editedAt": 12, "summaryFrom": 9, - "stateDigest": "9193eb4e96dbbc19844bc1372d3c7efdf75e5f0099df3244265b030974cdecdc", + "stateDigest": "3acc6f901de3a5578f5bb6b3b490f755718460cd9e7f99ffe8e8e4240ffcef57", "sectionDigests": { "state": "1361703652576fc5", "blockContents": "1727e2e1faf79b55", "stats": "07d32933c52cb7f8", - "metadata": "afaa2775e026f8d5" + "metadata": "47e382185dd4770d" }, "stateKeyDigests": { "blocks": "0458e9c8a7bb1a99", From 41eeefadb6de7f5e609f2746e66c00d447932654 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 22:28:41 +0800 Subject: [PATCH 09/17] web(#2929): fold the attribution minis into the unattributed bucket as an inline breakdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The economics card and the separate attribution card read as two parallel grids, hiding that seam/provider/TTL/rewind/abort are subsets of the unattributed-repay bucket. Render them as an inline breakdown inside the 未归因回补 mini (zero rows skipped, residual row only when >8192) and keep the standalone card only for the seam event list. Rows use literal t() calls so the #1024 dead-key scan still sees every tip key. --- src/web/client.ts | 29 ++++++++++++++++++++++------- src/web/i18n.ts | 6 ++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index 2c66e8c92d..b017886ff1 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1190,6 +1190,7 @@ export const WEB_CLIENT = `(function () { missed: Number(seamRaw.missed) || 0, events: Array.isArray(seamRaw.events) ? seamRaw.events.filter((e) => e && e.at > 0) : [], providerSide: { count: (seamRaw.providerSide && Number(seamRaw.providerSide.count)) || 0, missed: (seamRaw.providerSide && Number(seamRaw.providerSide.missed)) || 0 }, + providerTtl: { count: (seamRaw.providerTtl && Number(seamRaw.providerTtl.count)) || 0, missed: (seamRaw.providerTtl && Number(seamRaw.providerTtl.missed)) || 0 }, rewinds: { count: (seamRaw.rewinds && Number(seamRaw.rewinds.count)) || 0, missed: (seamRaw.rewinds && Number(seamRaw.rewinds.missed)) || 0 }, abortCorrelated: Number(seamRaw.abortCorrelated) || 0, } : null; @@ -1298,22 +1299,36 @@ export const WEB_CLIENT = `(function () { parts.push('
'); mini(parts, t("det.ce_new"), fmtW(tot.newContent || 0)); mini(parts, t("det.ce_comp"), fmtW(tot.compRepay || 0)); - mini(parts, t("det.ce_ttl"), fmtW(tot.ttlRepay || 0)); + // #2929: the unattributed bucket carries its own breakdown inline — + // the containment (接缝/TTL/上游… are slices OF 未归因回补) is the + // layout itself, not a footnote on a separate card. + parts.push('
' + t("det.ce_ttl") + '
' + fmtW(tot.ttlRepay || 0) + "
" + + (seam ? (function () { + // Plain JS (this template ships to the browser verbatim) and + // literal t("…") calls so the i18n dead-key scan still sees them. + var rows = []; + if (seam.missed > 0 || seam.suspects > 0) rows.push('' + t("det.attr_seam") + " " + fmtW(seam.missed) + (seam.suspects > 0 ? " ×" + seam.suspects : "") + ""); + if (seam.providerTtl.missed > 0 || seam.providerTtl.count > 0) rows.push('' + t("det.attr_ttl") + " " + fmtW(seam.providerTtl.missed) + (seam.providerTtl.count > 0 ? " ×" + seam.providerTtl.count : "") + ""); + if (seam.providerSide.missed > 0 || seam.providerSide.count > 0) rows.push('' + t("det.attr_provider") + " " + fmtW(seam.providerSide.missed) + (seam.providerSide.count > 0 ? " ×" + seam.providerSide.count : "") + ""); + if (seam.rewinds.missed > 0 || seam.rewinds.count > 0) rows.push('' + t("det.attr_rewind") + " " + fmtW(seam.rewinds.missed) + (seam.rewinds.count > 0 ? " ×" + seam.rewinds.count : "") + ""); + if (seam.abortCorrelated > 0) rows.push('' + t("det.attr_abort") + " ×" + seam.abortCorrelated + ""); + var rest = Math.max(0, (tot.ttlRepay || 0) - seam.missed - seam.providerTtl.missed - seam.providerSide.missed - seam.rewinds.missed); + if (rest > 8192) rows.push('' + t("det.attr_rest", { x: fmtW(rest) }) + ""); + return rows.length ? '
' + rows.join("
") + "
" : ""; + })() : "") + + "
"); mini(parts, t("det.ce_residual"), fmtW(tot.residual || 0)); parts.push("
"); } - if (seamActive) { + if (seamActive && seam.events.length > 0) { + // #2929: the numeric minis moved into the 未归因回补 breakdown above; + // this section is the per-event forensic list for the seam slice only. parts.push('" + '
' + '
' + escapeHtml(t("det.attr_seam")) + '
' + fmtW(seam.missed) + (seam.suspects > 0 ? ' ×' + seam.suspects : "") + "
" // Per-event attribution inside the seam mini: which samples the aggregate points at. + (seam.events.length ? '
' + seam.events.slice(0, 6).map((ev) => "#" + ev.seq + " " + (ev.at ? fmtDT(ev.at) : "") + (typeof ev.hitPct === "number" ? " " + ev.hitPct.toFixed(1) + "%" : "") + " ≥" + fmtB(ev.lcpBytes || 0) + " @m" + (ev.msgIndex != null ? ev.msgIndex : "?") + (ev.prevMsgs != null && ev.curMsgs != null ? " (" + ev.prevMsgs + "→" + ev.curMsgs + ")" : "") + "
").join("") + (seam.events.length > 6 ? "+" + (seam.events.length - 6) + " …
" : "") + "
" : "") + "
" - + '
' + escapeHtml(t("det.attr_provider")) + '
' + fmtW(seam.providerSide.missed) + (seam.providerSide.count > 0 ? ' ×' + seam.providerSide.count : "") + "
" - + '
' + escapeHtml(t("det.attr_ttl")) + '
' + fmtW((seam.providerTtl && seam.providerTtl.missed) || 0) + (seam.providerTtl && seam.providerTtl.count > 0 ? ' ×' + seam.providerTtl.count : "") + "
" - + '
' + escapeHtml(t("det.attr_rewind")) + '
' + fmtW(seam.rewinds.missed) + (seam.rewinds.count > 0 ? ' ×' + seam.rewinds.count : "") + "
" - + '
' + escapeHtml(t("det.attr_abort")) + '
' + String(seam.abortCorrelated) + "
" - + "
" + '
' + t("det.attr_note") + "
"); } const folds = ledger.folds || []; diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 31a422903f..21bf182047 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -247,6 +247,9 @@ export const MESSAGES: Record> = { "det.ce_new": "新内容", "det.ce_comp": "折叠后重建", "det.ce_ttl": "未归因回补", + "det.ce_ttl_tip": "无 fold/切换归因、又不能算新增的重付 token。下方细分为事件级归因(接缝 / TTL 过期 / 上游异常 / 回退 / 中断),互斥分区、已含在本数内", + "det.attr_rest": "其余 {x}", + "det.attr_rest_tip": "低于定性门槛的小额残差(单笔 <8K 或 <30% 输入),不逐一归类", "det.ce_residual": "残差", "det.ce_balanced": "账目平衡 ✓", "det.ce_unbalanced": "账目不平衡 ✗", @@ -691,6 +694,9 @@ export const MESSAGES: Record> = { "det.ce_new": "New content", "det.ce_comp": "Post-fold re-read", "det.ce_ttl": "Unattributed repay", + "det.ce_ttl_tip": "re-paid tokens with no fold/switch attribution that are not new content. The breakdown below is the event-level split (seam / TTL expiry / abnormal provider / rewind / abort) — mutually exclusive slices already included in this number", + "det.attr_rest": "rest {x}", + "det.attr_rest_tip": "small residuals below the classification threshold (<8K or <30% of input per sample), not individually classified", "det.ce_residual": "Residual", "det.ce_balanced": "Ledger balanced ✓", "det.ce_unbalanced": "Ledger unbalanced ✗", From b896a09ad71bf1f10fc278f4fd5010dca5fc2ea2 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 22:38:53 +0800 Subject: [PATCH 10/17] =?UTF-8?q?web(#2929):=20clean=20attribution=20prese?= =?UTF-8?q?ntation=20=E2=80=94=20one=20composition=20strip,=20no=20duplica?= =?UTF-8?q?te=20grids?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous pass nested a line list inside the unattributed KPI tile and kept a second attribution grid with a duplicate seam mini + event list (the events table already lives under the trajectory chart). Now the four KPI tiles stay clean, the bucket composition renders as one subordinate strip directly beneath them (containment is the layout), the redundant attribution section and attr_title/attr_note keys are gone, and the stale en 'Post-fold re-read' label is renamed to 'Post-fold rebuild'. --- src/web/client.ts | 46 +++++++++++++++++----------------------------- src/web/i18n.ts | 12 +++++------- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index b017886ff1..9468414f0c 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1299,37 +1299,25 @@ export const WEB_CLIENT = `(function () { parts.push('
'); mini(parts, t("det.ce_new"), fmtW(tot.newContent || 0)); mini(parts, t("det.ce_comp"), fmtW(tot.compRepay || 0)); - // #2929: the unattributed bucket carries its own breakdown inline — - // the containment (接缝/TTL/上游… are slices OF 未归因回补) is the - // layout itself, not a footnote on a separate card. - parts.push('
' + t("det.ce_ttl") + '
' + fmtW(tot.ttlRepay || 0) + "
" - + (seam ? (function () { - // Plain JS (this template ships to the browser verbatim) and - // literal t("…") calls so the i18n dead-key scan still sees them. - var rows = []; - if (seam.missed > 0 || seam.suspects > 0) rows.push('' + t("det.attr_seam") + " " + fmtW(seam.missed) + (seam.suspects > 0 ? " ×" + seam.suspects : "") + ""); - if (seam.providerTtl.missed > 0 || seam.providerTtl.count > 0) rows.push('' + t("det.attr_ttl") + " " + fmtW(seam.providerTtl.missed) + (seam.providerTtl.count > 0 ? " ×" + seam.providerTtl.count : "") + ""); - if (seam.providerSide.missed > 0 || seam.providerSide.count > 0) rows.push('' + t("det.attr_provider") + " " + fmtW(seam.providerSide.missed) + (seam.providerSide.count > 0 ? " ×" + seam.providerSide.count : "") + ""); - if (seam.rewinds.missed > 0 || seam.rewinds.count > 0) rows.push('' + t("det.attr_rewind") + " " + fmtW(seam.rewinds.missed) + (seam.rewinds.count > 0 ? " ×" + seam.rewinds.count : "") + ""); - if (seam.abortCorrelated > 0) rows.push('' + t("det.attr_abort") + " ×" + seam.abortCorrelated + ""); - var rest = Math.max(0, (tot.ttlRepay || 0) - seam.missed - seam.providerTtl.missed - seam.providerSide.missed - seam.rewinds.missed); - if (rest > 8192) rows.push('' + t("det.attr_rest", { x: fmtW(rest) }) + ""); - return rows.length ? '
' + rows.join("
") + "
" : ""; - })() : "") - + "
"); + // #2929: composition of the unattributed bucket as one subordinate strip + // directly under the tiles — containment IS the layout, no nested lists + // inside KPI tiles and no parallel-looking attribution grid. + parts.push('
' + t("det.ce_ttl") + '
' + fmtW(tot.ttlRepay || 0) + "
"); mini(parts, t("det.ce_residual"), fmtW(tot.residual || 0)); parts.push("
"); - } - if (seamActive && seam.events.length > 0) { - // #2929: the numeric minis moved into the 未归因回补 breakdown above; - // this section is the per-event forensic list for the seam slice only. - parts.push('" - + '
' - + '
' + escapeHtml(t("det.attr_seam")) + '
' + fmtW(seam.missed) + (seam.suspects > 0 ? ' ×' + seam.suspects : "") + "
" - // Per-event attribution inside the seam mini: which samples the aggregate points at. - + (seam.events.length ? '
' + seam.events.slice(0, 6).map((ev) => "#" + ev.seq + " " + (ev.at ? fmtDT(ev.at) : "") + (typeof ev.hitPct === "number" ? " " + ev.hitPct.toFixed(1) + "%" : "") + " ≥" + fmtB(ev.lcpBytes || 0) + " @m" + (ev.msgIndex != null ? ev.msgIndex : "?") + (ev.prevMsgs != null && ev.curMsgs != null ? " (" + ev.prevMsgs + "→" + ev.curMsgs + ")" : "") + "
").join("") + (seam.events.length > 6 ? "+" + (seam.events.length - 6) + " …
" : "") + "
" : "") - + "
" - + '
' + t("det.attr_note") + "
"); + if (seam) { + // Plain JS (this template ships to the browser verbatim) and + // literal t("…") calls so the i18n dead-key scan still sees them. + var chips = []; + if (seam.missed > 0 || seam.suspects > 0) chips.push('' + t("det.attr_seam") + " " + fmtW(seam.missed) + (seam.suspects > 0 ? " ×" + seam.suspects : "") + ""); + if (seam.providerTtl.missed > 0 || seam.providerTtl.count > 0) chips.push('' + t("det.attr_ttl") + " " + fmtW(seam.providerTtl.missed) + (seam.providerTtl.count > 0 ? " ×" + seam.providerTtl.count : "") + ""); + if (seam.providerSide.missed > 0 || seam.providerSide.count > 0) chips.push('' + t("det.attr_provider") + " " + fmtW(seam.providerSide.missed) + (seam.providerSide.count > 0 ? " ×" + seam.providerSide.count : "") + ""); + if (seam.rewinds.missed > 0 || seam.rewinds.count > 0) chips.push('' + t("det.attr_rewind") + " " + fmtW(seam.rewinds.missed) + (seam.rewinds.count > 0 ? " ×" + seam.rewinds.count : "") + ""); + if (seam.abortCorrelated > 0) chips.push('' + t("det.attr_abort") + " ×" + seam.abortCorrelated + ""); + var rest = Math.max(0, (tot.ttlRepay || 0) - seam.missed - seam.providerTtl.missed - seam.providerSide.missed - seam.rewinds.missed); + if (rest > 8192) chips.push('' + t("det.attr_rest", { x: fmtW(rest) }) + ""); + if (chips.length) parts.push('
' + t("det.ce_breakdown", { v: fmtW(tot.ttlRepay || 0) }) + " " + chips.join(' · ') + "
"); + } } const folds = ledger.folds || []; parts.push('"); diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 21bf182047..076e1ca0a5 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -247,13 +247,13 @@ export const MESSAGES: Record> = { "det.ce_new": "新内容", "det.ce_comp": "折叠后重建", "det.ce_ttl": "未归因回补", - "det.ce_ttl_tip": "无 fold/切换归因、又不能算新增的重付 token。下方细分为事件级归因(接缝 / TTL 过期 / 上游异常 / 回退 / 中断),互斥分区、已含在本数内", + "det.ce_ttl_tip": "无 fold/切换归因、又不能算新增的重付 token。下方一行为其事件级构成(接缝 / TTL 过期 / 上游异常 / 回退),互斥分区、已含在本数内", + "det.ce_breakdown": "未归因回补 {v} 的构成:", "det.attr_rest": "其余 {x}", "det.attr_rest_tip": "低于定性门槛的小额残差(单笔 <8K 或 <30% 输入),不逐一归类", "det.ce_residual": "残差", "det.ce_balanced": "账目平衡 ✓", "det.ce_unbalanced": "账目不平衡 ✗", - "det.attr_title": "归因 · 未解释残差", "det.attr_seam": "⚠ 缓存接缝", "det.attr_provider": "▲ 上游侧失效(异常)", "det.attr_ttl": "⏱ 上游 TTL 过期(正常)", @@ -268,7 +268,6 @@ export const MESSAGES: Record> = { "det.attr_restart_tip": "bili 重启或会话恢复后,账本窗口断裂:重启后的首个请求无法与重启前样本配对,miss 按首账计费(初始内容)", "det.ledger_gap": "账本未覆盖 {n} 请求", "det.ledger_gap_tip": "命中/miss 账本只从最近一次账本(重)建立点开始记录;窗口外的请求不在统计内——多实例共享 state 目录时常见。折叠若发生在窗外,经济性折叠数也不含它", - "det.attr_note": "接缝 / 上游侧(异常)/ 上游 TTL 过期(正常)/ 回退 / 宿主改写 / 代理投影:互斥分区,是「未归因回补」的细化(已含在上方数字内,不重复计数);中断为叠加标记,不计入任何桶", "det.seam_events": "⚠ 缓存接缝事件 · {n}", "det.seam_events_tip": "相邻出站体的首个字节分叉位置;若可复现,请附上该时间附近的 bili.log(#1548 类问题)", "det.stab_title": "体稳定性(逐调用字节证明)", @@ -692,15 +691,15 @@ export const MESSAGES: Record> = { "ov.saved_neg_tip": "Negative net savings: post-fold rebuild (summary re-read cost) exceeded the theoretical gain; typical of short sessions that ended right after folding", "det.cache_econ": "Cache economics", "det.ce_new": "New content", - "det.ce_comp": "Post-fold re-read", + "det.ce_comp": "Post-fold rebuild", "det.ce_ttl": "Unattributed repay", - "det.ce_ttl_tip": "re-paid tokens with no fold/switch attribution that are not new content. The breakdown below is the event-level split (seam / TTL expiry / abnormal provider / rewind / abort) — mutually exclusive slices already included in this number", + "det.ce_ttl_tip": "re-paid tokens with no fold/switch attribution that are not new content. The strip below is its event-level composition (seam / TTL expiry / abnormal provider / rewind) — mutually exclusive slices already included in this number", + "det.ce_breakdown": "Unattributed repay {v} — composition: ", "det.attr_rest": "rest {x}", "det.attr_rest_tip": "small residuals below the classification threshold (<8K or <30% of input per sample), not individually classified", "det.ce_residual": "Residual", "det.ce_balanced": "Ledger balanced ✓", "det.ce_unbalanced": "Ledger unbalanced ✗", - "det.attr_title": "Attribution · unexplained residual", "det.attr_seam": "⚠ Cache seam", "det.attr_provider": "▲ Provider-side miss (abnormal)", "det.attr_ttl": "⏱ upstream TTL expiry (normal)", @@ -715,7 +714,6 @@ export const MESSAGES: Record> = { "det.attr_restart_tip": "After a bili restart or session restore the ledger window breaks: the first post-restart request cannot pair with pre-restart samples, so its miss is billed as a first bill (initial content)", "det.ledger_gap": "ledger misses {n} reqs", "det.ledger_gap_tip": "The hit/miss ledger only covers requests since its last (re)build point; requests outside the window are not counted — common with multiple instances sharing a state directory. Folds inside the gap are also missing from fold economics", - "det.attr_note": "seam / provider-side (abnormal) / upstream TTL expiry (normal) / rewound / host-rewrite / proxy-projection: mutually exclusive refinements of \u201cunattributed repay\u201d (already included in the numbers above, not double-counted); abort-correlated is an overlay marker counted in no bucket", "det.seam_events": "⚠ Cache-seam events · {n}", "det.seam_events_tip": "First divergence between consecutive outbound bodies; if reproducible attach bili.log around this time (#1548-family)", "det.stab_title": "Body Stability (per-call byte proof)", From 6f4cd2380137ff1e0906e349be164695080351b7 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 22:50:30 +0800 Subject: [PATCH 11/17] web(#2929): trajectory bands follow the ledger's authoritative attribution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The chart used to re-derive miss causes with its own gap heuristic, so the paint and the economics card told two different stories, and the legend asserted a guess ('likely upstream TTL/eviction'). detectSeam now stamps each settled line with the arm it booked (prov: ttl | side | rewind; seam already existed), the report exposes seam/prov per line, and the chart paints those fields first — the gap heuristic remains only as the legacy fallback for old ledgers. The unattributed family renders as one bordered legend group (⊇) with only the sub-causes that actually occur, matching the economics composition strip bucket-for-bucket. --- src/cache-ledger.ts | 14 +++++++++++++- src/web/client.ts | 40 +++++++++++++++++++++++++++++++++------- src/web/i18n.ts | 14 ++++++++++++-- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/src/cache-ledger.ts b/src/cache-ledger.ts index 0c01a2559e..ba11826d09 100644 --- a/src/cache-ledger.ts +++ b/src/cache-ledger.ts @@ -109,6 +109,13 @@ interface LedgerLine { /** #1592 follow-up: 1 iff this sample settled within 30s of a client * mid-stream abort in the same session (abort/retry churn correlation). */ abortedNear?: 1; + /** #2929: which attribution arm detectSeam booked this sample's residual + * into — "ttl" (long-idle byte-stable miss, normal ageing), "side" + * (short-idle byte-stable miss, abnormal provider failure) or "rewind" + * (client revert/trim re-bill). Sparse: omitted unless booked. The seam + * arm sets `seam` above instead. Lets the web trajectory chart paint the + * same bucket membership the economics card aggregates. */ + prov?: "ttl" | "side" | "rewind"; /** #1535: 1 iff `model` differs from the previous sample's KNOWN model * (unknown sides never flag); marks the re-billed stable prefix on the * first request after a model switch. Sparse: omitted unless set. */ @@ -585,6 +592,7 @@ function detectSeam(session: Session, led: CacheLedger): void { const prevSampleAt = led.lines.length >= 2 ? led.lines[led.lines.length - 2].at : line.at; const ttlExpired = line.at - prevSampleAt > PROVIDER_TTL_GAP_MS; const bookProvider = (): void => { + line.prov = ttlExpired ? "ttl" : "side"; if (ttlExpired) { agg.providerTtlMisses += 1; agg.providerTtlMissed += line.tr; @@ -607,6 +615,7 @@ function detectSeam(session: Session, led: CacheLedger): void { // clipped at SEAM_BODY_CAP parses to zero messages and would fake a // shrink (or hide one); those pairs go to the #2131 byte/count arms. if (!prevCapped && !curCapped && f.prevMsgs > 0 && f.curMsgs < f.prevMsgs) { + line.prov = "rewind"; agg.rewinds += 1; agg.rewindMissed += line.tr; return; @@ -618,6 +627,7 @@ function detectSeam(session: Session, led: CacheLedger): void { // a sanctioned client-side trim/fold re-bill of the retained prefix, // NOT a provider miss. Must run before the byte-stable arm, which // would otherwise read "all of cur survives" and book it provider-side. + line.prov = "rewind"; agg.rewinds += 1; agg.rewindMissed += line.tr; return; @@ -1345,7 +1355,7 @@ interface BodyStability { interface BiliCacheReport extends CacheReport { stability: BodyStability; /** #2131: line set widened with the per-call body-stability fields. */ - lines: Array; + lines: Array; modelSwitches: ModelSwitchStats; /** #2131: relay account rotations (credential fingerprint changes) — * the identity a URL-granular upstream switch cannot see. */ @@ -1527,6 +1537,8 @@ export function buildSessionCacheReport(session: Session): BiliCacheReport { compRepay: l.cr, ttlRepay: l.tr, foldSeq: l.foldSeq, + seam: l.seam, + prov: l.prov, bodyDigest: l.bd, keyFp: l.kp, sysFp: l.sp, diff --git a/src/web/client.ts b/src/web/client.ts index 9468414f0c..3cce9c2d5c 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -823,8 +823,13 @@ export const WEB_CLIENT = `(function () { // ledger's own attribution and must not re-arm, or the chart keeps // coloring comp up to 4 lines past the ledger retiring the window. const GAP_MS = 600_000; - const CAUSE_COLOR = { cold: "#6e7681", comp: "#bf8700", ttl: "#8250df" }; - const CAUSE_KEY = { cold: "det.cause_cold", comp: "det.cause_comp", ttl: "det.cause_ttl" }; + // #2929: per-sample causes follow the LEDGER's authoritative attribution + // (foldSeq / seam / prov), not a parallel heuristic — the chart paints + // the same bucket membership the economics card aggregates. The gap + // heuristic remains only as the legacy fallback for old ledgers whose + // lines carry no attribution fields. + const CAUSE_COLOR = { cold: "#6e7681", comp: "#bf8700", seam: "#cf222e", pt: "#1a7f37", ps: "#f0883e", rw: "#57606a", rest: "#8250df" }; + const CAUSE_KEY = { cold: "det.cause_cold", comp: "det.cause_comp", seam: "det.legend_seam", pt: "det.leg_pttl", ps: "det.leg_pside", rw: "det.leg_rewind", rest: "det.cause_ttl" }; let foldTailClaims = 0; const causes = lines.map((l, i) => { if (i === 0) return !(l.cached || 0) ? "cold" : "new"; @@ -846,7 +851,13 @@ export const WEB_CLIENT = `(function () { tailComp = true; } if ((foldOwned || tailComp) && missed > growth + 256) return "comp"; - if ((l.at || 0) - (p.at || 0) > GAP_MS && missed > growth + 2048) return "ttl"; + // Authoritative unattributed sub-causes (#2929 ledger fields): + if (l.seam === 1) return "seam"; + if (l.prov === "ttl") return "pt"; + if (l.prov === "side") return "ps"; + if (l.prov === "rewind") return "rw"; + // Legacy fallback only: no attribution fields on this line. + if (l.foldSeq == null && l.seam === undefined && l.prov === undefined && (l.at || 0) - (p.at || 0) > GAP_MS && missed > growth + 2048) return "rest"; return "new"; }); let bands = "", hovers = ""; @@ -1204,13 +1215,28 @@ export const WEB_CLIENT = `(function () { parts.push(legendItem("background:var(--accent)", t("det.legend_input"))); parts.push(legendItem("background:var(--accent);opacity:.4", t("det.legend_cached"), false)); parts.push(legendItem("#cf222e", t("det.legend_fold"), true)); - if (seamActive && seam.events.length > 0) - parts.push(legendItem("background:#cf222e", t("det.legend_seam"))); parts.push(legendItem("#cf222e", t("det.legend_window"), true)); - // Swatches carry real backgrounds (a bare hex in style= renders nothing): + // Swatches carry real backgrounds (a bare hex in style= renders nothing). + // #2929: miss-cause swatches mirror the ledger buckets — the + // unattributed family renders as ONE bordered group (外框) with its + // sub-causes inside, so containment is visible, not implied. parts.push(legendItem("background:#bf8700", t("det.cause_comp"))); - parts.push(legendItem("background:#8250df", t("det.cause_ttl"))); parts.push(legendItem("background:#6e7681", t("det.cause_cold"))); + if (seam) { + const sub = []; + if (seam.missed > 0 || seam.suspects > 0) sub.push(legendItem("background:#cf222e", t("det.legend_seam"))); + if (seam.providerTtl.count > 0) sub.push(legendItem("background:#1a7f37", t("det.leg_pttl"))); + if (seam.providerSide.count > 0) sub.push(legendItem("background:#f0883e", t("det.leg_pside"))); + if (seam.rewinds.count > 0) sub.push(legendItem("background:#57606a", t("det.leg_rewind"))); + sub.push(legendItem("background:#8250df", t("det.leg_rest"))); + parts.push('' + + legendItem("background:#8250df", t("det.cause_unattrib")) + + '⊇' + + sub.join("") + + ""); + } else { + parts.push(legendItem("background:#8250df", t("det.cause_ttl"))); + } if (d.systemPromptTokens || lines.length >= 20) parts.push(legendItem("border:1.5px solid #8b949e;background:#f2f5f7;", d.systemPromptTokens ? t("det.legend_base") : t("det.legend_base_est"))); parts.push("
"); if ((ledger.linesOmitted || 0) > 0) parts.push('
' + t("det.omitted", { n: ledger.linesOmitted }) + "
"); diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 076e1ca0a5..c3a9b36ab1 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -237,7 +237,12 @@ export const MESSAGES: Record> = { "det.legend_window": "上下文窗口上限", "det.cause_cold": "冷启动(无历史缓存)", "det.cause_comp": "折叠后重建", - "det.cause_ttl": "未归因回补——疑似上游过期/淘汰(长间隔后重读)", + "det.cause_ttl": "未归因回补 · 其余", + "det.cause_unattrib": "未归因回补", + "det.leg_pttl": "⏱ 上游 TTL 过期", + "det.leg_pside": "▲ 上游侧失效", + "det.leg_rewind": "↩ 历史回退", + "det.leg_rest": "其余", "det.fold_short": "折叠", "ov.gross_note": "按每次折叠的节省量 × 其后每个请求累计(理论上界)", "ov.net_excl": "未含旧版本无采样会话", @@ -683,7 +688,12 @@ export const MESSAGES: Record> = { "det.legend_window": "context window limit", "det.cause_cold": "cold start (no prior cache)", "det.cause_comp": "post-fold rebuild", - "det.cause_ttl": "unattributed repay — likely upstream TTL/eviction after a long gap", +"det.cause_ttl": "unattributed repay · rest", + "det.cause_unattrib": "unattributed repay", + "det.leg_pttl": "⏱ upstream TTL expiry", + "det.leg_pside": "▲ provider-side miss", + "det.leg_rewind": "↩ rewind", + "det.leg_rest": "rest", "det.fold_short": "fold", "ov.gross_note": "sums each fold's savings across every later request (theoretical upper bound)", "ov.net_excl": "pre-tagging sessions without samples not included", From 9b8a6fa86fc8642ecfe3c931ad1dfe1d3f18b84b Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 22:58:51 +0800 Subject: [PATCH 12/17] =?UTF-8?q?web(#2929):=20the=20unattributed=20KPI=20?= =?UTF-8?q?tile=20lost=20its=20box=20=E2=80=94=20route=20it=20through=20mi?= =?UTF-8?q?ni()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hand-rolled the tile with class="mini", which is not a CSS class in this page (the helper emits class="stat"), so the tile rendered as bare text between its boxed neighbours and the row looked broken. One-liner: call mini() like its three siblings, which also gives the tile the "?" qmark with the bucket tooltip. --- src/web/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/client.ts b/src/web/client.ts index 3cce9c2d5c..24f6651a0d 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1328,7 +1328,7 @@ export const WEB_CLIENT = `(function () { // #2929: composition of the unattributed bucket as one subordinate strip // directly under the tiles — containment IS the layout, no nested lists // inside KPI tiles and no parallel-looking attribution grid. - parts.push('
' + t("det.ce_ttl") + '
' + fmtW(tot.ttlRepay || 0) + "
"); + mini(parts, t("det.ce_ttl"), fmtW(tot.ttlRepay || 0), false, null, t("det.ce_ttl_tip")); mini(parts, t("det.ce_residual"), fmtW(tot.residual || 0)); parts.push(""); if (seam) { From 75212082257408cafcf9e1ef3fa8be3176dc4a27 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 23:00:04 +0800 Subject: [PATCH 13/17] =?UTF-8?q?chore(#2929):=20refresh=20storage-render?= =?UTF-8?q?=20goldens=20=E2=80=94=20per-line=20prov=20attribution=20stamps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit detectSeam now stamps each settled line booked into a provider-side arm (prov: ttl | side | rewind); the golden fixture's 8 side-arm lines carry the new sparse field. A/B persisted-state dump (b896a09ad vs this head) shows exactly those 8 fields and nothing else. --- tests/golden/storage-render/anthropic.json | 4 ++-- tests/golden/storage-render/google.json | 4 ++-- tests/golden/storage-render/responses.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/golden/storage-render/anthropic.json b/tests/golden/storage-render/anthropic.json index 814862e5e1..4e2a78c32f 100644 --- a/tests/golden/storage-render/anthropic.json +++ b/tests/golden/storage-render/anthropic.json @@ -80,12 +80,12 @@ "foldAt": 9, "editedAt": 12, "summaryFrom": 9, - "stateDigest": "dbf2e0ce4e89ca1f0582706802ec40c7574c3a93747e69dc2d6092f0471d17c6", + "stateDigest": "1088bae87675b4b44d38c604cd1f7456b665e53dd4ba27649048ebda00ec31f8", "sectionDigests": { "state": "b8d5d5c3a1d6423b", "blockContents": "b3a9c59b22ec1a3a", "stats": "5dedce65e3559c6c", - "metadata": "577cf6d9b51b4984" + "metadata": "e912f03b1cd341f4" }, "stateKeyDigests": { "blocks": "8a3021f39f1f2eb8", diff --git a/tests/golden/storage-render/google.json b/tests/golden/storage-render/google.json index 6bcaff94bc..9f4049d79e 100644 --- a/tests/golden/storage-render/google.json +++ b/tests/golden/storage-render/google.json @@ -80,12 +80,12 @@ "foldAt": 9, "editedAt": 12, "summaryFrom": 9, - "stateDigest": "0f70a384cd9e43019336cda7c65aad47aedbb48057787e3ad4ada62b418d69e9", + "stateDigest": "7fd4909d7178239b13237590d0ccd03103dd8e46e7642ea620dcc82155187a78", "sectionDigests": { "state": "3d8afb23f4d63b31", "blockContents": "4cc83a808a659f28", "stats": "c95acb7dd4c8d0b4", - "metadata": "5470934a63e25925" + "metadata": "db5726ac9598a0e2" }, "stateKeyDigests": { "blocks": "9adb53303cd4b786", diff --git a/tests/golden/storage-render/responses.json b/tests/golden/storage-render/responses.json index 3f8c437e60..cb2790f43b 100644 --- a/tests/golden/storage-render/responses.json +++ b/tests/golden/storage-render/responses.json @@ -80,12 +80,12 @@ "foldAt": 9, "editedAt": 12, "summaryFrom": 9, - "stateDigest": "3acc6f901de3a5578f5bb6b3b490f755718460cd9e7f99ffe8e8e4240ffcef57", + "stateDigest": "e6e2a18fc7c9b1f44a0572b54008817e21db85fb0e98829e3bde7d1506c21820", "sectionDigests": { "state": "1361703652576fc5", "blockContents": "1727e2e1faf79b55", "stats": "07d32933c52cb7f8", - "metadata": "47e382185dd4770d" + "metadata": "61c8172889bbdc91" }, "stateKeyDigests": { "blocks": "0458e9c8a7bb1a99", From c20078d43bff5fa0866f4bd4bc0a06d50f71cb47 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 23:11:01 +0800 Subject: [PATCH 14/17] web(#2929): composition moves INSIDE the unattributed tile; chart bands bind to their bars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Requested after visual review of the rendered page: - The 'of which' breakdown (seam / TTL / provider / rewind / rest) was a caption floating under the KPI row — it is now part of the unattributed-repay tile itself: label · value · then the parts, top to bottom. Containment is the layout, not an annotation beside it. The dead ce_ttl_tip qmark key goes away. - The trajectory chart only labelled samples 1/5/10 and each miss-cause band floated free of any bar, so band-to-bar mapping required detective work. Now every sample gets a seq label (thinned only when dense) and each band drops a thin same-colour spine from its floor to the baseline, tying it to the exact bar column it annotates. --- src/web/client.ts | 49 +++++++++++++++++++++++++++++------------------ src/web/i18n.ts | 6 ++---- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index 24f6651a0d..31395125fc 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -868,6 +868,10 @@ export const WEB_CLIENT = `(function () { const x0 = Math.max(PL, x(i) - swSeg / 2), x1 = Math.min(W - PR, x(i) + swSeg / 2); if (c !== "new") { bands += ''; + // Vertical spine: the miss band floats above the cache line, so drop + // a thin same-colour rule down to the baseline — the bar the band + // belongs to becomes self-evident instead of floating free. + bands += ''; } const hitPctLine = (l.input || 0) > 0 ? ((l.cached || 0) / l.input * 100).toFixed(1) + "%" : t("common.none"); hovers += '' @@ -931,8 +935,10 @@ export const WEB_CLIENT = `(function () { baseline = '<line x1="' + PL + '" y1="' + yy.toFixed(1) + '" x2="' + (W - PR) + '" y2="' + yy.toFixed(1) + '" stroke="#8b949e" stroke-width="1" stroke-dasharray="2 4"/>' + '<text x="' + PL + '" y="' + Math.max(10, yy - 4).toFixed(1) + '" font-size="9.5" fill="#8b949e">' + t(baseMeasured ? "det.legend_base" : "det.legend_base_est") + " " + fmtW(baseVal) + "</text>"; } - const xt = [0, Math.floor((lines.length - 1) / 2), lines.length - 1] - .map((i) => '<text x="' + x(i).toFixed(1) + '" y="' + (H - 20) + '" text-anchor="middle" font-size="10" fill="var(--text-muted)">' + lines[i].seq + "</text>").join(""); + // #2929: per-sample seq labels (thinned only when dense) — every band + // must map to a visible index, not "somewhere between 5 and 10". + const tStep = lines.length <= 14 ? 1 : lines.length <= 28 ? 2 : lines.length <= 70 ? 5 : 10; + const xt = lines.map((l, i) => i % tStep ? "" : '<text x="' + x(i).toFixed(1) + '" y="' + (H - 20) + '" text-anchor="middle" font-size="10" fill="var(--text-muted)">' + l.seq + "</text>").join(""); const xtTime = (lines[0] && lines[0].at ? '<text x="' + PL + '" y="' + (H - 8) + '" text-anchor="start" font-size="9.5" fill="var(--text-faint)">' + dt(lines[0].at) + "</text>" : "") + (lines.length > 1 && lines[lines.length - 1].at ? '<text x="' + (W - PR) + '" y="' + (H - 8) + '" text-anchor="end" font-size="9.5" fill="var(--text-faint)">' + dt(lines[lines.length - 1].at) + "</text>" : ""); @@ -1325,25 +1331,30 @@ export const WEB_CLIENT = `(function () { parts.push('<div class="grid cols-4">'); mini(parts, t("det.ce_new"), fmtW(tot.newContent || 0)); mini(parts, t("det.ce_comp"), fmtW(tot.compRepay || 0)); - // #2929: composition of the unattributed bucket as one subordinate strip - // directly under the tiles — containment IS the layout, no nested lists - // inside KPI tiles and no parallel-looking attribution grid. - mini(parts, t("det.ce_ttl"), fmtW(tot.ttlRepay || 0), false, null, t("det.ce_ttl_tip")); + // #2929: the unattributed bucket shows its own composition INSIDE the + // tile (label · value · then the parts, top to bottom) — containment + // rendered as layout, not as a caption floating beside the tiles. + const plainUnattrib = () => '<div class="stat"><div class="k">' + t("det.ce_ttl") + '</div><div class="v mono">' + fmtW(tot.ttlRepay || 0) + "</div></div>"; + if (seam && (seam.missed > 0 || seam.providerTtl.count > 0 || seam.providerSide.count > 0 || seam.rewinds.count > 0)) { + var uChips = []; + if (seam.missed > 0 || seam.suspects > 0) uChips.push('<span style="color:#cf222e" title="' + escapeHtml(t("det.attr_seam_tip")) + '">' + t("det.attr_seam") + " " + fmtW(seam.missed) + (seam.suspects > 0 ? " ×" + seam.suspects : "") + "</span>"); + if (seam.providerTtl.missed > 0 || seam.providerTtl.count > 0) uChips.push('<span style="color:#1a7f37" title="' + escapeHtml(t("det.attr_ttl_tip")) + '">' + t("det.attr_ttl") + " " + fmtW(seam.providerTtl.missed) + (seam.providerTtl.count > 0 ? " ×" + seam.providerTtl.count : "") + "</span>"); + if (seam.providerSide.missed > 0 || seam.providerSide.count > 0) uChips.push('<span style="color:#bf8700" title="' + escapeHtml(t("det.attr_provider_tip")) + '">' + t("det.attr_provider") + " " + fmtW(seam.providerSide.missed) + (seam.providerSide.count > 0 ? " ×" + seam.providerSide.count : "") + "</span>"); + if (seam.rewinds.missed > 0 || seam.rewinds.count > 0) uChips.push('<span style="color:#57606a" title="' + escapeHtml(t("det.attr_rewind_tip")) + '">' + t("det.attr_rewind") + " " + fmtW(seam.rewinds.missed) + (seam.rewinds.count > 0 ? " ×" + seam.rewinds.count : "") + "</span>"); + if (seam.abortCorrelated > 0) uChips.push('<span style="color:#d4a72c" title="' + escapeHtml(t("det.attr_abort_tip")) + '">' + t("det.attr_abort") + " ×" + seam.abortCorrelated + "</span>"); + var uRest = Math.max(0, (tot.ttlRepay || 0) - seam.missed - seam.providerTtl.missed - seam.providerSide.missed - seam.rewinds.missed); + if (uRest > 8192) uChips.push('<span class="dim" title="' + escapeHtml(t("det.attr_rest_tip")) + '">' + t("det.attr_rest", { x: fmtW(uRest) }) + "</span>"); + if (uChips.length) { + parts.push('<div class="stat"><div class="k">' + t("det.ce_ttl") + '</div><div class="v mono">' + fmtW(tot.ttlRepay || 0) + '</div>' + + '<div class="dim small mono" style="margin-top:6px;line-height:1.7"><span>' + escapeHtml(t("det.ce_breakdown")) + "</span><br>" + uChips.join("<br>") + "</div></div>"); + } else { + parts.push(plainUnattrib()); + } + } else { + parts.push(plainUnattrib()); + } mini(parts, t("det.ce_residual"), fmtW(tot.residual || 0)); parts.push("</div>"); - if (seam) { - // Plain JS (this template ships to the browser verbatim) and - // literal t("…") calls so the i18n dead-key scan still sees them. - var chips = []; - if (seam.missed > 0 || seam.suspects > 0) chips.push('<span style="color:#cf222e" title="' + escapeHtml(t("det.attr_seam_tip")) + '">' + t("det.attr_seam") + " " + fmtW(seam.missed) + (seam.suspects > 0 ? " ×" + seam.suspects : "") + "</span>"); - if (seam.providerTtl.missed > 0 || seam.providerTtl.count > 0) chips.push('<span style="color:#1a7f37" title="' + escapeHtml(t("det.attr_ttl_tip")) + '">' + t("det.attr_ttl") + " " + fmtW(seam.providerTtl.missed) + (seam.providerTtl.count > 0 ? " ×" + seam.providerTtl.count : "") + "</span>"); - if (seam.providerSide.missed > 0 || seam.providerSide.count > 0) chips.push('<span style="color:#bf8700" title="' + escapeHtml(t("det.attr_provider_tip")) + '">' + t("det.attr_provider") + " " + fmtW(seam.providerSide.missed) + (seam.providerSide.count > 0 ? " ×" + seam.providerSide.count : "") + "</span>"); - if (seam.rewinds.missed > 0 || seam.rewinds.count > 0) chips.push('<span style="color:#57606a" title="' + escapeHtml(t("det.attr_rewind_tip")) + '">' + t("det.attr_rewind") + " " + fmtW(seam.rewinds.missed) + (seam.rewinds.count > 0 ? " ×" + seam.rewinds.count : "") + "</span>"); - if (seam.abortCorrelated > 0) chips.push('<span style="color:#d4a72c" title="' + escapeHtml(t("det.attr_abort_tip")) + '">' + t("det.attr_abort") + " ×" + seam.abortCorrelated + "</span>"); - var rest = Math.max(0, (tot.ttlRepay || 0) - seam.missed - seam.providerTtl.missed - seam.providerSide.missed - seam.rewinds.missed); - if (rest > 8192) chips.push('<span class="dim" title="' + escapeHtml(t("det.attr_rest_tip")) + '">' + t("det.attr_rest", { x: fmtW(rest) }) + "</span>"); - if (chips.length) parts.push('<div class="dim small" style="margin-top:8px">' + t("det.ce_breakdown", { v: fmtW(tot.ttlRepay || 0) }) + " " + chips.join(' <span class="dim">·</span> ') + "</div>"); - } } const folds = ledger.folds || []; parts.push('<div class="section-label" style="margin-top:14px">' + t("det.folds") + "</div>"); diff --git a/src/web/i18n.ts b/src/web/i18n.ts index c3a9b36ab1..8f1a113a70 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -252,8 +252,7 @@ export const MESSAGES: Record<Locale, Record<string, string>> = { "det.ce_new": "新内容", "det.ce_comp": "折叠后重建", "det.ce_ttl": "未归因回补", - "det.ce_ttl_tip": "无 fold/切换归因、又不能算新增的重付 token。下方一行为其事件级构成(接缝 / TTL 过期 / 上游异常 / 回退),互斥分区、已含在本数内", - "det.ce_breakdown": "未归因回补 {v} 的构成:", + "det.ce_breakdown": "其中:", "det.attr_rest": "其余 {x}", "det.attr_rest_tip": "低于定性门槛的小额残差(单笔 <8K 或 <30% 输入),不逐一归类", "det.ce_residual": "残差", @@ -703,8 +702,7 @@ export const MESSAGES: Record<Locale, Record<string, string>> = { "det.ce_new": "New content", "det.ce_comp": "Post-fold rebuild", "det.ce_ttl": "Unattributed repay", - "det.ce_ttl_tip": "re-paid tokens with no fold/switch attribution that are not new content. The strip below is its event-level composition (seam / TTL expiry / abnormal provider / rewind) — mutually exclusive slices already included in this number", - "det.ce_breakdown": "Unattributed repay {v} — composition: ", + "det.ce_breakdown": "of which:", "det.attr_rest": "rest {x}", "det.attr_rest_tip": "small residuals below the classification threshold (<8K or <30% of input per sample), not individually classified", "det.ce_residual": "Residual", From 77108258fd9c06b0146da648f90bf2c3fa94bc03 Mon Sep 17 00:00:00 2001 From: ework-agent <ework@relay> Date: Mon, 12 Oct 2026 23:54:44 +0800 Subject: [PATCH 15/17] =?UTF-8?q?fix(#2929):=20let=20dense=20charts=20thin?= =?UTF-8?q?=20ticks=20=E2=80=94=20remove=20the=20backwards=20barW=20floor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `Math.ceil(24 / Math.max(barW, 1))` clamped sub-pixel bar widths UP to 1px, so sessions with thousands of samples (barW≈0.36) always got tStep=24 → 100+ overlapping vertical labels. The demo case (N=10, barW≈99 > 1) never exercised the clamp, which is how it shipped. Drop the inner max (the ternary guarantees barW>0 for N≥2, N=1 → 1): dense charts now hold the intended ~24px horizontal pitch (N=2494 → tStep=68 → 37 labels). --- src/web/client.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index 31395125fc..e27f0d66d5 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -935,10 +935,23 @@ export const WEB_CLIENT = `(function () { baseline = '<line x1="' + PL + '" y1="' + yy.toFixed(1) + '" x2="' + (W - PR) + '" y2="' + yy.toFixed(1) + '" stroke="#8b949e" stroke-width="1" stroke-dasharray="2 4"/>' + '<text x="' + PL + '" y="' + Math.max(10, yy - 4).toFixed(1) + '" font-size="9.5" fill="#8b949e">' + t(baseMeasured ? "det.legend_base" : "det.legend_base_est") + " " + fmtW(baseVal) + "</text>"; } - // #2929: per-sample seq labels (thinned only when dense) — every band - // must map to a visible index, not "somewhere between 5 and 10". - const tStep = lines.length <= 14 ? 1 : lines.length <= 28 ? 2 : lines.length <= 70 ? 5 : 10; - const xt = lines.map((l, i) => i % tStep ? "" : '<text x="' + x(i).toFixed(1) + '" y="' + (H - 20) + '" text-anchor="middle" font-size="10" fill="var(--text-muted)">' + l.seq + "</text>").join(""); + // #2929: per-sample seq labels — every band must map to a visible + // index, not "somewhere between 5 and 10". Thinning is PIXEL-driven, + // not count-driven: real sessions carry hundreds/thousands of samples + // (~0.4px/sample), where any flat count step either mosaics the axis + // or drops to two naked numbers. Vertical (rotated) ticks reclaim the + // unused Y range; hold a constant ≥24px HORIZONTAL pitch. + // (#2929 cont.) NO Math.max(barW,1) here — that floor clamps + // sub-pixel bars UP to 1 and silently disables thinning exactly on + // the dense sessions this exists for. + const barW = lines.length > 1 ? (W - PL - PR) / (lines.length - 1) : 1; + const tStep = Math.max(1, Math.ceil(24 / barW)); + const xtArr = []; + for (let i = lines.length - 1; i >= 0; i -= tStep) { + const l = lines[i]; + xtArr.push('<text transform="translate(' + x(i).toFixed(1) + ',' + (H - 28) + ') rotate(-90)" text-anchor="end" font-size="10" fill="var(--text-muted)">' + l.seq + "</text>"); + } + const xt = xtArr.join(""); const xtTime = (lines[0] && lines[0].at ? '<text x="' + PL + '" y="' + (H - 8) + '" text-anchor="start" font-size="9.5" fill="var(--text-faint)">' + dt(lines[0].at) + "</text>" : "") + (lines.length > 1 && lines[lines.length - 1].at ? '<text x="' + (W - PR) + '" y="' + (H - 8) + '" text-anchor="end" font-size="9.5" fill="var(--text-faint)">' + dt(lines[lines.length - 1].at) + "</text>" : ""); From f17471a93e674fdbd0efb7de8ebd83caa8b624fe Mon Sep 17 00:00:00 2001 From: ework-agent <ework@relay> Date: Tue, 13 Oct 2026 00:09:52 +0800 Subject: [PATCH 16/17] web(#2929): mitigation tip under the post-fold rebuild stat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Show a one-line small-text hint on the 折叠后重建 tile whenever the value is non-zero: lowering compress.preserveRecentMessages (the protected recent-message count) reduces how much recent content each fold drags back into context — minimum recommended value 1. Bilingual zh/en, conditional so zero-rebuild sessions stay clean. --- src/web/client.ts | 2 +- src/web/i18n.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/web/client.ts b/src/web/client.ts index e27f0d66d5..64d2d02e59 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1343,7 +1343,7 @@ export const WEB_CLIENT = `(function () { if (tot) { parts.push('<div class="grid cols-4">'); mini(parts, t("det.ce_new"), fmtW(tot.newContent || 0)); - mini(parts, t("det.ce_comp"), fmtW(tot.compRepay || 0)); + mini(parts, t("det.ce_comp"), fmtW(tot.compRepay || 0), false, (tot.compRepay || 0) > 0 ? t("det.ce_comp_hint") : ""); // #2929: the unattributed bucket shows its own composition INSIDE the // tile (label · value · then the parts, top to bottom) — containment // rendered as layout, not as a caption floating beside the tiles. diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 8f1a113a70..9d8ef8beb9 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -251,6 +251,7 @@ export const MESSAGES: Record<Locale, Record<string, string>> = { "det.cache_econ": "缓存经济学", "det.ce_new": "新内容", "det.ce_comp": "折叠后重建", + "det.ce_comp_hint": "提示:保护最近消息条数(compress.preserveRecentMessages)调小可缓解,建议最低 1", "det.ce_ttl": "未归因回补", "det.ce_breakdown": "其中:", "det.attr_rest": "其余 {x}", @@ -701,6 +702,7 @@ export const MESSAGES: Record<Locale, Record<string, string>> = { "det.cache_econ": "Cache economics", "det.ce_new": "New content", "det.ce_comp": "Post-fold rebuild", + "det.ce_comp_hint": "Tip: lowering compress.preserveRecentMessages (the protected recent-message count) reduces this — minimum 1", "det.ce_ttl": "Unattributed repay", "det.ce_breakdown": "of which:", "det.attr_rest": "rest {x}", From e76b35f9ebbe2772cdc855ce259a5e1a5a086ad1 Mon Sep 17 00:00:00 2001 From: ework-agent <ework@relay> Date: Tue, 13 Oct 2026 00:18:38 +0800 Subject: [PATCH 17/17] web(#2929): de-conflict unattributed-bucket chip colors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ▲上游侧失效 reused #bf8700 (the 折叠后重建 amber) while 其余 rendered as #656d76 dim — two muddy earth tones that read as one color at chip size. Align the provider-side chip with its chart band (#f0883e) and lighten the rest-of-dust chip to neutral #9aa1a8, so every bucket now has a distinct hue: red seam / green TTL / orange provider-side / slate rewind / gold abort / light-gray rest. --- src/web/client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index 64d2d02e59..e2e623f9b2 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1352,11 +1352,11 @@ export const WEB_CLIENT = `(function () { var uChips = []; if (seam.missed > 0 || seam.suspects > 0) uChips.push('<span style="color:#cf222e" title="' + escapeHtml(t("det.attr_seam_tip")) + '">' + t("det.attr_seam") + " " + fmtW(seam.missed) + (seam.suspects > 0 ? " ×" + seam.suspects : "") + "</span>"); if (seam.providerTtl.missed > 0 || seam.providerTtl.count > 0) uChips.push('<span style="color:#1a7f37" title="' + escapeHtml(t("det.attr_ttl_tip")) + '">' + t("det.attr_ttl") + " " + fmtW(seam.providerTtl.missed) + (seam.providerTtl.count > 0 ? " ×" + seam.providerTtl.count : "") + "</span>"); - if (seam.providerSide.missed > 0 || seam.providerSide.count > 0) uChips.push('<span style="color:#bf8700" title="' + escapeHtml(t("det.attr_provider_tip")) + '">' + t("det.attr_provider") + " " + fmtW(seam.providerSide.missed) + (seam.providerSide.count > 0 ? " ×" + seam.providerSide.count : "") + "</span>"); + if (seam.providerSide.missed > 0 || seam.providerSide.count > 0) uChips.push('<span style="color:#f0883e" title="' + escapeHtml(t("det.attr_provider_tip")) + '">' + t("det.attr_provider") + " " + fmtW(seam.providerSide.missed) + (seam.providerSide.count > 0 ? " ×" + seam.providerSide.count : "") + "</span>"); if (seam.rewinds.missed > 0 || seam.rewinds.count > 0) uChips.push('<span style="color:#57606a" title="' + escapeHtml(t("det.attr_rewind_tip")) + '">' + t("det.attr_rewind") + " " + fmtW(seam.rewinds.missed) + (seam.rewinds.count > 0 ? " ×" + seam.rewinds.count : "") + "</span>"); if (seam.abortCorrelated > 0) uChips.push('<span style="color:#d4a72c" title="' + escapeHtml(t("det.attr_abort_tip")) + '">' + t("det.attr_abort") + " ×" + seam.abortCorrelated + "</span>"); var uRest = Math.max(0, (tot.ttlRepay || 0) - seam.missed - seam.providerTtl.missed - seam.providerSide.missed - seam.rewinds.missed); - if (uRest > 8192) uChips.push('<span class="dim" title="' + escapeHtml(t("det.attr_rest_tip")) + '">' + t("det.attr_rest", { x: fmtW(uRest) }) + "</span>"); + if (uRest > 8192) uChips.push('<span style="color:#9aa1a8" title="' + escapeHtml(t("det.attr_rest_tip")) + '">' + t("det.attr_rest", { x: fmtW(uRest) }) + "</span>"); if (uChips.length) { parts.push('<div class="stat"><div class="k">' + t("det.ce_ttl") + '</div><div class="v mono">' + fmtW(tot.ttlRepay || 0) + '</div>' + '<div class="dim small mono" style="margin-top:6px;line-height:1.7"><span>' + escapeHtml(t("det.ce_breakdown")) + "</span><br>" + uChips.join("<br>") + "</div></div>");