Skip to content

[PR] fix: thinking-then-stop — skip refetch, emit in-band error for host retry (#7410) - #7414

Open
ranxianglei wants to merge 2 commits into
masterfrom
2026-11-20_fix-7410-thinking-then-stop
Open

ranxianglei wants to merge 2 commits into
masterfrom
2026-11-20_fix-7410-thinking-then-stop

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

问题

DSH 车道上,模型「思考完就停、不给正文」(thinking-then-stop)时,proxy 会 refetch 一次。实测 refetch 后 41% 仍然退化(46 次 nudge 里 19 次 degenerate-again),既慢又费 token。

修法

thinking-then-stop 不再 refetch,直接发 in-band error 交回宿主重试(和 exhausted-retry 路径同一个 frame shape)。第一次的 thinking block 是完整的可见输出,所以不会出现第二个 thinking block。

行为变更

  • 旧:thinking-then-stop → refetch 一次 → 41% 仍然退化 → in-band error
  • 新:thinking-then-stop → 直接 in-band error → 宿主重试

宿主(DSH)本来就配了 5 次重试(retryableCodes 含 EMPTY_RESPONSE / MALFORMED_RESPONSE),in-band error 会触发宿主重试。所以这个变更只是把「白跑一次 + 报错」换成「直接交给能兜底的」。

测试

新增 tests/plugin-empty-turn-retry.test.ts 里的 plugin chat (anthropic) thinking-then-stop: no refetch, in-band error for host retry 测试,验证:

  • calls === 0(不 refetch)
  • 输出包含 event: error + "code":"stream_error" + thinking-then-stop
  • 日志包含 thinking-then-stop + not refetching

Closes #7410

…etry (#7410)

When the model thinks but produces no answer or tool call (thinking-then-stop),
refetching the same request + same nudge degenerates again 41% of the time
(measured). This change skips the refetch and hands the turn back to the host
as a retryable in-band error (same frame shape as the exhausted-retry path).
The first attempt's thinking block is the complete visible output, so no second
thinking block is appended.

Closes #7410
@ranxianglei ranxianglei added bug Something isn't working dsh p2 scope/wiring labels Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-20_fix-7410-thinking-then-stop (82aeaff)

Latest build — install this exact version

npm install -g billion-context@0.0.11105-pr.7414.a76b4be

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

Recent builds (commit → version)

commit version build
82aeaff billion-context@0.0.11105-pr.7414.a76b4be build
e939826 billion-context@0.0.11104-pr.7414.40cb210 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: thinking-then-stop — skip refetch, emit in-band error for host retry (#7410) [PR] fix: thinking-then-stop — skip refetch, emit in-band error for host retry (#7410) Nov 20, 2026
…#7410)

The error message is shown verbatim in the host UI. The mechanism explanation
(not refetching, handing back to host for retry) belongs in the log, not in
the user-facing error. Shortened to 'the turn degenerated (thinking-then-stop)'
per reviewer feedback.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷

PR #7414 审核 — thinking-then-stop 跳过 refetch,直接 in-band error 交宿主重试

查重:不重复。这是 #7410 的修复 PR,无其他在途 PR 针对同一主题(已搜 open PR,只有 #7414 匹配 "thinking-then-stop" / "7410")。

审核结论(八问):

  1. 是什么问题:DSH 车道上,模型「思考完就停、不给正文」(thinking-then-stop)时,proxy 会 refetch 一次;实测 refetch 后 41% 仍然退化(46 次 nudge 里 19 次),既慢又费 token,且两次 thinking 块被拼进同一条消息(第一条 921 字,第二条 0 字)。

  2. 什么原因导致的:根本原因是 retryEmptyTurn() 对 thinking-then-stop 形状走「refetch 一次」的恢复路径,但 refetch 的是同一个请求 + 同一个 nudge,模型以 41% 概率再次退化;且 refetch 时第一次已 append 的 thinking 块没被清掉(streams.clear() 只清 filter 状态,不清已写进回复的块),导致两次 thinking 块拼进同一条消息。

  3. 影响范围与严重程度:影响所有走 plugin 车道且使用 thinking 块(anthropic 协议)的宿主上 thinking-then-stop 形状的恢复路径。严重程度:体验瑕疵 + 性能浪费(41% 的 refetch 白跑 + 消息里多一个空 thinking 块),不是完全无法使用。

  4. 怎么修复的:thinking-then-stop 形状(sawThinking && answerChars === 0 && !sawToolUse && !stalledTail)不再走 refetch,直接发 in-band error(和 exhausted-retry 路径同一个 frame shape,stream_error code),交回宿主重试。宿主(DSH)本来就配了 5 次重试,in-band error 会触发宿主重试。第一次的 thinking 块是完整的可见输出,所以不会出现第二个 thinking 块。

  5. 是否有回归问题:

    • 高危模式逐项过:
      • 语义漂移:无。thinking-then-stop 的恢复路径从「refetch 一次」变成「直接 in-band error」,这是有意变更(已在 PR 描述里披露)。
      • fail-fast 变吞错:无。in-band error 是 fail-fast(明确报错),不是吞错。
      • 阈值/时序/输出格式变化:有(有意)。thinking-then-stop 的输出从「refetch 后的内容(59% 成功,41% 退化)」变成「in-band error」。这是有意变更。
      • 缓存/重试策略静默失效:无。缓存不受影响;重试策略从「proxy refetch 一次」变成「宿主重试 5 次」,这是有意变更。
    • 关键回归风险(需 owner 确认):PR 的变更在 GENERIC plugin 车道(src/plugin.ts),影响所有 plugin 宿主。如果某个宿主(非 DSH)不重试 on stream_error,那么 thinking-then-stop 的恢复路径会失效(从 59% 成功变成 0% 成功)。但 exhausted-retry 路径(既有,src/plugin.ts:3044)也发 stream_error 且依赖宿主重试,所以这个依赖是既有的,不是新引入的。DSH(本 issue 的宿主)确认重试。其他使用 thinking 块的宿主(opencode/pi/claude-code 的 anthropic 车道)是否重试 on stream_error 未逐一验证——建议 owner 确认,或观察合并后的宿主行为。
  6. 是否破坏缓存:无。缓存不受影响。

  7. 是否改了设计方向:有(有意)。thinking-then-stop 的恢复路径从「proxy refetch 一次」变成「直接 in-band error 交回宿主重试」。理由是:refetch 同一个请求 + 同一个 nudge 41% 仍然退化,而宿主的重试(5 次)是更可靠的恢复路径,且避免了两次 thinking 块拼接。

  8. 是否引入了新的配置:无。没有新的 env/config/默认值。

验证情况:

判定:PR 可合并。修法合理(疏而非堵——从源头跳过无意义的 refetch,而非在下游过滤拼接的块),测试有效(有牙齿,断言 calls === 0 + error frame + log line),diff 干净(12 行源码 + 38 行测试,无无关改动)。唯一需 owner 拍板的点:其他使用 thinking 块的宿主是否都重试 on stream_error(第 5 问的关键回归风险)——若确认,可直接合并。

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

Projects

None yet

1 participant