Skip to content

[PR] Configurable hard timeout for the compress tool call (compress.timeoutSeconds) - #2535

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-09_compress-timeout-config
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-09_compress-timeout-config

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2524

What

Adds compress.timeoutSeconds — a configurable hard timeout for the agent-side compress tool call.

  • positive number → abort the forwarded compress call after N seconds; the host receives an error (timeout after …ms (compress.timeoutSeconds)), which pi surfaces as an isError tool result
  • 0 / null → disable the hard cap entirely (host turn cancellation via AbortSignal still works)
  • unset (default) → today's behavior: fixed 60 s backstop in shared.forwardTool

How

  • Enforcement point is forwardTool in src/agent/shared.ts — the single seam through which every agent extension (pi / omp / dsh / opencode lanes) forwards tool calls — gated on tool === "compress". One seam covers all plugin-mode lanes uniformly; no per-agent duplication.
  • fetchJson gains an optional timeout label and treats timeoutMs <= 0 as "no timer" (an external abort still aborts; with no timer, an external abort throws the original AbortError).
  • New exported resolver configuredCompressTimeoutSeconds() reads the config file live on each call (hot reload, no restart). Tri-state: undefined = unset → built-in backstop; null/0 = disabled; >0 = cap in seconds. Any read/parse failure degrades to unset — a bad config file can never break tool calls.
  • The resolver deliberately does NOT import src/config.js: that module pulls acp-kernel values in, which would inline the kernel into light agent bundles (dsh-acp.js declares "no acp-kernel import"). It mirrors parseCompressSettings' validation for just this one key (null | finite number ≥ 0).
  • src/config.ts: parseCompressSettings now accepts timeoutSeconds (null | finite ≥ 0; anything else rejects the whole section, matching the existing section-level contract) so the web-UI save path round-trips it; added to COMPRESS_SETTING_FIELDS.

config surface

New key: compress.timeoutSeconds (number | null, global level only).

  • Why the existing surface cannot express it: bili has no per-tool execution bound at all today — toolBashDefaultTimeout applies to bash only, delegate.*TimeoutMinutes to acp_delegate only, httpIdleTimeoutMs to provider HTTP streaming only. The only generic bound was the hard-coded 60 s backstop inside shared.forwardTool, not user-visible.
  • Mechanisms considered: knobs.ts (default home for new behavior knobs per 彻底整治环境变了滥用,除非必要都走配置文件 #2030) rejected — its import graph drags acp-kernel into light agent bundles; a new BILI_* env var rejected — 彻底整治环境变了滥用,除非必要都走配置文件 #2030 discipline reserves env vars for secrets/spawn channels/host posture/path relocation/third-party conventions, and the issue itself specified the JSON shape; a kernel-side timeout rejected — wrong layer, the kernel does not own host tool forwarding.
  • Provider/model-level compress sections intentionally do NOT honor it (same as the injection toggles): the extension-side consumer reads the global block only. Documented in CONFIGURATION.md en+zh.
  • Migration: none. Additive key; unset preserves byte-identical behavior.

Behavior change disclosure

None on the default path: with the key unset, every tool still gets exactly the fixed 60 s backstop it gets today. Observable differences only when the key IS set: (a) the compress cap becomes N seconds or unlimited; (b) when the configured cap fires, the error text gains a (compress.timeoutSeconds) label.

Out of scope / residuals

  • src/mcp.ts (codex/claude MCP lane) has its own forwardTool copy with a fixed 60 s; untouched here — separate failure domain, follow-up candidate.
  • Client-side abort does not cancel in-flight proxy work (pre-existing; the proxy may finish work whose response is dropped). Not addressed by design of this issue.
  • Provider-stream hangs while the model is still generating the compress tool call remain out of scope (the separate docs: record kernel id-immutability contract (ids/refs never reused) #494 discussion).

Tests

  • New tests/issue2524-compress-timeout.test.ts (25 tests): parse accept/reject matrix; resolver tri-state incl. BOM / malformed JSON / misplaced top-level / provider-level cases + live reload across two writes; forwardTool against real listen(0) servers proving the cap fires before a slow response, is compress-only, honors 0/null-disable, keeps the backstop when unset, and lets a pre-aborted host signal win when disabled.
  • Local targeted green on the rebased head (full suite left to CI): typecheck clean; build + dist annotation check OK; dsh-acp.js verified kernel-free after bundling; issue2524 + compress-settings + config-file-cache 78/78; all 15 parseCompressSettings consumer suites 231/231.
  • Note: one pre-existing timing flake in the plugin-agent retry-throttle test family was observed on shared local machines (reproduces on a reverted tree too); not related to this change.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-09_compress-timeout-config (3f21e93)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.5256-pr.2535.71fc3de

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

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

继续 看上面消息

@ranxianglei
ranxianglei force-pushed the 2026-10-09_compress-timeout-config branch from dc5576b to 9b665f4 Compare October 10, 2026 01:25
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

继续处理完成(上一会话因磁盘空间中断,本次接手)。PR 代码本身此前已完成且 CI 绿,但分支落后 master 60 个提交——本轮做了完整 review + rebase 到最新 master + 重新验证。新 head:9b665f4ca(基于 055caad7e),rebase 零冲突,CI 25/25 全绿(含真实客户端 e2e),本地 typecheck 干净、issue2524 + compress-settings + config-file-cache 78/78 绿。

Review 结论(结构化八问)

  1. 是什么问题:功能需求([Feature][pi] Add configurable hard timeout for compress #2524,自 billion-context-pi#597 迁移)——compress 工具调用没有可配置的硬超时;现状是 shared.forwardTool 里写死的 60 秒兜底,既放宽不了(>60 秒的合法大上下文压缩被强制打断)也收紧不了(无法设确定性上限)。原 issue「只能手动 abort」的说法不准确——60 秒兜底一直存在,实现方已在 PR 中纠正。
  2. 什么原因导致的:设计缺口——bili 现有按工具执行时限都不覆盖 compress(toolBashDefaultTimeout 只管 bash、delegate.*TimeoutMinutes 只管 acp_delegate、httpIdleTimeoutMs 只管 provider HTTP 流式);唯一通用上限就是那个硬编码常量,从未暴露成配置。
  3. 影响范围与严重程度:所有 plugin 模式宿主(pi / omp / dsh / opencode 各通道)。能力缺失/体验限制,不是缺陷——无数据丢失或损坏。
  4. 怎么修复的:新增配置键 compress.timeoutSeconds(number|null,仅全局层级):正数 = N 秒后中止(宿主收到带 (compress.timeoutSeconds) 标识的错误);0/null = 完全关闭上限(宿主回合取消仍有效);未设置 = 保持现有 60 秒兜底。执法点在唯一转发缝 shared.forwardTool(一处覆盖全部 agent 通道);扩展侧每调用实时读配置文件(热加载、免重启),刻意不走 src/config.js——那会把 acp-kernel 拖进 dsh-acp 这类轻量 bundle(已核验 paths.js 只依赖 node:os/node:path,kernel-free 声明成立);config.ts 侧 parseCompressSettings 接受该键并加入 COMPRESS_SETTING_FIELDS(Web UI 保存回写不丢字段)。
  5. 是否有回归问题:无。默认路径(键未设置)逐字节不变,逐项清点过:fetchJson 的 no-timer 分支只在显式禁用时生效,默认 TOOL_TIMEOUT_MS > 0 路径与旧逻辑等价;非 compress 工具保持固定兜底(有测试钉住);非法值 reject 整个 section(与既有 section 级契约一致);外部 abort 优先语义不变。分支点之后 master 侧对触碰文件的改动只有 shared.ts 的 asciiHeaderValue guard([bug] 模型 id 含中文时 x-bili-plugin-model 触发 undici ByteString 异常,整轮请求发不出去(7 文件 8 处写入点,pi/omp/opencode/dsh) #2455,无关区域)与 config.ts 注释更新——无语义交互,rebase 干净。
  6. 是否破坏缓存:不涉及——未触碰会话持久化、引用游标、去重键或任何缓存/重试策略。
  7. 是否改了设计方向:不涉及——无架构/边界/数据流变化;只是把硬编码常量提升为配置项,执法点原地不动。
  8. 是否引入了新的配置:是——compress.timeoutSeconds(number | null,仅全局层级;默认未设置 = 60 秒兜底)。刻意不加 BILI_* env var(彻底整治环境变了滥用,除非必要都走配置文件 #2030 纪律);provider/model 层级 compress 段不生效(与注入开关一致)。文档已同步 CONFIGURATION.md en+zh 与 website(yaml 种子 + 生成页,docs-sync 守卫兼容)。

测试有效性:25 个测试用真实 listen(0) HTTP server(端口确定性符合 §7.2),断言有牙——上限在 ~200ms 对 500ms 慢响应提前触发、仅对 compress 生效、0 禁用后慢响应仍完成、未设置不提前中止、禁用时宿主 abort 优先;解析层覆盖 BOM/坏 JSON/错位顶层/provider 层级/热加载等负例。bug 回归时抓得住。

遗留项(PR 已声明,不在本 PR 范围):src/mcp.ts 自己的 forwardTool 拷贝(固定 60 秒)未动,属另一失败域可作 follow-up;客户端 abort 不取消 proxy 端在途工作(既有行为);模型生成阶段的流挂起(#494 讨论)同样不在范围。

判定:review 通过,分支已更新到最新 master,CI 全绿——可合并(feat 类新增配置面,按仓库纪律由人工合并:https://github.com/ranxianglei/billion-context/pull/2535)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

状态确认(本轮无新变化,不重复上轮结论):PR 仍 open、head 9b665f4 未变、CI 25/25 全绿(无失败项)、issue 线程无新评论。上一条评论(floor 7)的完整 review 结论与八问仍然有效——判定不变:可合并,feat 类新增配置面,按仓库纪律等待人工合并:#2535

@ranxianglei ranxianglei changed the title Configurable hard timeout for the compress tool call (compress.timeoutSeconds) [PR] Configurable hard timeout for the compress tool call (compress.timeoutSeconds) Oct 23, 2026
@ranxianglei
ranxianglei force-pushed the 2026-10-09_compress-timeout-config branch from 9b665f4 to 3f21e93 Compare October 23, 2026 12:20
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

上游冲突已解决并 force-push。PR #2535 的单提交 rebase 到最新 master(8d24bf9d4),新 head 3f21e9312,分支现直接落在 master 之上、冲突清除。本地 typecheck 干净、build 绿(dist-import-annotations / dist-external OK)、dsh-acp.js 6.91KB 确认 kernel-free、定向测试 89/89 全绿(含两套超时机制同跑);全量回归交 CI。

冲突点与解法(核心判断,两处文件)

src/agent/shared.ts forwardTool(语义冲突):master 在 merge-base 之后落了 #2652——新增 effectiveToolTimeoutMs(),按 proxy manifest 广播的 maxToolDurationMs 抬高 compress 调用的 HTTP 等待(无广播时回落固定 60s 底);本 PR 则新增 compress.timeoutSeconds 配置三态。这是同一转发缝上的两个正交机制,只取任一侧都会坏:取 PR 侧会丢掉 #2652 的预算抬升(低预算场景提前掐掉合法长折叠=回归 master)连同 blocksCreated 宽类型;取 master 侧会让整个 timeoutSeconds 配置失效(等于废掉本 PR)。正确解法是组合,不是二选一:

src/config.ts(两处):① 类型声明处 add/add 撞车——master 的 RolloutFeatureOverride/RolloutFileConfig(#3062)与本 PR 的 CompressFileExtras 互不相干,取并集两者都留。② COMPRESS_SETTING_FIELDS——master 已把 stripImages/imageCompression 从解析器移除(现为 inert 移除键、触发告警),本 PR 分支早于该移除仍列着它们;解法=沿用 master 的确切集合 + 仅追加 timeoutSeconds(不复活那两个死键)。

八问

  1. 是什么问题:上游 PR 与目标分支冲突(master 自 merge-base 前进了 2196 个提交),需 rebase 解冲突。是合并卫生,不是缺陷。
  2. 什么原因导致的:本 PR 基于较老 master 开出,期间 master 在同一转发缝落了 [Bug][dsh] plugin-tool bridge hard-codes a 60s timeout that contradicts the configurable externalSummary.budget — long summaries die with "timeout after 60000ms" #2652(广告式超时底)与 feat: 灰度发布机制 —— 新特性按安装维度百分比放量(支持嵌套灰度 A→B) #3062(rollout 配置块)等改动,与本 PR 的 timeoutSeconds 在同一行域相撞。
  3. 影响范围与严重程度:仅 plugin 模式各通道的 compress 工具转发超时路径;无数据丢失/损坏。属可合并性阻断(dirty 挡 merge),不影响运行中用户。
  4. 怎么修复的:单提交 rebase 到最新 master,手工组合两侧意图(见上),保留双方各自新增能力而非二选一。
  5. 是否有回归问题:无。逐项清点:未设置路径逐字节等价于 master 现状(effectiveToolTimeoutMs 无广播时=60s、有广播时按 [Bug][dsh] plugin-tool bridge hard-codes a 60s timeout that contradicts the configurable externalSummary.budget — long summaries die with "timeout after 60000ms" #2652 抬升——若误留 PR 写死的 60s 反而会回归 [Bug][dsh] plugin-tool bridge hard-codes a 60s timeout that contradicts the configurable externalSummary.budget — long summaries die with "timeout after 60000ms" #2652);非 compress 工具不受配置影响(测试钉住);0/null 关上限语义不变;非法值 reject 整个 section 不变;外部 abort 优先不变。定向 89/89 绿,其中 issue2652 与 issue2524 同跑通过即证明两机制共存成立。
  6. 是否破坏缓存:不涉及——未触碰会话持久化、引用游标、去重键或任何缓存/重试策略。
  7. 是否改了设计方向:不涉及——无架构/边界/数据流转向;只是把 PR 的单一常量默认值接到 master 已有的 effectiveToolTimeoutMs 上,执法点原地不动。
  8. 是否引入了新的配置:本次我没有新增任何配置面,PR 本身的 compress.timeoutSeconds(number|null,仅全局层级)维持原状。一个需知会的细节:显式正数若低于 [Bug][dsh] plugin-tool bridge hard-codes a 60s timeout that contradicts the configurable externalSummary.budget — long summaries die with "timeout after 60000ms" #2652 的广告底,以用户值为准(不与广告底取 max)——这是 PR 自身测试钉死的语义(0.2s 须对未广播 server 提前触发);含义是用户显式设低值就按低值掐断,错误信息带 (compress.timeoutSeconds) 标识可归因,属显式 opt-in,默认路径不受影响。

判定:冲突已解、rebase 干净、本地定向验证绿、分支直接落在 master 之上——可进入人工合并(feat 类新增配置面,按仓库纪律由人工合并)。全量回归以 CI 为准:#2535

This branch has not been deployed

No deployments
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.

[Feature][pi] Add configurable hard timeout for compress

1 participant