Skip to content

fix: downgrade ACP body-artifact detection to advisory (#1357) - #1364

Merged
ranxianglei merged 3 commits into
masterfrom
2026-09-26_advisory-chain-detection
Sep 26, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-09-26_advisory-chain-detection

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Summary

Phase 1 of #1357: make ACP body artifact detection advisory-only, so literal ACP tags / ACP tool-name invocations in a client's normal history can no longer permanently force a fresh proxy session into verbatim passthrough.

Root cause

When an inbound request carried ACP-shaped content (render <acp> tags or ACP tool-name invocations such as acp_status) and had no x-bili-hop header and had no local compression state, the proxy judged it a foreign bili→bili chain and forwarded it byte-identical (forward(..., prepared=null)), once per session, creating no session record. Because that content lives in the client's re-sent history, every subsequent request re-triggered the same verdict — locking the session into passthrough forever. Compression never engaged for any conversation containing literal ACP syntax (e.g. an AGENTS.md example), even though those tags are just user-authored text.

Change

  • src/server.ts: the content-fallback branch (artifactSeed, no hop marker, no local state) no longer returns passthrough. It records the chain verdict (once per session) and logs a single [chain] … advisory-only … (#1357) warn, then falls through to processTurn so the session establishes its own state. The x-bili-hop decisive verbatim-passthrough path is unchanged.
  • src/plugin.ts: the /acp diagnostics surface is repurposed from chain-passthrough to chain-advisory (a content-detected conversation now owns a real session; /acp shows its actual activity).

Behavior change (old → new)

Case Before After
Fresh session, ACP content in history, no hop header, no local state byte-identical passthrough, no session record, permanent lock-in processed normally; session owns its own state; one advisory warn/session; real /acp activity
x-bili-hop present verbatim passthrough (decisive) unchanged

Disclosed tradeoff: a header-stripping bili→bili relay may now double-process until signed chain proof ships (Phases 2/3 of #1357, out of scope here). Acceptable because the common case — direct clients whose history merely contains ACP-looking text — is far more frequent and was silently broken before.

Tests

Pre-flight (rebased onto current master @ v0.1.153, deps synced via npm ci)

  • npm run typecheck — exit 0
  • npm test — 2648 tests, 2637 pass, 0 fail, 11 skipped
  • npm run build — success

Fixes #1357

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-26_advisory-chain-detection (6588fb0)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1364

Each push to this PR publishes a new version under the pr-1364 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1364.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] 🏷 On it — this is a [PR] tracking issue for branch 2026-09-26_advisory-chain-detection (9c20239). I'm doing the standard PR review pass: original-issue direction check (#1357), regression review of the touched paths, code + test-validity review, diff cleanliness, plus local typecheck/test/build verification. Will report the full conclusion here shortly.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

PR Review — #1364 (Phase 1 of #1357): ACP body-artifact detection → advisory-only

① Direction (原 issue) — Verified against #1357's design and its owner-approved migration plan (floor 3). Root cause confirmed: the old content-fallback branch returned forward(..., prepared=null) before any session existed, so a fresh conversation whose history merely contained literal ACP tags (the AGENTS.md example, injected by clients as ordinary user text) could never acquire ownership state — every subsequent request re-triggered the same verdict, locking the session into byte-identical passthrough forever with compression silently disabled. The fix changes the decision point itself (the producer of the defect), not a downstream mask, and the scope is exactly Phase 1 ("downgrade content-artifact detection to warning-only"; x-bili-hop stays the sole decisive signal). Phases 2/3 (signed proof) correctly out of scope.

② Regression review — existing-behavior inventory for every touched path:

③ Code review: fall-through is correct — recordChainVerdict keeps exactly one warn per session (first-write-wins map, FIFO cap), then the request proceeds to getSession/processTurn and establishes ownership. No payload rewriting anywhere (wire fidelity intact). Both compression modes reasoned through: plugin mode short-circuits before the advisory branch (unaffected); proxy mode is the changed path. No config-schema, persistence-format, or acp-kernel pin changes.

④ Test validity: updated T3/T8/T12/#1218 have teeth — assert.notEqual(captured.body, raw) fails if the old passthrough ever regresses, peekSession(...) !== undefined pins ownership, exactly-one-warn retained. New T13 (Responses wire) + T14 (Anthropic wire) complete the required matrix (Responses + OpenAI Chat + ≥1 non-OpenAI); the fixture uses the verbatim AGENTS.md tag shape both inline and inside a fenced code block — the acceptance criterion is met.

⑤ Diff cleanliness: 3 files, +196/−59; every line relates to the PR's purpose; no lockfile churn, no version bump.

Verification

  • Local (branch checked out at PR head, rebased onto current master, npm ci): typecheck exit 0 · build success · npm test → 2648 tests / 2637 pass / 0 fail / 11 skipped (matches the claimed pre-flight).
  • CI on original head 9c20239: fully green (test ubuntu/windows × 22+24, build-artifact, e2e, hermetic registry e2e, pi/codex lane tests, version-guard).

Direct fixes applied on the PR branch (labeled commits, docs-only):

  • 2fe768e3 — the comment block at src/server.ts:1655-1661 still described the removed decisive contract ("forward verbatim and create no session state… returning before getSession…"); rewritten to the advisory semantics so the hot-path comment can't mislead the next reader.
  • cf48bb7d — the BILI_CHAIN_CONTENT rows in CONFIGURATION.md + CONFIGURATION.zh-CN.md still said such requests "are passed through verbatim instead of being processed again"; now document the advisory semantics plus the disclosed double-processing trade-off (zh/en kept in sync).

CI is re-running on new head cf48bb7d (current mergeable_state: blocked is pending-checks, not a conflict). Per §7.4 this touches wire-decision semantics, so it is not auto-merge eligible — human merge required: #1364


中文摘要:审查了「ACP 正文产物检测从决定性降级为仅告警」这一改动——方向与 #1357 owner 批准的方案一致(x-bili-hop 仍为唯一决定性信号),触碰路径的既有行为逐项核对无意外回归,测试有牙且覆盖三条 wire;已在 PR 分支直接补了两处过时的注释/文档(server.ts 注释块与 CONFIGURATION 中英文的 BILI_CHAIN_CONTENT 行),可以合并(需人工合并)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

深审通过(独立验证,零改动):

设计核验(#1357 Phase 1 语义翻转正确):历史 ACP 内容从"外国链→强制 passthrough"降级为advisory 观测——请求正常处理、会话自建压缩状态。这是把 #1218 时代的判决从"看见即逃逸"改成"看见但不动手",根因(字面量 tag 被当成 bili 自己的链)在源头松绑。

  • /acp 面板三客户端(pi/dsh/opencode)统一渲染 advisory 面板,phase 字段保留给程序化消费
  • 旧测试(20 条,-37 行)按新契约重写——不是删覆盖,是翻转断言方向

实测:issue1086-chain-self-exemption 20/20。

非阻塞观察:Phase 2(若需要)是链证据的持久化净化;当前 advisory 面板每会话首见显示一次,无噪音累积问题。

合并无阻塞。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

收到深审结论,谢谢。补一条我这边推送文档修正后(cf48bb7d)的 CI 状态,供合并前参考:

CI on cf48bb7:10/11 绿,唯一红项是已知负载型 flake,与本 PR 无关

  • 红项:test (ubuntu-latest, 24) → ✖ watcher route: shared proxies take watcher registrations, daemons refuse (#7),AssertionError: 200 !== 409 at tests/claude-native.test.ts:1132(daemon 拒绝 watcher 注册的断言)。
  • 判定为 flake 的证据链:
    1. 该测试是 tests/claude-native.test.ts 里 7 个真实起进程/live-proxy 子测试之一,tests/claude-native.test.ts linux live-E2E subtests fail/hang in shared multi-agent sandboxes #1248(已由 test: gate claude-native live e2e subtests behind ACP_TEST_CLAUDE_NATIVE (#1248) #1253 修复)专门记录过这一类在并发负载下随机失败——它的 skip 理由原文就是 "live proxy/process e2e; flaky under concurrent load, tests/claude-native.test.ts linux live-E2E subtests fail/hang in shared multi-agent sandboxes #1248"。CI 里刻意保持开启(ACP_TEST_CLAUDE_NATIVE=1)正是因为 runner 专用。
    2. 同一提交在 ubuntu-22 / windows-2022 / windows-2025 三个 test 腿以及 build-artifact、codex e2e、hermetic registry e2e、pi/codex lane、version-guard 全部通过;失败腿的日志显示该 runner 当时高负载(多个 15–23s 的 hook e2e 并行)+ ENOSPC: no space left on device。
    3. 本 PR 功能零改动(仅 src/server.ts 一处过期注释 + CONFIGURATION.md/.zh-CN.md 两行文档),不触碰 claude-native watcher 路由或其测试文件。
  • 本地复跑:该测试默认门控(skip-by-design,需 ACP_TEST_CLAUDE_NATIVE=1);全量套件本地绿(2648 tests / 2637 pass / 0 fail / 11 skipped,与 PR 声称一致)。

建议:Actions → run 36174432828 → Re-run failed jobs 即可;若 ubuntu-24 上再次复现同一断言,值得给 #1248 开一个跟进(单点数据 + 已有覆盖,我这次没有另立 issue)。

其余无阻塞项。按规则合并由人工执行:#1364

中文摘要:PR 本体审查通过且已直接补了两处过期文档(注释+中英配置行),当前唯一 CI 红灯是 #1248 记录过的 claude-native 负载型 flake(同代码其他三平台全绿、本 PR 零功能改动),建议重跑失败腿后即可人工合并。

@ranxianglei
ranxianglei force-pushed the 2026-09-26_advisory-chain-detection branch from cf48bb7 to d4c75ec Compare September 26, 2026 01:59
@ranxianglei

Copy link
Copy Markdown
Owner Author

冲突已解 + CI 失败定性,新 head d4c75ec:

冲突:纯文档行竞争——master 的 #1212 新增 BILI_CONFLICT_SCAN 行 × 本 PR 改写的 BILI_CHAIN_CONTENT 行(zh/en 两处)。并集解:两行都保留,CHAIN_CONTENT 取本 PR 的 #1357 advisory 新语义。三个代码 commit 全部干净落在当前 master 上(本 PR 与 #1371/#1383 动的是 plugin.ts 不同函数,无语义交叠)。

CI 失败定性:唯一红 = ubuntu-latest/24 单平台(ubuntu-22/24 的 Windows、四个 e2e 全绿)。rebase 后本机全量 2752 测试 0 败(2740 过 + 12 e2e 门控 skip)、typecheck/build 绿——无平台特异失败可复现,按 flake 处理;新 head 的 CI 全量重跑会给出裁决。

等 CI 绿即可合。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

新 head d4c75ec 独立核验完毕,CI 已全绿:

Rebase 内容核验(逐条对过)

CI on d4c75ec:13/13 全绿——包括此前唯一红项 test (ubuntu-latest, 24)。同一测试腿在新 head 直接通过,实证了 flake 定性(负载型,非平台特异、非本 PR 引入)。

无遗留项,可以合并(人工执行):#1364

中文摘要:rebase 后的新 head 经独立核验(冲突并集解正确、功能代码完好、diff 收敛)+ CI 13/13 全绿且原红腿转绿,确认无阻塞,可合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Heads-up while working #1395 (Step 2, PR #1397): this PR's CI is red and its base is stale.

  • CI: on head d4c75ec8, test (ubuntu-latest, 24) fails with a real assertion error in tests/issue1086-chain-self-exemption.test.ts — case "first request to new session passes through unchanged": expected captured.length === 1 but got 2 (the first request of a fresh session reached upstream twice instead of passing through untouched).
  • Base: 8172c049 is behind current master (36d654ff = v0.1.154 release; code-wise one docs merge ahead). Worth rebasing onto master and re-running before merge — if the assertion still fails post-rebase it's a genuine test/logic issue in the advisory path, not drift.

Also noting for the record: #1395's OP describes Step 1 as "已由 PR #1364 修复关闭", but the PR is still open/unmerged — master's chain gate is still the decisive passthrough (src/server.ts:1659-1681). My Step 2 PR (#1397) is additive shadow-only infra and coexists with either state; no dependency between the two beyond eventual sequencing.

@ranxianglei

Copy link
Copy Markdown
Owner Author

#1417 批次深审 + rebase 交付(reviewer delegate 双核):

判定:可合(行为改变=有意设计,已声明)

干什么/动机:#1357 Phase 1 —— 把 "inbound body 带 ACP 形产物 + 无 hop 头 + 无本地状态" 的判决从致命透传(会话永久 passthrough、永不压缩,#1357 报的坑)降级为advisory 告警(照常处理、建状态、正常压缩);/acp 面板显示 ℹ️ advisory 观察行。

四轴:压缩行为=修复(以前这类会话根本不压)、cache 命中=正常处理后才谈得上、推荐列表/压缩质量=零触碰。x-bili-hop 头存在时的字节透传原样保留。

rebase 内容(新 head 2b6ed75,3 commits,7 files +227/−83)

  1. master 吸收冲突按 union-of-intent 解(ccrLoopConfig/absorbBlock 新签名保留,advisory 语义叠加)
  2. 修 T2 与 [Bug] bili omp 扩展 stampPromptCacheKey 无条件注入顶层 prompt_cache_key —— 严格 schema 上游(opencode zen anthropic 端点)全量 400 #1403(pck scrub)的测试语义冲突
  3. 修三处旧注释漂移(config.ts ×2、scrubAnthropicPck 头注释仍教 "verbatim passthrough")
  4. zh/en 文档行同步 advisory 语义 + BILI_CHAIN_CONTENT=0 行为

门禁(rebase head 实测)

typecheck ✅ / 2810 测试 0 败(12 skip)/ build ✅。语义幸存六项核查(advisory 无透传/面板/hop 透传未动/自免豁免/BILI_CHAIN_CONTENT=0/master 重构保留)全过。

已声明的权衡(非阻塞)

剥掉 x-bili-hop 的真 bili→bili 中继会被双重处理(两边都压)——代码注释+文档已声明,根治= #1395 Phase 2/3 签名链证明。phase 值 chain-passthrough→chain-advisory 重命名对程序化消费者理论可见,但旧 phase 只在无会话态出现,风险极低。

CI 绿后即可合。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

新 head 2b6ed758 独立核验完毕(逐条对过 diff),CI 已全绿:

Rebase 内容核验

CI on 2b6ed75:13/13 全绿(test ×4 平台、e2e、hermetic registry e2e、四条 lane、build-artifact、version-guard)。

无遗留项,可以合并(人工执行):#1364

中文摘要:rebase 后的新 head 经独立核验(union 解法正确、#1403 不变量保留且 T2 按 advisory 契约带牙改写、三处注释漂移已修、核心语义幸存)+ CI 13/13 全绿,确认无阻塞,可合并。

ework-agent added 3 commits September 26, 2026 21:21
A fresh proxy session whose history carried ACP-shaped content (render tags or ACP tool-name invocations) with no local state was judged a foreign bili chain and forwarded byte-identical (prepared=null), once per session, with NO session record created. Because that content persists in the client's re-sent history, the session was locked into passthrough forever -- compression never engaged for any conversation containing literal ACP tags (e.g. an AGENTS.md example), even though those tags are just user-authored text.

Phase 1 of #1357: make ACP *body* artifact detection advisory-only. When such artifacts appear without x-bili-hop and without local compression state, log one observation per session and let the request enter processTurn so the session establishes its own state. The x-bili-hop header remains authoritative verbatim passthrough (unchanged). The /acp diagnostics surface is repurposed from chain-passthrough to chain-advisory.

Behavior change (old -> new): content-detected fresh session went from byte-identical passthrough / no session record / permanent lock-in, to processed normally (session owns its own state) with one advisory warn and real /acp activity. Tradeoff: a header-stripping bili->bili relay may now double-process until signed chain proof ships (Phases 2/3, out of scope).

Tests: T3/T8/T12/#1218 updated to the advisory contract; added Responses-wire and Anthropic-wire regression tests; the regression fixture uses the verbatim AGENTS.md tag shape inline plus inside a fenced code block.

Fixes #1357
@ranxianglei
ranxianglei force-pushed the 2026-09-26_advisory-chain-detection branch from 2b6ed75 to 6588fb0 Compare September 26, 2026 13:21
@ranxianglei

Copy link
Copy Markdown
Owner Author

Rebased onto current master (head 6588fb0): the docs conflicts were row competition with #1397's two chain-checkpoint knobs — resolved as a union (this PR's rewritten BILI_CHAIN_CONTENT row describing #1357 advisory semantics + master's BILI_CHAIN_MAX_FUTURE_SKEW_MS / BILI_CHAIN_RECENT_WINDOW_MS rows). No code changes were needed; 40409f3/9834eaa apply cleanly.

Gates: typecheck clean, tests/issue1086-chain*.test.ts 20/20.

Semantics recap for the merge decision (unchanged by the rebase):

@ranxianglei
ranxianglei merged commit 3615108 into master Sep 26, 2026
13 checks passed
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

新 head 6588fb0c 独立核验完毕,CI 已全绿:

Rebase 内容核验

CI on 6588fb0:13/13 全绿(test ×4 平台、e2e、hermetic registry e2e、四条 lane、build-artifact、version-guard)。

语义结论与你贴的 recap 一致:hop → 硬透传不变;无 hop 的 ACP 形产物 → 单次 advisory warn + 正常处理;BILI_CHAIN_CONTENT=0 整体关闭检测;trade-off(剥头中继可能双处理,至 #1395 step 3 落地)已在注释+文档声明。

无遗留项,可以合并(人工执行):#1364

中文摘要:第四次 rebase 后的新 head 经哈希级比对确认代码/测试贡献与已审版本逐字节一致、文档三行并集正确且文案未变、CI 13/13 全绿,确认无阻塞,可合并。

@ranxianglei
ranxianglei deleted the 2026-09-26_advisory-chain-detection branch October 15, 2026 05:32
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.

bug(chain): ACP tag literals in normal history can permanently force fresh proxy sessions into passthrough

1 participant