Skip to content

fix(ccr): plugin-mode sessions execute the base ccr block exclusively - #1360

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-25_ccr-plugin-base-governance
Sep 26, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-25_ccr-plugin-base-governance

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

#1345: in plugin mode the manifest — the host's only declaration of the retrieve surface — is built from the base config, but sessions armed from the three-level merged ccr policy. Two divergences reproduced:

  1. Base ccr.enabled=true + provider/model ccr.toolName override → manifest advertises acp_retrieve, but the session gate wants the renamed name → the advertised tool 400s at /__bili/plugin/tool, stored content unreachable, placeholder hints print the wrong name.
  2. Base ccr.enabled=true + provider/model ccr.enabled=false → manifest still advertises, but the merged policy disarms the session → oversized results silently forwarded verbatim.

Fix (direction approved in the #1345 thread)

  • Stamp site (src/server.ts): plugin mode now stamps the base ccr block (arm iff base enabled); proxy mode unchanged (stamps the merged block). Normalization strictly inside the pluginMode branch, so per-route renames keep working on the proxy lane.
  • New store.ccrLoopConfig(session, config) resolves the loop config from the session stamp (kernel DEFAULT_CCR_CONFIG fill); every processTurn call site (src/server.ts ×8, src/preflight.ts, src/acp-status.ts, src/plugin.ts) uses it — the stamp becomes the single CCR policy source.
  • Load-time diagnostic (src/config.ts): findCcrPluginDivergences() reports every provider/model ccr.* field diverging from the base block, once per config load (the web hot-reload path is collapsed to a single loadOptions() call so it fires once per reload):
    [acp-config] ccr override ignored in plugin sessions: <level> ccr.<field>=<value> — plugin sessions use <effective> …
  • Docs: CONFIGURATION.md + zh-CN plugin-lane governance note under compress.ccr.
  • Tests: e2e toolName/enabled divergence (plugin lane base-governed incl. endpoint accept/reject; proxy lane keeps its overrides), unit findCcrPluginDivergences, loadOptions diagnostic integration. Also fixed a latent cross-test pollution trap in this file (conversation-id reuse against the file-global SessionStore — see comment above postOpenai).

Behavior change (old → new)

  • OLD: plugin-mode sessions executed the three-level merged ccr policy (every field) while the manifest advertised the base block → divergent overrides made the advertised tool unexecutable or silently disarmed it.
  • NEW: plugin-mode sessions execute the base ccr block exclusively; provider/model ccr.* overrides remain in effect for proxy-mode sessions only (they were never executable on the plugin lane). Every affected override logs a warning at config load.
  • Proxy mode: no change.

Sibling finding (separate issue)

The same divergence class exists for absorb: the manifest always advertises the static ABSORB_TOOL_NAME (src/plugin.ts:578-581), never following an absorb.toolName rename at ANY level including global, while adjudication reads the effective name (src/absorb.ts:52). Filed as #1359 — reproducible with one top-level config line; the normalize-at-stamp + load-diagnostic pattern transfers directly. Not bundled here (distinct root cause/surface).

Pre-flight

typecheck ✓ · full suite 2629/2629 pass (11 skipped by design) ✓ · build ✓ · tests/ccr-plugin.test.ts 10/10 ✓

Fixes #1345

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-25_ccr-plugin-base-governance (efce7c8)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1360

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

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1360.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] 🏷 Picked up — this is completed work (PR #1360), so I'm reviewing rather than re-doing it. Pulling the branch (dec9930c), checking CI status, and running local verification on a head rebased onto current master (d3c8af84, 4 commits newer than the PR base). I'll report the full review conclusion here shortly.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 结论:PR #1360 可以合并(需人工 merge)。完整审查如下。

① 方向关(原 issue #1345)— 通过。实现与 BsoBird 在 #1345 thread floor 5 批准的方向逐条一致:(a) plugin mode 整体执行 base ccr block(arm 仅看 base enabled:true);(b) provider/model ccr.* override 仅对 proxy lane 生效,并由一次性的 load-time diagnostic 按字段报告;(c) 归一化严格位于 pluginMode 分支内(stamp site 同时服务 proxy session,不受影响);(d) 诊断每次 config load/reload 只触发一次。修在决策点(哪份配置治理执行),不是 wire 层遮症状。

② 回归审查 — 按触碰路径清点既有行为:

  1. Stamp site(src/server.ts:1843-1861):proxy mode 与旧逻辑字节等价(同样的 injectTool/storeChannelOk gate、同样 stamp merged block);plugin mode = 有意变更(stamp base block,arm 不再受 merged.enabled 约束)。无披露之外的静默变化。
  2. 8 个 loop-config 点(server.ts prepareAnthropic/Openai/Google/GoogleCountTokens/Responses/CountTokens/ResponsesCompact/forward)+ src/acp-status.ts:59、src/plugin.ts:759、src/preflight.ts:851:disarmed 路径不变(ccr: undefined)。armed 路径现在传 DEFAULT_CCR_CONFIG 填充后的 stamped block 而非请求期解析的 config —— 等价性成立,因为 (a) stamp 在 handle() 内每请求、dispatch 前完成(无 stale 窗口),(b) kernel 自身的 resolveCcrConfig 就是同一个 {...DEFAULT_CCR_CONFIG, ...ccr} fill(已对照 acp-kernel@0.0.93 dist 验证)⇒ proxy mode 有效配置不变。preflight 保留 noEmergencyTruncate 包裹顺序。
  3. handleConfigReload:三次 loadOptions() 收敛为一次 —— 赋值字段相同;诊断从 3×/reload 降为 1×/reload(有意)。web PUT 路径本已单次调用。
  4. findCcrPluginDivergences:纯增量日志;base disabled 时静默(feat: enable CCR (acp_retrieve) on host/plugin lanes (#1271) #1273 route-scoped-only enablement 保持静默是设计)。参考 base 用 fileConfig.compress 验证正确 —— compress block 中 env 只影响两个 injection toggle,base ccr 只能来自配置文件。白名单 CCR_FIELDS == kernel DEFAULT_CCR_CONFIG 字段 == CompressSettings.ccr 类型字段(三集合完全相同:enabled/toolName/minToolTokens/excludeTools/maxHeadChars),无缺漏字段。
  5. Docs:zh/en 均在 compress.ccr 下更新,措辞与实现一致。

高危模式检查:无 fail-fast→吞错、无阈值/默认值漂移、输出格式除已披露的 warn 行外无变化、kernel pin 未动(两侧均 0.0.93)、持久化形状未变。

③ 代码审查 — 两个小 nit,均不阻塞:

  • ccrLoopConfig(src/store.ts):if (!eff) return config; 不可达(ccrEnabled 为真 ⇒ eff 必为真)。死守卫,无害。
  • 诊断边界:provider 设 X≠base 且 model 把 X 重置回 base 时,provider 行声称 "proxy-mode sessions honor the override",但 deepest-wins 下 proxy 有效值其实也是 base。边缘中的边缘,措辞略过强。

未发现逻辑/不变量/错误处理/安全问题。

④ 测试有效性 — 断言有牙:e2e name-divergent 断言 manifest 内容、placeholder hint 名、session gate 名、store ref 存在,并走真实 /__bili/plugin/tool endpoint 断言 accept(200+receipt)与 reject(400)——覆盖 conversation gate 和 ack 往返,不止 inner executeRetrieve;e2e enabled-divergent 断言 plugin lane 在 route enabled=false 下仍 ARMED(旧 bug = 静默 verbatim 丢失)且 proxy lane 尊重 disable;unit finder 覆盖 base-disabled 静默、per-field 报告(kernel 默认值作参考)、等值静默、base 显式值优先于 kernel 默认;loadOptions 集成用真实临时配置文件 + log capture 断言精确的警告条数与内容。若 stamp 回归为 merged policy,name-divergent 会在 endpoint/gate 断言处失败,enabled-divergent 会在 [acp-stored 断言处失败。跨测试污染修复(unique conv ids vs file-global SessionStore)在 postOpenai 上方有注释说明。端口经 listen(0) 动态分配(:129),确定性达标。

⑤ diff 整洁度 — 单 commit、9 文件,每一行都服务于 issue 目的;无空白 churn、无 lockfile/生成物 churn(acp-kernel pin 未动)。已本地 rebase 到 d3c8af8 验证干净(共享 src/config.ts 的重叠区不相交)。

验证证据:CI(head dec9930)11/11 全绿(test ubuntu/windows ×22/24、e2e、hermetic registry、real pi/codex lanes、version-guard、build-artifact)。本地 rebased head(master d3c8af8 + PR):typecheck ✓ · build ✓(dist-import-annotations OK)· 全量套件 2639 pass / 0 fail / 11 skipped(共 2650;PR 正文的 2629 是旧 base 数字,master 其后新增 ~21 个测试)。

行为变更(复述 PR 披露):OLD plugin sessions 执行三级 merged ccr policy 而 manifest 广播 base block → NEW plugin sessions 仅执行 base block,provider/model overrides 仅 proxy lane 生效并在 load 时告警。Proxy mode 不变。有意变更、thread 内批准、披露到位。

⚠️ 协调发现 — PR #1352:另有一个 open PR("fix: plugin manifest / session-effective ccr toolName divergence")也声称 Fixes #1345,采用更窄的 toolName-only 方案,已被批准的 whole-block 方向取代,且重写同一 stamp-site 区域 —— 两者同合会冲突。建议合并 #1360 前先关闭 #1352 标记 superseded(owner 决定,我未动它)。分支落后 master 4 个 commit 但 GitHub 报 mergeable,直接 merge-commit 可行,作者也可先 rebase。

按 §7.4 不属于 auto-merge(多模块 policy 变更 + 产品决策)→ 需人工合并。


中文摘要:审了 #1345 的修复(plugin 模式 CCR 执行 merged policy 而 manifest 广播 base block 的分裂):改为 plugin lane 专属执行 base 配置、load 时按字段告警被忽略的 override,proxy lane 行为逐项验证不变,CI 11/11 绿 + 本地 rebase 后全量套件 2639/0/11 全过,建议关闭已被取代的 PR #1352,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Deep review: ✅ merge. Verified on the triple-stacked tree (#1367+#1361+#1360, all merges clean; typecheck + full suite green on the stack; this PR's 6 tests pass in isolation AND on the stack).

Design holds up — and it generalizes correctly. #1345 named two divergences (toolName rename, enabled=false), but the root cause is structural: in plugin mode the static manifest is the host's ONLY declaration of the retrieve surface, and it reads the base config alone — so any per-field divergence between base and merged splits declared from dispatched. This PR fixes the class, not the instances: the session stamp carries the whole base block verbatim for plugin sessions (merged block for proxy sessions), and ccrLoopConfig makes the stamp the single policy source for every processTurn call site (all 8+ call sites migrated: prepares ×4, countTokens ×2, plugin status, preflight, compress loop, responses-compact). Placeholder hints, session gate, and manifest can no longer disagree.

Points I probed specifically:

  • ccrLoopConfig fills {...DEFAULT_CCR_CONFIG, ...eff} — no undefined field can reach the kernel even when the stamp was set from a partial block.
  • findCcrPluginDivergences stays silent when base ccr is off — feat: enable CCR (acp_retrieve) on host/plugin lanes (#1271) #1273's route-scoped-only enablement (proxy-lane-only by design) produces no warning noise. Correct scoping.
  • handleConfigReload now funnels through ONE loadOptions() call — divergence warns re-fire on hot reload (they should), and the triple loadOptions() call is gone.
  • Proxy lane keeps full three-level merge semantics: per-route renames and per-route disarm both verified e2e (forwarded bodies assert the placeholder hint name and verbatim passthrough respectively).
  • Effective-value reference is base[f] ?? DEFAULT_CCR_CONFIG[f] — a base-set value wins over the kernel default as the comparison anchor. Pinned by unit tests.

Docs: both CONFIGURATION.md and zh-CN updated with the plugin-lane governance paragraph. ✅

Merge note for the release: the three CCR PRs (#1367, #1361, #1360) stack cleanly in any order (verified pairwise + triple); no sequencing constraint.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,感谢深审确认。协调项已闭环:PR #1352 已关闭(superseded),我 review 中提出的唯一阻塞性协调问题不复存在。

当前状态(刚查过):#1367 / #1361 / #1360 三者均 open、待人工合并;按你的验证结论无顺序约束,任意顺序合并即可。合并链接:https://github.com/ranxianglei/billion-context/pull/1360(我无法代合,规则限定 PR merge 为人工操作)。

发布备注素材(供 release notes):三个 CCR PR 同批落地时,行为变更集中在 #1360 一条 —— plugin-mode sessions 从执行三级 merged ccr policy 改为仅执行 base block(provider/model ccr.* overrides 仅 proxy lane 生效 + config load 时按字段告警),proxy mode 不变;#1361(fork-adoption)与 #1367(retrieve ack lifecycle)各按其 PR 正文披露。


中文摘要:确认 #1352 已关闭、三个 CCR PR(#1367/#1361/#1360)均 open 且验证可任意顺序合并,合并需人工操作,已附发布备注的行为变更要点。

In plugin mode the manifest is the host's only declaration of the
retrieve surface, yet sessions armed from the three-level merged ccr
policy: a provider/model-level toolName rename pointed the execution
gate away from the advertised name (endpoint 400s, stored content
unreachable), and enabled=false disarmed a session whose manifest still
advertised acp_retrieve (silent verbatim forwarding).

- stamp site: plugin mode stamps the base ccr block (arm iff base
  enabled); proxy mode unchanged (stamps the merged block)
- new store.ccrLoopConfig resolves the loop config from the session
  stamp; every processTurn call site uses it (one policy source)
- config load: per-field divergence warning naming level/field/value
  (once per load; hot-reload path collapses to one loadOptions call)
- docs en+zh: plugin-lane governance note under compress.ccr
- tests: e2e toolName/enabled divergence (plugin lane base-governed,
  proxy lane keeps its overrides) + findCcrPluginDivergences unit +
  loadOptions diagnostic integration

Behavior change: provider/model-level ccr.* overrides no longer apply
to plugin-mode sessions (they made the advertised tool unexecutable or
silently disarmed it); they stay in effect for proxy-mode sessions.
Every affected override now logs at config load.

Fixes #1345

# Conflicts:
#	src/config.ts
#	src/server.ts
@ranxianglei
ranxianglei force-pushed the 2026-09-25_ccr-plugin-base-governance branch from dec9930 to efce7c8 Compare September 26, 2026 02:25
@ranxianglei

Copy link
Copy Markdown
Owner Author

Rebased onto master (efce7c8) — conflicts resolved as union, zero behavior drift.

Master had moved under this PR twice since the review: #1367 (retrieve lifecycle imports) and #1369's absorb divergence machinery — the same warn-at-load pattern as this PR's ccr machinery, in adjacent code — plus its absorbBlock refactor of every loop-config site. Resolution:

Gates on the rebased head: typecheck ✓ · ccr-plugin 10/0 · absorb-plugin 10/0 · store 16/0 · fork-ccr-adoption 6/0 · full suite 2772 tests, 0 fail (12 e2e-gated skips). CI re-runs on this head; merge when green.

@ranxianglei
ranxianglei merged commit 9b5ea92 into master Sep 26, 2026
13 checks passed
antclt pushed a commit to antclt/billion-context that referenced this pull request Sep 26, 2026
… agree (ranxianglei#1359)

The plugin manifest advertised absorb under its static constants while
per-session adjudication resolved the merged route/model name, so a renamed
absorb.toolName made the advertised tool 400 (same silent-loss class as ranxianglei#1345,
wider trigger surface: one base-level rename suffices).

- resolveAbsorbSettings(): single source of truth for raw->resolved absorb,
  shared by applyCompressSettings and the plugin-lane base stamp.
- server.ts: in plugin mode the whole absorb block follows the BASE config
  (advertise + adjudicate the same name); provider/model absorb.* overrides
  stay proxy-lane-only. Proxy mode unchanged (still honors the merged name).
- plugin.ts: manifest advertises the resolved name via absorbToolsFor(), which
  builds byte-identical wire shapes at the default name.
- config.ts: load-time per-field divergence warning (findAbsorbPluginDivergences),
  mirroring the ranxianglei#1360 ccr diagnostic.
- docs (en+zh): document lane governance for absorb.toolName.
- tests/absorb-plugin.test.ts: regression coverage (plugin manifest follows the
  resolved name and the gate agrees; proxy still honors the merged override;
  default shapes byte-identical; divergence diagnostic fires/stays silent).

Fixes ranxianglei#1359
@ranxianglei
ranxianglei deleted the 2026-09-25_ccr-plugin-base-governance 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(ccr): plugin manifest tool name can diverge from the route/model-resolved CCR tool name

1 participant