Skip to content

fix: floor the #2490 planning-clamp output at a 4096 capability minimum (#3071) - #3101

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-14_planning-floor-min-output
Oct 15, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-14_planning-floor-min-output

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

What

Floors the #2490 planning-clamp output at a 4096 capability minimum, per owner sign-off in #3071.

When dsh's compaction is refused (#2490), the sticky planning floor drives clampOutputBudget (src/server/budget.ts) to cap outgoing max_tokens at window - floor - margin. For a 262144-window session whose refused replay is ~247K tokens, that clamps output into the low thousands (1479–2623), so every reply truncates at finish=length before any visible text lands — a share of the 9 empty turns reported in #3071 came from this path.

The fix

In clampOutputBudget, where a clamp already fires (cap >= OUTPUT_CLAMP_FLOOR):

const floorOut = Math.min(OUTPUT_CLAMP_MIN_OUTPUT /* 4096 */, Math.floor(nativeWindow - inputEstimate));
const clamped = Math.max(cap, floorOut);
if (clamped >= requested) return undefined;   // never RAISES
return clamped;

Per the owner's constraint (#3071): floor_out = min(4096, window - input), applied only where a clamp already fires. The sub-floor surrender (cap < OUTPUT_CLAMP_FLOOR) stays byte-identical, so fail-closed overflow protection is preserved — input + output never exceeds the window, and when raw headroom < 4096 the floor is bounded by headroom (it does not force 4096 onto a payload that would overflow). The clamp never raises a client budget already under the floor; raising belongs to the restore lane (PR #3080).

Behavior change (old -> new)

  • OLD: a refused-compaction session's outgoing output was clamped to window - floor - margin = 1479–2623 on this class of session -> every reply truncated empty.

  • NEW: floored to 4096 when headroom allows (bounded by window - input otherwise). Fail-closed preserved. No pinned #2490 assertion changes — the smallest pinned clamp value is 55K, far above the floor (verified below).

  • The dsh压缩与bili压缩冲突 #2490 pins are untouched, but two OTHER incident pins sit inside the band this fix removes and are re-pinned in a follow-up commit (review finding, CI was red on 293e859): tests/issue2122-clamp-calibration.test.ts (naive cap 3357 → floored 4096) and tests/issue2558-clamp-image.test.ts (naive cap 2016 → floored 4096). Both teeth still bite — the scenarios still clamp far below the requested budget; only the sub-floor starvation values change, exactly per the signed formula.

Tests

New tests/issue3071-planning-floor-min-output.test.ts (7 cases: the two incident floors 2623->4096 / 1479->4096, no-raise honoring a sub-floor client budget, sub-floor surrender untouched, headroom-bounded floor, healthy cap unchanged, integration through clampOutgoingOutput). All 6 existing tests/issue2490-ledger-floor-doomed-probe.test.ts cases stay green — confirming the STICKY high-water recording and the 55K incident clamp are untouched.

Local: targeted suites green, npm run typecheck clean, npm run build green. Full-suite verdict = remote CI on this head.

No config surface added (internal constant, like OUTPUT_CLAMP_FLOOR).

Part of #3071

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-14_planning-floor-min-output (c8c4cae)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3792-pr.3101.8e4ca1f

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-pr3101.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

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

PR 审完。结论先行:修法本身正确、与批准公式逐字一致;但原 head(293e859e)CI 是红的 —— 两个既有 incident pin(#2122 / #2558)钉的正是本 PR 要移除的 sub-4096 饥饿值,PR diff 没更新它们。我已在 PR 分支直接修掉(独立标注 commit 42481442,test: 前缀),并补了 PR 描述披露。修复后本地定向全套绿(58/58)+ typecheck/build 绿;新 head CI 已在跑(30 个 run 已触发)。

独立验证过程:拉分支逐行读 diff;手算复核每个钉住值(含 #2490 s2 的 55_000 = max(55000, 4096) 不变、s4 sub-floor surrender cap=−39500<1024 不变);本地跑全部 8 个直接调 clamp* 的测试文件(新文件 + #2490 STICKY pin + #453/#2011/#2096/#2122/#2558/deferred-tool);比对旧 head 的 CI check-runs——红的只有 test lane(ubuntu 22/24 已完成 failed,windows 检查时仍在跑),与本地复现完全吻合,static-gates 与全部 e2e lane 全绿。

八问:

  1. 是什么问题:dsh 原生 compaction 被拒后(dsh压缩与bili压缩冲突 #2490 sticky planning floor 顶在 window−~15K),输出预算钳制把 max_tokens 压到 1479–2623,每轮回复都在出字前被 finish=length 截断成空轮——[bug] 0.1.195 输出预算三路饿死仍复现:无 output 上限模型 restore 无下限(1→252、fork 原样转发 1)、#2490 planning floor 钳到 1479–2623 → 3 会话 9 次 finish=length 空轮不重试(#546/#1665/#1840/#2904/#2756 残留) #3071 九次空轮中的路径 3。
  2. 什么原因导致的:cap = window − input − margin(≥max(2048, 5%))。planning input 顶墙时 margin 吃掉大部分余量,cap 数学上必然落进低千位——而原始余量(~15K)其实够一条正常回复。不是没空间给输出,是「削减目标」公式没有下界。
  3. 影响范围与严重程度:仅「compaction 被拒 且 planning input 贴近 window」这一类会话(即本事故类);此类会话内每一轮都受影响 → 用户可见空白回复,对该类会话等于完全不可用;其余会话不受影响。
  4. 怎么修复的:按 owner 批准公式 floor_out = min(4096, window − input),在钳制已触发处取 max(cap, floorOut);新增 clamped >= requested → 放行不动 守卫(never RAISES——抬高属于 fix: floor the ceiling-less starved output budget at an absolute minimum (#3071) #3080 restore lane,两 lane 职责不混);sub-floor surrender(cap < 1024)路径字节级不变。
  5. 是否有回归问题(逐项清点既有行为):
  6. 是否破坏缓存:否——不碰缓存/重试/增量游标/去重键;wire 前缀字节不变,只有 max_tokens 数值变化。
  7. 是否改了设计方向:否——仍在 plugin mode: no hard backstop when the agent ignores the compress nudge — context grows past the window and upstream 400s #453/dsh压缩与bili压缩冲突 #2490 clamp 机制内部,只给削减目标加了下界;与 fix: floor the ceiling-less starved output budget at an absolute minimum (#3071) #3080 不交叉(本 PR 动 budget.ts 的 clamp lane,fix: floor the ceiling-less starved output budget at an absolute minimum (#3071) #3080 动 side-request.ts 的 restore lane,不同文件,可组合:restore 抬到 8192 后若 headroom 允许再钳到 4096)。
  8. 是否引入了新的配置:否——内部常量 OUTPUT_CLAMP_MIN_OUTPUT=4096,与既有 OUTPUT_CLAMP_FLOOR=1024 同类,不进配置面。

收工判定:等新 head(42481442)CI 全绿即可合(wire-shape 相关,人合,不满足 auto-merge 条件)。合并顺序按 owner 建议:#3080 先行(覆盖 9 次空轮中 6 次的根因),本 PR 随后——两者无冲突,也可并行合。

ranxianglei pushed a commit that referenced this pull request Oct 14, 2026
ework-agent added 2 commits October 14, 2026 12:34
…um (#3071)

When dsh's compaction is refused (#2490), the sticky planning floor drives clampOutputBudget to cap outgoing max_tokens at window - floor - margin; for a 262144-window session that clamps output into the low thousands (1479-2623), so every reply truncates at finish=length before any visible text lands (a share of the 9 empty turns in #3071).

Per owner sign-off in #3071, floor the CLAMPED value at a 4096 capability minimum: floor_out = min(4096, window - input). The floor applies only where a clamp already fires (cap >= OUTPUT_CLAMP_FLOOR); the sub-floor surrender stays byte-identical, so fail-closed overflow protection is preserved (input+output never exceeds window) and no pinned #2490 assertion changes (smallest pinned clamp is 55K). The clamp never RAISES - a client budget already under the floor is honored; raising belongs to the restore lane (PR #3080).
Review follow-up on 293e859: the CI test lanes went red because two existing
incident pins encode the exact sub-4096 starvation values this PR's floor
removes:

- tests/issue2122-clamp-calibration.test.ts: naive cap 3357 -> floored 4096
  (headroom 10219 >= 4096)
- tests/issue2558-clamp-image.test.ts: naive cap 2016 -> floored 4096
  (headroom 13349 >= 4096)

Both teeth still bite (the scenarios still clamp far below the requested
budget); only the floor changed, per the owner-signed formula
floor_out = min(4096, window - input) from #3071.
@ranxianglei
ranxianglei force-pushed the 2026-10-14_planning-floor-min-output branch from 30fbbd7 to fe0d17f Compare October 14, 2026 04:39
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

补充上一轮 review 的结论:CI 上挂掉的 4 个 storage-render golden 测试与本 PR 的 diff 无关,已定位根因并解决。先更正我上一轮「等新 head(42481442)CI 全绿即可合」的说法——当时 CI 确实是红的。

发生了什么:推送 4248144 后,CI 四条 lane 全红(storage-render golden × chat/anthropic/responses/google),但本地在每一种环境组合下都稳定绿(node 22.23.3 / 24.11.1、UTC/CST 时区、加压并发、模拟 CI 环境变量袋)。我在 golden 失败信息里临时加了逐字段输出(临时 commit 30fbbd7):CI 打印显示会话 metadata 的每个字段取值与本地逐字节一致,唯一差异是顶层键顺序——CI 上 biliVersion 排在第一个,golden 和本地排最后一个。

根因:golden 的指纹按「键插入顺序」对整个持久化对象做哈希。#3094(修 #3093)把 biliVersion 从「写盘时追加」改成「建会话时最先写入」,键位置前移;而 golden(#3092 重生成)钉的是旧顺序,且 #3092 当时没被全量 lane 的 CI 校验过。GitHub Actions 的 pull_request 检出的是 head+master 的合并提交,同时含新顺序代码和旧顺序 golden → metadata 段整体指纹偏移。本地裸跑本 PR head 不含 #3094,所以绿。凡是 base 同时含这两个提交的 PR 都会同样红(#3094 自己也是红的);master 的 push 触发 CI 不含全量 test lane,所以一直没暴露。

处置:master 已修好(#3113/#3119,commit 5278e82ee):harness 侧哈希前先对对象键做深排序(数组顺序保留),钉逻辑内容而非序列化顺序,并重生成四个 golden。我已把本 PR rebase 到新 master b5b73b396,并移除临时诊断 commit——分支现在只剩两个提交:fix(6e6361e6b)+ 两处旧 clamp 值改钉(fe0d17fa7,3357→4096 / 2016→4096)。插曲:rebase 后首次推送时分支曾被并发会话覆盖回诊断版,已重新 force-push 恢复为 fe0d17fa7(该 sha 的全量 CI 已有一次全绿记录:run 38511141353),当前等待这次重触发的 CI 收尾。

八问(本轮):

  1. 是什么问题:不是修复本身的问题,是 golden 测试的钉法与 fix: 运行中会话的详情面板不再误显示 legacy(仅 JSON)存储与版本 —(自 #3093) #3094 引入的新 metadata 键顺序不匹配,导致 4 个回归测试在 CI 全 lane 红。
  2. 什么原因导致的:钉法按键插入顺序哈希而非逻辑内容;fix: 运行中会话的详情面板不再误显示 legacy(仅 JSON)存储与版本 —(自 #3093) #3094 移动了 biliVersion 的位置;golden 重生成后未被全量 CI 验证过。
  3. 影响范围与严重程度:所有 base 同时含这两个提交的 PR 在这 4 个测试上红(含 fix: 运行中会话的详情面板不再误显示 legacy(仅 JSON)存储与版本 —(自 #3093) #3094 自身);纯测试钉法问题,对用户零影响。
  4. 怎么修复的:master 侧(master CI 常红:storage-render 四个 golden 测试漂移(#3093 版本戳进会话元数据后未重生 golden),拖红所有新 PR #3113/修复 master CI 常红:storage-render golden 对元数据字段顺序过敏(#3113) #3119)把钉法改为键序无关 + 重生成 golden;本 PR 只需 rebase 到新 master。
  5. 是否有回归问题:无。本 diff 在 golden fixture 内是惰性的;sub-floor fail-closed 路径未动(dsh压缩与bili压缩冲突 #2490 六个钉住用例验证);改钉的两个值正是本修复要消灭的饥饿值,断言牙仍在。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:无。
  8. 是否引入了新的配置:无。

判定:可合(人合;wire-shape 变更不满足 auto-merge 条件)。合并顺序按 #3071 里 owner 的决定:#3080 先行,本 PR 随后。无需另开 issue——根因已在 master 跟踪并修复(#3113),再开即重复。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI 收尾确认:head fe0d17fa7 全部 33 个 check-run 绿,包括之前挂掉的 4 条 test lane(ubuntu/windows × node 22/24,storage-render golden 已随 master 的 #3113 键序无关钉法恢复)。分支最终形态 = 两个提交(fix + 两处 re-pin),直接坐在 master b5b73b396 上。可以合并了(人合;按 #3071 的顺序,#3080 先行、本 PR 随后)。

@ranxianglei
ranxianglei merged commit 7a3f22f into master Oct 15, 2026
25 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.449-master.7a3f22f (rolling master tag).

npm install -g billion-context@0.0.449-master.7a3f22f  # 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.

ranxianglei pushed a commit that referenced this pull request Oct 15, 2026
PR #3101 (#3071) floors the output-clamp reduction target at min(4096,
window-input); the #3148 test still expected the pre-floor raw cap of
1360 for the same numbers, so every master CI test shard fails on it.
Update the recorded-event and wire assertions to 4096 and document the
formula step. Same failure reproduced on plain master (6b5b283).
ranxianglei pushed a commit that referenced this pull request Oct 15, 2026
…ssed by #3101's re-pin)

#3154 (merged 2026-10-15 09:35) pinned the #3148 clamp event at capped=1360. #3101 (merged 2026-10-15 20:30) introduced the owner-signed #3071 floor floor_out=min(4096, window-input) and re-pinned the pre-existing #2122/#2558 pins, but its re-pin commit predates #3154, so the newer #3148 pin stayed stale and every CI test shard touching this file has been red since. Both asserts (event.capped and rebuilt.max_tokens) come from the same floored value in clampOutgoingOutput; headroom 51228 >= 4096 so the floored value is 4096. The tooth still bites: the scenario still clamps 65536 far below the requested budget.
ranxianglei pushed a commit that referenced this pull request Oct 15, 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