Skip to content

[PR] fix: esc-interrupted output no longer triggers the growth-cadence nudge on resume (#5298) - #5356

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-31_abort-nudge-reanchor
Oct 31, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-31_abort-nudge-reanchor

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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

Closes #5293

查重: 不重复 (screened open+closed vs #5300 per-session opt-out, #4831 precompute folds, #3006/#3012 escalation-vs-suppression, #5055 model-decided nudge — different mechanisms).

What & why

In pi, pressing Esc mid-stream and continuing triggers an immediate compression nudge injection ("压缩注入"). Other agents with the same persist-aborted-partials behavior are affected too.

Mechanism (verified against pi source, earendil-works/pi packages/agent/src/agent-loop.ts:254):

  1. Esc aborts the stream; pi persists the partial assistant message into its session.
  2. The interrupted turn never reports usage for that output — the proxy settles only what the aborted stream reported (the request's input size).
  3. The continue turn resends history including the partial; the next usage-grade reading jumps by exactly the unreported partial size.
  4. The flat-growth cadence (KDD feat: release CI (npm auto-publish on release branch) #8, floor 50K default) counts that jump as organic growth — so the nudge fires within one or two requests of the user's redirect, summarizing work the user just rejected.

Fix

Event-driven re-anchor, host-side only (no kernel change):

  • noteAbortedTurn(session) — stamped in both plugin pipe client-abort catches (src/plugin.ts, after settleUsage has landed the pre-abort input size), recording session.transient.abortReanchor = {anchor, at}.
  • absorbAbortedTurnGrowth(session, tokenCount) — called in all four prepares right before the main processTurn. When the meter has actually moved past the pre-abort anchor (the persisted partial now shows up in measurement), it re-anchors the low-water reference to the current reading and clears the pending-nudge stamps — same full-reset shape as applyCompression's post-success reset (kernel compress.ts). Stale flags (>30 min) drop without touching state; sessions without an abort see byte-identical decisions.

This is the deliberate inverse of #3674's retired event-gated re-anchor: that one moved the reference on drift heuristics and dead-zoned small drops; this moves it UP, gated on a witnessed client abort, for a known unmeasured mass.

Behavior change (disclosed per policy)

  • Old: interrupted-turn output counted as growth debt — a nudge could fire within 1–2 requests of resume whenever debt + existing growth crossed the interval.
  • New: the first post-resume measurement re-anchors the reference; the next nudge requires a fresh full growth interval.
  • Untouched: preflight hard backstop, pressure bands, fold eligibility, all non-abort sessions (flag absent → no-op).

Boundaries

  • Plugin lanes covered (pi/dsh/opencode/omp/codex pipes; inline-engine included — its abort error propagates into the same pipe catches). Bare-proxy lane not instrumented (no session in the dispatch catch path); documented boundary.
  • Flag is in-memory by design (dies on restart; abort→resume causality holds for one process lifetime) plus a 30-min staleness guard.
  • No new config keys. No kernel/ changes.

Tests

New tests/issue5293-abort-nudge.test.ts: unit edge cases (skip/no-op/wait/consume/stale-drop/max-guard) + hermetic integration scenario through the real proxy (pi plugin lane, anthropic wire): warmup below floor → abort mid-SSE with persisted partial → resume turn reads stale anchor (no nudge, flag survives) → debt turn absorbed (no nudge = the fixed behavior) → organic growth still fires the nudge later (negative direction, #3617 discipline). Verified RED without the src changes (debt-turn assertion fails: nudge present) and GREEN with them.

@ranxianglei ranxianglei changed the title fix: esc-interrupted output no longer triggers the growth-cadence nudge on resume (#5298) [PR] fix: esc-interrupted output no longer triggers the growth-cadence nudge on resume (#5298) Oct 31, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。 独立检索 open+closed issue/PR(按失败签名「abort/Esc 中断 + nudge 误触发」与机制「growth reference re-anchor」查过),无既有条目覆盖本缺陷;PR 正文自查的相关项(#5300 per-session opt-out、#4831 precompute folds、#3006/#3012 escalation-vs-suppression、#5055 model-decided nudge)机制均不同,作者查重结论成立。

标签: bug + pi + scope/kernel + p2(缺陷类;报告宿主 pi;失败域是压缩决策面的增长节奏记账;能用但有明显问题→p2)。

审核进行中,初步结论:

  1. 方向过关:机制链成立——Esc 中断 → pi 把 partial assistant message 持久化进会话 → 中断回合从未上报该输出的 usage → resume 后计量跳变恰好等于未上报的 partial 体积 → flat-growth cadence(KDD feat: release CI (npm auto-publish on release branch) #8)把它当有机增长,nudge 在用户改向后的 1–2 个请求内触发。修在决策点(事件驱动 re-anchor)是治因不是堵症状;与 The nudge growth reference point, once clamped by a single high-water mark, never recedes — long sessions must wait unti | nudge 增长参考点被单次高水位钳死后永不回落,长会话只能等到 75% OVER-LIMIT 才压缩 #3674 low-water 教义的关系也核对过:本修复把参考值向上移、且门控在亲眼见证的客户端 abort、一次性消费,不重新引入被退役的漂移启发式/死区。
  2. 发现一个 provenance 小问题:标题、commit message 和全部代码注释引用的都是「decision request: kernel change to stop dsh-injected user messages stealing the "last user message" compression protection slot (#5174) #5298」,但 decision request: kernel change to stop dsh-injected user messages stealing the "last user message" compression protection slot (#5174) #5298 是一个不相关的 dsh kernel 决策请求;真实目标是 In pi, Esc triggers compression injection. | pi中esc会触发压缩注入 #5293(测试文件名与 Closes 行都正确指向 5293)。会在 PR 分支上补一个只改注释引用的 additive commit;标题归系统管道所有,不动,仅在此说明。
  3. 本地定向验证:新测试在 PR head 上 2/2 绿(unit 边界 + hermetic 集成场景);正在补做「去掉修复则红」的牙齿验证 + typecheck,全量回归交 CI。

结构化八问结论随后跟上。

…5298

The original commit's title/message/comments cited #5298, which is an
unrelated open decision request (dsh-injected user messages stealing the
last-user-message protection slot). The bug report fixed here is #5293
(pi Esc-interrupt triggers compression injection); the test filename and
the Closes line already said 5293. Comments/test labels only — zero
behavior change. (review fix-up on PR branch)
@ranxianglei ranxianglei added bug Something isn't working p2 pi scope/kernel labels Oct 31, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

结构化八问(PR #5356 审核结论)

1. 是什么问题
pi 里按 Esc 中断模型输出后继续对话,bili 会在继续轮的 1–2 个请求内注入「现在压缩」nudge——压缩提示正好落在用户刚打断/否定的工作上。凡「abort 时把 partial assistant message 持久化进会话」的宿主都中招(pi 确认;修复覆盖全部插件车道)。

2. 什么原因导致的
因果链三层:(a) pi 在 abort 时把 partial 持久化进 transcript;(b) 中断回合从未上报该输出的 usage——代理只 settle 流里已报告的部分(即该请求的 input 尺寸);(c) resume 轮重发含 partial 的历史,下一个 usage-grade 计量读数恰好跳变 = 未上报的 partial 体积,flat-growth cadence(KDD #8,#3674 low-water 参考值)把这个跳变计为有机增长并越过 ready gate。根本原因:增长记账把一块「已知未计量质量」当成了债。宿主侧行为改不了(pi 持久化是它的设计),中断流也补不上 usage 报告——所以修在决策点:跳变落地的瞬间、以亲眼见证的客户端 abort 为门控,重锚参考值。这是治因不是堵症状(同一个根因换个形状出现——比如宿主 partial 落地时机不同——门控条件「计量越过 pre-abort anchor + 已见证 abort」仍然接得住)。

3. 影响范围与严重程度
所有插件车道上「用户中途 Esc 再恢复」的会话(pi/dsh/opencode/omp/codex 管道共享同一组 abort catch)。严重程度 p2:nudge 是软引导,最坏情况是 Esc 后立刻多一次无谓压缩提示(可能把刚被否定的工作摘要掉);不丢数据、不影响可用性。bare-proxy 车道未插桩(分发 catch 路径没有 session),属文档化边界;且多数裸客户端 abort 时丢弃 partial 而非持久化,暴露面有限。

4. 怎么修复的
事件驱动 re-anchor,纯 host 侧,无 kernel 改动。两个函数:noteAbortedTurn(session) 插在两条插件管道的 client-abort catch 里(settleUsage 已把 pre-abort input 尺寸落账之后),记 session.transient.abortReanchor={anchor, at};absorbAbortedTurnGrowth(session, tokenCount) 在四个 prepare 的 processTurn 前一刻调用——一旦计量真的越过 anchor(partial 已在测量中显现),把 low-water 参考值移到 max(oldRef, 当前读数),清掉 pending-nudge 与 tier stamp(与 applyCompression 成功后重置同形),一次性消费 flag。>30 min 的陈旧 flag 静默丢弃不动状态;无 abort flag 的会话决策逐字节不变。与 #3674 退役机制的关系核对过:#3674 退役的是「按漂移启发式向下重锚、把小跌陷进死区」的 reanchorNudgeOnUsageDrop;本修复方向相反(向上)、门控不同(见证事件而非漂移)、对象明确(已知未计量质量),不重新引入死区。

5. 是否有回归问题
审过的既有行为清单及结论:

  • 无 abort flag 的会话:早退返回,决策不变(单测 u-noop + 集成 r1/r2/r6/r7 钉住)——保持;
  • preflight 硬背板:独立窗口溢出路径,不消费 nudge stamp——不受影响;
  • 压力带(pressure band):kernel 内部按 usage 百分比裁决,绕过 growth gate——不受影响;
  • fold 资格判定:不触碰——保持;
  • fix: compress over unpruned view + acp-kernel 0.0.38 (billion-context-pi#195) #194 first-sight mass bypass:键在 baseline===0 && shown===0,absorb 会把 baseline 置 >0,故只在罕见交集(会话带着巨量 backlog 到达且 baseline 尚未 stamped 时用户恰好 abort)被抑制一次——有界,压力带仍在窗口边缘兜底,可接受;
  • tier stamp 清空:T2/T3 mass 触发从当前计数重新武装——与 applyCompression 重置完全同语义(既有先例),非新行为;
  • shown stamp 清空:取消挂起的半节奏 re-nudge——有意为之(挂起 nudge 随其回合而死);不清的话,半节奏 re-nudge 本身就是 Esc 后的过早 nudge 压力的一部分。
    高危模式逐项过:非 abort 路径无语义漂移、无 fail-fast 变吞错、除披露的行为变更外无阈值/时序/输出格式漂移。结论:无意回归未发现。

6. 是否破坏缓存
否。不改任何 wire 字节(nudge 时机走既有机制);前缀缓存、fold 覆盖、重试/去重键均不受影响。

7. 是否改了设计方向
无架构转向。沿用既有 transient-flag 模式(requestMembership 先例)+ 既有 post-compression 重置形状;host 侧收口,kernel 边界未动。唯一需要点名的教义例外:这是对 #3674「references never ride UP」low-water 规则的一次有据可查的事件门控例外(info 日志留痕:aborted-turn growth absorbed: nudge reference X→Y),理由充分——跳变是记账债不是有机增长。

8. 是否引入了新的配置
无。ABORT_REANCHOR_MAX_AGE_MS(30 min)是内部常量,非 config/env 面。行为变更已按政策披露:旧 = 中断回合输出计入增长债(debt+已有增长跨过 interval 时 resume 后 1–2 请求内必触发 nudge);新 = resume 后首个越过 anchor 的计量重锚,下次 nudge 需攒满一个完整 fresh interval。

验证与处置记录

判定

可合入(待 CI 绿)。方向正确、根因层修复、回归面清点干净、测试有牙;唯一遗留是标题里的错号(系统管道归属,仅记录)。

@ranxianglei ranxianglei left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审查完成(本地分支 @e2f3fdef,已合并最新 master @42cd5ba 并推送)。结论:代码通过,无阻塞项;CI 全绿即可人工合并。

冲突解决(本次推送)

分支落后 master 较多,试合并只有 src/plugin.ts 一处真实冲突:master(#5286 系)把 getSession 换成了 getSessionAsync(fork snapshot 冷恢复路径),本 PR 在同一 import 行加了 noteAbortedTurn。取并集一行解决——两侧改动正交、都保留。其余文件全部自动合并。验证:tsc --noEmit exit 0;新套件 2/2 + nudge/cadence 相关两批 59/59 绿(nudge-decide / fork-nudge-deadzone/trigger / anthropic-lane-nudge / issue1470 / issue3004 / issue3159 / issue3204 / issue3910-lane-nudge-wiring / plugin-nudge-injection / silent-backend-nudge / prepare-* / issue5293)。

修复本身核验

  1. 机制对症:故障链是「中断轮的部分输出从不报 usage → 续跑请求的重发历史里带着这段未计量质量 → 下一个 usage-grade 读数一跳正好等于这段 → flat-growth cadence 把跳变当有机增长」。「在见证客户端 abort 后、等表针真的越过锚点时再一次性上移基准」是对该因果的正确形状——与 applyCompression 成功后同一 full-reset 形状(清 shown 戳 + tier 节拍戳),不留半阈值残留。✓
  2. 事件门控而非启发式:只在 pipePluginChatWithStrip(:3654) / pipePluginResponsesWithStrip(:4522) 的 client-abort catch 里 stamp(且要求已有 metered 基线 lastInputTokens>0);absorb 只认「meter > pre-abort anchor」才消费,flag 一次性用掉;>30min 静默过期。无 abort 的会话 flag 不存在 → 决策逐字节不变。✓
  3. 吸收时机正确:四个 prepare 全部在 processTurn 之前调用(openai:216 / responses:340 / anthropic:361 / google:199),传的就是本轮 meter tokenCount——先修基准再让内核做 nudge 判定,顺序无竞态。✓
  4. 边界如实披露:bare-proxy lane 不 instrument(dispatch catch 路径没有 session 对象)——我核实过 server.ts/handle.ts 确实无 noteAbortedTurn 挂载点,注释成立;inline-engine 走同一 pipe catch 所以覆盖到。✓

「彻底吗?只针对 pi 吗?」

不是 pi 专属。 挂点选在两个共享 plugin pipe 的 client-abort catch + 四个 wire prepare——任何走插件车道的客户端(pi/dsh/opencode/omp/codex pipe 都经过这两条 pipe),只要「中流 abort → 客户端把部分输出持久化进自己的会话 → 续跑重发」这一组合成立,就被同样处理。触发判据是 bili 侧观测到的连接中断事件,与是哪个 agent 无关。已知未覆盖面(按风险排序):① bare proxy lane(客户端直接把 base URL 指向 bili 的场景)没有 session 挂载点——同类问题在那条车道理论上仍存在,是文档化边界不是遗漏;② 首个 usage 之前就被 abort 的新会话(lastInputTokens<=0 不打标)——保守 no-op,实际被 growth floor(默认 50K)挡着,早期债务要一次未计量输出 ≥50K 才会立即触发,罕见;③ flag 在内存(重启即失)+ 30min 窗口——窗口内若客户端实际丢弃了部分输出(没有跳变),后续无关增长越过锚点会消费掉 flag,代价至多多等一轮 nudge 节拍,自愈。三者都不阻塞。

本地验证(正式全量留给远程 CI):定向批 59/59 + tsc 绿 + merge 后工作树干净。

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-31_abort-nudge-reanchor (42cd5ba)

Latest build — install this exact version

npm install -g billion-context@0.0.7547-pr.5356.65d36a9

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
42cd5ba billion-context@0.0.7547-pr.5356.65d36a9 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei merged commit 44fcbe4 into master Oct 31, 2026
49 of 52 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.967-master.44fcbe4 (rolling master tag).

npm install -g billion-context@0.0.967-master.44fcbe4  # 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 p2 pi scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In pi, Esc triggers compression injection. | pi中esc会触发压缩注入

1 participant