Skip to content

fix: retry terminal turns ending in a compression-draft closing tag (#2303) - #2304

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-07_draft-tail-terminal-retry
Oct 7, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-07_draft-tail-terminal-retry

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2303

What this fixes

A terminal turn whose last visible text block ends with a fully-closed compression-draft closing tag (</summary> / </analysis>) and carries no tool call was judged "completed" by every host-side convergence check, so the conversation stopped silently (149 production samples / 70 sessions in #2303; DSH native plugin mode over an OpenAI-compatible upstream). Upstream truncation dropped the step's final tool call, leaving "visible text + no trailing tool call" — a shape the existing zero-tool-ending fallbacks structurally cannot catch (#2248 floor-11 analysis of the retryEmptyTurn predicate chain).

Mechanism

One shared detector + one bypass per lane, reusing the EXISTING one-shot continuation budgets — no new state machine, no new config/env:

Behavior change (disclosed)

DEGENERATE_RETRY_NUDGE wording generalizes:

  • old: "Your previous response ended with no visible text and no tool call. Continue now: take your next concrete action."
  • new: "Your previous response ended without a tool call. Continue now: take your next concrete action — issue the tool call you were about to make, or state your final answer explicitly."

Reason: the old sentence is factually wrong for the draft-tail shape (there WAS visible text), and the single shared constant must stay accurate for both shapes. The nudge is ephemeral — never persisted, never replayed; byte-stability of all normal turns is unaffected (cache-proof suite green, incl. the degenerate-refetch tail-append proof).

Deliberately NOT done here

Evidence

  • New tests/issue2303-draft-tail.test.ts (14 tests): detector unit cases; chat openai/anthropic positives (draft split across deltas, retry lands in-stream, exactly one terminal frame); negatives (normal ending, truncated form, tool-call present, finish_reason=length stays on the truncation path); double draft-tail → Plugin passthrough leaves the client an empty turn when the model echoes a render tag #870 in-band error; responses positive + function-call negative; loop-lane positive / one-shot bound / negatives asserting nudge-in-body and client-visible ordering.
  • Targeted local runs green: issue2303 + plugin-empty-turn-retry + loop-degenerate-retry (39/39); cache-proof (5/5); plugin-passthrough-tag-strip-chat + loop-truncation-continuation + issue2171-zero-byte-truncation-retry (37/37); typecheck clean.
  • Real-client codex lane: ci-e2e.yml auto-triggers on src/loop/** (this PR touches src/loop/core.ts); the local sandbox has no live upstream for ACP_TEST_E2E=1.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-07_draft-tail-terminal-retry (0a41147)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2436-pr.2304.4bd0e5e

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

Install instructions are refreshed on each push.

…2303)

A terminal turn whose last visible text ends with a fully-closed
</summary> or </analysis> draft tag and carries no tool call is now
treated as non-converged instead of completed: each of the three
auto-retry lanes (plugin chat pipe, plugin responses pipe, proxy
compress loop) spends its existing one-shot degenerate budget on a
continuation-nudge re-issue, after which the turn passes through
exactly as before (a second draft-tail still hits the #870 in-band
error path in the plugin pipes). DEGENERATE_RETRY_NUDGE wording is
generalized from 'no visible text and no tool call' to 'without a
tool call' so it stays accurate for both shapes.
@ranxianglei
ranxianglei force-pushed the 2026-10-07_draft-tail-terminal-retry branch from a4fa488 to 8b7e8f9 Compare October 7, 2026 04:29
…ate)

Labeled in-passing fix found while reviewing #2303: the new unused-exports
gate (master-only, post-#1443) flags src/launcher.ts codexRewriteInsertionIndex
as INTERNAL_ONLY on current master itself, which kept every rebased PR red.
All references are file-local (call site + doc comment); dropping the export
keyword is behavior-neutral.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #2304 review 完成 —— 可合并(最终 head 0a4114791,CI 26/26 全绿)。review 期间做了两件事,均已推到 PR 分支:

  1. Rebase 到当前 master(74cf5246d):原分支基于旧 master,缺新落地的 unused-exports gate(audit: 全仓冗余审计与重构计划——server.ts 解体、客户端矩阵去重、死代码、AGENTS.md 模块图腐化 #1440 P6)与 refactor: drop dead declarations + demote internal-only exports + unused-export gate (#1440) #1443 死代码清理——rebase 前树上有 254 个 gate 命中(全是旧基座遗留的 export 修饰符)。rebase 无冲突,diff 完整(7 文件,+510/−13),rebase 后本 PR 归因的命中为 零。
  2. 顺手小修(独立标注 commit 0a4114791):gate 落地后 master 自身一直红——src/launcher.ts:1020 codexRewriteInsertionIndex 被标 INTERNAL_ONLY(5336c07 引入,全部引用文件内:调用点 :980 + 文档注释 :986),每个 rebase 到当前 master 的 PR 都会被它卡住。按 gate 脚本自带修复指引去掉 export 关键字,行为零变化,gate 转绿。

结构化七问

  1. 是什么问题:DSH native 模式下,模型把 handoff/压缩草稿写在 prose 里(结尾 </summary> / </analysis>)而没发出它描述的工具调用,叠加上游截断把该步尾部工具调用切掉后,该步呈现「有可见文本、无工具调用」,宿主判定回合已收敛,静默停摆。生产证据:149 样本 / 70 sessions,全部为完整闭合形式,零截断形态。
  2. 什么原因导致的:三条终局判定 lane(plugin chat pipe / plugin responses pipe / compress loop)的收敛判据只认「有工具调用」或「空回合」两种形状,「带可见文本的草稿尾」形状两边都不匹配——bili 侧当健康完成放行,宿主侧「零工具收尾才续跑」兜底的判据也只认完全无工具调用的步骤,于是无人续跑。根因在判据缺口,不在出口层文本。
  3. 怎么修复的:新增窄检测器 endsWithDraftClose(恰好生产见过的两个闭合标签、必须完整闭合、大小写不敏感、容忍尾随空白;截断形态显式排除——那是 tag-echo filter leaks bare <ac / <ac> render-tag fragments to the client (bare truncated open tag survives both process() and flush()) #1755/【bug】最终版issue: 模型生成的 <acp …> 标签会漏到用户可见输出(附根因、量化与修法建议) #2190 缺陷类),接入三条 lane 既有的 one-shot continuation-nudge 机制:终局满足「可见文本 + 无工具调用 + 尾是草稿闭合标签 + clean finish reason」时,复用 degenerateRetried 预算重发一次并注入 nudge,重试内容追加进同一条流;二次退化走既有 Plugin passthrough leaves the client an empty turn when the model echoes a render tag #870 in-band error(plugin lane)/ 普通完成(loop lane)。帧处理代码零改动,纯判据/门限扩展(rebase 后逐 hunk 核对过)。
  4. 是否有回归问题:无。逐项审过的既有行为及结论:① [BUG] In some cases, with Codex's auto model + DeepSeek, it will suddenly terminate automatically. #732/workbuddy报错Empty stream: upstream gateway sent only placeholder chunks without any model output (chunks=0, bytes=0) #821 空回合重试——该形状判据不变(可见文本=0),既有套件含 cache-proof 的 verbatim 断言全绿;有意变更(已披露):DEGENERATE_RETRY_NUDGE 措辞由 "ended with no visible text and no tool call" 改为 "ended without a tool call … issue the tool call you were about to make, or state your final answer explicitly",同时作用于旧空回合形状的 model-facing 提示(泛化措辞、信息量严格增加),两处既有测试断言已同步;② 截断路径(Plugin mode: upstream stream truncated before terminal event → client gets bare cut-off SSE (no completion/error event) #721/启动横幅硬编码 raw-HTTP-capture(on) 而真开关是 ACP_DUMP_BODY(默认关):日志永远撒谎,取证被带偏过 #413-follow-up)——新 lane 要求 clean terminal,finish_reason=length 留在截断路径,有专门负例钉住;③ 每请求一次重发预算——flag 语义未动,双重退化路径有专门测试;④ wire fidelity——chat lane 的 block-index offset、responses lane 的 id rewrite/drop 均为既有机制,新形状只是复用;⑤ degenerate warn([bug] #644 follow-up (post-#646, v0.1.97): typo'd render-tag echo (<acip …) bypasses the strip regex and passes through as a 43-char degenerate end_turn turn — agent stalls mid-orchestration until manual nudge #673)——未触碰。
  5. 是否破坏缓存:否。重试请求体 = 原 body + 临时 nudge user turn(不写 session state、下次请求不回放),前缀缓存命中热前缀,与既有 [BUG] In some cases, with Codex's auto model + DeepSeek, it will suddenly terminate automatically. #732/启动横幅硬编码 raw-HTTP-capture(on) 而真开关是 ACP_DUMP_BODY(默认关):日志永远撒谎,取证被带偏过 #413 路径同构;缓存失效策略、去重键、增量游标均不受影响。
  6. 是否改了设计方向:否。把既有 one-shot continuation-nudge 机制扩展到第二种非收敛形状;出口层剥离仍属 [bug] 出口层缺口:文本不在受管字段的帧绕过 tag-echo 状态机(E1/E5 原始转发出口 + 零日志真泄漏样本) #2248/[meta] ACP 标签泄漏综合治理:#2023/#2066/#2190 三切面统筹(修复 #2025/#2067/#2211) #2229(owner 待拍板),与 issue 圈定的范围一致。
  7. 是否引入新配置:无。无 env/config/CLI flag;标签词表硬编码(两个标签),系 issue 的范围决策。

测试有效性:新套件 402 行 / 12 例,断言有牙——正例钉住「恰好一次重发 + 单一终局帧 + id 一致性 + 草稿原文到达客户端且不被本 fix 剥离」;负例覆盖正常完成 / 截断形态 / 与工具调用共存 / length cut;另有 one-shot 上限与 #870 双重退化路径。本地定向验证:44/44 通过(新套件 + plugin-empty-turn-retry + loop-degenerate-retry + cache-proof),typecheck 干净,unused-export gate 干净。

两个残余边界(非拦阻项,如实记录):

结论:方向正确(修在判据层而非出口层剥离,与 issue 定位一致)、回归审查通过、最新 master 上全量 CI 26/26 绿(含 windows 22/24 与 dsh/opencode/pi/codex 各真实 lane)。满足合入条件——跨多模块且含 model-facing 措辞变更,不走 auto-merge 通道,请人工合并:#2304

@ranxianglei
ranxianglei merged commit a2d2895 into master Oct 7, 2026
26 checks passed
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.105-master.a2d2895 (rolling master tag).

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

DSH native mode: assistant text ending with </summary> is treated as a completed step, so the turn silently stops (149 samples from session transcripts)

1 participant