Skip to content

[PR] fix: shape the double-degenerate retry terminal by streamErrorShape (#5958) - #5965

Merged
ranxianglei merged 1 commit into
masterfrom
2026-11-08_degenerate-retry-error-shape
Nov 9, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-11-08_degenerate-retry-error-shape

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #5958

What & why

pipePluginChatWithStrip hard-wired the #870 double-degenerate terminal — the turn that degenerates AGAIN after the continuation nudge — to the legacy "completion" stream-error shape, ignoring ProxyOptions.streamErrorShape. It was the one stream-error site in the codebase that did not honour the global policy (default "protocol"; every other site resolves via ?? 'protocol').

Consequence (reported on 0.1.213, DSH native lane, local Qwen over OpenAI chat completions): after a browser tool call succeeds the model returns a render-tag echo with no usable answer; bili retries once with the continuation nudge; the retry degenerates too. The proxy logs "the turn degenerated again after the continuation nudge" but serializes that terminal as a completed turn — OpenAI finish_reason:"stop" / Anthropic synthetic completion block carrying the error text. DSH therefore books stopReason:"stop" + turn/end reason "completed" even though the task is still unfinished.

Fix

Thread opts.streamErrorShape through the pipe (new trailing optional param on pipePluginChatWithStrip; omitted → protocol-native via emitStreamError's own default) and emit with it from both forwardCaptured call sites. This re-couples the lone exception to the standard policy every other stream-error path already uses, instead of hard-coding a second shape:

No new config surface: reuses the existing compat.streamErrorShape knob.

⚠️ Behavior change (default)

The double-degenerate (#870) terminal in the plugin chat lane changes its default shape from the legacy success-shaped completed-turn frame to the protocol-native error frame, matching every other stream-error path. Affects all plugin-lane chat hosts that leave streamErrorShape unset. Hosts that depend on the old shape set compat.streamErrorShape:"completion".

Residual risk: I could not verify from here how an anthropic host (ZCode) handles event:error versus the old synthetic completion block; the escape hatch covers it if it does not.

Tests

  • Regression (the assertion this issue asked for): an exhausted retry is asserted to NOT be serialized as a successful completion — "code":"stream_error" present, no finish_reason:"stop", no legacy [ACP] stream error prefix.
  • Both-direction gate rows: explicit "completion" keeps the legacy shape (openai); default anthropic emits event:error with no synthetic block. The [bug] #870 in-band error 在 anthropic 协议下缺 content_block_delta.index —— 严格校验客户端整轮 Type validation failed #2689 anthropic well-formedness test is preserved verbatim under explicit "completion".
  • issue2303-draft-tail retry-degenerates row updated to the protocol-native shape.
  • typecheck clean; targeted suites green locally (full-suite verdict = CI).

Related facets (separate scope, cross-referenced, not merged): #4913 (the degraded-after-retry turn becoming a fatal in-band error), #5897 (empty-turn continuation retry off-by-default + neutral nudge wording).

…5958)

pipePluginChatWithStrip hard-wired the #870 double-degenerate terminal to the
legacy "completion" shape, ignoring ProxyOptions.streamErrorShape — the one
stream-error site that did not honour the global policy (default "protocol").
Hosts like DSH therefore received an unfinished turn serialized as a completed
turn (openai finish_reason:"stop" / anthropic synthetic completion block) and
booked it as stop/completed while the task was still unfinished.

Thread opts.streamErrorShape through the pipe (new trailing optional param;
omitted -> protocol-native) and emit with it from both forwardCaptured call
sites. streamErrorShape:"completion" restores the #870/#2689 legacy shape for
hosts that need the error text inside a well-formed turn.

Behavior change (default): the double-degenerate terminal in the plugin chat
lane now defaults to the protocol-native error frame, matching every other
stream-error path. Set compat.streamErrorShape="completion" to restore the old
shape.

Regression tests assert an exhausted retry is NOT serialized as a successful
completion (no finish_reason:"stop"), plus both-direction gate rows pinning the
explicit "completion" opt-in for openai and anthropic.
@ranxianglei ranxianglei added bug Something isn't working dsh p2 scope/wiring labels Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-08_degenerate-retry-error-shape (771d5d9)

Latest build — install this exact version

npm install -g billion-context@0.0.8667-pr.5965.739824e

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
771d5d9 billion-context@0.0.8667-pr.5965.739824e build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: shape the double-degenerate retry terminal by streamErrorShape (#5958) [PR] fix: shape the double-degenerate retry terminal by streamErrorShape (#5958) Nov 8, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复 — 检索 open PR 后确认只有一个 PR 针对 #5958(本 PR #5965),无并列修复;#4913/#5897 是相邻但机制不同的面(失败语义 vs 重试默认值/nudge 措辞),PR 已交叉引用、未并入,符合粒度政策。
标签: PR 已带 bug / p2 / dsh / scope/wiring(GitHub 实测在位)——按本 PR diff 独立复核:类别=缺陷、客户端=DSH(症状首发宿主)、范围=wiring(出站 wire 帧形状)、严重度=p2(状态误报、触发窄、有配置绕行),判定成立,不改。

Independent review conclusion — mergeable once CI goes fully green

I re-derived the review from the diff rather than from the issue-side report. Verified live against head 771d5d9:

① Direction (original issue). Version-first triage passes: at tag v0.1.213, src/plugin.ts:2802 carries exactly the hard-coded "completion" the reporter quoted — the mechanism exists in their build, so this is a real defect, not a version-lag misread. The fix re-couples the lone exception to the global policy at the decision point (root cause), instead of the reporter's one-line "protocol" hard-code, which would have deleted the #2689 escape hatch. Correct layer, correct direction.

② Regression inventory. Touched behavior: only the double-degenerate terminal frame shape. Checked every existing-behavior facet:

  • emitStreamError's own default is "protocol" (src/stream-error.ts:117), so all ~40 test call sites that omit the new param keep protocol-native output — no silent drift elsewhere.
  • Both production call sites (src/server/relay.ts:~1955 captured path, src/server/relay.ts:~2162 proxy 模式 SSE 出站不 strip 模型 emit 的渲染标签(openai/anthropic wire)— #457 分析发现的同类遗漏 #460 verbatim path) pass opts.streamErrorShape; there are no other production callers of pipePluginChatWithStrip.
  • No remaining hard-coded "completion" in src/ after the change (grep-verified); every other stream-error site already threads the knob (relay.ts:691/748/761/954/1744/2357, loop adapters via pickAdapter at relay.ts:2252).
  • No twin defect in the responses lane: src/plugin.ts has exactly ONE emitStreamError call site; the responses pipe's zero-byte-cut retry terminates via the Plugin mode: upstream stream truncated before terminal event → client gets bare cut-off SSE (no completion/error event) #721 truncation error, which is native-by-design.
  • Scanned ALL tests for stale legacy-shape pins on this terminal: fix-1760 and issue2612 rows are negative assertions (!includes("[ACP] stream error")) — still true under the new default; proxy-stream-error.test.ts:97 tests the emitter directly with explicit legacy input — untouched; issue-null-toolcalls-degenerate-retry / issue2756 assert logs/content, not wire shape. Nothing stale.
  • Exit matrix (src/exit-matrix.ts) is a registry of upstream-failure exits; the degenerate-retry terminal was never a cell there (content-degeneration, different concern) — no matrix update required by this change.
  • The only behavior drift is the intended default-shape change, disclosed old→new with reason and escape hatch in both PR body and commit message.

③ Code. Minimal (+63/−12, 4 files), trailing optional param keeps source compatibility, comments explain why with issue anchors (repo style), no dead code/magic values/new deps/new config surface. Clean single commit, branch name compliant, GitHub numbers only in artifacts.

④ Test validity. The regression has teeth: it asserts "code":"stream_error" present AND finish_reason:"stop" absent AND legacy prefix absent — I byte-checked each assertion against the actual emitters (nativeErrorChunk openai = top-level {error:{type:"server_error",code:"stream_error"}} + [DONE]; anthropic = event: error; legacy openai = text delta + finish_reason:"stop" + [DONE]). Both-direction gate rows present for openai and anthropic; the #2689 well-formedness test is preserved verbatim under explicit "completion".

Residual risk, independently assessed: since #1455, every OTHER stream-error path on the anthropic wire already delivers event:error under default config — so this fix introduces NO new frame class to any host. A host unable to handle event:error was already exposed to it on every mid-stream upstream failure; the escape hatch covers even that case. The author's stated uncertainty is therefore bounded, not open-ended.

CI (live, mirror cache): 30 checks — 0 failed, 7 pending (remaining test shards still running); static-gates green on ubuntu+windows; PR build artifact published (0.0.8667-pr.5965.739824e). Full-suite verdict lands when the last shard finishes — I will confirm here.


结构化八问(中文)

  1. 是什么问题:continuation nudge 重试后又退化一次的终态 turn,被序列化成「成功完成」的帧(openai finish_reason:"stop" / anthropic 合成 completion block 携带错误文本),宿主(DSH)于是把没做完的任务记成 stop/completed。
  2. 什么原因导致的:pipePluginChatWithStrip 的 degenerateRetried 分支把 stream-error 形状硬编码为 "completion",是全代码库唯一无视全局 streamErrorShape 策略(默认 protocol)的出错点;已在 v0.1.213 tag 上核实该硬编码存在(版本先行 triage 通过)。
  3. 影响范围与严重程度:所有 plugin chat 车道且未显式设置 streamErrorShape 的宿主;触发条件窄(需连续两轮退化/draft-tail 重试再退化)。属状态误报(失败记成成功,宿主可能丢失重试机会)——非不可用、无数据丢失、无缓存泄露 → p2。
  4. 怎么修复的:把 ProxyOptions.streamErrorShape 透传进管道(尾部可选参数,缺省经 emitStreamError 自身默认落到 protocol 原生错误帧),两个生产调用点均传入;复用既有 compat.streamErrorShape 旋钮,不发明新配置。比 issue 里的一行改法多保留了 [bug] #870 in-band error 在 anthropic 协议下缺 content_block_delta.index —— 严格校验客户端整轮 Type validation failed #2689 逃生门。
  5. 是否有回归问题:逐项清点过——非退化路径零改动;其余约 40 处测试调用点因新参数缺省而行为不变;responses 车道无同类缺陷(plugin.ts 仅一个 emitStreamError 站点);全测试扫描无残留旧形状断言;[bug] #870 in-band error 在 anthropic 协议下缺 content_block_delta.index —— 严格校验客户端整轮 Type validation failed #2689 anthropic well-formed 测试逐字保留并在显式 completion 下通过。唯一漂移即本 PR 要修的默认形状,已披露旧值→新值+原因+绕行方式。无意外回归。
  6. 是否破坏缓存:不涉及(不动缓存、重试游标、去重键)。
  7. 是否改了设计方向:无架构/边界/数据流转向;把一个例外重新接回既有标准策略,根因修复而非打补丁。
  8. 是否引入了新的配置:无。复用既有 BILI_STREAM_ERROR_SHAPE / compat.streamErrorShape(默认 protocol)。

收工判定:审核通过,CI 全绿后可由 owner 合并(wire 消息形状变更 → 按仓库规则仅人工合并,不自动合并)。CI 收尾后我会在本帖补一行最终确认。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI final confirmation (live-verified): all checks settled on head 771d5d9 — 30 checks: 13 success / 17 skipped (gated e2e lanes) / 0 failed. Full-suite verdict: green.

One nuance: the branch now reads behind master, but I checked the intervening master commits (#5859 CI-signal batch + ci-fixes merge) — none touch any of this PR's four files (src/plugin.ts, src/server/relay.ts, tests/plugin-empty-turn-retry.test.ts, tests/issue2303-draft-tail.test.ts), so the merge is conflict-free without a rebase.

Verdict stands: review passed, CI green — ready for your merge whenever. Wire-message-shape change → human-only merge per repo rules; compat.streamErrorShape:"completion" remains the escape hatch for any host that needs the legacy completed-turn frame.

@ranxianglei
ranxianglei merged commit c7c808d into master Nov 9, 2026
92 of 132 checks passed
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1111-master.c7c808d (rolling master tag).

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

bug Something isn't working dsh p2 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[dsh] Retry-exhausted degenerate turn is serialized as successful completion (0.1.213)

1 participant