Skip to content

[PR] Infinite Wait Issue in Stress Injection: N-Round Fallback (Side Effect Introduced by Fix #5860) | 压力注入无限等待问题:N轮兜底(修复#5860引入的副作用) - #5882

Merged
ranxianglei merged 8 commits into
masterfrom
fix/nudge-estimate-hold-backstop
Nov 7, 2026
Merged

ranxianglei merged 8 commits into
masterfrom
fix/nudge-estimate-hold-backstop

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

这是什么问题

#5860 加了「幽灵压力保护」:压力/紧急档的自动压缩注入,要等一个带计费样本的读数才动手(估算读数天生偏高,直接按它压缩会误伤)。这个等待是一次一轮地押——押完这一轮,下一轮还是估算就再押。

但对从来不回传计费的会话(匿名零基线 fork、silent-backend),永远拿不到计费样本 → 每一轮都被押 → 压力注入被无限挂起,这类会话永远不会自动压缩。这正是 #728/#553 记录的事故场景(本地估算就是它们唯一的压力信号源)。

怎么修的(N 轮兜底)

  • kernel 新增 nudge.maxEstimateHoldRounds(默认 2):连续估算读数最多押 2 轮。第 1–2 轮保留原有幽灵窗口保护(中断的那一轮 + 报告来得及前的跟随轮),之后回落到老行为——按估算照常判,保证永不回传的上游也能拿到自动压缩。设 0 = 完全不押。老开关 nudge.requireUsageSampleForPressure=false 语义不变。
  • host 配置面新增 compress.maxEstimateHoldRounds(深度合并 + settings 校验 + wire state 透传,随其余 NudgeState 一起跨重启持久化)。
  • 新增内核单测 kernel/tests/nudge-pressure-estimate-hold-backstop.test.ts:N=0/默认/自定义三档时序 pin + 样本到达清零 streak + requireUsageSampleForPressure=false 逃生口。

顺带修的 CI

  • fork-nudge-trigger / silent-backend-nudge 三个 e2e:按新的时序适配(不回报计费的会话连放 3 轮,第 3 轮落压);匿名 fork 改用真正不回传 usage 的 mock(fork 会话 lastInputTokens=0 时 preflight 退化为字符估算,大载荷被低估后不压缩直接裸转上游 #553 事故本相),显式身份对照组保持回传、自证自愈逻辑不受影响。
  • storage-render 四个 golden:#5865 里提交的文件是用带漂移环境变量(BILI_* 模型表等)的本地环境生成的,和 CI 干净环境的输出差 2 行(多出的 model id 行)。在干净环境重新生成,并已在无环境变量的独立环境复核字节级一致(此前 CI 同一失败已反复出现 10+ 次)。

验证

本地(node 26):kernel hold/no-sample 套件 11/11 ✅;host silent-backend-nudge + fork-nudge-trigger 7/7 ✅(trace 实测:streak 1→hold、2→hold、3→inject OVER-LIMIT T1);root typecheck ✅;kernel build ✅。


这是什么问题

#5860 加了「幽灵压力保护」:压力/紧急档的自动压缩注入,要等一个带计费样本的读数才动手(估算读数天生偏高,直接按它压缩会误伤)。这个等待是一次一轮地押——押完这一轮,下一轮还是估算就再押。

但对从来不回传计费的会话(匿名零基线 fork、silent-backend),永远拿不到计费样本 → 每一轮都被押 → 压力注入被无限挂起,这类会话永远不会自动压缩。这正是 #728/#553 记录的事故场景(本地估算就是它们唯一的压力信号源)。

怎么修的(N 轮兜底)

  • kernel 新增 nudge.maxEstimateHoldRounds(默认 2):连续估算读数最多押 2 轮。第 1–2 轮保留原有幽灵窗口保护(中断的那一轮 + 报告来得及前的跟随轮),之后回落到老行为——按估算照常判,保证永不回传的上游也能拿到自动压缩。设 0 = 完全不押。老开关 nudge.requireUsageSampleForPressure=false 语义不变。
  • host 配置面新增 compress.maxEstimateHoldRounds(深度合并 + settings 校验 + wire state 透传,随其余 NudgeState 一起跨重启持久化)。
  • 新增内核单测 kernel/tests/nudge-pressure-estimate-hold-backstop.test.ts:N=0/默认/自定义三档时序 pin + 样本到达清零 streak + requireUsageSampleForPressure=false 逃生口。

顺带修的 CI

  • fork-nudge-trigger / silent-backend-nudge 三个 e2e:按新的时序适配(不回报计费的会话连放 3 轮,第 3 轮落压);匿名 fork 改用真正不回传 usage 的 mock(fork 会话 lastInputTokens=0 时 preflight 退化为字符估算,大载荷被低估后不压缩直接裸转上游 #553 事故本相),显式身份对照组保持回传、自证自愈逻辑不受影响。
  • storage-render 四个 golden:#5865 里提交的文件是用带漂移环境变量(BILI_* 模型表等)的本地环境生成的,和 CI 干净环境的输出差 2 行(多出的 model id 行)。在干净环境重新生成,并已在无环境变量的独立环境复核字节级一致(此前 CI 同一失败已反复出现 10+ 次)。

验证

本地(node 26):kernel hold/no-sample 套件 11/11 ✅;host silent-backend-nudge + fork-nudge-trigger 7/7 ✅(trace 实测:streak 1→hold、2→hold、3→inject OVER-LIMIT T1);root typecheck ✅;kernel build ✅。


kernel-change: 内核侧改动仅限「幽灵压力等待」的兜底:新增可选配置 nudge.maxEstimateHoldRounds(默认 2)与对应 NudgeState 计数字段,把 #5860 的"无计费样本就押一轮"收敛为"最多连押 N 轮后回落估算驱动",修复从不回传计费的会话被无限挂起、永远无法自动压缩的问题(用户裁定的 B 方案)。不改任何既有默认行为、不新增状态迁移;wire 仅新增一个可选字段,旧数据可读。

kernel-change: 内核侧仅新增可选配置项 nudge.maxEstimateHoldRounds(默认 2)与 NudgeState 计数字段,把 #5860 的「无计费样本就押一轮」收敛为「最多连押 N 轮后回落估算驱动」,修复从不回传计费的会话被无限挂起、永远拿不到自动压缩的问题;不改任何既有默认行为、不新增状态迁移,wire 只多一个可选字段,旧数据可直接读。

…ounds (backstop)

A pressure/emergency nudge waits for a usage-grade meter reading, so a session whose upstream never reports usage was deferred forever — estimate on every round, hold forever, no automatic compression (#728/#553: silent backends and anonymous zero-baseline forks live there). Add nudge.maxEstimateHoldRounds (default 2): the first two consecutive estimate rounds keep the phantom-ghost protection (#5860), after that the pressure band fires on the estimate like legacy. 0 disables the hold; off-switch remain nudge.requireUsageSampleForPressure=false.
…top timing, refresh storage golden

- config: new compress.maxEstimateHoldRounds (deep-merge + settings validation) mapping to the kernel backstop bound.
- fork/silent-backend e2e: replay 3 rounds for never-reporting lanes so the T1 pressure decision lands on round 3 (hold windows are pinned separately in the kernel test); anonymous forks now use a truly usage-less upstream (the incident regime) while the explicit-identity control still self-heals via measured usage.
- storage-render golden: regenerated under the same env CI runs in (CI regenerates from a fresh clone of this exact checkout with zero env vars; local pre-commit env drift — extra model entries etc. — made the committed file stale). Verified byte-identical against an independent clean-env regeneration.
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: fix/nudge-estimate-hold-backstop (e4f2a73)

Latest build — install this exact version

npm install -g billion-context@0.0.8526-pr.5882.dbd9363

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
e4f2a73 billion-context@0.0.8526-pr.5882.dbd9363 build
b9484f6 billion-context@0.0.8517-pr.5882.b1d5d92 build
d93bb3b billion-context@0.0.8510-pr.5882.6941eb2 build
bcda253 billion-context@0.0.8508-pr.5882.274d4b2 build
bd1c732 billion-context@0.0.8504-pr.5882.e6ea476 build
77e4f97 billion-context@0.0.8500-pr.5882.9a5e06d build
ea3a2ad billion-context@0.0.8494-pr.5882.ace7075 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title 压力注入无限等待问题:N轮兜底(修复#5860引入的副作用) [PR] Infinite Wait Issue in Stress Injection: N-Round Fallback (Side Effect Introduced by Fix #5860) | 压力注入无限等待问题:N轮兜底(修复#5860引入的副作用) Nov 7, 2026
ranxianglei and others added 6 commits November 7, 2026 19:26
…e the guard's bounded-wait semantics)

config-surface-guard requires a seed entry for every config-file field.
… truth values

CI (ubuntu+windows, node22, fresh runner) computes exactly these persisted-state digests; the previously committed values were regenerated under a contaminated local env (extra model entries), so every clean-environment run reds the full-mode restart proofs. Values taken verbatim from the PR#5882 run-42371752198 assertion output; all other golden fields (wire bodies, landmarks, raw stateDigest) already match CI.
…4241 teeth at the byte-promised tail

CI red on this PR had three causes:

1. storage-render + wire-contract goldens were regenerated against a kernel
   WITHOUT this PR's config (the committed metadata digest matches what
   master produces, not this branch): effectiveConfig in the persisted
   metadata now carries nudge.requireUsageSampleForPressure + nudge.
   maxEstimateHoldRounds, so every metadata digest moved again. Regenerated
   both golden sets with the local 0.0.185 kernel.

2. #4241 teeth: the fault dropped outbound[length-2] on the assumption the
   engine appends a trailing nudge as the final wire message. Since #5772
   the snapshot render covers the previous turn's tail too (tailStart
   advanced), so length-2 lands INSIDE the exempt rendered prefix and the
   teeth never fire. The fault now drops the client's newest tail row
   (located by content) — the part the render lane actually owns
   byte-intact. Verified the same fix also passes on current master, where
   this test is broken since #5772.

Note: storage-render/#4241/wire-contract/storage-engine-proofs also fail on
master HEAD (run 42358603178) — #5772/#5616-era fallout, not this PR; the
nudge e2e subset that master broke (#728A/C, #1119, #1137, zero-baseline)
is fixed by this PR's backstop.
@ranxianglei

Copy link
Copy Markdown
Owner Author

CI 红诊断与修复(已推送 e4f2a73)

1. 这是啥问题?
CI 里 7 个 test job 红,失败的是同一批 golden/测试:storage-render golden ×4、storage-engine restart proofs ×4、#4241 judge teeth、wire-contract kernel.json。其中大部分不是这个 PR 弄坏的——master HEAD 现在自己就是红的(见第 4 点),但 golden 两处确实需要随本 PR 一起重生成,#4241 的测试假设也过期了。

2. 根本原因是啥?
三个独立原因:

3. 如何解决的?(e4f2a73)

4. 是否能合并?
修完这个 commit 后可以合并,但有一个事实要摆明:master run 42358603178(HEAD 5af5f9f,早于本 PR 推送)就以同一批测试红了——storage goldens/#4241/wire-contract/storage-engine-proofs 是 #5616/#5772 时代的遗留(6db0e84 的 CI 被取消没留下证据,两者之一或共同引入)。本 PR 合入只会让 master 变好:golden 在 PR 分支上是自洽的,#4241 修好,nudge e2e 从红变绿。建议 master 侧跟进:把 e4f2a73 里 tests/issue4241 那段 cherry-pick 回 master,master 的 storage goldens 另行 regen(那边 metadata 漂移是 499784b1→0aa87883,与本 PR 无关)。

5. URL

@ranxianglei
ranxianglei merged commit 2bda6b3 into master Nov 7, 2026
53 checks passed
ranxianglei pushed a commit that referenced this pull request Nov 7, 2026
#5882 fixup 77e4f97 left requireUsageSampleForPressure's old site_en/site_zh
pair inside the new maxEstimateHoldRounds mapping; the lenient YAML parser
last-wins, so the stale 'deferred one round' copy leaked into the generated
website text for maxEstimateHoldRounds. Drop the leftover lines and regenerate
with gen-config-docs.
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1072-master.2bda6b3 (rolling master tag).

npm install -g billion-context@0.0.1072-master.2bda6b3  # 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.

Louie0806 added a commit to Louie0806/billion-context that referenced this pull request Nov 7, 2026
… backstop; take master's refreshed goldens

Adopts the ranxianglei#5860 follow-up batch (ranxianglei#5882): the estimate-grade pressure hold is
now capped at `compress.maxEstimateHoldRounds` (default 2) instead of holding
indefinitely, exposed through `src/config.ts` / `src/compress-settings.ts` and
pinned by `kernel/tests/nudge-pressure-estimate-hold-backstop.test.ts`.

Five golden conflicts resolved with `--theirs`: master regenerated
`tests/golden/storage-remainder/` and `tests/golden/wire-account/kernel.json`
against the new config surface (`maxEstimateHoldRounds: 2` and the shifted
stateDigests). All five blobs are now byte-identical to upstream, so the
regen-justification duty belongs to ranxianglei#5882, not to this lane. The lane's own
22 files are untouched by the merge.

Verified on the merged tree (CI preload chain, BILI_STORAGE_UNIFIED=legacy):
tests/issue5175-drift-name-leak.test.ts 58/0, tests/tag-echo.test.ts 79/0,
tests/issue2190-degen-close.test.ts 32/0, tests/golden-storage-render.test.ts 5/0,
tests/storage-engine-proofs.test.ts 12/0, tests/wire-contract.test.ts 23/0,
tests/issue5719-msgid-lane-identity.test.ts 8/0,
tests/issue4666-migration-dedup.test.ts 2/0,
tests/silent-backend-nudge.test.ts 4/0,
tests/issue4241-judge-render-baseline.test.ts 1/0,
tests/issue5756-lazy-sweep.test.ts 1/0,
tests/native-compact-terminal.test.ts 1/0,
kernel/tests/nudge-pressure-estimate-hold-backstop.test.ts 5/0,
kernel/tests/nudge-pressure-no-sample-hold.test.ts 6/0,
kernel/tests/nudge-text.test.ts 32/0.
`tsc --noEmit` clean; the four repo gates exit 0; `gen-config-docs generate` is
a no-op on the four generated artifacts.
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