Skip to content

[PR] feat: self-classifying diagnostics for degenerate terminal turns (part of #3102) - #3107

Open
ranxianglei wants to merge 8 commits into
masterfrom
2026-10-14_degenerate-turn-diagnostics
Open

ranxianglei wants to merge 8 commits into
masterfrom
2026-10-14_degenerate-turn-diagnostics

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

Part of #3102 — observability only; no wire, config, kernel, or persistence behavior change.

Background

Two of the finish=length empty turns in #3071 had normal output budgets (32768) yet returned zero visible chars; both coincided with the dsh title-gen sidecar (#2503). The code audit (full write-up in the #3102 thread) ruled out stream interleaving as a bili-level cause: undici defaults to pipelining=0 (one socket per concurrent request; each fetch owns its response stream), and the side lane touches neither kernel state nor session stats (the strip pipe runs with session=undefined). Remaining suspects — budget burned in reasoning before any prose vs an upstream co-occurrence effect — were NOT distinguishable from current logs: the #2756 refusal line reported only char counters, and the reasoning-token split that gateways report inside completion_tokens was never sniffed.

What this PR adds

old: ...not retried (finish length is not a clean stop): visibleTextChars=0, releasedMarkupChars=0 (#2756)
new: ...not retried (finish length is not a clean stop): visibleTextChars=0, releasedMarkupChars=0, outputTokens=32768, reasoningTokens=32768, sawThinking=true, elapsedMs=1450, sessConcurrentForwards=1 (#2756/#3102)

The next occurrence states its own class: budget burned in reasoning (reasoningTokens≈outputTokens, sawThinking=true) vs produced nothing (reasoningTokens=?/0, small elapsedMs) — and whether the sidecar was actually in flight.

Behavior-change disclosure

Log-line format extension only (additive fields on one warn line). No wire/message shape, config surface, persistence format, kernel, or retry-semantics change. The forward() export keeps its exact signature; the original body moved into forwardInner unchanged (pure rename + wrapper).

Tests

  • New tests/issue3102-degenerate-diag.test.ts: counter semantics (own-forward exclusion, underflow clamp, session isolation); an openai length-finish zero-visible turn reporting the full field set incl. concurrency=1; the zero-concurrency control; Anthropic thinking_tokens capture.
  • Targeted local runs green on the rebased head: issue3102 (4 tests), issue2756 gate, host-usage-postfold, dsh-title-side-lane, dsh-title-sidecar-handle, plugin-empty-turn-retry — 70/70. Full-suite verdict comes from CI.

Fixes #3102

(孤儿认领:标题本已指向 #3102,补上关闭关键字 —— 第三批清理)

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-14_degenerate-turn-diagnostics (852166d)

Latest build — install this exact version

npm install -g billion-context@0.0.6203-pr.3107.2f98734

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
852166d billion-context@0.0.6203-pr.3107.2f98734 build
326ab84 billion-context@0.0.6115-pr.3107.097c706 build
e23595e billion-context@0.0.6023-pr.3107.9e3e1b9 build
75bf19c billion-context@0.0.5540-pr.3107.7d35bbf build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr3107.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

[bot] 🏷
(ai: vllm-qwen/qwen3.8-27b)

审核结论:PR 代码本身通过审核,可合;CI test lane 的红是 master 既有回归(已单独立项 #3125),与本 PR 无关。

已完成:rebase 到当前 master(d2c64e35 → b90da1b4a,已 push;master 新增的 14 个提交不触碰本 PR 任何文件)、逐行核代码、本地定向验证。

结构化八问

  1. 是什么问题:本 PR 是 When the bypass request for auto-generating a title runs concurrently with the main request, the first-round response under normal budget occasionally returns blank (TBD). | dsh 自动生成标题的旁路请求与主请求并发时,正常预算的首轮回复偶尔变空白(待查) #3102 的可观测性部分——给 【bug】空轮重试门闸把 reasoning 记成可见正文 —— Responses 协议下 item.content[] 带 reasoning 的退化轮永不重试(客户端拿到空轮) #2756 的「finish=length 非干净收尾」拒绝日志行加自分类字段,让下一次出现「输出预算正常却零可见字符」的退化终局轮时,日志能自述属于哪一类(reasoning 烧光预算 vs 什么都没产出),以及当时 dsh title-gen sidecar 是否真的在并发飞行。
  2. 什么原因导致的:非缺陷,属功能补充。背景:[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 的两个 finish=length 空轮现有日志无法区分成因——拒绝行只报字符计数,网关在 completion_tokens 里上报的 reasoning token 拆分从未被嗅探。
  3. 影响范围与严重程度:一条 warn 日志行的纯附加扩展;无 wire/消息形状、配置面、持久化格式、kernel、重试语义变更。对外零行为变化,纯内部可观测性。
  4. 怎么修复的(实现思路):三件套——① 每 session in-flight forward 计数器(src/concurrent-forwards.ts,内存 only;forward() 导出签名不变,原函数体原样移入 forwardInner,diff 纯 additive;begin/end 用 try/finally 配对,归零删 entry 无泄漏);② UsageSample.reasoningTokens 从 openai completion_tokens_details.reasoning_tokens(兼顶层拼写)和 anthropic thinking_tokens 嗅探,随其他字段并入累加器;③ 拒绝行追加 outputTokens/reasoningTokens/sawThinking/elapsedMs/sessConcurrentForwards 字段。核对过:dsh side lane 保留主 session 原始 key(sideRequestLike 门控),计数器按同 key 记账且排除自身 forward,关联信号对动机场景成立;新字段不流入 stats/baseline(acc 只被显式字段读取消费)。
  5. 是否有回归问题:审过既有行为清单并逐项判定——forward() 导出签名与语义(保持,【bug】空轮重试门闸把 reasoning 记成可见正文 —— Responses 协议下 item.content[] 带 reasoning 的退化轮永不重试(客户端拿到空轮) #2756 gate 重试语义未动)、usage 累加路径(新字段无泄漏路径)、dsh sidecar session keying(不变,仅新增计数)、日志行格式(纯附加)。结论:无回归。
  6. 是否破坏缓存:不涉及——未触碰任何缓存/重试/增量游标/去重键逻辑。
  7. 是否改了设计方向:不涉及——纯观测面,无架构/边界/数据流转向。
  8. 是否引入了新的配置:无。

验证与 CI 状态

收工判定:代码可合。 唯一拦路的是 master 自身的 golden 回归(#3125)——它清掉后 lane 即绿;若 owner 判定该漂移可接受并走 regen,同样解锁。合并动作留给人工。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷
(ai: vllm-qwen/qwen3.8-27b)

CI 终态更新:b90da1b4a 上 33/33 check 全绿,含四条 test lane(ubuntu/windows × node 22/24)。

之前预期会继承的 4 个 storage-render golden 失败没有发生——test lane 跑的是 PR merge ref(head + 当时最新 master),而 master 在跑测窗口内已合入该回归的修复(#3119,merge 68e32ffdb,harness 侧键序归一 + golden 重生;根因见 #3113:#3093 的 metadata 打戳让持久化 JSON 键序翻转,golden 哈希按插入顺序不排序键)。我先前立的 #3125 经比对与 #3113 完全重复,已关闭归并。

最终收工判定:全绿可合——代码审核通过、rebase 到当前 master、定向本地验证 70/70、CI 33/33。合并动作留给人工:#3107

@ranxianglei

Copy link
Copy Markdown
Owner Author

冲突

The #2756 refusal line reported only char counters, so the two
normal-budget length-finish empty turns of #3102 could not be
self-classified from logs (budget burned in reasoning vs produced
nothing; sidecar co-occurrence needed manual archaeology).

- src/concurrent-forwards.ts: per-session in-flight forward counter
  (in-memory only) — correlation signal for same-session sidecars
- relay.ts: thin forward() wrapper counts model forwards per session
- plugin.ts: UsageSample.reasoningTokens sniffed from
  completion_tokens_details.reasoning_tokens / top-level spelling /
  anthropic thinking_tokens; degenerate-terminal line now carries
  outputTokens, reasoningTokens, sawThinking, elapsedMs,
  sessConcurrentForwards
@ranxianglei
ranxianglei force-pushed the 2026-10-14_degenerate-turn-diagnostics branch from b90da1b to 09ef5bb Compare October 16, 2026 02:50
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

冲突已解决,rebase 到当前 master(d8c0e50)后 force-push,新 head 09ef5bbb6。GitHub 已确认 mergeable(当前 blocked 只是新 head 的 CI 还在跑)。

结构化八问

  1. 是什么问题:PR 分支落后 master 两天,master 期间删掉了 absorb 蒸馏功能(开了 absorb 之后,插件模式会话被指示调用一个永远不会出现的 absorb 工具(与 #3177 同症状家族,机制不同) #3293)并给 forward() 加了 v1Meta 参数,与本 PR 改动的同一批行撞车——src/plugin.ts 的 import 块文本冲突。
  2. 什么原因导致的:merge-base 之后 master 侧两次独立变更(absorb 移除、v1Meta 新增)都落在本 PR 触碰的行上。更隐蔽的是:src/server/relay.ts 被 git 自动合并成功但语义错了——master 的 forward() 有 13 个参数(含 v1Meta,函数体里 v1Active/wrapV1Internal 依赖它),而 PR 把函数拆成「计数 wrapper + forwardInner」后,自动合并出的 forwardInner 签名丢了 v1Meta,wrapper 调用也没传它。这种冲突 git 不报,直接推上去要么 typecheck 红,要么 V1 内联包装路径被静默关掉。
  3. 影响范围与严重程度:若不手工核对就推,CI 必红(relay.ts 里 v1Meta 未声明);假设绕过编译,V1 模式走 forward() 的全部流量会丢失 wire 包装行为。本次在推送前全部修掉,无用户可见影响。
  4. 怎么修复的:rebase 而非 merge,保持单提交线性历史。plugin.ts 冲突取并集意图:保留 master 的 compress-tool import 列表(absorb 符号已不存在,不能留)+ 加入本 PR 新增的 otherForwardsInFlight import。relay.ts 把 v1Meta 补回 forwardInner 签名和 wrapper 调用处。修复后做了逐字节校验:forwardInner 函数体与 master 原 forward 函数体(归一化命名后)diff 完全一致,确认没有第二处静默丢参。
  5. 是否有回归问题:审过的既有行为——relay.ts 相对 master 只有「改名 + 计数 wrapper + v1Meta 透传」,函数体零漂移;plugin.ts 相对 master 只剩本 PR 自己的 hunk(diffstat 4 文件 +229/-2,多出的 1 行就是补回的 v1Meta 参数)。本地验证:typecheck 干净、build 干净、定向测试 tests/issue3102-degenerate-diag.test.ts 4/4 过、覆盖 forward() 的 tests/issue3129-v1internal.test.ts + preflight-client-abort + issue1195-overflow-refold 共 24/24 过。全量回归以远程 CI 为准(test lane 正在新 head 上跑)。
  6. 是否破坏缓存:不涉及——无缓存/重试/游标/去重键改动;并发计数是纯内存关联信号,不落盘。
  7. 是否改了设计方向:不涉及——纯 rebase,PR 原设计(只加诊断日志字段,不改压缩行为)原样保留。
  8. 是否引入了新的配置:不涉及——无新 env/config/CLI。

行为变更披露(本 PR 自身内容,非 rebase 引入):#2756 的 degenerate-terminal 告警行末尾追加 outputTokens / reasoningTokens / sawThinking / elapsedMs / sessConcurrentForwards 五个字段——这是 PR 描述里已声明的诊断增强,旧字段与触发条件不变。

收工判定:冲突清零,分支可合并,等 CI 绿灯即可由人工合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

这条「冲突」评论(01:52)早于我刚才的修复——已处理完,现在没有冲突了。刚重新核过一遍:

  • master 没有再动,仍在 d8c0e50e7;PR head 09ef5bbb6 就坐在当前 master 顶上(fast-forward 关系,结构上不可能有冲突);
  • GitHub API 实时状态:mergeable: true,当前 blocked 只是因为新 head 的 CI 还有 5 个 test shard 在跑(其余 gate/build/static-gates 全绿);
  • 本地已验证:typecheck、build 干净,定向测试 28/28 过(含覆盖 forward()/v1Meta 路径的 3 个套件)。

等 CI 全绿后页面冲突标记会消失,可以直接合并。详情见我上一条八问回复。

@ranxianglei ranxianglei changed the title feat: self-classifying diagnostics for degenerate terminal turns (part of #3102) [PR] feat: self-classifying diagnostics for degenerate terminal turns (part of #3102) Oct 24, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

冲突已解决并推送(merge commit 75bf19cce,master 2e7052077 并入分支),PR 恢复可合并。

冲突点与解法(两文件、六处 hunk,全部按「双方意图取并集」解,无功能取舍):

八问:

  1. 是什么问题:PR 分支与 master 文本冲突(merge state dirty),阻塞合并。
  2. 什么原因导致的:分支 10-14 切出后,master 上 [Bug] anthropic lane: cache-hit % halved when the upstream relays an OpenAI-semantics backend (billing_usage.semantic=openai, input_tokens inclusive) #4128(usage 字段面)、[Bug] Jimp is active, but image accumulation still triggers Responses WS 1009; duplicate request size not reduced (v0.1. | [Bug] Jimp 已生效,图片累积仍触发 Responses WS 1009;重复请求未缩小(v0.1.200) #3701/Silent upstream stall is invisible in logs: no 'awaiting first byte' warning between forward POST and client disconnect #3434(relay 重构 + 同区域新增)与本 PR 的计数包装撞在同一批行上。
  3. 影响范围与严重程度:仅本 PR 可合并性;对用户无影响。若解错会回归两侧任一功能,故逐处核对。
  4. 怎么修复的:union 解决,如上;无一方逻辑被丢弃或改写。
  5. 是否有回归问题:逐项审过既有行为——[Bug] anthropic lane: cache-hit % halved when the upstream relays an OpenAI-semantics backend (billing_usage.semantic=openai, input_tokens inclusive) #4128 declaredInclusive 全链路(message_start/delta → merge → applyUsageSample → promptInputTotal)原样;cache-capture 仍包住实际转发;计数仍排除 GET/HEAD、finally 兜底。本地 typecheck 干净(tsc exit 0),定向测试 tests/issue3102-degenerate-diag.test.ts + tests/usage-observability.test.ts 11/11 过;全量交给 CI。
  6. 是否破坏缓存:不涉及——只动日志诊断字段与内存计数,不碰缓存键/重试/游标。
  7. 是否改了设计方向:不涉及,纯机械冲突解决。
  8. 是否引入新配置:不涉及。

判定:冲突闭环,等 CI 全量绿后即可合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

第二轮冲突已解决并推送(head fee6ce489),PR 恢复可合并(mergeable=true;当前 state=blocked 是 CI/保护规则待过,非冲突)。

这一轮撞了什么:master 又前进了(2e7052077 → 931c66a2f,含 #4248 handoff-latest-reply、#4535 日志本地时间、#4644/#4646 hermes 自愈等)。这次只有一处文本冲突——src/plugin.ts pipePluginChatWithStrip 函数体开头:本 PR 在 const acc: UsageSample = {} 后加 pipeStartedAt(degenerate-terminal 诊断的计时起点),master 的 #4248 在同一位置加了 handoff reply 追踪块(replyPart/appendReply/setReplyTool/sawReplyError)。src/server/relay.ts 本轮自动合并干净,无需手解。另注:上一轮推送后分支上被 #4599 help-merge sweep 合入了 ci-fixes(e23595e15),推前一并合入,无冲突。

解法:union 保留双方——pipeStartedAt 在前,#4248 的 reply 块原样在后。两边符号都在下游被使用(计时用于 2598 行诊断日志;reply 块贯穿 anthropic/openai/gemini 各分支与 reply?.save()),互不重叠,无取舍。

八问:

  1. 是什么问题:分支再次落后 master 产生文本冲突,阻塞合并。
  2. 什么原因导致的:PR 生命周期长,hot file(src/plugin.ts)被多路 PR 持续重写([PR] fix: Save and export the latest assistant reply in the handover document | fix: 交接文档保存并导出最新一条助手回复 #4248 与本 PR 在同一函数开头各自插声明)。
  3. 影响范围与严重程度:仅本 PR 可合并性;对用户无影响。
  4. 怎么修复的:单一 hunk union 解决 + 合入分支上的 ci-fixes sweep,详见上。
  5. 是否有回归问题:逐项核对——[PR] fix: Save and export the latest assistant reply in the handover document | fix: 交接文档保存并导出最新一条助手回复 #4248 reply 追踪链完整保留(声明→各 wire 分支 append/setTool→终态 save);When the bypass request for auto-generating a title runs concurrently with the main request, the first-round response under normal budget occasionally returns blank (TBD). | dsh 自动生成标题的旁路请求与主请求并发时,正常预算的首轮回复偶尔变空白(待查) #3102 诊断字段(reasoningTokens/sawThinking/elapsedMs/sessConcurrentForwards)原样;relay 侧本轮零手动改动。本地 typecheck 干净(tsc exit 0),定向测试 tests/issue3102-degenerate-diag.test.ts + tests/usage-observability.test.ts 11/11 过;全量交给 CI。
  6. 是否破坏缓存:不涉及——纯局部变量声明合并,不碰缓存键/重试/游标。
  7. 是否改了设计方向:不涉及。
  8. 是否引入新配置:不涉及。

判定:冲突闭环,等 CI 全量绿后即可合并。若 master 再前进导致第三次冲突,按同一 union 原则处理即可。

ci-check added 3 commits October 26, 2026 14:17
master window commits 293ae65/de5e03659 bumped kernel/package.json to
0.0.165 without regenerating the lockfiles; lock-sync re-resolution then
rewrites the stale recorded versions (root 0.0.163, kernel 0.0.164) and
fails. Pure recorded-version sync via npm install --package-lock-only;
no dependency or semantic change.

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

None yet

Projects

None yet

1 participant