Skip to content

feat: message-level protection hook + dsh durable-state guards (skill catalog #2419, workspace instructions #2447) - #2428

Merged
ranxianglei merged 7 commits into
masterfrom
2026-10-08_message-level-protection
Oct 9, 2026
Merged

ranxianglei merged 7 commits into
masterfrom
2026-10-08_message-level-protection

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

Closes #2419
Closes #2447
Closes #2481

kernel-change: add optional Config.isMessageProtected host-programmatic predicate so plugin lanes can hard-protect non-tool messages from ACP folds

Owner pre-approval for this kernel change: #2419 thread — owner chose "B. bili/kernel 侧通用治本(推荐主轴)" after the triage analysis.

Problem

With bili enabled, DSH injects three DURABLE STATE carriers as ordinary user-role messages, each fingerprint-gated so the host sends it once per session and never resends it while unchanged:

  1. Skill catalog (开启 bili 后「规矩与 skill 好像没被使用」? #2419): the <available_skills> message from the dsh-tool-skill plugin. User forensics (开启 bili 后「规矩与 skill 好像没被使用」? #2419 attachments): catalog missing from 323/600 outbound requests; per-session survival 6–7% in long sessions vs ~100% short.
  2. Workspace instructions (dsh 车道:AGENTS.md(workspace instructions,user 消息形态)被折叠后从 wire 消失 —— 与 #2419 同类,但 #2428 白名单只覆盖 <available_skills> #2447): the merged global (~/.dsh/AGENTS.md) + project AGENTS.md baseline from @deepseek-ai/dsh-agent-instructions — one <system-reminder> user message whose sections are labelled Instructions from: <path>, re-emitted only when baselineIdentity (projectRoot + discovery/budget config, NOT file contents) changes. Field evidence (dsh 车道:AGENTS.md(workspace instructions,user 消息形态)被折叠后从 wire 消失 —— 与 #2419 同类,但 #2428 白名单只覆盖 <available_skills> #2447): folded into block b1 (m00001–m00038), absent from the summary, absent from every subsequent wire payload ⇒ hard constraints like "任何 web search/fetch 前必读 X" silently stop applying.
  3. Runtime-context snapshot (dsh 车道第三个载体:runtime-context 快照(沙箱/审批策略)同属一次性 baseline user 消息,#2428 的文本标记守卫覆盖不到 #2481): the sandbox/approval-policy state message — opens Current runtime context. (e.g. Current DSH file policy: danger-full-access … / Approval prompts are disabled in this session: … do not request sandbox escalation). Self-declared This snapshot supersedes earlier runtime-context snapshots: re-sent only when the context CHANGES, not every turn (field evidence dsh 车道第三个载体:runtime-context 快照(沙箱/审批策略)同属一次性 baseline user 消息,#2428 的文本标记守卫覆盖不到 #2481: exactly 1 occurrence across 6 turns), so one fold silently loses the session's sandbox/approval semantics — the model may then request forbidden sandbox_permissions. The sibling per-turn time-context snapshots are NOT durable (re-sent every turn) and stay foldable.

Root cause for ALL THREE = the same cross-system contract mismatch: DSH treats these as persistent state sent once (or on change); ACP treats all history as consumable; and the kernel's protection machinery only covered tool exchanges (isMessageProtected required contentType tool-call/tool-result), so host-injected durable state had NO way to survive a fold, permanently. One mechanism, three carriers — hence one PR.

Fix

Kernel (acp-kernel 0.0.109 → 0.0.110):

  • New optional Config.isMessageProtected?: (msg: CoreMessage) => boolean — host-programmatic (same discipline as the existing isToolProtected), NOT a user-facing config surface. Unset ⇒ byte-identical behavior to before.
  • The dispatcher isMessageProtected() checks it first, for EVERY content type; assignRefsNode marks matching messages with a BLOCKED ref (never advertised / foldable-by-ref), and filterProtectedToolMessages excludes them from effectiveMessageIds at apply time — they stay visible, summaries are untouched, and decompress of adjacent blocks still works.
  • New kernel/tests/message-protection.test.ts (6 tests: exclusion from direct+effective ids, content-type agnosticism, control fold without predicate, processTurn wiring ⇒ BLOCKED ref, upgrade path — refs assigned BEFORE protection still protected, entirely-protected range ⇒ clean error). Full kernel suite green on rebased head: 1281/1281.
  • Version note: master independently reached 0.0.109 (d9ce7ad) while this PR was in flight; after rebasing onto master the hook lands with its own increment to 0.0.110 (CI kernel-guard version discipline).

Host (billion-context):

Regression review (existing behaviors audited)

  • Predicate unset (every lane except dsh): byte-identical wire behavior — control tests pin that an unregistered lane folds ALL THREE carriers away exactly as before.
  • Existing protected-tools/media paths: untouched — dispatcher's first check returns false when unset; all existing kernel tests unchanged and green.
  • Golden pin tests/golden/wire-contract/kernel.json: unaffected (optional field absent from defaultConfig output); pin not regenerated.
  • Both compression modes reasoned: dsh runs PLUGIN mode (x-bili-plugin header); proxy mode unaffected because no host attaches a predicate outside the registry.
  • Rebase note: branch was rebased onto current master (4d5dab9, post-v0.1.189 release) before this push; the earlier src/server.ts → src/server/handle.ts relocation carried over cleanly, and the kernel bump moved 0.0.108→0.0.109 ⇒ 0.0.109→0.0.110 as described above. All gates re-run on the rebased head.

Behavior-change disclosure

New capability. The only behavioral change is in the dsh lane: the skill-catalog message, the workspace-instructions baseline, AND the runtime-context snapshots can no longer be folded — they stay resident across compressions. Bounded cost: DSH keeps exactly one live catalog instance per session (in-place replacement on update), ~one live baseline per session (replacement baselines only on rare identity changes, which DSH itself keeps in its own history with a "replaces all earlier baselines" intro), and runtime-context instances only appear on actual context CHANGES (~100–400 chars each, newest self-declares supersession) — no unbounded growth. All other lanes and all other messages are unchanged (pinned by the control-lane tests); per-turn time-context snapshots and approval-change deltas remain foldable by design.

Config surface

None added — programmatic host hook in the same category as isToolProtected; no new env var, config field, or CLI flag.

Tests & gates (all on rebased head b9569de)

  • kernel/tests/message-protection.test.ts (new, 6) + full kernel suite 1281/1281 green (two-layer rule: both layers green on rebased head)
  • tests/issue2419-dsh-skill-catalog.test.ts (4): unit guard+registry; dsh-lane e2e fold through real proxy (catalog survives AND requested range consumed — fold is real); control lane (unregistered agent folds the catalog away — pins scope and teeth); session-level effective-config stamping
  • tests/issue2447-dsh-workspace-instructions.test.ts (4): same four surfaces for the workspace-instructions carrier (incl. assertion that lowercase reconciliation variants stay foldable)
  • tests/issue2481-dsh-runtime-context.test.ts (new, 4): same four surfaces for the runtime-context carrier (incl. assertions that the cleared form is pinned, and that per-turn time-context + approval-change delta shapes stay foldable)
  • root typecheck clean; targeted bili suites green (20/20 across the three issue suites + dsh-persona-fingerprint); npm run build green. Full bili suite left to CI.

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-08_message-level-protection (517adb7)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2723-pr.2428.9acf019

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-pr2428.tgz
npm install -g package

Install instructions are refreshed on each push.

ranxianglei pushed a commit that referenced this pull request Oct 8, 2026
…ata (#2428)

Storing the dsh guard FUNCTION in session.metadata.effectiveConfig broke
fork/derived-child adoption: plugin.ts structuredClones that metadata and a
function throws DataCloneError -> FORK_FAILED 503 (5 #2399 fork tests red on
CI), and disk persistence cannot serialize a function either.

Stamp the clone-safe config first, then attach the guard to the turn-local
reqConfig so processTurn protects the message this turn; effectiveConfig()
re-resolves the guard from the clone-safe pluginAgent lane id at read time,
so /__bili/plugin/tool sees the same protection. Non-dsh lanes byte-identical.

Also drop the unused DurableMessageGuard export (unused-exports gate).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 核验了这个 agent PR(拉分支读代码 + 本地复现 + 定向测试),发现它把 CI 跑红了——是自己引入的两处缺陷,已在 PR 分支上补了两个 commit 修掉并 push。结论按八问:

1. 是什么问题
两件事。(a) PR 本体:给内核加 Config.isMessageProtected 消息级保护钩子,dsh 用它保住注入的 \x3cavailable_skills\x3e skill-catalog 不被 ACP fold 掉。(b) 我实际要修的:PR 交付即红——它把 guard 函数 存进了 session.metadata.effectiveConfig,而 fork/派生子会话采纳会 structuredClone 这段元数据 → DataCloneError → 5 个 #2399 fork 测试挂掉;外加一个 unused-export lint 失败。

2. 什么原因导致的
storeEffectiveConfig 把 dshSkillCatalogGuard 函数写进会话元数据;src/plugin.ts:1155(fork 采纳)对 parent.metadata.effectiveConfig 做 structuredClone,函数不可克隆 → FORK_FAILED 503 / 级联 PARENT_NOT_FOUND 404。master 上没有哪条 lane 往 stamp 的 config 里塞过函数,所以这个坑直到本 PR 才暴露。unused-export:DurableMessageGuard 类型导出了却只在本文件用。

3. 影响范围与严重程度
修复前:任何 dsh-lane 会话都无法 fork / 派生子会话(title-gen sidecar、omp/pi 式 adopt、fork endpoint)——全部 503/404。硬功能断裂,但仅限本未合并的 PR(master 无此问题)。严重度:阻塞(CI 红、fork 路径不可用),范围受限于本 PR。

4. 怎么修复的
让函数永远不落进可克隆/可持久化的元数据:先 stamp 一份 clone-safe config,再把 guard 挂到本轮局部 reqConfig(processTurn 当轮生效);effectiveConfig() 在读取时从 clone-safe 的 pluginAgent lane id 重新解析 guard,这样 /__bili/plugin/tool 也看得到同一份保护。同时删掉未用的 DurableMessageGuard 导出。纯 host 侧改动,没动 kernel/。

5. 是否有回归问题
无。非 dsh lane 逐字节不变(durableMessageGuards 只有 dsh;谓词缺省 = 行为不变)。本地已验证:原先挂的 5 个 #2399 fork 测试全绿(dsh-fork-adopt 15/15、fork-side-request-lane 1/1、pi-omp-fork-adopt 13/13),两个特性套件保持绿(kernel 6/6、host 4/4);typecheck 干净、build 绿、unused-exports gate 干净。全量回归交给 CI。

6. 是否破坏缓存
否。前缀缓存相关字节(head system、wire 形状)未动;guard 只是把 catalog 消息排除出 fold 候选。fork 快照/克隆路径现在拿到的是 clone-safe 数据(恢复 base 行为)。

7. 是否改了设计方向
否。内核钩子设计照原样(谓词在 isMessageProtected 里最先判定,流到 BLOCKED ref + effectiveMessageIds 排除)。只是 host 侧载体换了:从「函数存进元数据」改为「lane id 存进元数据、读取时重建函数」——严格更稳,顺带堵掉了「磁盘持久化无法序列化函数」这个潜在坑。

8. 是否引入了新的配置
否。无新 env/config/CLI。guard 注册表是纯代码(KDD#9 证据白名单,仅 dsh),与 PR 声明的「非用户配置面」一致。


顺手小修(独立 chore commit):package-lock.json 的 kernel 版本 0.0.108→0.0.109——作者的内核 bump 漏更了 lock,npm install 会重同步,留着不一致会让 npm ci 报错。已单独成一个标注 commit。

判定:两处 CI 回归已修、定向验证全绿,待 CI 转绿即可合并。注意本 PR 触碰了 kernel/(钩子本身),按 Kernel Boundary 仍属人工合并门禁——我这里没动 kernel/,合并权在你。已推 f8b1bab0d 到 PR 分支,CI 会自动重跑。

@ranxianglei
ranxianglei force-pushed the 2026-10-08_message-level-protection branch from 92ad586 to 8f5666f Compare October 9, 2026 01:50
ranxianglei pushed a commit that referenced this pull request Oct 9, 2026
…ata (#2428)

Storing the dsh guard FUNCTION in session.metadata.effectiveConfig broke
fork/derived-child adoption: plugin.ts structuredClones that metadata and a
function throws DataCloneError -> FORK_FAILED 503 (5 #2399 fork tests red on
CI), and disk persistence cannot serialize a function either.

Stamp the clone-safe config first, then attach the guard to the turn-local
reqConfig so processTurn protects the message this turn; effectiveConfig()
re-resolves the guard from the clone-safe pluginAgent lane id at read time,
so /__bili/plugin/tool sees the same protection. Non-dsh lanes byte-identical.

Also drop the unused DurableMessageGuard export (unused-exports gate).
@ranxianglei ranxianglei changed the title feat: message-level protection hook + dsh skill-catalog durable guard (#2419) feat: message-level protection hook + dsh durable-state guards (skill catalog #2419, workspace instructions #2447) Oct 9, 2026
@ljyzww

ljyzww commented Oct 9, 2026

Copy link
Copy Markdown

PR #2428 未进0.1.189版本吗

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 对,没进。v0.1.189 是通过 release PR #2451(分支 2026-10-09_release-v0.1.189)发布的,而 #2428 目前仍是 open、未合并(GitHub API 确认 state=open, merged=false)。所以 0.1.189 里既没有内核的 Config.isMessageProtected 谓词字段(kernel/src/types.ts),也没有 host 侧的 dsh guard(src/durable-message-guards.ts)。这个特性要等 #2428 真正合并后才会进后续版本。

一个容易看花眼的点:0.1.189 的代码里确实 already 有个叫 isMessageProtected 的函数——那是 acp-kernel v0.0.101 源码原样导入(#2092)时自带的 dispatcher 函数,和 #2428 新加的 Config.isMessageProtected 配置字段不是同一回事。所以你在 0.1.189 里 grep isMessageProtected 能搜到,但那是旧的内核机制,不等于这个 PR 的 skill-catalog 保护已上线。

顺带一提:这 PR 后来还在扩(标题现在带上 #2447 workspace instructions,head 也往前走了),仍在等合并——所以它大概率落在下一个版本,而不是 0.1.189。

awork added 6 commits October 9, 2026 15:56
…2419)

Host-declared predicate hard-protects ANY message (every content type)
from compression: BLOCKED ref in assignRefs (never advertised, never
foldable-by-ref) and exclusion from effectiveMessageIds in
applyCompression (stays fully visible, summary reflects only what was
actually folded). Unset = byte-identical behavior (only tool exchanges
and media payloads were protectable before).

Needed because hosts can inject DURABLE STATE as ordinary conversation
messages — dsh's skill catalog, which DSH fingerprint-gates and never
resends while unchanged, so folding it loses skill visibility
permanently (#2419). The existing protectedTools/isToolProtected
surface is tool-exchange-only by design and cannot express this.

Version bump 0.0.107 -> 0.0.108 (CI-enforced for kernel/src changes).
Tests: kernel/tests/message-protection.test.ts (6 cases incl. upgrade
path and entire-range veto).
…P folds (#2419)

src/durable-message-guards.ts: registry keyed by plugin-agent name;
only dsh is registered (KDD #9 evidence-permitlist discipline — the
predicate matches the <available_skills> marker on text messages,
matched alone so wrapper wording changes cannot disarm it).

server.ts: attaches the guard to reqConfig immediately before
storeEffectiveConfig so this turn's processTurn AND the stamped
effective config (read by /__bili/plugin/tool) carry it. Lanes absent
from the registry are byte-identical.

Behavior change (dsh lane only): the skill catalog message can no
longer be folded away by ACP compression — it stays fully visible.
Unregistered lanes fold it exactly as before (pinned by the control
test). See #2419 for the full chain of evidence.
…ata (#2428)

Storing the dsh guard FUNCTION in session.metadata.effectiveConfig broke
fork/derived-child adoption: plugin.ts structuredClones that metadata and a
function throws DataCloneError -> FORK_FAILED 503 (5 #2399 fork tests red on
CI), and disk persistence cannot serialize a function either.

Stamp the clone-safe config first, then attach the guard to the turn-local
reqConfig so processTurn protects the message this turn; effectiveConfig()
re-resolves the guard from the clone-safe pluginAgent lane id at read time,
so /__bili/plugin/tool sees the same protection. Non-dsh lanes byte-identical.

Also drop the unused DurableMessageGuard export (unused-exports gate).
…seline (#2447)

#2447: dsh's @deepseek-ai/dsh-agent-instructions plugin carries the merged
global+project AGENTS.md as a user-role system-reminder baseline (sections
labelled 'Instructions from: <path>'), re-emitted only when baselineIdentity
(projectRoot + discovery/budget config, NOT file contents) changes — same
durable-user-message contract as the #2419 skill catalog, second carrier
missed by the original whitelist. Extend the dsh-lane predicate with
dshWorkspaceInstructionsGuard (case-sensitive 'Instructions from:' inner
marker; lowercase reconciliation variants stay consumable). No kernel change:
the generic Config.isMessageProtected hook from #2419 already covers it.
master independently reached 0.0.109 (d9ce7ad); the isMessageProtected hook
(#2419) is a kernel/src change and must land with its own version increment
(CI kernel-guard version discipline).
@ranxianglei
ranxianglei force-pushed the 2026-10-08_message-level-protection branch from 8f5666f to b9569de Compare October 9, 2026 08:02
@ranxianglei
ranxianglei merged commit 89f0a27 into master Oct 9, 2026
28 checks passed
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.186-master.89f0a27 (rolling master tag).

npm install -g billion-context@0.0.186-master.89f0a27  # 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.

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