Repository navigation
feat: message-level protection hook + dsh durable-state guards (skill catalog #2419, workspace instructions #2447) - #2428
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2723-pr.2428.9acf019This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2428.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…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).
[bot] 🏷 核验了这个 agent PR(拉分支读代码 + 本地复现 + 定向测试),发现它把 CI 跑红了——是自己引入的两处缺陷,已在 PR 分支上补了两个 commit 修掉并 push。结论按八问: 1. 是什么问题 2. 什么原因导致的 3. 影响范围与严重程度 4. 怎么修复的 5. 是否有回归问题 6. 是否破坏缓存 7. 是否改了设计方向 8. 是否引入了新的配置 顺手小修(独立 chore commit): 判定:两处 CI 回归已修、定向验证全绿,待 CI 转绿即可合并。注意本 PR 触碰了 |
92ad586 to
8f5666f
Compare
…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).
|
PR #2428 未进0.1.189版本吗 |
[bot] 🏷 对,没进。v0.1.189 是通过 release PR #2451(分支 一个容易看花眼的点:0.1.189 的代码里确实 already 有个叫 顺带一提:这 PR 后来还在扩(标题现在带上 #2447 workspace instructions,head 也往前走了),仍在等合并——所以它大概率落在下一个版本,而不是 0.1.189。 |
…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.
8f5666f to
b9569de
Compare
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.186-master.89f0a27 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #2419
Closes #2447
Closes #2481
kernel-change: add optional
Config.isMessageProtectedhost-programmatic predicate so plugin lanes can hard-protect non-tool messages from ACP foldsOwner 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:
<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.~/.dsh/AGENTS.md) + project AGENTS.md baseline from@deepseek-ai/dsh-agent-instructions— one<system-reminder>user message whose sections are labelledInstructions from: <path>, re-emitted only whenbaselineIdentity(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.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-declaredThis 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 forbiddensandbox_permissions. The sibling per-turntime-contextsnapshots 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 (
isMessageProtectedrequired 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):
Config.isMessageProtected?: (msg: CoreMessage) => boolean— host-programmatic (same discipline as the existingisToolProtected), NOT a user-facing config surface. Unset ⇒ byte-identical behavior to before.isMessageProtected()checks it first, for EVERY content type;assignRefsNodemarks matching messages with a BLOCKED ref (never advertised / foldable-by-ref), andfilterProtectedToolMessagesexcludes them fromeffectiveMessageIdsat apply time — they stay visible, summaries are untouched, anddecompressof adjacent blocks still works.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.Host (billion-context):
src/durable-message-guards.ts: registry keyed by agent name, currently registering onlydsh(KDD release v0.1.2 #9 evidence-permitlist discipline — never enabled wholesale). The dsh entry ORs three shape guards:dshSkillCatalogGuard(开启 bili 后「规矩与 skill 好像没被使用」? #2419): text messages containing<available_skills>(hex-escaped literal).dshWorkspaceInstructionsGuard(dsh 车道:AGENTS.md(workspace instructions,user 消息形态)被折叠后从 wire 消失 —— 与 #2419 同类,但 #2428 白名单只覆盖 <available_skills> #2447): text messages containing the inner per-file labelInstructions from:(case-sensitive on purpose — reconciliation change messages use lowercase variants like "Updated instructions from:" that remain ordinary consumable history). Marker-over-wrapper matching so intro/wrapper rewording cannot silently disarm the guard; a false positive is benign (the message simply stays visible). At most ~one such baseline lives per session (replacements are rare identity changes), so pinning every match is bounded.dshRuntimeContextGuard(dsh 车道第三个载体:runtime-context 快照(沙箱/审批策略)同属一次性 baseline user 消息,#2428 的文本标记守卫覆盖不到 #2481): text messages containingCurrent runtime context— matches BOTH emitter variants (snapshot formCurrent runtime context. This snapshot supersedes…and cleared formCurrent runtime context: none. Earlier runtime-context snapshots no longer apply., source: deepseek-harness MITpackages/core/agent-loop/src/runtime-context.ts; same stable prefix bili already verified under 会话标题被自动注入的系统通知占用,无法反映真实会话内容 #2286 inAUTO_INJECTED_NOTIFICATION_PREFIXES). The cleared form MUST be pinned too: it invalidates older snapshots, so folding it would leave a stale pinned policy looking current. Pinning cost bounded: ~100–400 chars per instance, newest carries the supersedes clause. Deliberately NOT pinned: the transient approval-change delta (The approval policy changed from …) — the current approval state rides in the snapshot'sapproval:policysection, and no loss of the delta itself has been observed (evidence-permitlist discipline).source.kindthese hosts stamp internally (dsh 车道第三个载体:runtime-context 快照(沙箱/审批策略)同属一次性 baseline user 消息,#2428 的文本标记守卫覆盖不到 #2481 suggestion):source.kindlives only in DSH's own session store — the proxy wire carries no per-message metadata field (CoreMessagehas none), so the criterion must be a stable text marker at this layer. ExtendingCoreMessagewould be a new kernel data-shape change for no added robustness here (the markers above are emitter-stable and already verified against upstream source).src/server/handle.ts:reqConfig.isMessageProtectedset immediately BEFOREstoreEffectiveConfig, so this turn's processTurn, overflow refolds, and the stamped effective config read by/__bili/plugin/toolall see it.effectiveConfig()re-resolves the guard from the lane id at read time (functions must never be persisted into session metadata — fork-adoption structuredClone + disk persistence, fixed in 978cf87).Regression review (existing behaviors audited)
tests/golden/wire-contract/kernel.json: unaffected (optional field absent fromdefaultConfigoutput); pin not regenerated.x-bili-pluginheader); proxy mode unaffected because no host attaches a predicate outside the registry.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-contextsnapshots 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 stampingtests/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)npm run buildgreen. Full bili suite left to CI.