Skip to content

[PR] fix: read Responses additional_tools preamble in tool reachability observation - #5528

Merged
ranxianglei merged 1 commit into
masterfrom
2026-11-02_additional-tools-reachability
Nov 2, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-11-02_additional-tools-reachability

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #5527

Summary

DSH's pi-ai Codex Responses path declares the model-visible bili tools (incl. compress) inside input[] items type: "additional_tools" (role developer), with NO top-level tools array. Both reachability consumers read only the top level:

  • observeDeclaredTools (src/server/lane-decisions.ts) -> declaredTools empty -> dsh profile (toolsHostScopedByDefault) -> compressReachable=false -> compressSurfaceOn=false -> nudge AND standing compression prompt permanently suppressed (issue log: nudge ARMED-SUPPRESSED T1 pendingT1=62364/50000 surface=off(no-tools));
  • biliToolsDeclaredOnWire (src/session-self-heal.ts) — the 会话卡死自愈机制:卡死模式检测与代理侧主动补救 #2155 zombie-lane signal carried the same blind spot.

The kernel already treats additional_tools as an opaque preamble item (kernel/src/wire/responses.ts OPAQUE_ITEM_TYPES); wire handling was fine, only the reachability observation was blind.

Fix

One collector, two consumers (#3417 drift-prevention discipline): declaredToolEntries(parsed, protocol) in src/session-self-heal.ts gathers entries from top-level tools (all protocols) plus, for responses, each input[].type==="additional_tools" preamble item's nested tools. observeDeclaredTools and biliToolsDeclaredOnWire both iterate it. Per-entry extraction (flat name / function.name / functionDeclarations) and named-tool precision are byte-identical; non-responses protocols do not scan input[] (the location is wire-specific).

Behavior change (old -> new)

dsh lanes declaring bili tools ONLY via the Responses additional_tools preamble: compress surface OFF -> ON when compress is actually declared there. Previously the nudge stayed ARMED-SUPPRESSED forever after crossing the 50K growth threshold while the model could still call compress (the reported "compress cannot be triggered").

  • Negative protection RETAINED (reporter requirement): a preamble exposing only acp_status keeps the surface OFF — named-tool precision, not unconditional on.
  • Log string formats UNCHANGED (surface=off(no-tools) / surface=off(top-level=[...])).
  • No other lane/wire behavior changes: all 90 pre-existing matrix rows stay green alongside the 3 new ones.

Tests

config surface: none. kernel: untouched. version: untouched.

…servation

Codex-shaped hosts (DSH via pi-ai) declare the model-visible bili tools in
input[].type==="additional_tools" preamble items and send no top-level
tools array. Both reachability consumers (observeDeclaredTools in
lane-decisions + biliToolsDeclaredOnWire feeding the session-self-heal
zombie signal) read only the top level, so such requests were read as "no
tools at all": compress surface off and the nudge permanently suppressed
even after the growth threshold was crossed (issue log: pendingT1=62364/
50000 ARMED-SUPPRESSED surface=off(no-tools)).

declaredToolEntries (session-self-heal.ts) is now the single collector for
every wire declaration location: top-level tools on all protocols plus the
Responses additional_tools preamble; both consumers share it (#3417
drift-prevention discipline). Per-entry extraction and named-tool precision
are byte-identical; an acp_status-only preamble keeps the surface off.
Log string formats unchanged.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-02_additional-tools-reachability (69babfc)

Latest build — install this exact version

npm install -g billion-context@0.0.7858-pr.5528.204f537

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
69babfc billion-context@0.0.7858-pr.5528.204f537 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr5528.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: read Responses additional_tools preamble in tool reachability observation [PR] fix: read Responses additional_tools preamble in tool reachability observation Nov 2, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重结论:不重复(独立缺陷,无既有修复)。检索 open+closed 的 issue 与 PR:把 Responses input[].type==="additional_tools" preamble 纳入工具可达性检测,没有任何既有 issue/PR 覆盖,本 PR(#5528)是首个。与既有项同症状、不同机制:

标签:bug / dsh / scope-wiring / p2(沿用源 issue #5527 的分类)。说明:[PR] 线程的镜像 labels API 在本环境未实现(endpoint not implemented)、tools/add-label.sh 也不存在,无法在此线程物理打标;分类已在源 issue #5527 上齐备。


PR 审核结论(结构化八问)

  1. 是什么问题:DSH 走 pi-ai 的 Codex Responses 路径时,bili 工具(compress 等)声明在 input[] 的 additional_tools 项里、没有顶层 tools;bili 的工具可达性检测只读顶层,于是把「模型其实能调 compress」误判成「一个工具都没声明」→ 自动压缩提醒(nudge)和常驻压缩提示被永久压制,日志 ARMED-SUPPRESSED … surface=off(no-tools)。
  2. 什么原因导致的:观测层盲区——两个消费方(observeDeclaredTools、biliToolsDeclaredOnWire)都只扫顶层 tools,没看 Responses 特有的 preamble 位置。kernel 侧 wire 处理本来就把 additional_tools 当 opaque 项(kernel/src/wire/responses.ts:98 的 OPAQUE_ITEM_TYPES),wire 没问题,只有 host 侧观测瞎了。
  3. 影响范围与严重程度:仅 DSH 这类「Codex 形状、用 additional_tools 声明工具」的插件车道;触发条件 = 该车道 + 可压缩量越过 50K 阈值。严重度 p2:模型仍能手动调 compress(工具确实可达),只是自动提醒失效——能用但有明显问题,不是完全不可用。
  4. 怎么修复的:抽一个收集器 declaredToolEntries(parsed, protocol)(src/session-self-heal.ts)作为唯一来源,同时收顶层 tools(所有协议)+ responses 的 additional_tools 嵌套 tools;两个消费方都改走它(根本原因立项:按 lane 名的大面积特判拷贝在 4 张 wire 适配器里各自漂移(#3293/#3401 同形 bug 家族),需要抽象重构 #3417 防漂移纪律)。逐条抽取逻辑与 named-tool 精度逐字节不变,只换迭代来源。
  5. 是否有回归问题:无。逐项核过——①非 responses 协议不扫 input[](有 protocol==="responses" gate);②named-tool 精度保留(acp_status-only 仍 surface off);③顶层声明行为不变(control 测试);④日志字符串格式不变(surface=off(no-tools)/surface=off(top-level=[…])),方括号内容现在正确含 preamble 工具名(更准),loud-miss 复用同一 declaredTools 集合、判定与日志一致;⑤proxy 模式 compressReachable 短路恒真,本修复只作用于 plugin 模式(=DSH),proxy 不受影响;⑥跨位置重复条目无害(Set/短路);⑦矩阵 harness 的 devItem 探针收紧到与生产 typed-item 处理一致(防 preamble 误当常驻提示载体),存量行不受影响。90 存量矩阵行 + 3 新行全绿。
  6. 是否破坏缓存:不引入新的缓存失效机制。surface 由 off→on 会在 dev 槽注入常驻压缩提示(这是预期功能开启),属一次性前缀增长、之后 append-stable;观测改动本身不触碰出站字节/缓存键。
  7. 是否改了设计方向:不涉及架构转向。是把两处各自扫一遍顶层的重复逻辑收敛成单一收集器(顺带落实 根本原因立项:按 lane 名的大面积特判拷贝在 4 张 wire 适配器里各自漂移(#3293/#3401 同形 bug 家族),需要抽象重构 #3417 纪律),数据流不变。
  8. 是否引入新配置:无。config surface:none,kernel 未动,version 未动。

测试有效性:新增 8 个单元测试(全走真实入口 resolveLaneDecisions/surfaceOffDetail/biliToolsDeclaredOnWire/declaredToolEntries,无 mock)+ 3 个矩阵行(真实链路、responses-only)。报告者点名的 5 种形态全覆盖;负向保留(acp_status-only、hostile get_weather、非 responses gate)满足 #3617 双向纪律;正向用例若回归会红,断言有牙。

CI:head sha 上 50 项 check,已完成 lane 全绿(static-gates、mysql-contract、ubuntu/windows × node22/24 各 test shard),e2e lane 按 env 门控正常 skip,唯一 test(ubuntu/node22/shard1) 评审时仍在跑,零失败。

diff 整洁度:4 文件 +195/-21,每行都与目的相关,无无关 churn/锁文件/生成物。命名达意、null-safe、注释讲 why(#5527/#3417/#3600/#3884 溯源)、无 as any/@ts-ignore/console.error、删了死代码 void protocol;外部提交从严清单逐项过,达标。

合入判定:可合

auto-merge gate §7.4 八条全过(单一观测层修复 / 回归测试复现且转绿 / head 上绿 / 不动 config·wire·kernel·持久化 / fix: / diff 干净 / Closes #5527 / 不碰 load-bearing infra)。两种压缩模式都推过(proxy 短路、plugin 受影响)。无需改任何代码。 唯一卫生建议:rebase 到当前 master(master 已领先 632 commit,但这 4 个文件在两处逐字节相同,rebase 必然干净、CI 结论可沿用),并等最后一个 CI shard 转绿即可合并。

注:本次为纯审核,我未 push/rebase/改动 PR 分支,以上 rebase 为建议而非已执行动作。

@ranxianglei
ranxianglei merged commit f294c54 into master Nov 2, 2026
51 checks passed
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1005-master.f294c54 (rolling master tag).

npm install -g billion-context@0.0.1005-master.f294c54  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

Louie0806 added a commit to Louie0806/billion-context that referenced this pull request Nov 2, 2026
…king replay + ranxianglei#5528 additional_tools reachability

Eight files; two overlap this lane and both auto-merged:
- src/loop/core.ts: master's ranxianglei#5495 replay/exposure hunks sit at :178 and
  :1317-1331, this lane's draft-dump gate at :1181 and the DEGENERATE_RETRY_NUDGE
  import at :49. Verified after the merge that both sides are present.
- src/server/relay.ts: master's hunk is at :1576, this lane's non-SSE
  pipePluginJson egress at :1976. Both present.

Post-merge: kernel build, tsc, lane suites and the four static gates re-run.
ranxianglei pushed a commit that referenced this pull request Nov 10, 2026
…conflict resolution)

Union-of-intent on src/session-id.ts: master already carries the functional
change via #5825 (x-conversation-id in conversationHeaderSource at the same
low-trust position, plus agent-session-id), so the conflicted hunk takes
master's version verbatim. Net PR delta vs master reduces to:
- tests/proxy-session-id.test.ts: priority-order regression assertions
  (complements #5825's identity-harvest coverage; adds claude/x-session-id
  vs x-conversation-id cells)
- README.md / README.zh-CN.md: list x-conversation-id in the session-identity
  header walks (the enumeration was left stale by #5825)
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.

compress cannot be triggered | compress无法触发

1 participant