Skip to content

docs: why message identity is a content hash (not an explicit id) - #1500

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-27_why-content-hash-message-id
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-09-27_why-content-hash-message-id

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Follow-up to the design review of #1496 (content-hash vs explicit auto-increment message identity). Verdict: B holds — content-hash is not replaceable by an explicit id (nor a net simplification). Per Q4's pre-authorized action, this records the rationale in the architecture spec so the choice stops being re-litigated.

What changed

Added ### Why message identity is a content hash (and not an explicit id) to AGENTS.md §2, immediately after the existing "Kernel Contract: Message Ids Are Never Reused" section. Purely additive — 42 insertions, 0 existing lines modified; no code touched.

The section encodes the three load-bearing reasons from the review:

  1. Authorship ≠ transshipment — the identity join runs on the INBOUND array (client → bili), which the host re-authors every turn from its own private store (codex rollout, claude-code transcript, pi/omp/hermes session). An id stamped on a foreign message evaporates next turn; only bytes survive the round trip, so only a content-derived id re-matches with zero round-trip channel. Plugin mode noted as a bounded exception (agent-executed compress tool calls/results round-trip in the agent's own history) that does not remove the join need for user/foreign messages.
  2. No writable + accepted + stored-back id field exists — anthropic/openai chat lanes carry none; Responses input[].id is provider-namespaced + shape-validated ([Bug] Responses ACP round 2 生成 66 字符 message id,导致 Codex 后续请求持续 400 #242: 66-char msg-proxy-* → 400; fix: scope Responses ingress id healing to Bili's msg-proxy namespace #1475: renaming provider rs_* ids → Copilot 400) and carries replay correspondence (reasoning id ↔ encrypted_content). Editing content bytes instead breaks wire fidelity ([bug] 插件透传会剥掉工具调用参数里的 render tag(arguments 流挂了 tag-echo 过滤器) #1039).
  3. The hash doubles as the change detector — any client-side edit/fork changes bytes → changes id → breaks the join → detected by foldCoverage (使用pi 压缩后就提示prompt is too long #1195), detectUnannouncedHistoryRewrite (模型切换后压缩块跨模型失配,新模型收到 61.3 万 token 全量上下文 #1001), fork-adoption (Design: tree-shaped prefix affinity — forked branches inherit the shared prefix's compression state #629). An explicit id would need a separate byte comparison to catch the same edits.

Plus the consequence note: the mNNNNN ref ledger IS the auto-increment identity (persistent, never rewritten); the content hash is the per-turn JOIN (byRaw: hash → ref). The collision fragility (#1476) belongs to the kernel's instance-durability contract (fixed by instance re-minting, kernel #459) and is NOT removable by switching to explicit ids — the colliding messages are user/foreign messages with no round-trip channel for a persistent id anyway.

Pre-flight

Markdown-only change to AGENTS.md; no TypeScript touched, so typecheck/test/build cannot regress by construction. Diff verified pure-additive (git diff --stat: 1 file changed, 42 insertions(+); no modified/deleted lines).

Closes #1496

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-27_why-content-hash-message-id (c5e057d)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1425-pr.1500.7476cef

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

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Reviewing this PR now. It's a pure-addition docs change to AGENTS.md §2 recording the content-hash-vs-explicit-id verdict from #1496. I'll verify: (1) diff is truly pure-additive, (2) every factual claim/issue reference in the new section checks out against the codebase, (3) placement and consistency with the existing Kernel Contract section, (4) CI status. Full review to follow shortly.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete. Verdict: mergeable. This is the exact pre-authorized Q4 deliverable of #1496 (verdict B holds), recorded faithfully. Every factual claim in the new section was verified against live code and the pinned kernel artifact — details below.

① Original issue (direction)

#1496 asked for an independent re-review of content-hash vs explicit auto-increment identity, with Q4 pre-authorizing: if B holds → write "why content-hash" into the architecture doc. The floor-2 review established B holds with per-host (codex/claude-code/pi/omp/hermes) and per-lane evidence. This PR is that action, verbatim in scope — no drift, no scope creep.

② Regression review (existing-behavior inventory)

AGENTS.md is auto-injected into every agent session, so the relevant "behavior" is what agents read:

  • Purely additive confirmed: git diff --stat = AGENTS.md | 42 insertions(+), 0 modified/deleted lines, single commit c5e057d2.
  • Placement as claimed: new ### Why message identity is a content hash… sits immediately after ### Kernel Contract: Message Ids Are Never Reused (merged-file lines 126→148), before ## 3. Heading level consistent with sibling subsections.
  • Consistency with neighbors: complementary, not contradictory — the Kernel Contract section states the guarantee (ids never reused/reissued); the new section explains why the raw id is content-derived and defers collision fragility to the kernel's instance-durability contract. Matches the §7.3 wire-fidelity bullet's treatment of [bug] 插件透传会剥掉工具调用参数里的 render tag(arguments 流挂了 tag-echo 过滤器) #1039.
  • Stale-base check: master moved ~17 commits past the branch point (incl. release v0.1.160) and also touched AGENTS.md (08a1e72a, "Configuration Surface Discipline", a disjoint region). Simulated merge onto current master via git merge-tree: clean, zero conflicts. Docs-only ⇒ no rebase required.

③ Fact-check of every claim (against live sources)

Verified against acp-kernel 0.0.95 (the exact pin in package.json; fetched the published tarball, not a stale local copy):

  • deriveMessageId in kernel wire/message-id.ts: impl is seed = ${role}|${contentType}|${toolCallId ?? ""}|${toolName ?? ""}|${text} → sha256 → first 16 hex → "h_" + …. The doc's formula and the h_<sha16> format are exactly right; "recomputed on every inbound request" matches the per-request wire→core converter path.
  • foldCoverage — src/session.ts:730, invoked at src/server.ts:2822/3027/3264/3510 ✓
  • detectUnannouncedHistoryRewrite — src/session.ts:697, invoked at src/server.ts:2846/3051 ✓
  • fork-adoption — src/fork-adoption.ts exists ✓
  • byRaw: hash → ref join — session.state.messageRefs.byRaw, used in src/decompress-shared.ts:186, src/preflight.ts:139, src/server.ts:2777 ✓
  • mNNNNN ledger = persistent auto-increment identity — consistent with the adjacent Kernel Contract section ✓

All 8 issue citations checked on GitHub (title + state match the doc's characterization):

Citation Verified
#242 [closed] 66-char message id → Codex 后续请求持续 400 ✓
#1475 [closed] scope Responses ingress id healing to Bili's msg-proxy namespace (rs_* rename → Copilot 400) ✓
#1039 [closed] arguments 流挂了 tag-echo 过滤器 — the wire-fidelity invariant ✓
#1195 / #1001 / #629 [closed] — origins of foldCoverage / detectUnannouncedHistoryRewrite / fork-adoption ✓
#1476 [closed] content-hash collision drops new user message matching a folded one ✓
kernel #459 [closed] "fix: re-mint live ids that collide with a folded copy (billion-context#1476)" — doc's "instance re-minting" phrasing matches ✓

④ Tests

N/A by construction (no TypeScript touched). CI still ran the full suite on head c5e057d: all 12 checks green (ubuntu/windows test matrices, codex/dsh/pi/opencode real-client lanes, hermetic registry e2e, version-guard, build-artifact).

⑤ Diff cleanliness & duplicates

Single file, single commit, pure addition, no whitespace churn, nothing unrelated. Duplicate screen: no other open issue/PR covers this doc change; it is the sole Q4 deliverable of #1496.

Nothing to fix in-passing — the section reads as written, citations included. Ready for human merge; Closes #1496 will fire on merge.


中文摘要:复核了这份纯文档 PR——逐条核对了新增小节里的全部事实主张(对照 package.json 精确钉住的 acp-kernel 0.0.95 发布产物验证了 deriveMessageId 的 hash 公式与 h_<sha16> 格式、在源码里定位了 foldCoverage/detectUnannouncedHistoryRewrite/fork-adoption/byRaw join、并在 GitHub 上核实了全部 8 个引用的 issue 标题与状态),diff 确认为单文件 42 行纯增量、与当前 master(含另一处 AGENTS.md 改动)合并零冲突、CI 12 项全绿;方向就是 #1496 Q4 预授权的落点,可以合并。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[design review] 消息身份层:content-hash 是否可被显式自增 id 取代?请复核

1 participant