Skip to content

feat(#2446): durable-state carriers become virtual tool paths (Config.messagePathOf) - #2736

Merged
ranxianglei merged 8 commits into
masterfrom
2026-10-11_durable-tool-identity
Oct 11, 2026
Merged

ranxianglei merged 8 commits into
masterfrom
2026-10-11_durable-tool-identity

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

feat(#2446): durable-state carriers become virtual tool paths (Config.messagePathOf)

What

The four dsh durable-state text carriers stop being host-hardcoded boolean guards:

A lane-scoped host classifier now projects each carrier to a canonical durable/<name> identity via the new kernel hook Config.messagePathOf, and the existing protectedTools / protectedLatestTools pattern machinery governs them — same knobs, same semantics as the tool channel (#1947 projected skill/<name> the same way). The kernel never learns dsh dialects: it only consumes identities.

kernel-change: yes — kernel/package.json 0.0.116 → 0.0.117 (post-merge bump: master already took 0.0.116 for #2663/#2695/#2607 kernel work). New optional Config.messagePathOf?: (msg) => string | undefined (pure, cheap, never re-projects tool-call/tool-result); protected.ts accepts virtual paths in isMessageProtected (pattern match) and collectLatestProtected / isMessageLatestProtected (per-path latest). Without messagePathOf behavior is byte-identical to before (all 1272 kernel tests unchanged).

Policy contract (host side)

withDurableProtection(config, classifier):

  • default (owner decision 2026-10-11: latest-per-identity, pi-aligned) — user configured nothing durable → bili injects protectedLatestTools: [..., "durable/*"] + attaches the classifier. Every carrier keeps exactly its newest instance pinned (skill/MCP visibility can never be lost — the 开启 bili 后「规矩与 skill 好像没被使用」? #2419 fingerprint gate never resends an unchanged catalog); superseded instances (runtime snapshots, re-based AGENTS.md baselines) fold normally. This mirrors the pi reference architecture, where the skill catalog and AGENTS.md live in the system prompt as a single live copy; dsh-native compaction protects neither (no skill/instructions section in its summary template, no re-injection) — not a precedent to follow.
  • whole-identity takeover — ANY durable* pattern in the user's protectedTools OR protectedLatestTools → bili attaches only the classifier, injects nothing. The user owns the entire durable policy:
    • protectedLatestTools: ["durable/*"] → every carrier keeps only its LATEST instance (all four are cumulative snapshots — older catalogs/baselines fold away);
    • protectedTools: ["durable/agents-md"] → exactly one identity protected; skill/mcp catalogs fold normally.
  • lane scoping unchanged: classifiers are per-host evidence-permitlist (durableMessageToolPaths = dsh only, KDD release v0.1.2 #9). Unregistered lanes get no projection at all.

Config flows through the normal three-level cascade (global → provider → model, whole-array replace) — durable patterns are ordinary pattern entries, no new knobs, no env vars.

Why this shape (vs. the boolean guards / #2557 marker)

Tests

Closes #2446 (the umbrella: host-hardcoded protection → configurable identity-based protection).
Supersedes the guard half of #2557's approach (marker protocol remains parked per owner — this PR needs no wire changes).

….messagePathOf)

The four dsh durable-state text carriers (#2419 skill catalog, #2446 mcp
catalog, #2447 workspace-instructions baseline, #2481 runtime-context
snapshot) stop being host-hardcoded boolean guards. A lane-scoped host
classifier now projects each carrier to a canonical durable/<name>
identity via the new kernel Config.messagePathOf hook, and the EXISTING
protectedTools / protectedLatestTools pattern machinery governs them —
same knobs, same semantics as the tool channel (#1947).

kernel (0.0.116):
- Config.messagePathOf: host-projected virtual tool path (pure, cheap,
  never re-projects tool-call/tool-result)
- protected.ts: virtualToolPathOf; isMessageProtected + collectLatestProtected
  + isMessageLatestProtected accept virtual paths (protectedTools patterns
  and per-path latest semantics both apply to projected carriers)

host:
- durable-message-guards.ts rewritten: DurableMessageClassifier per
  carrier (same matching predicates, evidence comments preserved),
  durableMessageToolPaths registry (KDD #9 dsh-only allowlist unchanged),
  withDurableProtection() — default injects durable/* all-instance
  protection (byte-equivalent to the old boolean guards); ANY durable
  pattern in protectedTools/protectedLatestTools = whole-identity
  takeover (user policy wins verbatim, only the classifier is attached)
- handle.ts / session.ts wiring + config.ts JSDoc for both knobs

tests: kernel protected-virtual-paths 6 (projection domain, pattern
matrix, per-path latest, tool-channel parity); host durable-tool-identity
8 (policy units + e2e: default all-instance, durable/* latest takeover,
exact-identity takeover, lane scoping); the four #24xx suites migrated
to the Path API with e2e assertions unchanged (behavioral parity).

kernel-change: yes — kernel/package.json 0.0.115 -> 0.0.116; new optional
Config field messagePathOf plus virtual-path support in protected.ts.
Backwards compatible: without messagePathOf the kernel behaves exactly
as before (all suites unchanged).
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_durable-tool-identity (001e4cc)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3009-pr.2736.36e9542

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-pr2736.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] 🏷 PR #2736 review 结论(分支 2026-10-11_durable-tool-identity,单 commit b09b252,base master @ aad0fee,落后 0 commit,mergeable=true)。diff 逐文件通读(kernel/src/types.ts、kernel/src/protected.ts、kernel/tests/protected-virtual-paths.test.ts、src/config.ts、src/durable-message-guards.ts、src/server/handle.ts、src/session.ts、tests/durable-tool-identity.test.ts、四个迁移套件),并核对了 kernel 内全部调用点与 CI 状态。

结构化八问

  1. 是什么问题:四个 dsh durable-state 载体(skill/mcp 目录、agents-md baseline、runtime-context 快照)此前由 bili 源码硬编码的布尔守卫钉住——策略不可配置(不能切 latest-only、不能只护某一个载体),每加一个载体都要改代码。本 PR 把它们收进既有 protectedTools/protectedLatestTools 模式词汇表。
  2. 什么原因导致的:kernel 保护面原生只认工具交换(pattern 键是工具名),文本载体只能挂在独立的布尔谓词通道(isMessageProtected 钩子)上——没有策略词汇、没有可配置性,这是机制层缺口而非某处实现错误。
  3. 影响范围与严重程度:feat+refactor,非 bugfix。仅影响 dsh plugin-lane 会话;默认行为与旧守卫等价(下述逐项验证);非 dsh lane 与 proxy 模式零变化。无外部可见回归面。
  4. 怎么修复的:host classifier 经新 kernel 可选钩子 Config.messagePathOf(纯函数,永不重投影 tool-call/tool-result)把载体投影为规范 durable/<name> 身份,之后由既有路径模式机制管辖(exact/首段/glob、大小写不敏感、* 不跨 /)。默认向 protectedTools 注入 durable/*(与旧全实例钉死等价);用户在任一列表写了任何 durable* 模式即整命名空间接管(只挂 classifier、不注入)。身份翻译归 bili,策略归 config,kernel 永不学 dsh 方言。
  5. 是否有回归问题:未发现,逐项审过:
    • 无 classifier 时 kernel 逐字节不变:virtualToolPathOf 返回 undefined,所有新分支 no-op;isMessageLatestProtected 放宽 msgIds 检查(去掉 tool-call 限定)安全——无 classifier 时 collectLatestProtected 的 last 只能是 tool-call,msgIds 内容集与改前相同;golden tests/golden/wire-contract/kernel.json 未变(defaultConfig 输出不变,新字段可选)。
    • 调用点传导完整:kernel 内全部消费点(compress/recommend/ccr/absorb/crush)都传完整 config 对象,messagePathOf 处处可达;assignRefsNode 的 hasProtection 门不含 messagePathOf 是正确的——虚拟路径只能经 pattern 受护,无 pattern 即无虚拟保护,该门纯为性能优化,不构成漏网路径。
    • clone-safe 纪律保持:handle.ts 先 storeEffectiveConfig 再挂 classifier/注 pattern(函数不进 metadata);session.ts effectiveConfig() 读时重跑 withDurableProtection,从持久化的用户 pattern 重算同一 default/takeover 判定,/__bili/plugin/tool 与 wire 路径看到同一保护;幂等(重复应用不重复注入,e2e 有钉)。
    • 四迁移套件 parity 成立:e2e 断言逐字节未变(diff 只动 unit 段),marker 语义全保留(含 case-sensitive Instructions from:、小写 reconciliation 变体保持可折)。
    • 高危模式逐项过:无语义漂移(默认等价)、无 fail-fast→吞错、无阈值/时序/输出格式漂移、lockfile 仅 kernel 版本行。
  6. 是否破坏缓存:否。受护载体原地常驻(与之前同位置),wire 字节不移动;非载体内容的折叠行为不变;prefix cache/增量游标/去重键均不受影响。
  7. 是否改了设计方向:是——umbrella 的架构收敛点:文本通道保护从「host 硬编码布尔」转向「统一模式词汇(virtual tool paths)」,[Feature] Per-skill compression protection: static per-name config + dynamic skill_pin/skill_unpin + cascade adoption #1947 skill/<name> 投影原则从工具通道扩展到文本通道;kernel 只消费身份,host 拥有方言翻译。
  8. 是否引入新配置:无新字段/env var。既有 protectedTools/protectedLatestTools 获得新值域(durable/*,仅注册 lane 生效);默认值不变。

测试有效性(质量关)

  • kernel/tests/protected-virtual-paths.test.ts(6):有牙——「工具交换永不被重投影」(classifier 对 tool-call 返回值被无视也钉住)、pattern 矩阵全形(含大小写)、per-path latest vs plain-name single-latest、classifier 在场时工具通道 latest 不变。
  • tests/durable-tool-identity.test.ts(8):4 个策略单元(default ensure/两种 takeover/幂等)+ 4 个真 e2e(真 proxy + mock upstream,经 /__bili/plugin/tool 真调 compress,对折后 body 断言具体内容存亡并验证折叠确实发生)——不是假测试。
  • CI:b09b252 上已完成 checks 全绿(kernel-guard、docs-sync、unused-exports、real-dsh-lane e2e、registry e2e、theorem 等),ubuntu test 矩阵绿;windows test 22/24 两个 job 写作时仍在跑。

发现(F1/F2 需你拍板,F3 已顺手修,F4/F5 记录在案)

判定

代码过审:kernel 侧改动最小且干净,调用点传导完整,clone-safe 纪律保持,测试真实,CI 绿。F1 补齐(或你明确豁免文档要求)后可合;F2 是方向确认项。按 Kernel Boundary,此 PR 属 human-only review 档(kernel 0.0.115→0.0.116 + feat + 配置语义),我不代合。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 F3 已修(上一条 review 的发现项):迁移后残留的四处旧函数名引用已直接在 PR 分支上修正——commit 4454751a8(docs(tests): align stale guard names with the classifier API):

  • tests/issue2446-dsh-mcp-catalog.test.ts:test title dshMcpCatalogGuard: matches… → dshMcpCatalogPath: projects the catalog marker to durable/mcp-catalog…(与其余三个迁移套件的命名对齐)+ 头注释指向现 classifier API;
  • tests/issue2447-dsh-workspace-instructions.test.ts、tests/issue2481-dsh-runtime-context.test.ts:头注释中已删除的 dshWorkspaceInstructionsGuard / dshRuntimeContextGuard 引用改为对应 classifier(dshWorkspaceInstructionsPath / dshRuntimeContextPath,feat(#2446): durable-state carriers become virtual tool paths (Config.messagePathOf) #2736)。

纯注释/测试标题改动,零逻辑变化;CI 将在新 commit 上重跑确认。其余发现项维持原结论:F1(CONFIGURATION.md en+zh 补 durable/ 值域)建议合并前补;F2(#2446 与 open PR #2576 的关系)待你方向确认*。

… single live copy)

Switch withDurableProtection's injected default from protectedTools
"durable/*" (all-instance) to protectedLatestTools "durable/*": every
carrier keeps exactly its newest instance pinned (skill/MCP visibility can
never be lost — the #2419 fingerprint gate never resends an unchanged
catalog), while superseded instances (runtime snapshots, re-based AGENTS.md
lines) fold normally. This matches the pi reference architecture, where the
skill catalog and AGENTS.md live in the system prompt as a single live copy,
and cuts the pinned tail (runtime-context snapshots accumulate per state
change). Explicit takeover unchanged: any durable pattern in
protectedTools/protectedLatestTools takes over the whole policy verbatim.

Owner decision 2026-10-11 (pi/dsh-native comparison: pi keeps both carriers
alive forever via system-prompt residency; dsh-native compaction protects
neither — its summary template has no skill/instructions section and there
is no re-injection).
…D BLOCKS section

The bare /\bb(\d+)\b/ harvest matched the ACTIVE SURFACE build stamp
"(b<shortsha>)" first whenever the CI merge ref abbreviates to 'b'+digits
(#2736 run 38119865934: merge b288144 → decompress "b288144" → block not
found → rebuilt-history assertion failed twice, deterministic per-merge-ref).
Anchor to the COMPRESSED BLOCKS section so the block listing is the only
harvestable surface.
@ranxianglei

Copy link
Copy Markdown
Owner Author

The two real pi codex-responses WebSocket lane failures on c2a1947 (run 38119865934, incl. rerun) were a merge-ref lottery in the test, not the branch diff: CI checks out refs/pull/2736/merge, whose abbreviated SHA b288144 landed in the acp_status build stamp line host=billion-context 0.1.191 (b288144), and the bare /\bb(\d+)\b/ harvest grabbed b288144 as the "block id" → decompress {"blockId":"b288144"} → [Block b288144 not found] → no SENTINEL in the rebuilt history. Reruns reuse the same merge ref, hence deterministic 2/2.

a5a29a1 anchors the harvest to the COMPRESSED BLOCKS section (deterministic, immune to the stamp). Verified locally against pinned pi-stable 0.83.6 (A green, 6.3s).

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Round-2 review: lottery diagnosis confirmed, c2a1947 policy flip reviewed, branch re-greened after the master merge

① Lottery diagnosis — verified point-by-point in code

Your root cause is exactly right; I traced every link:

  • Stamp chain: dev/tsx mode stamps BUILD_COMMIT = git rev-parse --short HEAD (src/version.ts:69) → meta host line host=billion-context 0.1.191 (<sha>) (src/acp-status.ts:87) → rendered as the first line of the overview report via surfaceLine() (kernel/src/report.ts:222-231).
  • GHA checks out refs/pull/2736/merge for PR workflows, so HEAD is the merge-ref commit. Its short SHA b288144 = b + six digits, which matches the bare unanchored /\bb(\d+)\b/ harvest scanning top-to-bottom — the stamp wins before any real block line. P(a random 7-hex short SHA ∈ ^b\d{6}$) ≈ (1/16)·(10/16)⁶ ≈ 1/1600 per merge ref — a genuine lottery; and the merge ref stays put while head/base don't move, hence deterministic 2/2 reruns.
  • Fix a5a29a1c: the anchored /COMPRESSED BLOCKS[^\n]*\n[\s\S]*?\n\s+b(\d+) \(/ is robust — block lines render as bN (tier) (report.ts:309-311), and between the header and the first block line there is only an optional Tier usage: line + blank, so no false match is possible. The empty-block case fails assert.ok exactly like before.
  • CI itself confirms the fix: e2e-pi-codex-ws lane went success on a5a29a1c (run 38121036811). Residual note for the future: the same latent lottery exists for any host-stamped bNNNNN-looking token anywhere in the panel — section anchoring is the right permanent shape, not just a patch.

② c2a1947 (default → latest-per-identity) — reviewed, sound

Semantics check on all four carriers: each is a cumulative snapshot where the newest instance IS the source of truth (catalogs are re-emitted only on visible-set change via the fingerprint gate; agents-md baseline only on baselineIdentity change; runtime-context carries the explicit supersedes clause + cleared form). So pinning only the latest never loses visibility, and it bounds protected mass to O(1) per carrier — this also resolves the unbounded-growth concern raised in the #2446 discussion. Explicit all-instance opt-in is retained and now has its own dedicated e2e. Tests flipped correctly (unit asserts moved to protectedLatestTools; default e2e expects the older catalog to fold + newest survive).

⚠️ Behavior-change disclosure (old → new):

  • Old default (b09b252..4454751): protectedTools += durable/* → every carrier instance pinned forever (strict parity with the legacy boolean guards).
  • New default (c2a1947+): protectedLatestTools += durable/* → only the newest instance per identity pinned; superseded instances fold normally.
  • Why: pi-aligned single live copy (skill catalog / AGENTS.md live once in pi's system prompt) + bounded growth; the PR body documents the owner decision 2026-10-11 ✓.
  • Scope: dsh plugin-lane sessions only (lane-scoped classifier, KDD#9). No migration concern — feature unreleased. Users who want the old behavior: protectedTools: ["durable/*"] (whole-identity takeover, now e2e-covered).

③ The #2658 reds — cross-branch flake, already fixed upstream

While chasing these I gathered independent evidence they were not your diff:

④ Fixes I pushed to the branch (all verified)

  1. d78bee636 — one genuinely stale comment left by the policy flip: src/durable-message-guards.ts:122-124 said superseded runtime snapshots "keep pinning harmlessly under the all-instance default" → now "fold harmlessly under the latest-per-identity default". All other "all-instance" mentions checked and accurate (they describe what each list does, not the default).
  2. f3701bbc4 — kernel-guard was failing on the merged head: after your master merge, both sides sat at kernel 0.0.116, but the branch still carries new kernel/src/** content vs master (the messagePathOf hook) → guard: "kernel/ source changed without bumping the version". Bumped kernel/package.json 0.0.116 → 0.0.117 — exactly the repo's established pattern (63308103d "master already took 0.0.112", 8d9a8c18a "after rebase onto master"). Also updated the PR body's version line to match. No npm collision risk: acp-kernel's latest published release is still 0.0.101 (no kernel-v* tags exist yet).
  3. Your parallel 001e4cc83 (lock-sync of the package-lock kernel entry to 0.0.117) is byte-identical to the one I was preparing — I dropped my duplicate commit; branch head is your 001e4cc83.

⑤ Final state

CI fully green on 001e4cc83 — all 14 workflow runs success (CI matrix incl. kernel-guard/lock-sync/windows overlay, e2e-pi-codex-ws, e2e-dsh-plugin-lane, real codex, native dsh/pi/opencode, local-registry, theorem, image). PR mergeable, 0 behind master.

结构化八问(round-2 delta)

  1. 是什么问题: 上轮后新增两个提交(pi-ws 测试彩票修复 + durable 默认策略翻转),复审中发现 master 合并后 kernel-guard 红。
  2. 什么原因导致的: (a) 测试正则未锚定,GHA 检出 merge ref 时其短 SHA b288144 落在 build stamp 行被误收为 block id(概率 ≈1/1600,合并 ref 稳定故重跑必现);(b) master 已把 kernel 版本用到 0.0.116,合并后两侧同号但分支仍含新增 kernel/src 变更,guard 要求新号。
  3. 影响范围与严重程度: (a) 仅该 e2e 断言在 GHA merge-ref 检出下触发,本地/master 均不中,纯测试卫生问题;(b) 零运行时影响。严重度:体验瑕疵/仅内部。
  4. 怎么修复的: harvest 锚定到 COMPRESSED BLOCKS 段(对任何 host-stamp 形态免疫);合并后按仓库既有先例补版本号 0.0.117(+lock 同步)。
  5. 是否有回归问题: 无。既有行为逐项过:默认策略翻转是已披露的有意变更(见上 old→new);all-instance 显式 opt-in 保留且有专门 e2e;无 classifier 时字节级不变;[bug] dsh 原生压缩单轮 rebase 兜底缺失于 anthropic 线路(#2432 修复未覆盖):checkpoint 落地后 ACP 状态永久失效 #2658 红与本 diff 无关(跨分支复现证据 + 上游 test: account for the #2592 rebase ref-floor pin in the #2658 rig (unred master) #2747 已修)。
  6. 是否破坏缓存: 不涉及(未触碰缓存/重试/游标/去重键)。
  7. 是否改了设计方向: 是——durable 保护默认从「全实例钉死」转为「每身份只钉最新实例」(owner 决策 2026-10-11,pi 对齐单份活副本);四个载体均为累积快照且宿主仅在变化时重发,可见性不变式成立。
  8. 是否引入了新的配置: 无新 knob/env;仅既有 protectedTools/protectedLatestTools 的注入默认值改变。

遗留项(不阻塞本次代码判定):F1 — CONFIGURATION.md en+zh 仍缺 durable/* 值空间说明,现在需按最新-per-identity 默认 + whole-identity takeover 描述(#1947 有同款文档先例);F2 — 方向性提示不变:#2446 原始报告方是 proxy 模式,本 PR 只覆盖 dsh plugin-lane,lane-less 通道仍在开放的 #2576。按 Kernel Boundary,kernel 变更保持人工审核,合并按钮在你。

@ranxianglei
ranxianglei merged commit 8e16c89 into master Oct 11, 2026
30 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.272-master.8e16c89 (rolling master tag).

npm install -g billion-context@0.0.272-master.8e16c89  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
YunzhouLi-hub pushed a commit to YunzhouLi-hub/billion-context that referenced this pull request Oct 11, 2026
…ages — model echo cannot take over a durable identity

The four dsh carriers are host INJECTIONS into the user channel, but the
classifiers matched on contentType+text alone: an assistant message
echoing a carrier marker (<available_skills>, Instructions from:,
<mcp_catalog>, Current runtime context) projected to durable/<name> too.
Under the default latest-per-identity policy (ranxianglei#2736) the LAST match wins,
so a later model echo took the identity over from the real carrier: the
echo got pinned, the real carrier demoted to foldable, and one
compression later the forged/partial copy was the only survivor —
including the adversarial variant where an injected instruction makes
the model emit a fake <mcp_catalog> with attacker-chosen server names
(the ranxianglei#2446 failure mode, attacker-authored).

Anything visible to the model eventually shows up in its output
(bili-chain tags, ranxianglei#2483 render tags, ranxianglei#933/ranxianglei#1039 echo noise), so the gate
cannot be the marker text. Every classifier now refuses assistant-role
messages first (system/user injections stay covered); zero legitimate
protection loss — no carrier is ever emitted as assistant output.

Kernel unchanged: virtualToolPathOf stays role-agnostic by design; the
boundary belongs to the classifiers that own the evidence (KDD ranxianglei#9).

tests/issue2766-durable-role-gate.test.ts: 11 cases — per-carrier echo
never projects (individual + lane-composed), user-role still projects,
system-role still projects, collectLatestProtected keeps the real
carrier as the latest instance across a later echo, echo between two
real snapshots does not break succession.
@ranxianglei
ranxianglei deleted the 2026-10-11_durable-tool-identity branch October 15, 2026 05:33
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.

compress 增加按内容标记的硬排除(protectedContentMarkers),保护会话的基础设施注入免于折叠

1 participant