Skip to content

fix: fork 子会话 nudge 全盲死区 — 收据播种 sizing 基线(0.1.195 卡死复现) - #2936

Merged
ranxianglei merged 2 commits into
masterfrom
fix/fork-nudge-dead-zone
Oct 12, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
fix/fork-nudge-dead-zone

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

复现(0.1.195 现场,确定性)

现场日志(同一父会话 session-c0ccf16d、同一 branch point 93、间隔 33 分钟的两个 fork 子会话,数字完全一致):

fork child session-927d2f8f adopted parent session-c0ccf16d at branch point 93 (#2399)
processTurn: 671 msgs, renderTags=text-only ...
nudge idle: usage=0% (0/936000), growth=0/675000 (ref=0, interval=1500000), pendingT1=929710/1500000 model=step-5-preview, reason="max compressible 929710 < threshold 1500000; growth 0 < floor 675000"
context 957750 tokens reached preflight target 936000 ... preflight compressing before forward
[preflight] payload ~1084337 tok vs window 936000 (~1.2x) — raising summarization budget 16 -> 19, rounds 16 -> 19
preflight still running after 30000ms grace — committed early SSE headers + keep-alive to hold the client (#568)

用户视角:fork 选压缩过的分支 + 换模型 → 对话卡住、上下文显示 0、压缩块形状怪异(branch point 处的 crossing 块展开态 + preflight 反复部分折叠)。不换模型则一切正常(窗口装得下,不触发 preflight)。

根因(三因叠加,核心是 A)

A. mid-history fork 子会话的 nudge 死区(本 PR 修复) — handlePluginFork(src/plugin.ts)给子会话建立全新 stats:计费隔离有意不继承 usage 基线(lastInputTokens/lastUsageGradeTokens 不播种),但 localInputEstimate 也没人播种 → effectiveTokenCount 的 #728 兜底链路返回 0 → kernel decideNudge 拿到 tokenCount=0:usage 恒 0%、growth 恒 0、first-sight mass 需 usage ≥ 45% —— 所有触发线结构性失明,恰发生在继承上下文最满的时刻。nudge 状态本身也只在全前缀 fork 时继承(prefix.length === snapshot.orderedMessages.length)。

B. 固定步长放大(文档修复) — 现场 nudgeGrowthTokens: 1500000 > 窗口 936k:T1 质量触发线在窗口内永远够不着。内核默认 50k 不会踩这个坑,但文档从没警告过步长必须与窗口成比例。

C. 无过程可见性(日志修复) — 19 轮 LLM 总结 × 每轮一次上游往返(分钟级),期间只有 #568 一行 hold 提示,轮次全程静默;两份现场日志都断在 #568 行,无法判断最终收敛与否。

修复

  1. src/plugin.ts — fork 收据在既有 recordContextObservation(est, "estimate") 之后补一行 child.stats.localInputEstimate = child.stats.contextTokens:收据自己的估计恰好描述子会话下一次出站的准确视图,播种它让 nudge 从第 1 轮就活着。只可能偏早(字符上界),真实 usage 报文立刻接管([Bug] 上游从不报告 usage 时 nudge 永不触发——上下文无界增长直到超窗(ChatGPT 登录态后端) #728 不变量),每次 prepare* 都会用实测出站覆盖。孙会话(fork 的 fork)走同一条收据路径,同样覆盖。
  2. src/preflight.ts — 每个 LLM 轮一行 info(digest 应急态每 32 轮一行):round N/M: payload ~X tok vs window W (deficit D), K viable range(s),马拉松进行中可观测。
  3. CONFIGURATION.md — nudgeGrowthTokens 增加与最小窗口成比例的警告(步长 > 窗口 → T1 质量触发不可达 → 增量折叠静默、超窗请求直坠 preflight 马拉松)。

测试(tests/fork-nudge-deadzone.test.ts,3 个,红-绿已验证)

测试 断言
mid-history fork 播种 收据后 localInputEstimate === contextTokens(141768);计费隔离保留(lastInputTokens===0、source≠usage);effectiveTokenCount>0 且落入 ≥75% 压力带;kernel processTurn(放宽 preserveRecent 与 harness 同参)→ nudge.shouldInject 为真,reason 命中 OVER-LIMIT/EMERGENCY
fork-of-fork 孙会话收据同样播种(106668)
lane 实证 calibrateRepeats() 二分校准 filler 使收据估计与入站载荷都落 [80%,98%]×窗口 30000(避开 preflight 触发),真实 wire 请求换小窗模型(small-test)→ 200,bili.log 子会话 nudge 行不含 usage=0% (0/(修复前该行正是现场签名),且无 preflight compressing before forward

修复前红:seed undefined / 死区行 usage=0% (0/30000) ... reason="growth 0 < floor 22500";修复后绿:usage=30% (9088/30000)。

回归

  • fork 家族:plugin-fork、dsh-fork-adopt、pi-omp-fork-adopt、fork-side-request-lane(91 pass)、fork-nudge-trigger、fork-adoption(+plan)、fork-ccr-adoption、issue2601-persona-fork-lineage、claude-fork-lineage — 0 fail
  • 基线/状态家族:context-provenance-outbound、issue2117、issue2129、silent-backend-nudge、issue2029(status 面 0 的既有设计不受影响)、issue2366、session-continuity-proof、issue2399、plugin-agent — 0 fail
  • preflight 家族全量 34 文件:180 pass 0 fail(新日志行无破坏)
  • tsc --noEmit clean

设计边界(有意不动)

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: fix/fork-nudge-dead-zone (0097033)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3280-pr.2936.248a91b

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-pr2936.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] 🏷 收到,开始 review PR #2936(分支 fix/fork-nudge-dead-zone,head f2712bac)。这是已完成的工作,我不重做——按 review 规范走:① 方向/根因审核 → ② 回归清点 → ③ 代码审查 → ④ 测试有效性 → ⑤ diff 整洁度,最后按结构化八问给结论。先拉分支核对代码与 CI 状态。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #2936 review 结论:可合(CI 绿后)

已拉取分支逐段审完代码,本地定向验证全过。以下按八问作答。

1. 是什么问题
mid-history fork 出来的子会话对 nudge 触发线结构性全盲(usage≡0%、growth≡0)——继承的满上下文永远不会增量折叠;一旦换到装不下继承上下文的更小窗口模型,每个请求都直坠多轮 preflight 总结马拉松(现场 19 轮 × 分钟级),用户视角就是对话卡死、上下文显示 0。附带两个次生面:文档从未警告 nudgeGrowthTokens 步长必须与窗口成比例(现场 1.5M 步长 > 936k 窗口,T1 质量触发不可达);马拉松全程零轮次可见性(两份日志都断在 #568 hold 行)。

2. 什么原因导致的
根因已按代码路径核实:fork 收据给子会话建全新 stats 块,计费隔离有意不播种 usage 基线,但 #728 sizing 兜底字段 localInputEstimate 也没人播种 → effectiveTokenCount(src/server.ts:1794-1845)兜底链返回 0 → kernel decideNudge 拿到 tokenCount=0:growth ref 回落到 tokenCount 自身 ⇒ growth≡0,first-sight mass 需 usage≥45% ⇒ 所有触发线失明,恰发生在继承上下文最满的时刻。另核实 nudge 状态本身仅在全前缀 fork 时继承(src/plugin.ts:1239)。三因叠加中 A 是机制根因,B/C 是放大与可观测性面。

3. 影响范围与严重程度
触发条件:plugin-mode host 做 mid-history fork(dsh/opencode/pi fork adoption)+ 随后换到比继承上下文更小的窗口模型。严重度:高——每个请求触发分钟级 preflight 马拉松,对话实质卡住(两个现场子会话间隔 33 分钟数字完全一致,确定性复现);无数据丢失,纯可用性降级。

4. 怎么修复的
在创建盲区的边界(fork 收据)播种判定输入:child.stats.localInputEstimate = child.stats.contextTokens——收据自己的估计恰好描述子会话下一次出站的准确视图。安全性由既有不变量保证(已逐一核对代码):真实 usage 报文立刻接管优先级(#728,server.ts:1804/1836 先于 estimate 分支);返回值取 min(est, raw) 被实际入站上界封顶,种子偏高也膨胀不出真实载荷;每次 prepare* 用实测覆盖;native-compaction rebase 的重置路径(session.ts:975)不受影响。孙会话走同一条收据路径。preflight 每轮一行 info(digest 应急态每 32 轮),CONFIGURATION 补步长-窗口成比例警告。

5. 是否有回归问题
无。逐项清点触碰路径的既有行为:

  • 计费/状态面隔离保持原样:usageGradeInputBaseline 只读 source==="usage",Status readers still trust estimate-grade failure baselines after #1846 #2029 pin 的「estimate 无锚点 → 状态面 0 = by design」不受影响(issue2029/issue2117/issue2129/context-provenance-outbound 本地全绿);
  • web 面微小正向差异(披露):sessions-data.ts:861 把 localInputEstimate>0 暴露为 contextUpperTokens——fork 子会话现在在首轮之前就在 Web UI 显示估计上界(此前要等首轮 prepare* 之后)。属可见性改善,非回归;
  • 持久化:persist.ts:1226 本就持久化该字段(>0 时),种子值落盘后首轮即被覆盖,生命周期一致;
  • wire/消息形状、kernel、persistence 格式、config schema:全部未动;
  • diff 基线新鲜度:base 即 master tip(f8f7d40a1),0 behind,热文件(plugin.ts/preflight.ts)仅两个小 additive hunk;
  • 本地定向验证:fork 家族 137/137、baseline/status 家族 132/132、preflight 家族 180/180(与 PR 声称一致)、tsc --noEmit clean。CI 在新 head 上运行中。

一处措辞精度说明(非阻塞):PR 正文说「每个 LLM 轮一行」,实际日志粒度是**每个 for-loop 轮次(round)**一行——单轮内可能含多次 LLM 调用(串行 walk 带减半重试,或一次 batch 调用覆盖多个 range)。观测目标(马拉松进行中可见)已达成,行内容报的是轮次状态,正是缺失的信息;不改。

6. 是否破坏缓存
不涉及。未改消息字节、身份、重试或游标;折叠提前发生在到达窗口之前,减少 preflight rebuild,缓存中性偏正。

7. 是否改了设计方向
没有转向。有意不做的事都对:不跨 fork 继承 usage 基线(那是跨模型计费造假)、不引入新配置面、preflight 保持独立安全兜底。收据估计是「下一出站视图」的诚实描述,是让触发线活着的最小喂法。

8. 是否引入了新的配置
无。无新 env/config/默认值。

顺手小修(独立 commit):review 发现 CONFIGURATION.md 的英文警告没有同步到 CONFIGURATION.zh-CN.md(违反 zh/en 同步纪律)——已直接在 PR 分支补一个标注 commit ccec401e8 docs: sync nudgeGrowthTokens window-proportionality warning to zh-CN (#2936) 并 push,diff 仍干净(+1/-1 单行)。

收工判定:代码方向正确、根因修复打在产生盲区的位置而非症状层、测试有牙(红-绿已复验、lane 实证用校准 filler 确定性落在 [80%,98%]×窗口并断言 pre-fix 签名消失)、回归面清点无破坏。CI 转绿后可合。

ranxianglei and others added 2 commits October 12, 2026 22:07
…zone)

A mid-history fork child starts on a fresh stats block: billing isolation
deliberately skips the usage baseline, but nothing seeded localInputEstimate
either, so effectiveTokenCount fed the kernel tokenCount 0 and every
nudge trigger went dark on the child's first turn — exactly when the
inherited context is at its fullest. A model switch onto a smaller window
then overflowed every request into the preflight summarization marathon
(0.1.195 field report: dsh fork at branch point 93, 671 msgs, 'nudge idle:
usage=0% (0/936000)' with 929710 pending, 19 rounds per request, #568
early-SSE hold reads as a stuck conversation; identical second fork child
33 min later = deterministic).

The receipt's own estimate describes the child's exact next outbound view:
seeding it keeps the nudge live from turn 1. It errs early only (char-count
upper bound), a real usage report takes precedence immediately (#728), and
every prepare* overwrites it with the measured outbound per turn. The
grandchild receipt covers fork-of-fork identically.

Also: one info line per preflight LLM round (every 32nd digest round) so
the marathon is observable while it runs — both field reports cut at the
#568 hold line with zero round visibility; and a nudgeGrowthTokens doc
warning to keep the step proportional to the smallest model window (a
1.5M step over a ~1M window makes the T1 mass trigger unreachable).
@ranxianglei
ranxianglei force-pushed the fix/fork-nudge-dead-zone branch from ccec401 to 0097033 Compare October 12, 2026 14:09
@ranxianglei
ranxianglei merged commit da15214 into master Oct 12, 2026
20 checks passed
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 补:rebase 到最新 master + CI 全绿

review 期间 master 前进 4 个 commit(#2922 dsh no-ceiling budget,触碰 src/plugin.ts 的 handlePluginStatus——与本 PR 的 handlePluginFork hunk 不同函数、无重叠)。已按 §7.2 把分支 rebase 到当前 master tip(bfbdb23db),无冲突,rebase 后本地重跑定向验证全过:typecheck clean、build OK、fork 家族 137/137、baseline/status 家族 132/132、preflight 家族 180/180。

新 head:009703321(force-with-lease 推到 PR 分支,仅重写本 PR 两个 commit 的 SHA,作者与 diff 不变)。

CI:20/20 全绿(static-gates ×6、lane-guard、version-guard、kernel-guard、docs-sync、docs-coverage、config-surface-guard、lock-sync、unused-exports、pi-subagents-guard、build-artifact、dsh plugin lane fork-adoption suite、real-image billing e2e、test 矩阵 ubuntu/windows × node 22/24),PR 状态 mergeable=True / clean。

收工判定不变:可合。

@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.327-master.da15214 (rolling master tag).

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

1 participant