From c7b851eb2699fd17da3840a7f65719654b8403d0 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Tue, 13 Oct 2026 13:06:13 +0800 Subject: [PATCH 1/2] fix: body-stability classifier gains a tail class for post-array divergences (#2982) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The per-call BODY STABILITY divergence classes only looked at the first diverging byte offset (LCP) plus a 64-byte append tolerance — never at where the messages array ENDS. Two harmless families were labelled mid ("mid-history rewrite"): trailing top-level param jitter (host-computed max_tokens/…) and ephemeral tail notes (nudge/imgNote/retrNote) that appear/vanish between adjacent requests, even though every shared history byte was untouched and hit rates stayed 90–95%+ (#2980 log: 181/182 pairs flagged mid, zero seam evidence). New fourth class tail: in the would-be-mid branch only (hot path pays nothing extra), scan the SHORTER full body for the top-level messages/input/contents array closing bracket (string-aware depth scan, same key set as seamLcp); lcp >= that offset ⇒ tail, else mid as before. Unparseable bodies keep the conservative pre-fix class. Report aggregate, acp-cache text and web UI legend (en+zh) surface the new class. --- src/cache-ledger.ts | 88 ++++++++- src/web/client.ts | 2 + src/web/i18n.ts | 6 +- ...ssue2982-body-stability-tail-class.test.ts | 176 ++++++++++++++++++ 4 files changed, 263 insertions(+), 9 deletions(-) create mode 100644 tests/issue2982-body-stability-tail-class.test.ts diff --git a/src/cache-ledger.ts b/src/cache-ledger.ts index 26ff36a43f..8a89869df3 100644 --- a/src/cache-ledger.ts +++ b/src/cache-ledger.ts @@ -179,9 +179,13 @@ interface LedgerLine { * 1 KiB (model/tools/sampling-params/system region → host-side parameter * change, not a history rewrite); "append": the whole shorter payload * survives ±64 closing-bracket bytes (pure tail growth/trim); "mid": a - * mid-history rewrite; "unknown": bodies above BODY_FULL_CAP (inequality - * proven by digest, offset unavailable). Sparse. */ - bs?: "head" | "append" | "mid" | "unknown"; + * mid-history rewrite; "tail" (#2982): the first divergence sits at/past + * the shorter body's message-array closing bracket — only trailing + * top-level params (host-computed max_tokens/…) or an ephemeral tail note + * that appeared/vanished between requests changed; shared history bytes + * untouched, prefix cache unaffected; "unknown": bodies above BODY_FULL_CAP + * (inequality proven by digest, offset unavailable). Sparse. */ + bs?: "head" | "append" | "mid" | "tail" | "unknown"; } interface CacheLedger { @@ -564,6 +568,57 @@ function byteLcp(a: string, b: string): number { return lcp; } +// #2982: byte offset of the CLOSING bracket terminating the top-level +// messages/input/contents array (same key set as seamLcp's msgsOf), or null +// when the body carries no such array (or is not valid JSON). String-aware +// depth scan over the raw text instead of JSON.parse + re-serialization: +// re-serialized element offsets do not match the original text (whitespace), +// and one linear pass keeps multi-MiB bodies cheap. Runs only on pairs that +// would otherwise class "mid" — the hot path never pays for it. +function messagesArrayCloseOffset(body: string): number | null { + const n = body.length; + let depth = 0; // object/array nesting depth + let inStr = false; + let esc = false; + let want = -1; // depth at which the tracked array closes (-1 = not tracking) + let keyAt = -1; // opening-quote offset of a candidate top-level key + for (let i = 0; i < n; i++) { + const c = body.charCodeAt(i); + if (inStr) { + if (esc) esc = false; + else if (c === 92) esc = true; // backslash + else if (c === 34) { + inStr = false; + if (keyAt >= 0) { + // +1/-1 strip the surrounding quotes from the captured range. + const key = body.slice(keyAt + 1, i); + keyAt = -1; + // A top-level string VALUE is also seen at depth 1 — the + // following-colon check below is what separates keys from it. + if (depth === 1 && (key === "messages" || key === "input" || key === "contents")) { + let j = i + 1; + while (j < n && body.charCodeAt(j) <= 32) j++; + if (body.charCodeAt(j) === 58) { // ':' + j++; + while (j < n && body.charCodeAt(j) <= 32) j++; + if (body.charCodeAt(j) === 91) want = depth + 1; // '[' + } + } + } + } + continue; + } + if (c === 34) { inStr = true; keyAt = depth === 1 ? i : -1; continue; } + if (c === 123 || c === 91) { depth++; continue; } + if (c === 125 || c === 93) { + if (want !== -1 && c === 93 && depth === want) return i; + depth--; + continue; + } + } + return null; +} + function detectSeam(session: Session, led: CacheLedger): void { const line = led.lines[led.lines.length - 1]; if (!line || line.unk === 1 || line.missed <= 0) return; @@ -1273,7 +1328,20 @@ export function settleUsageReport( // Append/trim first: "the whole shorter payload survives" // is anchored to the END of the payload and stays true on // small bodies where the head threshold alone would lie. - curLine.bs = lcp >= Math.min(prevSlot.full.length, curSlot.full.length) - 64 ? "append" : lcp < 1024 ? "head" : "mid"; + // #2982: the would-be-mid branch pays one extra scan over + // the SHORTER body: when the first divergence sits at/past + // that body's message-array closing bracket, no shared + // history byte moved — only trailing top-level params + // (host-computed max_tokens/…) or an ephemeral tail note + // that appeared/vanished between requests differ (#2980). + // The shorter side is decisive: when one side grew the + // array, the LCP stops at ITS closing bracket (`]` vs `,`), + // which lies inside the LONGER side's array — parsing that + // side would misread the pair as mid. No array locatable + // (unparseable body) keeps the conservative pre-fix class. + const shorterFull = prevSlot.full.length <= curSlot.full.length ? prevSlot.full : curSlot.full; + const arrClose = messagesArrayCloseOffset(shorterFull); + curLine.bs = lcp >= Math.min(prevSlot.full.length, curSlot.full.length) - 64 ? "append" : lcp < 1024 ? "head" : arrClose !== null && lcp >= arrClose ? "tail" : "mid"; } else { curLine.bs = "unknown"; } @@ -1353,7 +1421,7 @@ interface BodyStability { paired: number; /** be=1: byte-identical resends (transport retries, re-requests). */ equal: number; - /** be=0: diverged; the four classes partition this count. */ + /** be=0: diverged; the five classes partition this count. */ diverged: number; /** Divergence inside the first 1 KiB — host-side parameter region (model/tools/sampling/system), NOT a history rewrite. */ head: number; @@ -1361,6 +1429,8 @@ interface BodyStability { append: number; /** Mid-history byte change — the shape a real rewrite has. */ mid: number; + /** #2982: divergence at/past the shorter body's message-array closing bracket — trailing top-level params or ephemeral tail notes; shared history bytes untouched, prefix cache unaffected. */ + tail: number; /** Diverged but offset unknown (bodies above BODY_FULL_CAP, digest-only mode). */ unknownOffset: number; /** Median/min hit rate per 20K-token input-size bucket — flat across sizes argues against KV-pool capacity thrashing. */ @@ -1372,7 +1442,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. */ @@ -1491,6 +1561,7 @@ export function buildSessionCacheReport(session: Session): BiliCacheReport { let head = 0; let append = 0; let mid = 0; + let tail = 0; let unknownOffset = 0; for (const l of knownLines) { if (l.be === undefined) continue; @@ -1499,6 +1570,7 @@ export function buildSessionCacheReport(session: Session): BiliCacheReport { if (l.bs === "head") head += 1; else if (l.bs === "append") append += 1; else if (l.bs === "mid") mid += 1; + else if (l.bs === "tail") tail += 1; else unknownOffset += 1; } const sizeBuckets: BodyStability["sizeBuckets"] = []; @@ -1532,6 +1604,7 @@ export function buildSessionCacheReport(session: Session): BiliCacheReport { head, append, mid, + tail, unknownOffset, sizeBuckets, gapSplit: { lowHitMedGapMs: median(lowGaps), highHitMedGapMs: median(highGaps) }, @@ -1635,9 +1708,10 @@ function formatStability(st: BodyStability): string { if (st.paired === 0) return ""; const out: string[] = ["BODY STABILITY (per-call outbound byte proof, vs previous settled request)"]; out.push(` ${st.paired} pair(s): ${st.equal} byte-identical · ${st.diverged} diverged`); - out.push(` divergence class: head <1KiB ${st.head} · tail-append ${st.append} · mid-history ${st.mid} · offset-unknown(capped) ${st.unknownOffset}`); + out.push(` divergence class: head <1KiB ${st.head} · tail-append ${st.append} · mid-history ${st.mid} · tail(params/notes) ${st.tail} · offset-unknown(capped) ${st.unknownOffset}`); if (st.head > 0) out.push(` ⚠ ${st.head} head-region divergence(s) — model/tools/sampling/system changed between calls (host-side parameter change, NOT a bili history rewrite)`); if (st.mid > 0) out.push(` ⚠ ${st.mid} mid-history divergence(s) — real prefix rewrites; inspect the seam events above`); + if (st.tail > 0) out.push(` ${st.tail} tail-region divergence(s) — trailing top-level params or ephemeral tail notes at/past the message-array end; shared history bytes untouched, prefix cache unaffected (#2982)`); const sb = st.sizeBuckets.filter((b) => b.n >= 3); if (sb.length >= 2) out.push(" hit% by input size (median): " + sb.map((b) => `${Math.round(b.lo / 1000)}K=${b.hitMedian}%`).join(" ")); const g = st.gapSplit; diff --git a/src/web/client.ts b/src/web/client.ts index 89a7eb7cce..0a9ee6ac5b 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1345,6 +1345,7 @@ export const WEB_CLIENT = `(function () { head: Number(stRaw.head) || 0, append: Number(stRaw.append) || 0, mid: Number(stRaw.mid) || 0, + tail: Number(stRaw.tail) || 0, unknownOffset: Number(stRaw.unknownOffset) || 0, sizeBuckets: Array.isArray(stRaw.sizeBuckets) ? stRaw.sizeBuckets : [], gapSplit: stRaw.gapSplit && typeof stRaw.gapSplit === "object" ? stRaw.gapSplit : null, @@ -1354,6 +1355,7 @@ export const WEB_CLIENT = `(function () { if (st.head > 0) divParts.push('' + escapeHtml(t("det.stab_head")) + " " + st.head + ""); if (st.append > 0) divParts.push('' + escapeHtml(t("det.stab_append")) + " " + st.append + ""); if (st.mid > 0) divParts.push('' + escapeHtml(t("det.stab_mid")) + " " + st.mid + ""); + if (st.tail > 0) divParts.push('' + escapeHtml(t("det.stab_tail")) + " " + st.tail + ""); if (st.unknownOffset > 0) divParts.push('' + escapeHtml(t("det.stab_unknown")) + " " + st.unknownOffset + ""); let stabBody = '
' + escapeHtml(t("det.stab_pairs", { n: st.paired })) + ": " + (st.diverged > 0 ? '' + st.diverged + " ↓" : "0") + (divParts.length ? " — " + divParts.join(" · ") : "") + "
"; const sb = st.sizeBuckets.filter((b) => b && (Number(b.n) || 0) >= 3); diff --git a/src/web/i18n.ts b/src/web/i18n.ts index eaba5405f6..89a3f61337 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -280,11 +280,12 @@ export const MESSAGES: Record> = { "det.seam_events_tip": "相邻出站体的首个字节分叉位置;若可复现,请附上该时间附近的 bili.log(#1548 类问题)", "det.stab_title": "体稳定性(逐调用字节证明)", "det.stab_pairs": "相邻调用对 {n}", - "det.stab_tip": "每次出站请求体与上一个已结算请求做 SHA-256 字节比较:identical=逐字节相同(如传输重试);diverged 按首个分叉点分类——head<1KiB 是宿主侧参数变更(model/tools/采样),tail-append 是纯尾部增长,mid 是真实前缀改写,offset-unknown 表示 body 超保留上限(不等式仍由摘要证明)", + "det.stab_tip": "每次出站请求体与上一个已结算请求做 SHA-256 字节比较:identical=逐字节相同(如传输重试);diverged 按首个分叉点分类——head<1KiB 是宿主侧参数变更(model/tools/采样),tail-append 是纯尾部增长,mid 是真实前缀改写,tail 是消息数组结束之后的顶层参数或临时尾注抖动(历史字节未动、缓存不受影响),offset-unknown 表示 body 超保留上限(不等式仍由摘要证明)", "det.stab_identical": "逐字节相同", "det.stab_head": "头部<1KiB(参数变更)", "det.stab_append": "尾部追加", "det.stab_mid": "中段改写", + "det.stab_tail": "尾部参数/尾注", "det.stab_unknown": "偏移未知(截断)", "det.stab_size": "按输入尺寸的命中率(中位)", "det.stab_gap": "请求间隔中位:低命中(<80%) {a}s vs 高命中 {b}s", @@ -734,11 +735,12 @@ export const MESSAGES: Record> = { "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)", "det.stab_pairs": "{n} adjacent pairs", - "det.stab_tip": "SHA-256 byte comparison of each outbound body against the previous settled request: identical = byte-exact (e.g. transport retry); diverged pairs classified by first divergence — head <1KiB = host-side parameter change (model/tools/sampling), tail-append = pure tail growth, mid-history = a real prefix rewrite, offset-unknown = bodies above the retention cap (inequality still proven by digest)", + "det.stab_tip": "SHA-256 byte comparison of each outbound body against the previous settled request: identical = byte-exact (e.g. transport retry); diverged pairs classified by first divergence — head <1KiB = host-side parameter change (model/tools/sampling), tail-append = pure tail growth, mid-history = a real prefix rewrite, tail = trailing top-level params or ephemeral tail notes at/past the message-array end (history bytes untouched, cache unaffected), offset-unknown = bodies above the retention cap (inequality still proven by digest)", "det.stab_identical": "byte-identical", "det.stab_head": "head <1KiB (param change)", "det.stab_append": "tail-append", "det.stab_mid": "mid-history rewrite", + "det.stab_tail": "tail (params / ephemeral notes)", "det.stab_unknown": "offset unknown (capped)", "det.stab_size": "hit% by input size (median)", "det.stab_gap": "inter-request gap median: low-hit(<80%) {a}s vs high-hit {b}s", diff --git a/tests/issue2982-body-stability-tail-class.test.ts b/tests/issue2982-body-stability-tail-class.test.ts new file mode 100644 index 0000000000..10bc936a1f --- /dev/null +++ b/tests/issue2982-body-stability-tail-class.test.ts @@ -0,0 +1,176 @@ +// #2982 (来源: #2980 分析「缓存变低,上游还总丢缓存」时发现): the per-call +// body-stability classifier had only head/append/mid and looked solely at the +// first diverging byte offset — never at where the messages array ENDS. Two +// harmless divergence families were therefore labelled "mid" (= "历史中段重写"): +// 1. trailing top-level parameter jitter (host computes max_tokens etc. per +// turn — the divergence sits AFTER the message array); +// 2. ephemeral tail notes bili appends as trailing user messages (nudge / +// imgNote / retrNote, src/server/prepare-openai.ts) appearing/vanishing +// between adjacent requests (the divergence sits AT the shorter body's +// array-closing bracket). +// Both leave every shared history byte untouched and the prefix cache intact — +// yet #2980's log showed 181/182 adjacent pairs flagged "mid" while hit rates +// stayed 90–95%+. The label masqueraded jitter as a high-severity symptom and +// nearly produced a false "bili IS rewriting mid-history" conclusion. +// Fix: a fourth class "tail" — in the would-be-mid branch only, scan the +// SHORTER full body for the top-level messages/input/contents array's closing +// bracket; lcp >= that offset ⇒ tail. Existing head/append/mid classes are +// unchanged (mid still fires when the break lands INSIDE the array). +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { noteForwardedBody, settleUsageReport, getCacheLedger, buildSessionCacheReport, handleAcpCache } from "../src/cache-ledger.ts"; +import type { Session } from "../src/session.ts"; + +let seq = 0; +function makeSession(): Session { + seq += 1; + return { + id: `tailclass-${seq}`, + metadata: {}, + stats: {}, + state: { blocks: [], messageRefs: { byRaw: {}, byRef: {} }, tokenSnapshot: {} }, + } as unknown as Session; +} + +function settle(session: Session, input: number, cached: number): void { + settleUsageReport(session, { total: input, reportedCached: cached, output: 0, protocol: "openai", upstream: "http://u" }); +} + +// ~9 KiB of shared history so every pair clears the 1 KiB head threshold. +const many = Array.from({ length: 30 }, (_, i) => `msg${i}-${"x".repeat(300)}`); +const msgs = many.map((c) => ({ role: "user", content: c })); +// Trailing top-level fields. Deliberately LONGER than the 64-byte append +// tolerance: with such tails a would-be-tail pair reaches the mid branch +// (this is exactly why #2980's dynamic-max_tokens sessions were all "mid"). +const TAIL_A = '"max_tokens":16384,"top_p":0.9,"stop":["end-of-turn","stop-marker-one","stop-marker-two","presence-padding-field"]'; +const TAIL_B = '"max_tokens":4096,"top_p":0.9,"stop":["end-of-turn","stop-marker-one","stop-marker-two","presence-padding-field"]'; +const NUDGE = { role: "user", content: "[context nudge] You have used a lot of context — compress consumed ranges." }; + +test("identical messages, only trailing top-level params differ ⇒ bs=tail (was mislabelled mid)", () => { + const s = makeSession(); + const b1 = `{"model":"m","messages":${JSON.stringify(msgs)},${TAIL_A}}`; + const b2 = `{"model":"m","messages":${JSON.stringify(msgs)},${TAIL_B}}`; + noteForwardedBody(s, b1); + settle(s, 100_000, 99_000); + noteForwardedBody(s, b2); + settle(s, 100_000, 90_000); + const line = getCacheLedger(s).lines.at(-1)!; + assert.equal(line.be, 0); + assert.equal(line.bs, "tail", "divergence is past the message-array end — trailing param jitter, not a history rewrite"); + // The LCP must land inside the trailing region, after the history. + assert.ok(line.bl !== undefined && line.bl > b1.indexOf('"max_tokens"'), `bl=${line.bl} must be at/past the trailing fields`); + const rep = buildSessionCacheReport(s); + assert.equal(rep.stability.tail, 1); + assert.equal(rep.stability.mid, 0, "no mid count may be charged for trailing jitter"); +}); + +test("ephemeral tail note APPEARS between requests ⇒ bs=tail (was mislabelled mid)", () => { + const s = makeSession(); + const base = `{"model":"m","messages":${JSON.stringify(msgs)},${TAIL_A}}`; + const withNote = `{"model":"m","messages":${JSON.stringify([...msgs, NUDGE])},${TAIL_A}}`; + noteForwardedBody(s, base); + settle(s, 100_000, 99_000); + noteForwardedBody(s, withNote); + settle(s, 100_000, 90_000); + const line = getCacheLedger(s).lines.at(-1)!; + assert.equal(line.be, 0); + assert.equal(line.bs, "tail", "only the appended ephemeral user message differs — history bytes untouched"); + const rep = buildSessionCacheReport(s); + assert.equal(rep.stability.tail, 1); + assert.equal(rep.stability.mid, 0); +}); + +test("ephemeral tail note VANISHES between requests ⇒ bs=tail (was mislabelled mid)", () => { + const s = makeSession(); + const base = `{"model":"m","messages":${JSON.stringify(msgs)},${TAIL_A}}`; + const withNote = `{"model":"m","messages":${JSON.stringify([...msgs, NUDGE])},${TAIL_A}}`; + noteForwardedBody(s, withNote); + settle(s, 100_000, 99_000); + noteForwardedBody(s, base); + settle(s, 100_000, 90_000); + const line = getCacheLedger(s).lines.at(-1)!; + assert.equal(line.be, 0); + assert.equal(line.bs, "tail", "removal direction: divergence at the shorter body's array-closing bracket"); + const rep = buildSessionCacheReport(s); + assert.equal(rep.stability.tail, 1); + assert.equal(rep.stability.mid, 0); +}); + +test("rewriting the LAST message (same count) still classifies mid — boundary guard", () => { + const s = makeSession(); + const b1 = JSON.stringify({ model: "m", messages: msgs }); + const changed = [...msgs]; + changed[changed.length - 1] = { role: "user", content: `REWRITTEN-${"y".repeat(300)}` }; + const b2 = JSON.stringify({ model: "m", messages: changed }); + noteForwardedBody(s, b1); + settle(s, 100_000, 99_000); + noteForwardedBody(s, b2); + settle(s, 100_000, 90_000); + const line = getCacheLedger(s).lines.at(-1)!; + assert.equal(line.be, 0); + assert.equal(line.bs, "mid", "break INSIDE the latest element is a real prefix break — tail must not swallow it"); +}); + +test("genuine mid-history rewrite still classifies mid (regression mirror of #2131)", () => { + const s = makeSession(); + const b1 = JSON.stringify({ model: "m", messages: msgs }); + const changed = [...msgs]; + changed[5] = { role: "user", content: `msg5-${"y".repeat(300)}` }; + const b2 = JSON.stringify({ model: "m", messages: changed }); + noteForwardedBody(s, b1); + settle(s, 100_000, 99_000); + noteForwardedBody(s, b2); + settle(s, 100_000, 90_000); + const line = getCacheLedger(s).lines.at(-1)!; + assert.equal(line.be, 0); + assert.equal(line.bs, "mid", "element 5 of 30 rewritten = real mid-history break"); + const rep = buildSessionCacheReport(s); + assert.equal(rep.stability.mid, 1); + assert.equal(rep.stability.tail, 0); +}); + +test("Responses wire (`input` key) trailing-param jitter ⇒ bs=tail", () => { + const s = makeSession(); + const items = Array.from({ length: 30 }, (_, i) => ({ type: "message", role: "user", content: [{ type: "input_text", text: `item${i}-${"z".repeat(300)}` }] })); + const r1 = `{"model":"m","input":${JSON.stringify(items)},"max_output_tokens":1000,"temperature":0.3,"top_logprobs":7,"trailing-padding-field":"ppppppppppppppppppppppppppppppppppppppppppppppppppppp"}`; + const r2 = `{"model":"m","input":${JSON.stringify(items)},"max_output_tokens":500,"temperature":0.3,"top_logprobs":7,"trailing-padding-field":"ppppppppppppppppppppppppppppppppppppppppppppppppppppp"}`; + noteForwardedBody(s, r1); + settle(s, 100_000, 99_000); + noteForwardedBody(s, r2); + settle(s, 100_000, 90_000); + const line = getCacheLedger(s).lines.at(-1)!; + assert.equal(line.be, 0); + assert.equal(line.bs, "tail", "the scanner must recognize the Responses-wire `input` array, not just `messages`"); +}); + +test("unparseable bodies fall back to mid without crashing (pre-fix behavior preserved)", () => { + const s = makeSession(); + const g1 = `{"broken": "` + "a".repeat(3000); + const g2 = `{"broken": "` + "a".repeat(1500) + "b" + "a".repeat(1499); + noteForwardedBody(s, g1); + settle(s, 100_000, 99_000); + noteForwardedBody(s, g2); + settle(s, 100_000, 90_000); + const line = getCacheLedger(s).lines.at(-1)!; + assert.equal(line.be, 0); + assert.equal(line.bs, "mid", "no message array locatable ⇒ keep the conservative pre-fix class"); +}); + +test("report + acp-cache text surface the tail class", () => { + const s = makeSession(); + const b1 = `{"model":"m","messages":${JSON.stringify(msgs)},${TAIL_A}}`; + const b2 = `{"model":"m","messages":${JSON.stringify(msgs)},${TAIL_B}}`; + noteForwardedBody(s, b1); + settle(s, 100_000, 99_000); + noteForwardedBody(s, b2); + settle(s, 100_000, 90_000); + const rep = buildSessionCacheReport(s); + assert.equal(rep.stability.paired, 1); + assert.equal(rep.stability.diverged, 1); + assert.equal(rep.stability.tail, 1); + assert.equal(rep.lines.at(-1)!.bodyClass, "tail"); + const text = handleAcpCache(s).text; + assert.match(text, /BODY STABILITY/); + assert.match(text, /tail\(params\/notes\) 1/); + assert.match(text, /tail-region divergence/); +}); From 8d66ca28534dcd966dbb2f09bd7d0510c4a2e906 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Tue, 13 Oct 2026 13:37:43 +0800 Subject: [PATCH 2/2] test: regen storage-render goldens for #2982 tail class The new tail divergence class reclassifies 11 of 14 persisted cacheLedger bs values mid->tail in the golden conversations (divergence sits at the message-array closing bracket: trailing params / ephemeral notes), changing session.metadata digests. Regenerated via scripts/update-storage-render-goldens.ts; diff is digests-only (stateDigest + sectionDigests.metadata) for chat/anthropic/google. responses wire unaffected (its ledgers keep their classes). Closes nothing; completes PR #2983's required golden refresh. --- tests/golden/storage-render/anthropic.json | 4 ++-- tests/golden/storage-render/chat.json | 4 ++-- tests/golden/storage-render/google.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 a889ca6f59..e1f0e8b14f 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": "844d9a2cb33b5fd245855a2c59d9990bed56e081258979cca424db897388d9da", + "stateDigest": "eb6c69fb93598aeebe0d0e3db9f8d27ff5394431a2647585302a14305da392e7", "sectionDigests": { "state": "285aa622a037321b", "blockContents": "b3a9c59b22ec1a3a", "stats": "4271a6483e02458a", - "metadata": "4fce29292d9e44ac" + "metadata": "91e1dc401ea4af6c" }, "stateKeyDigests": { "blocks": "8a3021f39f1f2eb8", diff --git a/tests/golden/storage-render/chat.json b/tests/golden/storage-render/chat.json index 64eb7aee7e..9b7e5763b0 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": "b26f1509735ed4c9ee93d4fd3311d0f7926d8207a1cd4fecf59671c293e2050d", + "stateDigest": "d56dfe9eb890f9768ef1ad962f9d3667109e13cd4705929f8d6c711b53d46116", "sectionDigests": { "state": "6e905e4ae1e678b8", "blockContents": "dd2de296a5bc6160", "stats": "ed7d3e3f253e0942", - "metadata": "6d4760889050e964" + "metadata": "201a63bff674729d" }, "stateKeyDigests": { "blocks": "bdde93b0e100e13e", diff --git a/tests/golden/storage-render/google.json b/tests/golden/storage-render/google.json index b42fa0faec..96ada4cfdc 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": "2c70cf418e7d35e8a70774ce2a4341187ed3a00452b67480b742c1a1400e2b87", + "stateDigest": "e4ef707b7d0bbec43a2e87090cc30f19b96331f577a5790c8ec05b1865e3b02f", "sectionDigests": { "state": "0725cfe81690b748", "blockContents": "4cc83a808a659f28", "stats": "096da9a1f61d84d0", - "metadata": "b7ecdf2a5b9a97b8" + "metadata": "f4a1fae6aca16c5e" }, "stateKeyDigests": { "blocks": "9adb53303cd4b786",