Skip to content

fix: surface DSH no-output-ceiling degraded budget on user-visible surfaces (#2904) - #2922

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-12_dsh-no-ceiling-budget-visibility
Oct 12, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-12_dsh-no-ceiling-budget-visibility

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes #2904 — DSH long session switched to a user custom model with no declared output ceiling (deepseek-flash) → output budget restored to ~249 tokens → every turn reasoning-only, stopping at length/max-tokens.

Root cause. When all four sources of resolveKnownOutputCeiling() are empty (no models.dev entry, no bili-configured output, host never reported maxOutput), restoreOutputBudget() lifts a client-starved budget (<=200, driven down by DSH's raw-history estimate) to the session high-water mark — which on a long session has decayed to a poisoned low value. There is no floor. Model switching merely exposes it (a model with a known ceiling masks the poisoned water by flooring above it). The only prior signal was a once-per-model log warn, invisible to GUI hosts (#1158).

This PR makes that degraded state visible and diagnosable; it does not change what bytes are forwarded.

Changes

  • State tracking (src/server/side-request.ts): restoreOutputBudget records a single-slot outputBudgetDegraded {model, value, ts} on session.metadata when it restores a starved budget with no known ceiling; clears it as soon as a ceiling appears or the active model's own budget recovers to a healthy (>200) value. Last-model-wins.
  • Visibility — three persistent surfaces (disappear when resolved): /acp panel line, Web UI session-detail banner, and the /__bili/plugin/status?conversationId= JSON field outputBudgetDegraded.
  • Diagnostic linkage (src/degenerate-turn.ts, src/loop/adapter-responses.ts): degenerateTurnWarning now also fires for max-output terminations (length/max_tokens/MAX_TOKENS/incomplete/max_output_tokens) that left zero visible text and zero tool calls; the responses adapter's previously-silent response.incomplete branch feeds it. Log-only — no forwarded-byte change.
  • Contract docs (TECHNICAL-NOTES.md + boundary note at src/agent/dsh-native.ts): documents that DSH reports maxOutput only when the model item explicitly declares maxTokens (provider defaults are not forwarded), why an undeclared custom model empties the ceiling chain, and that the real fix home is DSH-side (report its configured default).

Behavior changes (disclosed)

Surface Old -> New
/__bili/plugin/status?conversationId= JSON additive new field outputBudgetDegraded (null or {model,value,ts}); no existing field changed
session.metadata persistence additive optional key outputBudgetDegraded; survives restart; absent when healthy
/acp panel new OUTPUT BUDGET: line only while the active model is degraded
Web UI session page new warning banner only while the active model is degraded
logs new [degenerate-turn] ... (max-output) warn class for truncated nothing-visible turns
forwarded request bytes unchanged — writeOutputBudget target computation untouched

No built-in quota floor added (#1842 decision preserved). No per-model budget isolation.

Config surface

None. No new config fields, env vars, or CLI flags.

Tests

  • tests/side-request-isolation.test.ts: regression test for the degraded-state lifecycle (set / clear-on-ceiling / clear-on-healthy / last-model-wins / born-dead verbatim-forward value).
  • tests/tag-echo.test.ts: degenerateTurnWarning max-output branch across provider reason vocabularies; guards (text/tool-call presence, non-limit reasons) still suppress.
  • Typecheck clean; targeted suites green locally (full regression + e2e via CI).

The immediate user workaround remains setting maxTokens on the model item (or declaring providers.<url>.models.<model>.output in bili config); this PR does not remove the need for it — it makes the missing ceiling visible instead of silent.

Closes #2904

…rfaces (#2904)

A user custom model whose host never declared an output ceiling leaves all
four sources of resolveKnownOutputCeiling empty (#1840), so restoreOutputBudget
lifts a client-starved budget to a poisoned session high-water mark and every
turn truncates at max-tokens. The only prior signal was a once-per-model log
warn invisible to GUI hosts (#1158).

- track the no-ceiling degraded state in restoreOutputBudget (single slot,
  last-model-wins); clear it when a ceiling appears or the active model's own
  budget recovers to a healthy value
- surface it persistently on the /acp panel, the Web UI session page, and the
  /__bili/status JSON (outputBudgetDegraded); disappears when resolved
- extend degenerateTurnWarning to length/max-output terminations that left
  nothing visible (log-only, no forwarded-byte change); wire the responses
  adapter's response.incomplete branch into it
- document the DSH declaration-gated maxOutput reporting contract and its
  DSH-side fix home (TECHNICAL-NOTES.md + boundary note at dsh-native.ts)

Closes #2904
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-12_dsh-no-ceiling-budget-visibility (622640b)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3260-pr.2922.50b64b3

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

Install instructions are refreshed on each push.

ework-agent added 2 commits October 12, 2026 19:31
- OutputBudgetDegradedState was exported but referenced only inside
  side-request.ts, tripping the unused-exports gate (which then skipped the
  test + static-gates jobs); make it module-local.
- soften the three user-facing strings: the marker value is the restored
  target (can be mid-range, not always ~249), so state replies 'may be cut
  off at the output limit' instead of asserting truncation, and note there is
  no authoritative ceiling backing the client estimate.
The outputBudgetDegraded field lives on /__bili/plugin/status?conversationId=
(and the Web UI data source /__bili/sessions/<id>/detail), not on the
instance-level /__bli/status. Correct the route in TECHNICAL-NOTES.md and the
side-request.ts comment so readers don't look at the wrong endpoint. Docs +
comment only, no functional change.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

PR review 收工结论(详细八问见 #2904 主线程;本 PR 即其交付物)。

做了什么

  • 按「自己的 PR 不重做」规则核对分支:diff vs origin/master 恰好 11 个文件、全部属 [Bug][DSH] 长会话切换自定义模型后输出预算恢复到 249 token,连续 thinking-only / max-tokens(#1840 零上限来源场景) #2904 范围,无跑题改动。
  • 独立对代码核实了 ljyzww floor-12 的路由判断——正确:GET /__bili/status(sendStatus,src/server/admin.ts:755)只返回实例级状态、无会话字段;outputBudgetDegraded 实际落在 GET /__bili/plugin/status?conversationId=(handlePluginStatus)与 GET /__bili/sessions/<id>/detail(renderDetail)。
  • 发现那条「三处措辞含 /__bili/status」的修正已由并行提交 622640bc2 落定(repo 文件 + PR 描述都改成真实路由 /__bili/plugin/status?conversationId=);我本地也起了等价修正但未推,避免撞同一行,以分支上的为准。

现状 / 结果

  • 功能面经 floor-12(隔离台)+ floor-15(实况安装真实 DSH 宿主复现)双重验收通过,负向对照无误报,转发字节不变。
  • 当前 head 622640bc2(纯文档提交)的 CI 已全绿:33/33 SUCCESS,mergeStateStatus=clean。
  • 无阻塞项。可合——合并为人工操作,我无法代合,请你点合:fix: surface DSH no-output-ceiling degraded budget on user-visible surfaces (#2904) #2922 。合版后再评估是否撤你本机 deepseek-flash 的止血项(显式 maxTokens: 65536)。

@ranxianglei
ranxianglei merged commit bfbdb23 into master Oct 12, 2026
33 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.326-master.bfbdb23 (rolling master tag).

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

Development

Successfully merging this pull request may close these issues.

[Bug][DSH] 长会话切换自定义模型后输出预算恢复到 249 token,连续 thinking-only / max-tokens(#1840 零上限来源场景)

1 participant