Skip to content

fix(#3384): gate the #2490 refused-ledger planning floor so healthy dsh sessions keep their output budget - #3391

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-16_dsh-ledger-floor-starvation
Oct 17, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-16_dsh-ledger-floor-starvation

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3384

What was wrong

Since #2490, clampOutgoingOutput plans the outgoing output budget against max(folded-view input, refused-dsh-compaction ledger floor), where the floor is the byte size of the last REFUSED dsh compaction replay / 4. The floor was applied unconditionally.

But the refusal guard (#1729/#2360) refuses by default, and a refused checkpoint never lands in the client's history — so the client's raw ledger only grows while bili's own folds keep the wire payload small. The floor therefore rises every turn against a wire that stays small, and the clamp deterministically starves the model's output budget:

Reported incident (bili 0.1.197, DSH desktop, 1M window, onlyReasoning model):

output budget clamped 50670 -> 5909 (input~89699, planning floor 946753 from the refused dsh compaction replay (#2490), window=1000000)

Folded wire sat at ~9% of the window while the ledger floor reserved ~95%. The clamped 5909-token budget was eaten entirely by thinking (canDisableThinking: false) → upstream stopReason: length → no text, no tool-call → empty GUI turns, every step from turn 8 on. The #3071 4096 capability floor cannot save this regime: 5909 > 4096, and any fixed floor is whack-a-mole against a monotonically rising ledger.

The fix

The floor exists for ONE threat: a giant requested output riding a small folded view out the door while the client's raw ledger hugs the wall (#2490: requested 384K = 38.4% of the window, folded 20%, ledger 90% → one 7.5MB assistant turn → un-fold kill chain). Gate its application on the two independent grounds under which that threat actually exists — either suffices:

  1. view-at-enforced-target: bili's own folded-view estimate has reached the headroom-adjusted window that nudge/preflight enforce (inputEstimate >= headroomWindow);
  2. giant requested budget: the request asks for >= 25% of the native window (OUTPUT_LEDGER_FLOOR_GIANT_REQUEST_PCT, aligned with the output headroom 目前仍按 max_tokens 全额预留,是否应改为最大输出的 1/4 / 支持配置比例? #896 default outputHeadroomMaxPct and the clampOutgoingOutput sizes max_tokens against the raw native window while preflight enforces the reserve-adjusted one — up to 25% of slack the clamp never sees #2096 comment line "when max_tokens > 25% of the window the overflow boundary lies BELOW the headroom target").

A modest request cannot push a near-wall ledger over in one turn, so planning against the ledger in that case buys nothing but starvation. When neither ground holds, planning uses the folded view alone — which is what actually goes out the door.

Behavior change (old -> new)

  • Old: whenever a dsh compaction refusal had been recorded for the session, the output-budget planning basis was ALWAYS max(folded view, refused-ledger floor) — even when the folded view was 8% of the window and the request modest.
  • New: the ledger floor engages only when the folded view has reached the enforced headroom target OR the requested budget is >= 25% of the native window. In the reported incident: old clamped 50670 -> 5909 / new: no clamp, full 50670 rides out. In the dsh压缩与bili压缩冲突 #2490 incident shape (requested 384K vs 1M window): unchanged, still clamps 384K -> 55K.
  • No new config/env/CLI surface: the 25% line is an internal constant (precedent: 会话卡死自愈机制:卡死模式检测与代理侧主动补救 #2155 "thresholds are internal constants").
  • The sticky high-water recording (dshCompactionRefusedBytes) is untouched — only its APPLICATION is gated.

Tests

Out of scope (deliberate): the reporter's suggestion to ALLOW one rebased dsh-native compaction after N refusals — that contradicts the owner ruling recorded in #3016 (order-first: anything breaking bili's fold order should be refused); raised as a decision item in the issue thread instead. Refusal-terminal visibility (bili_final marker + storm logging) is open PR #3045 — complementary, no overlap.

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-16_dsh-ledger-floor-starvation (84341b2)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4117-pr.3391.0baf062

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-pr3391.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 是 #3384 的修复本身(非并列工作)。相关条目均为互补机制而非重复:#2490(拒绝账本 floor 的出处 + giant-request 保护区间)、#3071(4096 能力底)、#3045(拒绝终局可见性,独立 PR 无重叠)。方向关通过——修的是「floor 无条件应用」这个根因,不是治标。

我独立核对了 diff、调用方、测试与合并状态(未照抄 #3384 线程结论;本地未跑全量,以 CI 为准)。

独立核验要点

  • 核心逻辑成立:门控 planningInput = (viewAtEnforcedTarget || giantRequestedBudget) ? max(inputEstimate, ledgerFloor) : inputEstimate。两条依据与既有 headroom 目标互补——默认配置下 headroom≈0.75·窗口、giant 线=0.25·窗口,二者之和 ≤100%:折叠视图 <0.75W 且请求 <0.25W ⇒ 下轮 wire(折叠旧段+新输出)< W,可证安全,故此区间撤掉 floor 是对的;近墙折叠视图走依据①,dsh压缩与bili压缩冲突 #2490 巨型请求走依据②。
  • 调用方正确:openai/google/responses 三条 lane 均传 headroomWindow=config.modelContextLimit、nativeWindow、ledgerFloorTokens=dshLedgerFloorTokens(...);已确认 modelContextLimit 正是 nudge/preflight 强制的那个目标(acp-status.ts:243、preflight.ts:1458),依据①复用了正确的参照值,无新魔法数。
  • legacy 字节一致:无 dsh 拒绝时 ledgerFloor=0,门控前后 planningInput=inputEstimate,与旧 max(x,0) 完全等价。
  • 测试有牙:新文件钉住事故形态不 clamp(修前红)、giant→5909 保留、25% 含边界、边界下一 token 不 clamp、近墙视图触发、legacy×2,外加一条真 startServer e2e(拒绝 envelope 记录 high-water → 后续 20K 温和轮次原样出站,修前 ~8056)。issue3148 主例提到 300K(≥25%)保住 onClamped hook 路径,旧 65536 断言原样保留为新的回归子用例(断言无 clamp 事件)——是加固不是削弱。issue2490 doomed-probe 用 384K(≥25%)走 giant 依据仍压到 55K,保护区间存活。
  • CI 全绿(pushed head):ubuntu/windows × node22/24 全分片 test、static-gates、version/unused-exports/plan/docs-sync/kernel-guard/pi-subagents/test-import-graph/lane/lock-sync/config-surface-guard 全 success,e2e lane 按设计 skip。
  • 可合并性:落后 master 15 个提交,但 git merge-tree 对当前 master 干净合并(单 tree、零冲突);master 侧 3 个 doc 提交与本 PR doc 区不重叠。非阻塞。

八问

  1. 是什么问题:dsh 原生压缩被默认拒绝后客户端原始账本只增不减,bili 却每轮按这份账本体积给模型预留输出额度,把 max_tokens 逐轮压低直到只剩几千 token。
  2. 什么原因导致的:dsh压缩与bili压缩冲突 #2490 起 clampOutgoingOutput 无条件用 max(折叠视图, 拒绝账本 floor) 做规划基准;floor 是 sticky high-water 永不下调,而 bili 的折叠让 wire 保持很小——两者单调背离,健康会话也必然被饿死。
  3. 影响范围与严重程度:默认配置、surfaceTokens 接近窗口的 dsh 长会话、且模型不能关 thinking——完全不可用(无报错的空白轮);能关 thinking 的先变短再空白。openai/anthropic/responses 三 lane 同中招。
  4. 怎么修复的:只给 floor 的应用加门控——仅当①bili 自己折叠视图已到强制 headroom 目标,或②请求 ≥25% 原生窗口时才按账本规划;记录侧(sticky high-water)不动。这是改「决策点」的疏,不是拦截症状的堵。
  5. 是否有回归问题:逐项过既有行为——无 dsh 拒绝的会话字节不变;dsh压缩与bili压缩冲突 #2490 giant-request 区间经依据②保留(issue2490 仍 55K);近墙折叠视图经依据①保留;基础 clamp(plugin mode: no hard backstop when the agent ignores the compress nudge — context grows past the window and upstream 400s #453 input+output≤窗口)、[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 能力底、onClamped hook 均未动且被测试钉住。一处非阻塞观察:giant 线硬编码 0.25,而依据①阈值随 operator 配置的 modelContextLimit 变化;默认下二者互补(和≤窗口),但若有人把 modelContextLimit 调到明显高于 0.75·窗口(即输出预留 <25%),存在一个理论窄带(折叠旧段落在 0.75W~modelContextLimit 之间 + 温和请求)两依据都不触发。该情形需非默认调参,且基础 clamp 仍保本轮 input+output≤窗口、下轮 preflight 兜底真实溢出,故判为可接受取舍,不拦。可选精修:把 giant 线改为 nativeWindow − modelContextLimit 派生,让二者恒互补——属设计取舍,需你拍板,不在本 PR 强塞。
  6. 是否破坏缓存:不涉及。改动只在出站额度规划基准,wire 前缀、缓存断点、去重键均未触碰。
  7. 是否改了设计方向:不涉及架构转向;仅在既有 dsh压缩与bili压缩冲突 #2490 机制内收紧其触发条件(fail-open 收窄到一个明确的安全带),数据流不变。
  8. 是否引入新配置:无。25% 是模块内常量(先例 会话卡死自愈机制:卡死模式检测与代理侧主动补救 #2155「阈值为内部常量」),config-surface-guard CI 通过;CONFIGURATION.md en+zh 同步补充了拒绝侧行为说明。

判定:可合并。 根因修复到位、两条保护区间均有测试钉住、diff 干净(单 commit / 5 文件全部相关)、CI 全绿、对当前 master 干净合并。合并由人来执行:#3391 。第 5 问的可选项(giant 线随配置派生)若要做建议另开 issue 讨论,不阻塞本 PR。

@ranxianglei
ranxianglei merged commit 9c56a54 into master Oct 17, 2026
43 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.516-master.9c56a54 (rolling master tag).

npm install -g billion-context@0.0.516-master.9c56a54  # 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant