Repository navigation
fix: accept the kernel BLOCKED sentinel in plugin snapshot/fork validation (#2620) - #2625
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2973-pr.2625.06af539This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2625.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Reviewed #2625 (accept the kernel BLOCKED sentinel in plugin snapshot/fork validation, closes #2620). Confirmed the root cause against the kernel source, audited every touched path for regression, ran targeted suites + teeth-checks on the rebased head, and — while sweeping ① 是什么问题:任何历史里含 ② 什么原因导致的:kernel 故意把受保护消息映射到 ③ 影响范围与严重程度:仅 plugin mode、且会话含受保护工具流量时触发;该配置条件下 snapshot/fork 功能完全不可用;proxy mode 不受影响;无数据丢失、无压缩语义影响。 ④ 怎么修复的:五处都做哨兵感知校验,同时保留对真正损坏的数字映射的 fail-closed——对 ⑤ 是否有回归问题:无。五处改动都是严格泛化——对所有原本合法的(数字)输入行为逐字节不变,只有此前必然报错的哨兵现在被接受;真正损坏的数字映射仍会 throw(PR 第二个测试钉住)。无 fail-fast→吞错漂移、无阈值/时序/输出格式变化。未改动的 ⑥ 是否破坏缓存:否。只动 snapshot/fork 校验;压缩、CCR 去重、重试、revision 缓存策略均未变。 ⑦ 是否改了设计方向:无架构转向——host 侧对齐既有 kernel 不变量的哨兵感知。一处已披露的 wire 变更:plugin snapshot/fork 协议新增接受字面量 ⑧ 是否引入新配置:无。 Review 中在分支上补修的一处(additive commit 验证(定向、rebased head 上跑;全量套件 + e2e 门禁交给 CI):typecheck 干净; 备注:本改动触碰 wire/message-shape + message-ref/id 逻辑 → §7.4 人工门禁(不自动合并),需人工 merge。PR 提到的 判定:可合(我补的修复 |
…2605) tests/issue2605-dsh-retry-patch.test.ts reads the patch file raw and byte-matches multi-line rows; Git-for-Windows autocrlf=true converts it to CRLF at checkout, failing both windows CI shards on every run since #2610 landed (master red at 98fb91c, run 38034641775). Same mechanism as the #1305 golden pin above. In-passing fix carried on #2625.
1bc881f to
9136c63
Compare
[bot] 🏷 收到上游 PR 冲突转发(merge state: dirty)。先按纪律用 git 核实而非照单执行——结论:这个冲突已经被 owner 用 rebase 自行解决了,我这边无需再 push 任何内容(也没有强推覆盖分支)。结构化说明如下: ① 是什么问题:#2625 与 master 出现文本冲突,唯一冲突点是 ② 什么原因导致的:两个 PR 针对同一个 Windows CRLF 失败类各自往 ③ 影响范围与严重程度:仅阻塞本 PR 合并(dirty merge state),不影响任何已发布行为、运行时或数据。低危。 ④ 怎么处理的:fetch 后发现远端 head 已是 ⑤ 是否有回归问题:无。关键验证: ⑥ 是否破坏缓存:不涉及(纯分支历史 / 文件属性整合,未触碰压缩、重试、去重或增量游标)。 ⑦ 是否改了设计方向:不涉及。 ⑧ 是否引入新配置:不涉及。 判定:冲突已由 owner 的 rebase 清除,本 PR 现在处于干净可合状态,无需我再操作。 仍需人工合并——本改动触碰 wire/message-shape + message-ref/id 逻辑,按 §7.4 属人工门禁,不自动合并。 |
|
重新做了 你再审核一下 之前的问题很大你没有拦住 |
[bot] 🏷 重新审核完成(head 重做方案( 逐点核实(都过了):
本地证据(head 八问:
判定:重做正确、完整、干净,且比初版更安全(彻底关闭了 |
…me-adoption applier applyForkAdoption re-derived byRef from plan.refs.byRaw, which still carries the shared BLOCKED sentinel entries (planForkAdoption guards byRef but not its byRaw sibling), so a #1486 resume of a parent with protected tool traffic reintroduced byRef["BLOCKED"] - the exact state this change removes at every other site. Guard the applier write to match, and pin it with a unit regression.
…wire (#2620) Owner review: accepting the kernel BLOCKED sentinel at six scattered validation sites was a band-aid — the protocol borrowed a kernel-internal constant as its own vocabulary, and every future consumer would have to re-learn the special case. The clean model: ref is optional in the protocol itself. The renderer maps the kernel sentinel to null at the single boundary; validation uniformly treats null as 'intentionally unaddressable' and keeps strict bidirectional checks for numeric refs (genuine corruption still fails closed); fork requests accept only mNNNNN or null (stricter than before for garbage). The sentinel now appears nowhere in wire bytes and only at the boundary mapping in host code. Compat: non-protected sessions are byte-identical; protected sessions had no working consumer path pre-fix (all 409/400), so swapping the literal before merge costs nothing. New proxy + old agent degrades gracefully (snapshot rejected -> adoption degrades, the pre-fix behavior); old proxy + new agent unaffected. PLUGIN.md documents the null value (en+zh).
b663386 to
7082175
Compare
|
Rebased this PR onto current master (6dafceb → 9e95c32 ancestry; the only conflict was the Stacked on top: #2729 (session-continuity proof pinning both branch scenarios — model switch = one session, fork = copied state; its scenario B teeth reproduces this PR's fix target as a 409 on master-without-this-PR). |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.257-master.e9efe63 # this exact build
npm install -g billion-context@master # always the newest merged build
|
…lei#2601/ranxianglei#2676) Scenario A pins the model-switch contract: a dsh model switch (system model line + x-bili-plugin-model header) landing in the same window as an unannounced history rewrite is ABSORBED — raw key kept, no |sub: fork, kernel machinery (compress → decompress) still works on the same session; the uncorroborated control still forks. Scenario B pins the fork contract: a fork with context COPIES the parent's state — inherited blocks (ids + summaries + originals, child decompress round-trip), seeded raw→ref map equal to the parent's, the durable-guard lane adoptable (null wire refs, BLOCKED never in byRef), parent untouched. A/B teeth: pre-ranxianglei#2719 master mints the fork (scenario A red); master without ranxianglei#2625 fails scenario B with 409 raw/ref mapping inconsistent — the ranxianglei#2676 silent degrade.
…itter shape (ranxianglei#7153) The ranxianglei#7153 carrier gates require the complete <system-reminder> frame around the workspace-instructions label, but two runtime fixtures still carried the bare label, so their guard message stopped classifying as durable/agents-md and was no longer pinned: the wire handed out a real ref where null was asserted. - tests/plugin-fork.test.ts (ranxianglei#2676): the durable-guard history row now carries the frame dsh-agent-instructions emits. - tests/session-continuity-proof.test.ts (ranxianglei#629/ranxianglei#2620/ranxianglei#2625/ranxianglei#2676): GUARD_TEXT likewise; the scenario-B fork-copy assertions are unchanged. CI was red on the one assertion in each file (ubuntu 22/3, ubuntu 24/3, windows 22/1, windows 22/4).
Closes #2620
What
With
compress.protectedToolsmatching a tool call/result in plain-text history,GET /__bili/plugin/snapshotreturned 409{"code":"SNAPSHOT_UNAVAILABLE","error":"Error: raw/ref mapping inconsistent"}— so any session containing protected tool traffic could not be snapshotted or forked by plugin agents at all (andsessionRevision/expectedRevisionpaths threw the same way).Root cause
The kernel deliberately maps protected messages into an unaddressable state: no numeric ref is issued, and
byRefnever holds them (kernel/src/refs.tsassignRefs). That is intended design — protected messages are never rendered, never CCR-stored, never foldable. The consumer bug is on the host side: the plugin protocol assumed every message has exactly one bidirectionalbyRaw ↔ byRefref pair (a total function) and classified the kernel's partial-function state as corruption.Fix (host-side only, no kernel change)
The clean model, per owner review: ref is optional in the protocol itself. The wire expresses "intentionally unaddressable" as
ref: null— the kernel's internal sentinel never appears in any wire byte, and no consumer special-cases a magic string:src/plugin.tsforkSnapshot(the reported 409 site) — the single boundary that maps the kernel sentinel tonull; numeric refs keep the strict bidirectional check, so genuinely corrupted mappings still throw.src/plugin.tsparseForkRequest— accepts onlymNNNNNornullper entry (stricter fail-fast than before for garbage strings).src/plugin.tschild ref copy-back —nullreserves the raw id under the kernel sentinel exactly as the parent holds it;byRef/tokenSnapshotstay pure numeric-ref spaces.src/plugin.tsCCR clone path — skips unaddressable entries (they have no store payload by construction).src/fork-adoption.tsplanForkAdoption+applyForkAdoption(Claude 上 resume 导致消息错乱 #1486 resume lane) — the internal plan/applier keep the same invariant: the sentinel may live inbyRaw, must never be written intobyRef. Pinned with unit regressions.src/agent/fork-adopt.ts— client type/parser widened tostring | null; matching and hashing are identity-based (identityHashexcludes refs), sonullflows through untouched. Hash-parity replicas unchanged.PLUGIN.md(en+zh) — documentsnullas the only other legal ref value.Forgery safety is unchanged: fork POSTs are still checked byte-for-byte against the live parent snapshot (
stableJson(prefix) === stableJson(request.orderedMessages)), so a forged ref for a numbered message failsBRANCH_POINT_CONFLICT; multiple unaddressable messages stay distinguishable via rawId + identityHash + order.Behavior change (disclosed)
Sessions with protected tool traffic go from unusable snapshot/fork (409 snapshot / 400 fork request / 409
FORK_PREFIX_CONFLICTchild first request) to fully usable, with protected messages carrying"ref": nullinorderedMessages/messages. Non-protected sessions are byte-identical — every previously-valid input behaves identically. No compression semantics, config fields, persistence format, or upstream wire changes. No new config surface.Cross-version matrix: new proxy + old agent → old agent rejects the snapshot and adoption degrades gracefully (exactly today's pre-fix behavior); old proxy + new agent → unaffected (
nullsimply never arrives). No released build ever emitted the intermediate"BLOCKED"literal this design replaced pre-merge, so there is nothing to migrate.Verification (on rebased head = current master)
tests/plugin-fork.test.ts: (1) protected-on A/B history with twoask_user_questionpairs → snapshot 200 with exactly fournullrefs, an explicit assertion that the string"BLOCKED"never appears on the wire, fork 201, child identity identical, childbyRef["BLOCKED"]stays undefined, child continuation request 200, status revision present — reproduced the exact issue 409 body pre-fix; (2) genuinely corrupted numeric mapping still rejected with 409raw/ref mapping inconsistent. Unit regression intests/fork-adoption-plan.test.tspins the applier facet.plugin-fork,fork-adoption-plan,fork-adoption,dsh-fork-adopt(hash-parity contract),fork-ccr-adoption,pi-omp-fork-adopt,fork-side-request-lane,opencode-fork-adopt,side-lane-invariants,resume-ref-inheritance,resume-adoption-wires,protected-tools.npm run typecheckclean.dist/passes the issue's own stdlib-only Python repro end-to-end:protectedTools: []→ 200 and["ask_user_question"]→ 200 (previously 409).Notes
.gitattributesLF pin fordsh.bundle.patch.yml(the Windows byte-exact gate red since fix: retry MALFORMED_RESPONSE on DSH built-in DeepSeek routes (#2605) #2610 landed). That problem has its own home and is already fixed on master (Windows CI 全红:#2610 新增的 bundle-patch 测试对 CRLF 签出的 yml 做字节级精确匹配(.gitattributes 未覆盖) #2631 → PR fix: pin dsh.bundle.patch.yml to LF + normalize CRLF before byte-exact includes (#2631) #2634, merged as 7cf6796), so the duplicate commit was dropped during the rebase onto master — no EOL changes remain in this diff.package-lock.jsoncurrently lags the committed vendored versions (acp-kernel0.0.110 vskernel/package.json0.0.112;billion-context-pi-subagents0.1.3 vs 0.1.4). Pre-existing cosmetic drift —file:links self-heal on anynpm install; left out of this diff deliberately.