Skip to content

feat: char-level degenerate-run valve for the outgoing view (session-death abort loop, real incident) | 出站视图的字符级退化阀门(会话死亡 abort 循环,真实事故) #517

Closed

Description

@SeniorHan

Motivation | 动机

Real incident (observed in the wild, adapter-side record): a 5968-char thinking block ended in 4655 consecutive 「【」 codepoints, escalating over turns until the turn aborted.

真实现场(适配器侧记录):一个 5968 字符的 thinking 块尾部出现 4655 个连续「【」,逐轮加剧直至回合 abort。

The failure is self-sustaining because of how hosts replay thinking:

  1. pi (and likely other hosts) sends prior assistant thinking back to the provider every request (reasoning_content, or plain text under requiresThinkingAsText).
  2. An aborted turn's partial message persists in the session log.
  3. The degenerated tail therefore rides along every later prompt; the model sees its own previous output ending in thousands of repeated characters — a continuation bias that re-triggers the same degeneration, aborting the next turn too.
  4. The session dies in an abort loop with no recovery path (user cannot edit persisted thinking).

失败自持的链条:宿主每轮回放 thinking → aborted 残缺消息持久化在 session log → 退化尾巴随每个后续 prompt 出行 → 模型看到自己上轮以千计的重复字符,继续偏置再退化 → 会话死于 abort 循环,用户无法编辑已持久化的 thinking。

Relation to existing guards | 与现有守卫的关系

repetitionGuard (#308) breaks byte-identical tool-call loops. Here the attractor is inside the generated text/thinking itself — no tool call involved, so nothing existing catches it.

repetitionGuard(#308)断的是字节级相同的 tool-call 循环;这里的吸引子位于生成文本/thinking 内部,不经过 tool call,现有机制接不住。

Proposed mechanism | 机制建议

A final pass over the outgoing view (persisted history is never modified):

  • Collapse single-codepoint runs with length ≥ minRun in assistant text/thinking, replacing the run with a short marker shorter than any detectable run.
  • Threshold: default 200 codepoints. Observed legitimate runs (markdown hrules, dotted leaders, comment banners) stay ≤ ~60 even during pre-degeneration drift; the incident run was 4655 — 200 gives wide margin. Values below 8 are raised to 8 (the marker must stay shorter than any detectable run).
  • Position-based self-limiting: while the degenerated message is the most recent assistant turn, append a one-shot recovery notice; once the model produces a fresh turn, the old message stops being last and the notice disappears — no persistent state, no accumulation (the feat: protectedLatestTools — protect only the latest instance of a tool #223 lesson).
  • Kill-switch config (enabled: false), never fails the session on internal errors.

对出站视图做最后一道 pass(不修改持久化历史):折叠 assistant text/thinking 中长度 ≥ 阈值的单码点 run;阈值默认 200 码点(合法装饰线/点线实测 ≤~60,事故 run 4655,余量充足);位置自限——仅当退化消息是最近一条 assistant 轮时附一次性恢复提示,模型产出新轮后自动停止,无持久状态不累积(#223 教训);带 kill-switch,内部错误绝不炸会话。

Evidence | 证据

  • Pre-degeneration drift observed max ~60 codepoints before the catastrophic run — a 200 threshold is far from legitimate content.

  • The aborted-loop dynamic was reproduced locally: replaying a session with a persisted 4655×「【」 tail aborted again on the next request; with the collapse pass, the same session recovered in one turn.

  • 退化前漂移实测上限 ~60 码点,200 阈值远离合法内容;本地复现:带持久化 4655×「【」尾巴的会话下一请求再次 abort,加折叠 pass 后同一会话一轮回合恢复。

Offer | 意向

Happy to submit a PR implementing this as an opt-out pass in the outgoing-view pipeline (reference implementation exists and runs in production in our adapter, ~290 lines with tests). If you prefer this to live in billion-context instead (per #513), tell me and I will file there.

愿意出 PR(出站视图管线的 opt-out pass;参考实现已在生产运行,约 290 行含测试)。若按 #513 的说法应落 billion-context,告知一声我去那边提。

Activity

  1. ranxianglei commented on Oct 23, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    查重: 不重复。 open+closed 全量检索 degenerate / repetition / abort / repetitionGuard / outgoing-view 等关键词,无相关条目。

    标签: pi, scope/kernel, p1(功能请求不打 bug;p1 按 owner 修订 2026-10-19「会话无法恢复类」——此类会话一旦死亡无自恢复路径)。

    先说落点:这个功能应该落 billion-context,不是本仓库

    按 #513(你的 2026-10-09 指示),内核代码已并入 billion-context、版本保持独立。今天核实了两点:

    • 本仓库 master 自 v0.0.101(2026-10-03)起无任何提交,已停更三周;
    • billion-context master 顶层有完整 kernel/ 源码树(与本仓库同一模块图),且带独立 release-kernel.yml 发版管线。

    所以正确落点是 ranxianglei/billion-context(kernel 目录)。你在 issue 里说「tell me and I will file there」——推荐方案 A:你直接在 billion-context 立 issue(正文+参考实现链接一起带过去),我们在那边接管 triage 与 review。跨仓库提交需要你明确批准,你自己立最合规。若希望由我们代为迁移,请在评论里明确批一句,我们再动手。

    一处引用勘误:你说的「#308 repetitionGuard」在本仓库源码里不存在(grep 0 命中);这里的 #308 实际是 release v0.0.74 PR。那个 guard 应是适配器侧(pi)的编号,到 billion-context 立项时请核对一下引用号。

    技术审核(功能类三步)

    合理性:真实现场+本地复现了循环动力学(回放→再 abort;加折叠 pass→一轮恢复),问题为真。自持链条成立:宿主每轮回放 thinking → aborted 残缺消息持久化 → 退化尾巴随每个 prompt 出行 → 继续偏置再触发退化。现有守卫只断 tool-call 循环,接不住生成文本内部的吸引子。

    系统设计:契合内核纯管线架构——内核本就管理可见上下文(hide/render-refs 节点),在出站视图加一道 opt-out 防御 pass 是自然延伸;确定性折叠意味着首次折叠后字节稳定,不会持续击穿 prefix cache(内核对此极敏感,你的机制天然满足);位置自限(仅当退化消息是最近一条 assistant 轮时附提示)对齐 #223 的教训——apply-time 从当前状态派生,不存持久标志。

    耦合/边界:view-only、不动持久化历史,不破坏 lossless round-trip(内核契约 §7.3-4),不改 message-id/ref 语义;kill-switch + never-fail 符合安全网哲学。三个实现时需明确的边界点:

    1. 覆盖面:退化 run 若出现在压缩块 summary 内(同样是模型生成文本、同样被回放),是否也折叠?建议覆盖——同一失败域;
    2. marker 安全性:替换 marker 必须短于 minRun,且不破坏 <acp> ref tag 或 mNNNNN 编号(render-refs 之后应用,或 tag-aware);
    3. 恢复提示措辞放内核 surface-text 层(与 nudge-text 同层),宿主可覆写。

    八问(按选项列第 3/5 问)

    1. 是什么问题:会话死亡 abort 循环——thinking 块尾部出现数千个连续同字符,宿主每轮回放该残缺消息,模型被继续偏置反复退化、反复 abort,用户无法编辑已持久化的 thinking,会话无恢复路径。
    2. 什么原因导致的:宿主侧 thinking 回放 + aborted 残缺消息持久化构成自持循环;现有守卫只断字节级相同的 tool-call 循环,生成文本/thinking 内部的吸引子无人拦截。
    3. 影响范围与严重程度(分选项):
    4. 怎么修复的(推荐 A):出站视图管线加一道确定性字符级折叠 pass(阈值默认 200、下限 8、kill-switch、内部错误绝不炸会话)+ 位置自限的一次性恢复提示;落 billion-context/kernel/,参考实现 ~290 行含测试。
    5. 是否有回归问题(分选项):
      • A/B:pass 是 view-only,不触碰持久化数据/wire 格式/ref 语义/管线节点顺序;两个风险点需盯:prefix-cache 交互(确定性折叠保证字节稳定,可控)、summary 覆盖边界(待明确,建议覆盖)。
      • C:代码级回归风险同 A/B,但违反仓库迁移方向,回归风险在流程层面(双轨维护)。
    6. 是否破坏缓存:确定性折叠 → 首次折叠后字节稳定,无持续失效;恢复提示仅在退化消息是最近 assistant 轮期间存在,新轮产出后自动消失,不累积(feat: protectedLatestTools — protect only the latest instance of a tool #223 教训)。
    7. 是否改了设计方向:不转向——出站视图管线新增一个 opt-out 防御节点,零新依赖,平台无关。
    8. 是否引入新配置:一组新配置项:enabled(默认 true,kill-switch)+ 阈值/minRun(默认 200,下限 8);默认值即安全值,无需迁移。

    决策请求:确认方案 A(你在 billion-context 立项、我们在那边接管)?若要我们代提,请明确批准。本 issue 先保持打开等你的决定。

  2. SeniorHan commented on Oct 24, 2026

    @SeniorHan
    Author

    已按方案 A 迁移:ranxianglei/billion-context#4476(三边界点答复已内联,引用勘误已修正)。感谢审核,请在那边接管 triage。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions