Skip to content

[PR] perf: Batch 2+3-1 consolidated — fingerprint change detection + ledger zero-hash inheritance + persona deprecation annot | perf: 批次二+三-1 合订 — 指纹变化探测 + 台账零哈希继承 + persona 退役标注 (#7149) - #7191

Merged
ranxianglei merged 5 commits into
masterfrom
2026-11-18_hash-cleanup-batch23
Nov 19, 2026

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

性能清理 · 批次二+三-1 合订(#7149 提案)

模型 qwen3.8-27b(provider sglang-gpu0)实现,提案见 #7149 。批次一(重复哈希 R1/R6)在 #7151。

改动(4 笔独立提交,可单独回退)

1. persona-anchor 退役标注(docs(persona))

  • 调查确认生产零调用方(身份解析在 session-resolve),文件被 3 个特征化测试当行为标本钉着
  • 文件头标注 RETIRED + 删除前提(先拆 pin 测试)。不删文件(owner 决定)

2. 系统提示词指纹 → 变化探测(perf(fold-reconcile))

3. 台账出站体 digest → 相同重复 note 零哈希(perf(cache-ledger))

  • noteForwardedBody:字节相同的重复 note(非流式结算路径的文档化常见场景)→ 纯字节比较继承上次 digest,热路径零哈希
  • 变化/新 body 保留全文哈希:bd 是 大量缓存接缝事件导致缓存命中率大幅度降低 #2131 的字节相等性证明、超 8MiB 不保留全文时唯一的地面真相(测试钉死)
  • 继承值与独立全文哈希逐字节一致(新增测试直接断言相等)

4. 黄金快照再生(test(golden),见下节论证)

侦察负结果(2 项,逐行验证后确认不改,记录防重复讨论)

插件车道 wireHash(第三-1 的其中一处):生产路径每请求只哈希一次(handle.ts:3608 唯一调用方传预制备的元数据;重哈希分支是测试/未来调用方兼容)。"视图 ID 结构锚定"落不了地:输入是原始入站 body,该时点规范视图不可得且变换不同。

chain-checkpoint 验章 JCS(第三-1 的另一处):digest 是整段 body 字节身份证明(多实例中继/重放防篡改:"a digest MATCH proves identity… never trust a newer forged timestamp over a verified digest"),换结构化摘要会削弱证明本身;且打戳/验证都在 chainArtifactsEnabled 配置门控的专用车道,非主流量。tag 已带 v= 版本字段,将来真要做有现成兼容机制。

黄金快照再生的正当性(f357310e,已 rebase 到最新 master a446a3c)

CI 首跑 5 个分片红,两族黄金测试(storage-render golden ×4 wire + storage-engine-proofs "full-mode restart is invisible" ×4 wire)。定位:master 在基线之后合并了 #6827 并把黄金快照再生到 75a45380(本分支基线之前没有),merge ref 上"master 的新快照 vs 本分支代码"失配。本地用正确 kernel 复现后形状干净:四条 wire 只有 metadata section 漂移。

字段级实证(anthropic drive,master 基线 vs 本分支完整状态 dump diff):

  • state / blockContents / stats 三段完全相同
  • metadata.systemFp 仅多一个字段:{fp: "f1c4e23132875dea", size: 27, head: "\"You are a test assistant.\""} ← fp/size 逐位相同,head(JSON 序列化 system prompt 的前 256 字符)是变化探测(b18d5967)的设计内新增

再生 diff:4 个文件各 3 行(stateDigest / stateDigestAligned / metadata section digest),所有 per-turn wire sha 字节级不变——与 master 侧 75a45380 同模式("wire shas unchanged, persisted digests only")。

实现级偏差(相对提案"视图 ID+差值"表述,如实记录)

提案里"哈希输入 MB→KB"对三处的适用性侦察后修正:台账这处调用点在发送 chokepoint(手里只有 wire 字符串,规范视图在存储层入库、时点不可得),落地为"相同重复 note 零哈希继承 + 变化体保留地面真相哈希";插件与验章两处如上述负结果。真正兑现"视图 ID 引用化"需要把台账/快照/验章的输入从 raw body 切到存储层视图——属于批次三-2 级别的方案对齐范围,本 PR 不做。

验证

明确不动

  • 安全三件套(APIG HMAC / 更新完整性 / 引擎下载 sha512)、身份骨架(消息 ID 派生)
  • 批次三-2(渐进链 O(n²) → 增量续算)hold 待方案对齐;批次三-3(图片指纹 → CAS)hold 最后讨论

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-18_hash-cleanup-batch23 (f47cc57)

Latest build — install this exact version

npm install -g billion-context@0.0.10871-pr.7191.11724d8

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
f47cc57 billion-context@0.0.10871-pr.7191.11724d8 build
f357310 billion-context@0.0.10856-pr.7191.a8511aa build
41a5acd billion-context@0.0.10843-pr.7191.ccb5d51 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr7191.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

模型 qwen3.8-27b(provider sglang-gpu0)。自审记录(3 笔提交 + 2 项侦察负结果):

改动评审

  1. 632fdecc persona 退役标注:纯注释。核查过生产引用面(session-resolve/plugin/side-request 均只有注释提及,零 import)+ 3 个特征化测试 pin(issue2944/issue2601×2),标注与事实一致,"删除需先拆 pin"的前提写明。
  2. bb95aaa9 系统提示词变化探测:探针条件 = prev.fp !== "-" && 长度相等 && prev.head === 前256字节,命中复用、未命中全文算。核查点:(a) 消费方 cache-ledger.ts:1807/2019 只读 .fp 松散 cast,新增 head 字段无影响;(b) 旧格式元数据(无 head)自动走全文路径,无崩溃面;(c) 文档化权衡(256 字节后同长改写不观测)写进代码注释;(d) 有→null 从"不记日志"变为"记一条"是有意行为变化,测试与 PR 说明均已注明。
  3. 41a5acd1 台账零哈希继承:sameBytes 要求字节数相等 + prior.full 存在 + Buffer.equals 纯字节比较。关键正确性核查:继承的 digest 必然等于独立全文哈希(同字节同摘要),所以 bd 地面真相语义、:2052 的 be 判定、msgs/keyFp/effFp 继承链全部等价;变化体仍走全文哈希路径,#2131 证明能力不受影响。新增测试直接断言"继承值 == 独立算的 sha256"。

负结果复核

  • 插件 wireHash:重新跟了一遍 preparePluginWireMetadata → handle.ts:3608(唯一生产调用方)→ publicSnapshotWireHash 的引用相等短路链,确认每请求一次哈希;重哈希分支确实只服务测试/未来调用方。
  • 验章 JCS:evaluateChain 的 digest MATCH 是多实例防篡改的恒等证明(源码注释原话已引在 PR 描述),换任何"只看结构不看全文"的摘要都会削弱它;且打戳/验证双门控在 chainArtifacts 车道。结论:不改是正确的。

验证:tsc 0 错;7 个相关测试文件 132/132 绿。与 #7151 无文件交集冲突面(fold-reconcile.ts 本分支只动两个 note* 函数)。

…size+head change (#7149 batch2)

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.
…st (#7149 batch3-1)

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.
…ysFp now persist the 256B change-probe head (#7149 batch2)

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: <first 256 chars of the JSON-stringified system prompt> } with
fp/size unchanged (verified by dumping both states and diffing).
@ranxianglei
ranxianglei force-pushed the 2026-11-18_hash-cleanup-batch23 branch from 41a5acd to f357310 Compare November 18, 2026 17:07
@ranxianglei ranxianglei changed the title [PR] perf: 批次二+三-1 合订 — 指纹变化探测 + 台账零哈希继承 + persona 退役标注 (#7149) [PR] perf: Batch 2+3-1 consolidated — fingerprint change detection + ledger zero-hash inheritance + persona deprecation annot | perf: 批次二+三-1 合订 — 指纹变化探测 + 台账零哈希继承 + persona 退役标注 (#7149) Nov 18, 2026
…etion prerequisites (#7149 batch2)

The RETIRED header added in 632fdec 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.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷
(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复 — 本 PR 是 #7149 提案的批次二+三-1 实现;批次一(R1/R6 重复哈希)在 #7151,与本 PR 无文件交集(fold-reconcile.ts 本分支仅动两个 note* 函数)。

审核结论: 可合 — 新 head f47cc57160 全部检查绿(11 个测试分片 + 全部静态门禁 + 全部 e2e,37 success / 13 skipped / 0 failed)。

结构化八问

  1. 是什么问题: 性能清理(性能清理提案:同一份内容每请求被重复哈希 3-5 次 —— 盘点结论与分批清理方案 #7149 提案批次二+三-1),不是缺陷修复。目标: 消除热路径上的冗余全文 SHA-256 —— 系统提示词指纹(fold-reconcile)、台账出站体 digest(cache-ledger),外加 persona-anchor 退役标注。
  2. 什么原因导致的: 不适用(性能优化,非缺陷)。原「问题」= 每次都全文哈希: 系统提示词没变也重算指纹;台账对字节相同的重复 note 重算 digest。
  3. 影响范围与严重程度: p3,仅性能,无用户可见缺陷。波及面: fold-reconcile 的每请求指纹路径(所有带系统提示词的会话)+ cache-ledger 出站体 digest(非流式结算路径)。压缩/身份/缓存语义零行为变更。
  4. 怎么修复的:
    • 指纹 → 变化探测: 在 session metadata 持久化 {fp, size, head: 前 256 字符};size+head 未变 → 复用已存 fp(跳过全文 SHA-256);变了/首次/旧形状 → 全文算。已存 fp 仍是实算时的真值。
    • 台账 digest 继承: 字节相同的重复 note(保留全文的纯字节比较)继承上次 digest;变化/新 body 保留全文 sha256(bd 是 大量缓存接缝事件导致缓存命中率大幅度降低 #2131 的字节相等性证明)。归纳: 继承值恒等于真 sha256(首次 note 必为真哈希)。
    • persona-anchor: 纯注释 RETIRED 标注;已验证生产零调用方(src/ 内 4 处命中全是注释)。
  5. 是否有回归问题:
    • 首版 CI(旧 head 41a5acd)5 个分片红: golden-storage-render + storage-engine-proofs。根因: 新持久化的 head 字段改变 persisted-state digest → 黄金快照漂移。已 rebase master + 再生黄金快照(f357310ed2),附字段级证据: 仅 metadata 段漂移、fp/size 位级一致、所有逐轮 wire sha 字节一致。作者本地验证(132/132)未覆盖这两个黄金套件,是首版漏网的原因。
    • rebase 完整性: PR 自身 hunk 跨 rebase 字节一致;fold-reconcile.ts 其余差异全部来自 master train(804c89baf8 candidateWordEvidence,不同区域)。
    • 新增可观测行为(已披露): 提示词撤回(非 null → null)现在记一条 Fold-state reconciliation: classify resent-history divergence (edit/fork/new/system-only) and make compression blocks re-anchorable chain units #1921 变更日志(此前静默),测试钉死。
    • 文档化权衡(测试钉死): 256 字节之后的同长改写不观测 —— 探测是检测信号,不是安全边界。
    • CI: f357310 与 f47cc57 两个 head 均 11 分片全绿 + 静态门禁全绿 + e2e 全绿。
  6. 是否破坏缓存: 否。探测仅在 size+head 未变时复用已存 fp —— 已存 fp 是实算时的真全文哈希。台账 digest 继承仅适用于字节相同的 body —— 继承值等于真 sha256(新增测试对独立计算的全文哈希断言相等)。settle 的 be/bd 不变量不受影响(代码验证: be 由 digest 相等判定,在继承下不变)。
  7. 是否改了设计方向: 否。提案的「视图 ID + 差值」重设计(哈希输入 MB→KB)明确推迟到批次三-2(需存储层视图 plumbing)。本 PR 是现有地面真相哈希之上的保守记忆化层。两处侦察负结果(插件 wireHash、chain-checkpoint JCS)附逐行理由记录。
  8. 是否引入了新的配置: 无新 env/config/默认值。持久化的 session metadata 形状变化(systemFp/canonicalSysFp 增加 head 字段)—— 属会话状态而非配置;旧形状 {fp,size} 有兼容路径(全文哈希 + 回填),测试钉死。

审核期间的动作

  • PR 打标签: perf / p3 / scope/kernel(原本无标签;按 PR 自身 diff 判定)。
  • 顺手修 f47cc57160: RETIRED 头注释(632fdeccf2)只列了 4 个 pin 测试文件中的 2 个 —— 漏了 tests/issue2601-persona-fork-lineage.test.ts 和 tests/dsh-persona-continuity.test.ts,照头注释删文件的人会漏拆这两个测试套件。已补全为四个。(PR 正文「3 个特征化测试」同样少算一个;正文不可编辑,在此记录。)
  • CI 事件披露: 我打标签(scope/kernel)时,labeled 事件触发了 scope=skip 的 run,其 concurrency 组取消了进行中的 push 触发测试矩阵 —— 这是 ci.yml labeled-event 门的设计行为,不是 CI 故障。已用 workflow_dispatch 重跑核心矩阵: run 44369394746(f357310ed2)全分片绿;推注释修复后新核心矩阵 run 44371625202(f47cc57160)亦全分片绿。

判定: 可合 —— 代码审核(3 个内容提交通读)+ 本地验证(黄金套件 17/17、PR 目标文件 204/204、typecheck 0 错误)+ CI(37 success / 13 skipped / 0 failed)全部通过。合并留给 owner。

@ranxianglei
ranxianglei merged commit cf97472 into master Nov 19, 2026
88 checks passed
ranxianglei pushed a commit that referenced this pull request Nov 19, 2026
…nder golden conflict

Master's hash-cleanup batches + kernel 0.0.200 bump (#7149/#7151/#7191/#7281) regenerated the storage-render goldens; the PR's lastFoldDrift field also touches them. Regenerated from the merged code so the snapshots reflect both; golden suite 5/5, PR test 3/3, typecheck clean. Built on the concurrent comment-fix commit 0cae5a0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant