From de75b18227f5b02e194aee5872bc4f86f4185bfa Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Wed, 18 Nov 2026 23:22:49 +0800 Subject: [PATCH 1/5] =?UTF-8?q?docs(persona):=20mark=20module=20RETIRED=20?= =?UTF-8?q?=E2=80=94=20no=20production=20importers,=20test-pinned=20only?= =?UTF-8?q?=20(#7149=20batch2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/persona-anchor.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/persona-anchor.ts b/src/persona-anchor.ts index 005d82fd75..853cc0993c 100644 --- a/src/persona-anchor.ts +++ b/src/persona-anchor.ts @@ -1,3 +1,10 @@ +// RETIRED — no production importers (identity resolution lives in +// src/session-resolve.ts, the neutral-skeleton successor). Retained ONLY as a +// characterization pin: tests/issue2944-neutral-skeleton.test.ts and +// tests/issue2601-model-drift-absorption.test.ts import it to freeze the old +// ladder's behavior as a comparison artifact. Removing this file requires +// dropping those pins deliberately, not incidentally. +// // #2241/#2250: continuity-aware persona anchor for id-sharing traffic // (dsh persona lanes, codex root threads / older builds, claude-over-Responses). // From b18d5967d1f9887d3b2d602e0ab177e1c938540d Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Wed, 18 Nov 2026 23:41:31 +0800 Subject: [PATCH 2/5] perf(fold-reconcile): system-prompt fingerprints recompute only when size+head change (#7149 batch2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit noteSystemPromptFingerprint (#1921) and noteCanonicalSystemFingerprint (#2867) now keep a 256-char head probe in session metadata. Unchanged prompt (size + head match) reuses the stored fp instead of re-hashing the full JSON.stringify'd text each request; changed / first-turn / legacy-shape stored values fall through to the full hash, so the stored fp is always a true full-hash value whenever it is computed. Semantics preserved: #1921 change ledger log, #2867 silent-twin pairing, "-" sentinel for absent prompts. One new observable: a prompt WITHDRAWAL (prev non-"-" -> null) now logs as a change (the projection dropped). Documented tradeoff: an edit beyond byte 256 that preserves length+head stays unobserved — the probe is a detection signal, not a boundary. Tests: fold-reconcile.test.ts +5 cases (probe hit / tail-only documented contract / visible change / legacy {fp,size} compat + head backfill / null sentinel delta counts); 92/92 across fold-reconcile + both cache-ledger prompt-switch consumer suites. --- src/fold-reconcile.ts | 26 ++++++++++--- tests/fold-reconcile.test.ts | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 5 deletions(-) diff --git a/src/fold-reconcile.ts b/src/fold-reconcile.ts index d9657f0f98..c82af5da17 100644 --- a/src/fold-reconcile.ts +++ b/src/fold-reconcile.ts @@ -2597,14 +2597,24 @@ export function reconcileFoldCoverage(session: Session, msgs: CoreMessage[], opt export function noteSystemPromptFingerprint(session: Session, system: unknown, opts: ReconcileOptions = {}): void { if (!session.metadata) return; const text = system === undefined || system === null ? "" : JSON.stringify(system) ?? ""; - const fp = system === undefined || system === null ? "-" : createHash("sha256").update(text).digest("hex").slice(0, 16); - const prev = session.metadata[METADATA_SYSTEM_FP] as { fp: string; size: number } | undefined; + // Change probe (#7149 batch2): the probe (size + first 256 chars) is a + // detection SIGNAL, not a security boundary — a rewrite that preserves + // length AND the first 256 chars stays unobserved, which is acceptable for + // a ledger (#1921), and the stored fp is still the true full-hash value + // every time it is actually computed. Probe miss / first turn / legacy + // stored shape (no head) ⇒ full hash. + const prev = session.metadata[METADATA_SYSTEM_FP] as { fp: string; size: number; head?: string } | undefined; + const fp = system === undefined || system === null + ? "-" + : (prev !== undefined && prev.fp !== "-" && prev.size === text.length && prev.head !== undefined && prev.head === text.slice(0, 256) + ? prev.fp + : createHash("sha256").update(text).digest("hex").slice(0, 16)); if (prev !== undefined && prev.fp !== fp) { if (opts.log !== undefined) { opts.log("info", `${opts.sessionId === undefined ? "" : `[${opts.sessionId}] `}[fold-reconcile] system prompt changed (${prev.size} → ${text.length} chars); fold state unaffected (#1921)`); } } - session.metadata[METADATA_SYSTEM_FP] = { fp, size: text.length }; + session.metadata[METADATA_SYSTEM_FP] = { fp, size: text.length, head: text.slice(0, 256) }; } /** #2867: canonical INCOMING system/developer fingerprint — the mode-independent @@ -2616,6 +2626,12 @@ export function noteSystemPromptFingerprint(session: Session, system: unknown, o export function noteCanonicalSystemFingerprint(session: Session, canonical: unknown): void { if (!session.metadata) return; const text = canonical === undefined || canonical === null ? "" : JSON.stringify(canonical) ?? ""; - const fp = canonical === undefined || canonical === null ? "-" : createHash("sha256").update(text).digest("hex").slice(0, 16); - session.metadata[METADATA_CANONICAL_SYS_FP] = { fp, size: text.length }; + // Same change-probe tradeoff as noteSystemPromptFingerprint (#7149 batch2). + const prev = session.metadata[METADATA_CANONICAL_SYS_FP] as { fp: string; size: number; head?: string } | undefined; + const fp = canonical === undefined || canonical === null + ? "-" + : (prev !== undefined && prev.fp !== "-" && prev.size === text.length && prev.head !== undefined && prev.head === text.slice(0, 256) + ? prev.fp + : createHash("sha256").update(text).digest("hex").slice(0, 16)); + session.metadata[METADATA_CANONICAL_SYS_FP] = { fp, size: text.length, head: text.slice(0, 256) }; } diff --git a/tests/fold-reconcile.test.ts b/tests/fold-reconcile.test.ts index e8dfc6d303..4d14263afd 100644 --- a/tests/fold-reconcile.test.ts +++ b/tests/fold-reconcile.test.ts @@ -8,6 +8,7 @@ import { reconcileFoldCoverage, resolveFoldReconcileMode, noteSystemPromptFingerprint, + noteCanonicalSystemFingerprint, METADATA_FOLD_COVERAGE, resetNormalizedIdentityWork, turnContexts, @@ -291,6 +292,77 @@ describe("reconcileFoldCoverage (#1921)", () => { assert.equal(logs.length, 1); assert.match(logs[0], /system prompt changed/); assert.match(logs[0], /fold state unaffected/); + // #7149 batch2: dropping the prompt to null is an observable projection + // change too (prev "…" → "-"), so it logs — "absence does not" only + // covers the first-ever null, not a withdrawal. + noteSystemPromptFingerprint(session, null, logOpts); + assert.equal(logs.length, 2); + assert.match(logs[1], /system prompt changed/); + }); + + test("system-fingerprint change probe (#7149 batch2): unchanged reuses, changed recomputes, legacy shape full-hashes", () => { + const logs: string[] = []; + const logOpts = { sessionId: "s1", log: (_l: string, m: string) => logs.push(m) }; + + // (a) unchanged input → stable fp, probe head stored, no log. NOTE: the + // probe sees the JSON.stringify'd text (a string input gains quotes), so + // head/size compare against the stringified form. + const session = fakeSession([]); + const longPrompt = "P".repeat(300); // > 256 so the head is a true prefix slice + const stringifiedLong = JSON.stringify(longPrompt); + noteSystemPromptFingerprint(session, longPrompt, logOpts); + const first = session.metadata.systemFp as { fp: string; size: number; head: string }; + assert.ok(first.fp !== "-"); + assert.equal(first.head, stringifiedLong.slice(0, 256)); + assert.equal(first.size, stringifiedLong.length); + noteSystemPromptFingerprint(session, longPrompt, logOpts); + const second = session.metadata.systemFp as { fp: string }; + assert.equal(second.fp, first.fp, "probe hit keeps the stored fp"); + assert.equal(logs.length, 0, "unchanged prompt logs nothing"); + + // (b) change beyond byte 256 with SAME length+head: documented tradeoff — + // the probe is a detection signal, not a boundary; fp stays the last true hash. + const tailTweaked = longPrompt.slice(0, 256) + longPrompt.slice(257) + "X"; + noteSystemPromptFingerprint(session, tailTweaked, logOpts); + assert.equal((session.metadata.systemFp as { fp: string }).fp, first.fp, "tail-only same-size edit stays unobserved (documented probe contract)"); + assert.equal(logs.length, 0); + + // (c) observable change (size differs) → recompute + log + noteSystemPromptFingerprint(session, "shorter now", logOpts); + const third = session.metadata.systemFp as { fp: string }; + assert.notEqual(third.fp, first.fp); + assert.equal(logs.length, 1); + assert.match(logs[0], /system prompt changed/); + + // (d) legacy stored shape { fp, size } without head → full-hash path (compat) + const legacy = fakeSession([]); + legacy.metadata.systemFp = { fp: first.fp, size: longPrompt.length }; + noteSystemPromptFingerprint(legacy, longPrompt, logOpts); + assert.equal((legacy.metadata.systemFp as { fp: string }).fp, first.fp, "full hash reproduces the stored fp"); + assert.equal((legacy.metadata.systemFp as { head?: string }).head !== undefined, true, "head backfilled for the next probe"); + + // (e) null/undefined → "-" sentinel, probe inert. (c) already logged one + // change into the shared array, so compare against a captured baseline. + const logsBeforeE = logs.length; + noteSystemPromptFingerprint(legacy, null, logOpts); + assert.equal((legacy.metadata.systemFp as { fp: string }).fp, "-"); + assert.equal(logs.length, logsBeforeE + 1, "prompt→null withdrawal logs once"); + noteSystemPromptFingerprint(legacy, null, logOpts); + assert.equal(logs.length, logsBeforeE + 1, "null→null logs nothing"); + }); + + test("canonical system fingerprint probe (#7149 batch2): silent twin, same contract", () => { + const session = fakeSession([]); + const longPrompt = "C".repeat(400); + noteCanonicalSystemFingerprint(session, longPrompt); + const first = session.metadata.canonicalSysFp as { fp: string; head: string }; + assert.ok(first.fp !== "-"); + noteCanonicalSystemFingerprint(session, longPrompt); + assert.equal((session.metadata.canonicalSysFp as { fp: string }).fp, first.fp); + noteCanonicalSystemFingerprint(session, "rewritten"); + assert.notEqual((session.metadata.canonicalSysFp as { fp: string }).fp, first.fp, "changed canonical recomputes"); + noteCanonicalSystemFingerprint(session, undefined); + assert.equal((session.metadata.canonicalSysFp as { fp: string }).fp, "-"); }); }); From 0702a64153340def38f65a7602fe2e93bcfc971a Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Thu, 19 Nov 2026 00:04:38 +0800 Subject: [PATCH 3/5] perf(cache-ledger): byte-identical re-notes inherit the outbound digest (#7149 batch3-1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The non-streaming settle path re-notes a byte-identical wire body; detect that with a pure byte compare (prior.full.equals) and inherit the prior digest — zero hashing on the common path. Changed/new bodies keep the full-body sha256: bd is the #2131 ground-truth equality proof and the only equality proof once the payload exceeds BODY_FULL_CAP (no retention), and tests pin bd to the full digest. The send chokepoints hold the wire string, not the stored canonical views, so view-ID anchoring is not available here; the delta-anchoring value is the hash-free identity inheritance. --- src/cache-ledger.ts | 11 ++++++++++- tests/issue2868-byte-lcp-utf8.test.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/cache-ledger.ts b/src/cache-ledger.ts index 4fceb4daa0..abd5888910 100644 --- a/src/cache-ledger.ts +++ b/src/cache-ledger.ts @@ -770,10 +770,19 @@ export function noteForwardedBody(session: Session, body: string, msgs?: number // sharing a 512 KiB prefix apart. Re-noting a byte-identical payload (the // non-streaming settle path) reuses the prior slot's count/full instead of // re-deriving them. + // #7149 batch3-1 (delta anchoring): the byte-identical re-note inherits the + // prior digest via a pure byte compare — ZERO hashing on the common path. + // Changed/new bodies keep the full-body digest: `bd` is the ground-truth + // equality proof (#2131) and the ONLY equality proof once the payload + // exceeds BODY_FULL_CAP (nothing is retained), so a delta descriptor cannot + // replace it without breaking settle's be decision. View-ID anchoring is + // not available here — the send chokepoints hold the wire string, not the + // stored canonical views (those live in the storage layer). const buf = Buffer.from(body, "utf8"); - const digest = createHash("sha256").update(buf).digest("hex"); const transient = pendingCapture(session); const prior = transient.sentBody; + const sameBytes = prior !== undefined && prior.bytes === buf.byteLength && prior.full !== null && prior.full.equals(buf); + const digest = sameBytes ? prior.digest : createHash("sha256").update(buf).digest("hex"); const samePayload = prior !== undefined && prior.digest === digest; transient.sentBody = { order: ++captureOrder, diff --git a/tests/issue2868-byte-lcp-utf8.test.ts b/tests/issue2868-byte-lcp-utf8.test.ts index 37e7b6fe34..930c374f8e 100644 --- a/tests/issue2868-byte-lcp-utf8.test.ts +++ b/tests/issue2868-byte-lcp-utf8.test.ts @@ -186,3 +186,30 @@ test("seam forensics reports byte-exact lcpBytes for CJK bodies", () => { assert.equal(ev!.lcpBytes, utf8Lcp(b1, b2), "SeamEvent.lcpBytes must be real UTF-8 bytes"); assert.notEqual(ev!.lcpBytes, codeUnitLcp(b1, b2), "must NOT be the old code-unit value"); }); + +// #7149 batch3-1: byte-identical re-notes inherit the digest via a pure byte +// compare (zero hashing on the common non-streaming settle path). The +// inherited value MUST equal the full-body sha256 — `bd` stays the +// ground-truth equality proof (#2131), only its derivation is memoized. +test("byte-identical re-note inherits the digest (delta anchoring, #7149 batch3)", () => { + const b = JSON.stringify({ model: "m", messages: [{ role: "user", content: "重复的载荷".repeat(300) }] }); + const s = makeSession(); + noteForwardedBody(s, b); + settle(s, T0, 100_000, 99_000); + // Non-streaming settle re-notes the identical wire body: no new hash, the + // inherited bd equals what an independent full digest would produce. + noteForwardedBody(s, b); + settle(s, T0 + 1000, 100_000, 99_000); + const line = lastLine(s); + assert.equal(line.bd, createHash("sha256").update(b, "utf8").digest("hex"), "inherited bd equals the independent full digest"); + assert.equal(line.be, 1, "identical re-note still settles as body-stable"); + + // A changed body recomputes a fresh digest and settles as changed. + const b2 = JSON.stringify({ model: "m", messages: [{ role: "user", content: "重复的载荷".repeat(299) }] }); + noteForwardedBody(s, b2); + settle(s, T0 + 2000, 100_000, 90_000); + const line2 = lastLine(s); + assert.notEqual(line2.bd, line.bd); + assert.equal(line2.bd, createHash("sha256").update(b2, "utf8").digest("hex"), "changed body gets a fresh full digest"); + assert.equal(line2.be, 0); +}); From f357310ed236b4e9d04702a0ec765dcbaf6271fe Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Thu, 19 Nov 2026 01:07:14 +0800 Subject: [PATCH 4/5] =?UTF-8?q?test(golden):=20regenerate=20storage-render?= =?UTF-8?q?=20goldens=20=E2=80=94=20systemFp/canonicalSysFp=20now=20persis?= =?UTF-8?q?t=20the=20256B=20change-probe=20head=20(#7149=20batch2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Persisted-state digests only; every per-turn wire sha is byte-identical to the previous goldens. Field-level diff (master vs branch, anthropic drive): state/blockContents/stats identical; metadata.systemFp gains { head: } with fp/size unchanged (verified by dumping both states and diffing). --- tests/golden/storage-render/anthropic.json | 6 +++--- tests/golden/storage-render/chat.json | 6 +++--- tests/golden/storage-render/google.json | 6 +++--- tests/golden/storage-render/responses.json | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/golden/storage-render/anthropic.json b/tests/golden/storage-render/anthropic.json index 9bfc0c1b60..7c01ccf504 100644 --- a/tests/golden/storage-render/anthropic.json +++ b/tests/golden/storage-render/anthropic.json @@ -95,13 +95,13 @@ "foldAt": 9, "editedAt": 12, "summaryFrom": 9, - "stateDigest": "201eb6df8c4cf505ffaa628e67f738fe31daf482eae08baeb3b704b68932571a", - "stateDigestAligned": "7b249e7388c7875c8540e7e950f6fda8aed08a57e1412149919e0a70e2eeec82", + "stateDigest": "ba0f75f6ddc882d00d5c456facd79166b62e3f2cacadd60744aa370d6b247105", + "stateDigestAligned": "66991d5cb8864f3ca029914aa9afc20cc8b9687cfd4391ffe200017c68057946", "sectionDigests": { "state": "37b26b4f6898afff", "blockContents": "dc7d13d250c94bb4", "stats": "7caf981f99159be9", - "metadata": "d5a483de67911378" + "metadata": "ba51746c6749d0cf" }, "stateKeyDigests": { "blocks": "3a454b9a16e4f0b9", diff --git a/tests/golden/storage-render/chat.json b/tests/golden/storage-render/chat.json index 1f7ba4fa8c..5ecde5722b 100644 --- a/tests/golden/storage-render/chat.json +++ b/tests/golden/storage-render/chat.json @@ -95,13 +95,13 @@ "foldAt": 9, "editedAt": 12, "summaryFrom": 9, - "stateDigest": "1377fd8b0e9aee644b0252ed66762fce72ce357778734c1e22a4b99d05c76fe9", - "stateDigestAligned": "402c083e9fcab5ba6b6d91fe2d4b4cf65f3b1fcf3fa88e2c040e81fc017d5765", + "stateDigest": "2c0b36206756617ae1e32cf0d221ddd8bf7f3e06994b49d11578bd1a35c90f26", + "stateDigestAligned": "3011800706759958cfeab6520289f1ffe257cf4f7c3275d846c03a991f9ed6b8", "sectionDigests": { "state": "90857fbf82001a2b", "blockContents": "94a58f96d7c5cfc3", "stats": "7b6162aef3873d31", - "metadata": "57404903cbbf85a1" + "metadata": "7218c1e3430c3d21" }, "stateKeyDigests": { "blocks": "d9770feee91dafc6", diff --git a/tests/golden/storage-render/google.json b/tests/golden/storage-render/google.json index d8799aad56..26c5f73b94 100644 --- a/tests/golden/storage-render/google.json +++ b/tests/golden/storage-render/google.json @@ -95,13 +95,13 @@ "foldAt": 9, "editedAt": 12, "summaryFrom": 9, - "stateDigest": "11bc49add04e1408678a44de2cc4142a623c6fa723d69277fd150c99be33ff11", - "stateDigestAligned": "08d9988e139152731ecefae4c320df288ee9a132ec5203ef8edff604c23681b1", + "stateDigest": "c5eefef6525f180ab54a7ea57c4ddf004a568db0fc2d6d227ede31dc960706db", + "stateDigestAligned": "5217aa02331256a419837cd91105d3e3172f2ff38f0f3914c0e01128e221f012", "sectionDigests": { "state": "c5243ba17364d3ac", "blockContents": "473264d9df8ba338", "stats": "c90671e484dc5d37", - "metadata": "518c072aca3f9f76" + "metadata": "2980a8959aa0a39c" }, "stateKeyDigests": { "blocks": "0cfd0b9c0fc53073", diff --git a/tests/golden/storage-render/responses.json b/tests/golden/storage-render/responses.json index 3f0b0d5575..8041cd5155 100644 --- a/tests/golden/storage-render/responses.json +++ b/tests/golden/storage-render/responses.json @@ -95,13 +95,13 @@ "foldAt": 9, "editedAt": 12, "summaryFrom": 9, - "stateDigest": "642951dac35e9b2eb4fb0b700f7d23e98f5477eb9c19e718b9deab62ce8485f5", - "stateDigestAligned": "c36820a7b7e8bda7541714cee83ffd4870e46602a6191956deaab15c0c91d12e", + "stateDigest": "ff092bc66e11c35b15ad98acf6206629115825b62168da2e5542e06297f6d47a", + "stateDigestAligned": "db5f08a7d57c14952c31571e45b4dbc6c2ed35fe8a97c58cda6fa854d411eb25", "sectionDigests": { "state": "bee6e1ba0c6fba62", "blockContents": "b6701268a0bdcd8a", "stats": "1b56c993f03cd122", - "metadata": "71746aec32a84063" + "metadata": "77714417e484ba89" }, "stateKeyDigests": { "blocks": "34b0dc17f8c24595", From f47cc571609bbb248513d25176cc7e457cd10c98 Mon Sep 17 00:00:00 2001 From: ci-check Date: Thu, 19 Nov 2026 02:36:24 +0800 Subject: [PATCH 5/5] docs(persona): list all four characterization pins in the RETIRED deletion prerequisites (#7149 batch2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The RETIRED header added in 632fdeccf2 named only 2 of the 4 test files that import this module (issue2944-neutral-skeleton, issue2601-model-drift-absorption). tests/issue2601-persona-fork-lineage. test.ts and tests/dsh-persona-continuity.test.ts also import it — a future deleter following the header would break those two suites. Drive-by fix found during review of the rebased head. --- src/persona-anchor.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/persona-anchor.ts b/src/persona-anchor.ts index 853cc0993c..055d6f7706 100644 --- a/src/persona-anchor.ts +++ b/src/persona-anchor.ts @@ -1,9 +1,11 @@ // RETIRED — no production importers (identity resolution lives in // src/session-resolve.ts, the neutral-skeleton successor). Retained ONLY as a -// characterization pin: tests/issue2944-neutral-skeleton.test.ts and -// tests/issue2601-model-drift-absorption.test.ts import it to freeze the old -// ladder's behavior as a comparison artifact. Removing this file requires -// dropping those pins deliberately, not incidentally. +// characterization pin: tests/issue2944-neutral-skeleton.test.ts, +// tests/issue2601-model-drift-absorption.test.ts, +// tests/issue2601-persona-fork-lineage.test.ts and +// tests/dsh-persona-continuity.test.ts import it to freeze the old ladder's +// behavior as a comparison artifact. Removing this file requires dropping all +// four pins deliberately, not incidentally. // // #2241/#2250: continuity-aware persona anchor for id-sharing traffic // (dsh persona lanes, codex root threads / older builds, claude-over-Responses).