Skip to content

[PR] feat: hold growth nudges during tool bursts while context has headroom - #1491

Closed
ranxianglei wants to merge 5 commits into
masterfrom
2026-09-27_tool-burst-hold
Closed

ranxianglei wants to merge 5 commits into
masterfrom
2026-09-27_tool-burst-hold

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

What

#1487: 检测到瞬间需要读大量文件的时候,瞬时放宽压缩.

New tool-burst nudge hold (compress.burstHold, on by default): while the tail of the resent history is dominated by fresh tool results (the agent mid-batch of reads/greps/globs/bash calls) AND context usage is below min(0.7, effective maxContextLimitPct), the proxy holds the GROWTH-based nudge injection so the agent finishes its batch before its working content gets folded. Automates the remedy for the fold→re-read loop reported in #1198/#1277 (dsh discussion #5795) — no recent-zone pinning config needed.

Design

  • Detection (src/burst-hold.ts): trailing lookbackMessages window (default 12); a burst = toolResults >= minToolResults (5) AND share >= minToolShare (0.55). Calibrated so steady assistant/tool alternation (~0.5 share) never trips while parallel batches (~0.8+) always trip.
  • Hold ceiling = min(EMERGENCY_NUDGE_ESCALATION_PCT = 0.7, nudge.maxContextLimitPct) (kernel default 0.75). At or above it, nothing is ever held.
  • Only PROACTIVE growth nudges are gated: (shouldInject && !holdGrowth) || emergencyNudge(...) — the kernel pressure-band force-nudge (usage ≥ maxContextLimitPct) and the host emergency nudge (≥ 0.7) always fire, so a context that runs out mid-burst still compresses immediately.
  • Stateless per request; wired identically in all four prepare paths (anthropic/openai/google/responses), each keeping its existing extra gates; applies in both compression modes (the proxy-side nudge is the proactive trigger in both). No wire/payload mutation — nudge-injection gating only.
  • Config: compress.burstHold.{enabled,minToolResults,lookbackMessages,minToolShare} — three-level sub-field-wise merge like absorb; malformed values reject the whole compress block loudly (existing parse discipline). enabled: false restores the legacy always-nudge behavior.
  • Diagnostics: the nudge log line now reports HOLD T{n}, burst-hold(10/12,share=0.83) instead of INJECT when a growth nudge is held (0.1.69 回归: plugin 模式 nudge 注入被 !pluginMode 静默禁用 — INJECT 日志照打但从不投递, 自动压缩只剩 preflight 应急 #451 log-honesty class).

Config surface

Adds one optional sub-object under the existing three-level compress hierarchy: compress.burstHold.{enabled, minToolResults, lookbackMessages, minToolShare} (sub-field-wise deepest-wins merge, same pattern as absorb/ccr/search). No new env vars or CLI flags; no existing field renamed or re-semantics'd.

⚠ Behavior change (intended — #1487 owner decision)

  • Old: growth nudge fires every 50K of context growth regardless of what the agent is doing.
  • New: while a tool burst is active AND usage < min(0.7, maxContextLimitPct) (default ceiling 0.7), growth-nudge injection is held. Timing precision: the kernel stamps its nudge state at DECISION time (lastNudgeShownTokens advances even when the host suppresses the text), so a held trigger is consumed — after the burst ends, the next proactive nudge lands at the kernel's next growth-cadence boundary rather than immediately. Deferral is bounded either way: usage reaching min(0.7, maxContextLimitPct) forces compression through the host-emergency / kernel-pressure-band paths. Pressure/emergency nudges unchanged.
  • Why: owner decision in the issue thread — 「只要上下文够用 默认允许他先干一票再压缩」 — hence ON by default.

Pre-flight

  • Rebased onto master @ 30b1574 (v0.1.160, clean — zero conflicts): typecheck ✓ · tests 2921 pass / 0 fail (12 skipped = gated e2e) ✓ · build ✓ (verified on the rebased head).
  • New regression suite tests/burst-hold.test.ts (14 tests): detector calibration (steady alternation must NOT trip), ceiling math, hold decision matrix, sub-field merge precedence, parser validation rejects.
  • Local full E2E not runnable here (no Responses-compatible upstream reachable from this environment); CI e2e runs automatically because this diff touches src/server.ts.

中文摘要:新增工具批量调用期间的增长型压缩提示暂缓(burstHold,默认开)——agent 批量干活且上下文用量低于 min(0.7, maxContextLimit) 时先让它干完再压,压力带/紧急提示不受影响。

Closes #1487

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-27_tool-burst-hold (62b1f8d)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1741-pr.1491.5e56624

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-pr1491.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei force-pushed the 2026-09-27_tool-burst-hold branch from 7ab5372 to 9f51975 Compare September 27, 2026 11:40
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — mergeable once CI is green on the rebased head. Human merges (feat + config surface + default-on = human territory per §7.4).

① Original issue / direction (#1487) ✓
Root-cause-class fix, not symptom-patching: the #1198/#1277/dsh-#5795 fold→re-read loop exists because growth nudges fire mid-batch and fold live working content. This gates the trigger on what the agent is doing instead of pinning content per tool name — matching the owner decision in #1487 floor 4 (「只要上下文够用 默认允许他先干一票再压缩」): generalized beyond read-family, ON by default. No kernel change, no wire mutation. Direction sound.

② Regression audit — existing behaviors on touched paths, each checked against pre-PR code:

  1. Growth-nudge injection (all 4 wires): changed by intent, disclosed old→new in the PR body. ✓
  2. Host emergency nudge (usage ≥ 0.7 + compressible ranges): unchanged — the OR-term is untouched in all four prepare paths. ✓
  3. Kernel pressure band (usage ≥ maxContextLimitPct): unchanged — verified the subtle invariant that makes this safe: ceiling = min(0.7, maxContextLimitPct) ≤ maxContextLimitPct, and holding requires usage strictly below the ceiling, so any usage at which the pressure band fires can never be held. Holds for any user-set maxContextLimitPct, including < 0.7. ✓
  4. Nudge delivery mechanics: still an ephemeral host-appended user message gated by willInjectNudge — no mutation of existing wire content. ✓
  5. Config parse/merge: new optional sub-block; existing fields untouched; malformed burstHold rejects the whole compress block (same discipline as sibling blocks). ✓
  6. diagNudge log: extended with the HOLD T{n}, burst-hold(...) variant (0.1.69 回归: plugin 模式 nudge 注入被 !pluginMode 静默禁用 — INJECT 日志照打但从不投递, 自动压缩只剩 preflight 应急 #451 honesty class); INJECT path unchanged. ✓
  7. src/server/budget.ts: only the export keyword was added to EMERGENCY_NUDGE_ESCALATION_PCT; value unchanged. ✓

③ Code review

  • Detector premise verified against all four wire codecs (acp-kernel 0.0.95): anthropicToCore/openaiToCore/googleToCore/responsesToCore each emit exactly ONE CoreMessage per individual tool result, so counting contentType === "tool-result" cores == counting results on every wire. msgs at all four wiring sites (src/server.ts:2840/3047/3285/3534) is exactly the inbound normalized array, pre-processTurn.
  • Ceiling math correct: min(0.7, valid maxPct else 0.75); strict < means at-or-above the ceiling nothing is ever held (test pins the exact 0.7 boundary → false).
  • NaN/missing contextUsage fails safe toward legacy behavior (no hold).
  • "Applies in both compression modes" claim verified: opts.compress.injectNudge is config-level, the prepare paths are shared, and the README two-modes table confirms the proxy-injected nudge stays active in plugin mode.
  • No as any/@ts-ignore; stateless per request; acp-kernel pin untouched.

One semantic nuance (documented, not a defect): the kernel stamps lastNudgeShownTokens at DECISION time even when the host suppresses the text (acp-kernel dist/index.js:5155), so a held trigger is consumed — after the burst ends, the next proactive nudge lands at the kernel's next growth-cadence boundary, not immediately. Deferral is bounded either way: reaching min(0.7, maxContextLimitPct) forces compression through the emergency/pressure paths. The PR body said "deferred until the burst ends," which overstated immediacy — corrected in the body (see ⑤).

④ Test validity — tests/burst-hold.test.ts (14 tests) has teeth: the calibration non-trip case (steady alternation share 0.5 < 0.55 must NOT trip — the exact regression class this feature could introduce), trip case (10/12 = 0.83), count gate, trailing-slice windowing, ceiling math incl. NaN/0 fallback, hold matrix incl. exact-ceiling boundary, sub-field merge precedence, parser rejects. Gap (acceptable for a feat): no server-level test drives the willInjectNudge expression through prepare* — the wiring itself is exercised by the CI e2e lanes running real clients end-to-end.

⑤ Diff cleanliness & actions taken

  • 11 files, +299/−16, single linear commit — every line purpose-related. ✓
  • Stale base fixed: the branch opened ~40 commits behind master (master moved to v0.1.160; overlaps in src/server.ts, src/config.ts, CONFIGURATION*.md). I rebased onto origin/master @ 30b1574 — zero conflicts — and re-ran the full pre-flight on the rebased head: typecheck ✓ · tests 2921 pass / 0 fail / 12 skipped (gated e2e) ✓ · build ✓. Pushed with --force-with-lease (feature branch only): new head 9f51975; CI re-runs on it.
  • PR body patched (small fix in passing): master commit 08a1e72 introduced Configuration Surface Discipline — config-touching PRs need a dedicated "config surface" section (what's added / why the existing surface can't express it / mechanisms considered / migration story). This PR had owner sign-off (检测到瞬间需要读大量文件的时候,瞬时放宽压缩 #1487 floors 4+6) but lacked the section; added it, plus the trigger-consumption timing precision from ③, and updated the Pre-flight line to the rebased-head numbers.
  • CI on the old head 7ab5372 was 13/13 green (incl. e2e, hermetic registry, real-client lanes on ubuntu/windows). Awaiting green on 9f51975.

中文摘要:审查 PR#1491(burstHold 工具批量压缩暂缓)——方向符合 #1487 owner 决策;检测器语义已对照四条 wire codec 与内核 0.0.95 逐一验证,ceiling 数学保证压力带/紧急提示永不被挡;已 rebase 到最新 master(v0.1.160)无冲突,typecheck/tests 2921/build 全绿并推送了 rebase 分支,顺手补上了 PR 描述缺失的 config-surface 章节与触发器时序的精确说明——等 CI 在新 head 上转绿即可合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Follow-up: CI on the rebased head 9f51975 is 13/13 green — full test matrix (ubuntu 22/24 + windows 22/24), e2e, hermetic registry e2e, and all real-client lanes (codex/opencode/pi/dsh) pass. All pre-flight conditions from my review are now met; ready for human merge.

中文摘要:rebase 后的新 head CI 全绿(13/13),审查结论不变——可以合并。

ranxianglei pushed a commit that referenced this pull request Sep 27, 2026
…1491)

burst-hold.test.ts pins the gate itself; this pins the WIRING — one lane
per protocol (anthropic / openai-chat / google / responses), steady
alternation (share 0.5 < 0.55) must still inject the growth nudge while
the same token mass in a parallel burst (10 results / 12-message window,
share 0.83 >= 0.55, usage ~1% << ceiling) must hold it. Mutation-verified:
dropping the holdGrowthNudge factor from any one handler reddens exactly
that lane's burst case.
@ranxianglei

Copy link
Copy Markdown
Owner Author

深审收尾:src 四轴(门逻辑/接线/配置面/文档)零缺陷,唯一缺口是测试只盖了 burst-hold 门本身(gate),四个 holdGrowthNudge 接线点没有回归覆盖——变异拔门全套仍绿。已补 tests/burst-hold-wiring.test.ts(head 4b739ab):

  • 四车道 × steady/burst 对照:anthropic / openai-chat / google / responses 各一条;尾部 12 消息窗口,稳态交替(share 0.5 < 0.55)必须照常注入 nudge,同 token 质量的并行批(10 结果,share 0.83 ≥ 0.55,usage ~1% ≪ ceiling)必须扣住。地板平到 nudgeGrowthTokens: 300 单轮武装,窗口 400K 保证只有 burst 形状是变量
  • 变异验证:拔掉任一 handler 的 hold 因子(如 openai 的 server.ts:3061)→ 恰好该车道 burst 用例红,其余绿;复原 4/4——咬合精确
  • 门禁:typecheck ✓ / 定向 4/4 ×(mut 前 3/1、复原 4/4)/ 全量 2933 过 0 败(goldens 漂移为已知环境差异,非本 PR)

可合并。

ranxianglei pushed a commit that referenced this pull request Sep 27, 2026
…1491)

burst-hold.test.ts pins the gate itself; this pins the WIRING — one lane
per protocol (anthropic / openai-chat / google / responses), steady
alternation (share 0.5 < 0.55) must still inject the growth nudge while
the same token mass in a parallel burst (10 results / 12-message window,
share 0.83 >= 0.55, usage ~1% << ceiling) must hold it. Mutation-verified:
dropping the holdGrowthNudge factor from any one handler reddens exactly
that lane's burst case.
@ranxianglei
ranxianglei force-pushed the 2026-09-27_tool-burst-hold branch from 4b739ab to 979b86d Compare September 27, 2026 12:52
ranxianglei pushed a commit that referenced this pull request Sep 27, 2026
…1491)

burst-hold.test.ts pins the gate itself; this pins the WIRING — one lane
per protocol (anthropic / openai-chat / google / responses), steady
alternation (share 0.5 < 0.55) must still inject the growth nudge while
the same token mass in a parallel burst (10 results / 12-message window,
share 0.83 >= 0.55, usage ~1% << ceiling) must hold it. Mutation-verified:
dropping the holdGrowthNudge factor from any one handler reddens exactly
that lane's burst case.
@ranxianglei
ranxianglei force-pushed the 2026-09-27_tool-burst-hold branch from 979b86d to 6cd4b32 Compare September 27, 2026 13:11
ework-agent and others added 2 commits September 27, 2026 21:19
…1491)

burst-hold.test.ts pins the gate itself; this pins the WIRING — one lane
per protocol (anthropic / openai-chat / google / responses), steady
alternation (share 0.5 < 0.55) must still inject the growth nudge while
the same token mass in a parallel burst (10 results / 12-message window,
share 0.83 >= 0.55, usage ~1% << ceiling) must hold it. Mutation-verified:
dropping the holdGrowthNudge factor from any one handler reddens exactly
that lane's burst case.
@ranxianglei
ranxianglei force-pushed the 2026-09-27_tool-burst-hold branch from 6cd4b32 to ecb75bd Compare September 27, 2026 13:23
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 独立复核完成——新测试提交验证通过,且分支已 rebase 到当前 master,CI 13/13 全绿、mergeable_state clean。合并仍由人来(系统规则禁止 agent 合并)。

① 新测试 tests/burst-hold-wiring.test.ts 复核

  • 设计审读:四车道 × steady/burst 对照成立。校准是精确的边界探针——steady 尾部 12 窗口恰好 6 个 tool-result(share 0.5 < 0.55):过了 count 门(≥5)、只被 share 门拦住,正是稳态交替与并行批的分界;burst 为 10/12 ≈ 0.83。决策链 usage-driven(warmup 1K → payload 41K → probe 轮),窗口 400K 把 usage 压在 ~10% ≪ ceiling,burst 形状是唯一变量。确定性良好:loopback only、listen(0) 端口、复用既有测试 seam(_setStoreForTest/setRegistryForTest)。
  • 独立变异抽查(不只采信报告):本地拔掉 openai 车道的 hold 因子(实际行号 src/server.ts:3062,注释里写的 :3061 差一行,无碍)→ 恰好 openai-chat 一条红(3/1),其余三条绿;复原后 4/4、工作树干净。变异咬合与报告一致。
  • 本地门禁:typecheck ✓ · 定向 18/18(burst-hold 14 + wiring 4)✓ · build ✓ · 全量 0 败(goldens 在本环境无漂移,你们环境里的漂移如标注属环境差异)。

② master 在验证期间两次移动,已 rebase 收尾(热文件争用,§7.2)

结论:我上轮 review 指出的唯一缺口(四接线点无回归覆盖)已由有牙的变异敏感测试关闭,代码与行为结论不变。所有审查条件满足,可以合并——请 @ranxianglei 人工合并:#1491

中文摘要:独立复核了新增的四车道接线回归测试(含亲手拔门变异验证,咬合精确),并在 master 两度移动(web-UI 重写、strict-echo、chain-checkpoint)后完成两轮 rebase 与全量重验——最终 head ecb75bd CI 13/13 全绿、状态 clean,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

陈旧票清理(第三批动作①):目标 issue #1487 已关。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。

@ranxianglei ranxianglei changed the title feat: hold growth nudges during tool bursts while context has headroom [PR] feat: hold growth nudges during tool bursts while context has headroom Oct 24, 2026
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.

检测到瞬间需要读大量文件的时候,瞬时放宽压缩

1 participant