Skip to content

fix: chain content-fallback false positives — tags scoped to history, plugin-announced exemption (#1197) - #1213

Merged
ranxianglei merged 2 commits into
masterfrom
2026-09-24_chain-tags-provenance
Sep 24, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-09-24_chain-tags-provenance

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #1197 (root cause + full evidence chain in the issue comment).

What

Two layers, both at the root cause:

  1. Tags-family detection scoped to HISTORY message content (src/server/chain-artifacts.ts). bili's compression artifacts (render tags, re-voiced acp_summary, plugin compress tool results) always live in history items — never in the system/developer/instructions section. Tag-shaped text there is client-authored context (AGENTS.md/CLAUDE.md/README quoting the wire format — the billion-context repo itself carries literal examples) and is not chain evidence. Unparseable bodies keep the legacy whole-buffer scan.
  2. Plugin-announced requests (x-bili-plugin header) are exempt from the content fallback (src/server.ts verdict site). The plugin protocol RE-SENDS bili's compression artifacts by design (the compress tool call + result live in the agent's own re-sent history), so a resumed plugin session can never be a "chain" verdict on content shape alone. The [Bug] 链检测把 bili 自己注入的 ACP 产物判成 bili→bili 链 —— 压缩内核永久跳过,长会话撞 1,048,576 上限 400(v0.1.133 回归) #1086 fallback still guards non-cooperative clients (T3 byte-identical passthrough preserved); the hop-marker path is unchanged.

Why

The #1197 incident: a fresh TUI session in a billion-context checkout (AGENTS.md carries literal tag examples) was permanently verdict-ed into verbatim passthrough — the kernel never ran (silent loss of compression) and /acp stuck on "No model request yet" forever. Reproduced byte-for-byte on 0.1.139 and master; after this fix the same scenario binds the real pi session id, runs processTurn, and /acp resolves.

Tests

+5 in tests/issue1086-chain-self-exemption.test.ts:

  • detector: tags in system-role / developer-role / anthropic top-level system / responses instructions → NOT artifacts
  • detector: tags in tool results and user messages → still artifacts
  • T10: system-prompt tags on a fresh plain-client session (enabled store, no state) → processed, no warn
  • T11: plugin-announced request with history artifacts (enabled store, no state) → processed, no warn, session created

All pre-existing #1086/#1100/#1101 tests (T1–T9, incl. T3 real-chain passthrough) unchanged and green.

Pre-flight

  • npm run typecheck ✓
  • targeted: chain tests 16/16, neighbors (e2e-bili-chain, prefix-affinity, plugin-bypass, passthrough-visibility, claude-native) 62/62 ✓ (claude-native needed a fresh dist — its 3 failures were a stale pre-merge build, also failing on clean master)
  • npm run build ✓ + live E2E repro before/after (see issue comment)
  • full suite delegated to CI (local full run hangs after issue790-* on this machine — 17 stray bili instances pollute env, tracked in the issue comment)

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-24_chain-tags-provenance (151757e)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1213

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

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1213.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] 🏷 Received — reviewing PR now. Plan: read #1197 evidence chain → audit the two-layer fix against current master (rebase freshness) → regression-check all existing behaviors the touched paths carry (#1086 fallback, T3 passthrough, hop-marker path) → run typecheck + targeted chain tests locally → check CI. Full review reply to follow.

ework-agent and others added 2 commits September 24, 2026 02:24
…1213)

T3 pins the #1086 content fallback for the tool-history family, but the
tags family — the one this PR re-scopes — had no server-level pin. T12
drives a non-cooperative client whose history carries real render tags
through a fresh enabled-store instance and asserts byte-identical
passthrough, exactly one warn (pointing at the escape valve), and no
session record.
@ranxianglei
ranxianglei force-pushed the 2026-09-24_chain-tags-provenance branch from 2e51208 to 151757e Compare September 23, 2026 18:44
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — mergeable (one small gap found and fixed directly on the branch; see ④).

① 原 issue / direction

Correct root cause, not a symptom mask. The #1197 producer was the verdict site judging any tag-shaped bytes in the body as bili→bili chain evidence — including client-authored context (AGENTS.md quoting the wire format) in the system section, and cooperative plugins re-sending their own artifacts by design. Both layers fix the decision point itself (detection scope + announcement outranks content shape), and the litmus test holds: the same root cause surfacing in a new shape (e.g. tag examples in instructions) is covered because the fix is "system-section text is never chain evidence", not "this exact string doesn't match". The #1086 fallback for genuinely foreign, non-cooperative clients is preserved (T3 byte-identical passthrough intact), and the hop-marker path is untouched.

② Regression inventory (existing behaviors of touched paths)

Behavior Verdict
#1086 T3: foreign tool-history artifacts → byte-identical passthrough, exactly-one-warn, no session record ✅ preserved (test unchanged, green)
Hop-marker path (src/server.ts:1115-1121, self-loop vs other-instance) ✅ untouched
artifactSeed gate incl. #1100 store-disabled skip + BILI_CHAIN_CONTENT escape valve (src/server.ts:1133-1134) ✅ untouched
Self-state exemption (T1/T7 disk branch), warn-set FIFO eviction (T8), liveness guard (T5), env parse (T9) ✅ untouched — test-file diff is purely additive (zero removed lines)
Unparseable-body path ✅ keeps legacy whole-buffer scan (correct: you can't scope what you can't parse)
Behavior change (a): tags in system/developer/instructions — old: chain verdict → permanent verbatim passthrough; new: processed normally. Intended; this IS the #1197 fix. ⚠️ disclosed
Behavior change (b): plugin-announced request (x-bili-plugin) with history artifacts + no local state — old: chain verdict → passthrough; new: processed. Trade-off documented in code comment: a double-chained plugin behind a header-stripping middlebox would now be double-processed instead of passed through (contrived; the hop marker still guards the common case). ⚠️ disclosed

Known residual gap (assessed acceptable, not blocking): collectHistoryText does not recurse into Anthropic tool_result.content or Responses function_call_output.output. Harmless in practice — plugin mode is exempted by layer 2 anyway, and the proxy-mode carriers (re-voiced acp_summary = user message string content; render tags in assistant/user text blocks) are covered.

③ Code review

Clean. ACP_TAG_RE unchanged; container walk (messages ?? input ?? contents) mirrors the existing historyToolCallNames; role skip matches how the kernel places its artifacts (history items only). No wire-shape side effects beyond the intended verdict change; both compression modes reasoned about (plugin exemption is exactly the plugin-mode case; proxy-mode carriers stay detectable).

④ Test validity

Tests have teeth: byte-equality assertions, exact warn counts, escape-valve text check, session-absence checks. One gap I fixed directly on the branch: T3 pins the fallback for the tool-history family at server level, but nothing pinned the tags family — the very family this PR re-scopes — so a future refactor could silently drop tags-in-history passthrough with no test catching it. Added commit 151757e5 ("test: pin tags-family foreign passthrough at server level"): fresh enabled-store instance, real render tag in a user message (the proxy-mode acp_summary shape), asserts byte-identical passthrough ×2, exactly one warn pointing at the escape valve, no session record. 17/17 pass.

⑤ Diff cleanliness

Single-purpose diff, every line on-topic. Rebased to current master (aae4de1c, which contains #1202 touching src/server.ts — no overlap with the verdict site; rebase conflict-free) and force-pushed so the PR head is current-master-based.

Verification

  • typecheck ✓ · chain suite 17/17 (incl. new T12) · neighbors (e2e-bili-chain, prefix-affinity, plugin-bypass, passthrough-visibility) 21/21 · build ✓ — all on rebased head
  • claude-native: 3 local failures (kill ESRCH in ps-walk/watchdog tests) — verified identical on a clean-master worktree with a fresh build, i.e. pre-existing/environmental, not PR-caused. (Note: the PR description attributes them to a stale pre-merge build, but they reproduce on a fresh master build too — attribution corrected, conclusion unchanged.)
  • Full suite: known local hang from 17 stray bili instances polluting the sessions dir (tracked in the bili pi always proxy connected, compression armed. No model request yet; send one, then run /acp again. #1197 comment); delegated to CI — CI, CI Windows codex overlay, e2e-fake-codex, PR Build Artifact all green on 151757e5.

中文摘要:修复了 AGENTS.md 等上下文文件中的字面 tag 示例被误判为 bili→bili 链证据、导致新会话被永久原文透传(压缩静默失效、/acp 卡死)的问题——tag 检测限定到历史消息、插件声明请求豁免内容判定,评审时补了一个 TAGS 家族透传的服务器级回归测试,本地复现前后对比 + 全量 CI 绿,可以合并。

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.

bili pi always proxy connected, compression armed. No model request yet; send one, then run /acp again.

1 participant