Skip to content

[PR] fix: demote stale-small usage anchors to the calibrated local estimate in baseline readers (#4383) - #4443

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-23_stale-anchor-estimate-fallback
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-23_stale-anchor-estimate-fallback

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #4383

问题

同一会话 id 下的一次小而真实的 usage-grade 样本(标题生成/探测等侧车请求,复现中为 4733 tokens)被 settleUsageReport 无条件写进 lastUsageGradeTokens,所有输入基线读者(statusInputBaseline / effectiveTokenCount)原样信任。kernel 的 growth reference 是低水位标记(#1595),跟到该值后 growth ≡ 0、压力带失效——自动折叠整段停摆 4h07m(154 次 nudge 全 idle,pendingT1 106k→284k,零折叠),重启不愈合(锚点持久化在 sessions.stats_json)。#1595 书面承诺的「改用本地估算」兜底在读者里从未实现。

修法

两个共享读者走同一个 stale-small 守卫(src/session.ts 新增导出 staleSmallAnchorFallback):

  • 锚点 < 25% × contextEstimateTokens(当前出站 billing-caliber 本地估算,k̂ 校准口径),且
  • contextTokensSource === "estimate"(其后已发生主发送——relay 主发送逐次盖章,settleUsageReport 翻回 "usage";
    两个字段都是既有的,无新字段)
    ⇒ 降级为该估算值(source "estimate")。

新鲜度闸门是关键:纯量级判定会误伤新鲜小样本(#1820 B:真实 usage 样本必须立即压过 post-rebuild anchor)——本地回归实测抓到了这个回归,加新鲜度条件后修复、测试钉死。高于估算的锚点保持 #1839 优先(单向,不复活 ghost class);无估算/无新鲜度戳的旧会话行为逐字节不变(负控测试钉死)。

行为变更(old → new)

配置面

无新增/改名/改语义字段。STALE_ANCHOR_RATIO = 0.25 是代码常量,非配置项。

测试

与在途 PR 的关系

PR #2725(open,#2683)处理相反方向(基线过高/跨模型存活),写侧 retireCrossModelBaselines;本修是读侧量级+新鲜度降级,两者互补。若 #2725 先合入,本分支 rebase 即可(触碰文件有重叠:src/session.ts / src/server.ts)。

…e in baseline readers (#4383)

A tiny but real usage-grade sample under the session id (title-gen/probe sidecar) settled into lastUsageGradeTokens blinded every input-baseline reader: the kernel growth reference is a low-water mark (#1595) and rode down to it, so growth stayed 0 and auto-folding was disabled for hours until an unrelated external event. statusInputBaseline and effectiveTokenCount now share one guard: an anchor below 25% of the billing-caliber local estimate of the current outbound send AND superseded by a later main send (contextTokensSource="estimate") is demoted to that estimate — #1595's promised local-estimate fallback. The freshness gate keeps fresh small samples authoritative (#1820 B); anchors above the estimate keep their #1839 precedence; sessions without an estimate or freshness stamp behave byte-identically.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-23_stale-anchor-estimate-fallback (8e0d8a9)

Latest build — install this exact version

npm install -g billion-context@0.0.5330-pr.4443.a732cbc

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
8e0d8a9 billion-context@0.0.5330-pr.4443.a732cbc build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: demote stale-small usage anchors to the calibrated local estimate in baseline readers (#4383) [PR] fix: demote stale-small usage anchors to the calibrated local estimate in baseline readers (#4383) Oct 23, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:重复——本 PR(#4443)与 #4413 是同一 issue #4383 的两个在途修复,均 open。 违反「一个 issue 一个 PR」的 loop guard。两者症状与机制家族相同(读侧降级「小而陈旧的 usage 锚点」),但对比后 #4443 更准,三点差异:

  1. 口径:[PR] Fix: compression prompt permanently broken — after upstream stopped reporting usage, baseline frozen at stale value, nud | 修复:压缩提示永久失灵——上游停报 usage 后基准冻结在旧值,nudge 4小时不触发 (#4383) #4413 降级时把字符级上界 localInputEstimate 喂进 meter(复现数据里 ~4.2× 高估:[Bug] statusInputBaseline falls back to lastUsageGradeTokens instead of the calibrated local estimate — so one 4.7k side-request sample blocks folding for 4 hours | #1595 承诺的"改用本地估算"兜底在 statusInputBaseline 里没有实现,一次 4.7k 侧请求样本即可挡住折叠 4 小时 #4383 正文实测 1,068,927 vs 真实 252,154);[Bug] statusInputBaseline falls back to lastUsageGradeTokens instead of the calibrated local estimate — so one 4.7k side-request sample blocks folding for 4 hours | #1595 承诺的"改用本地估算"兜底在 statusInputBaseline 里没有实现,一次 4.7k 侧请求样本即可挡住折叠 4 小时 #4383 原文明确要求用已校准 token 级读数(「量级闸门不能直接拿 localInputEstimate 当基准,必须用 estimateInputTokens 那条已校准的 token 级读数」)。[PR] fix: demote stale-small usage anchors to the calibrated local estimate in baseline readers (#4383) #4443 用的 contextEstimateTokens(k̂ 校准 billing 口径)正是 issue 指定方向;
  2. 覆盖:[PR] Fix: compression prompt permanently broken — after upstream stopped reporting usage, baseline frozen at stale value, nud | 修复:压缩提示永久失灵——上游停报 usage 后基准冻结在旧值,nudge 4小时不触发 (#4383) #4413 的新鲜度闸门只认 lastInputTokensSource === "usage",一旦 armFailureShrink 把 source 翻成 "estimate"(issue 点名的「紧急收缩抬高基线被同一兜底吞并」次出口),retained-grade 分支仍原样返回毒锚点——该次出口没修到;[PR] fix: demote stale-small usage anchors to the calibrated local estimate in baseline readers (#4383) #4443 的共享守卫对两个出口同时生效;
  3. 闸门:[PR] Fix: compression prompt permanently broken — after upstream stopped reporting usage, baseline frozen at stale value, nud | 修复:压缩提示永久失灵——上游停报 usage 后基准冻结在旧值,nudge 4小时不触发 (#4383) #4413 只有新鲜度门、无量级门——上报缺失的正常会话里任何 cycle-stale 锚点都会被字符上界顶替,meter 失真;[PR] fix: demote stale-small usage anchors to the calibrated local estimate in baseline readers (#4383) #4443 加 < 25% × est 量级门,估算误差带内的合法样本(≥~0.29×est)保持受信任(有测试钉死边界)。

建议:保留 #4443、关闭 #4413。 按先来后到本应留 #4413,但它的机制不达根(口径错 + 次出口漏修 + 无量化门),两害相权取 #4443。关不关由你定(agent 不关 PR);若你倾向另一侧,#4443 同样可弃。两者文件重叠(src/session.ts / src/server.ts)在 #4413 关闭后不再构成 rebase 负担。

标签:bug、scope/kernel、p1(缺陷类;核心折叠能力整段停摆 4h07m + 重启不愈合 = p1;修复面是 src 侧压缩决策层,kernel/ 未动;复现场景为通用 relay + 不上报 usage 的 upstream + 同 id 侧车样本,无具体客户端车道证据,不打客户端标签)

本地定向验证已完成:

  • 新套件 tests/issue4383-stale-anchor-fallback.test.ts 6/6 绿,含端到端 freeze-breaker(handleAcpStatus 精确复现形状:limit 750k / 毒样本 4733 / 冻结 ref / ~60 条消息 → tokenCount=303093 且 INJECT T1,growthReference 仍钉在 4733)+ 负控(无估计时逐字节 legacy,idle 维持);
  • 相邻回归 9 个套件 84/86:两红(fork-nudge-deadzone「lane proof」、issue1492 A)我在干净 base fe5ba59 上复跑,同样失败——确认既有环境 flake,与本 PR 无关;
  • typecheck 净、build 绿(CI build-artifact ✅、mysql-contract ✅)。

全量回归以远程 CI test lane 为准(当前运行中),八问结论在其出结果后补发。

@ranxianglei ranxianglei added bug Something isn't working p1 scope/kernel labels Oct 23, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI 全绿,审查完成。 主 CI(ubuntu/windows × node 22/24 × 3 shard 全量测试矩阵)、static gates、全部 e2e 车道(codex/pi/dsh/opencode/ws/registry/image/theorem)、PR Build Artifact 均 success(分支上更早几批 cancelled 是被重跑取代的旧触发,每个 workflow 的最新一次均为绿)。本地定向验证:新套件 6/6、相邻 9 套件 84/86(两红在干净 base fe5ba59 复跑同样失败,确认既有 flake)、typecheck 净。

回归清点(触碰路径的既有行为逐项):

八问:

  1. 是什么问题:同一会话 id 下一次小而真实的 usage 样本(标题生成等侧车请求,复现 4733 tokens)被写进输入基线锚点,两个读者原样信任,自动折叠整段停摆 4h07m 且重启不愈合。
  2. 什么原因导致的:settleUsageReport 无条件把任何 usage-grade 样本(含同 id 侧车)写成锚点,而读者没有「新鲜度+量级」概念,分不清「当前 payload 的真实测量」与「很久以前的旧小样本」;kernel growth reference 是低水位标记(nudge: no-usage recovery leaves stale reference after network or 5xx failure #1595),跟到小值后 growth≡0、压力带失效。nudge: no-usage recovery leaves stale reference after network or 5xx failure #1595 书面承诺的「改用本地估算」兜底在读者里从未实现。
  3. 影响范围与严重程度:触发面 = 不上报 usage 的中继 + 同 id 侧车样本 + 对话持续增长到远超样本量级(复现增长 64×)。严重度:核心能力(自动折叠)小时级完全停摆、重启不愈合、只能人工干预或换模型救回 = p1。正常上报的 upstream 不受影响(样本与估算同量级,比率≈1,远低于 25% 线)。
  4. 怎么修复的:读侧共享守卫(staleSmallAnchorFallback,src/session.ts)——「其后已发生主发送」(新鲜度戳)且「锚点 < 25%×k̂ 校准本地估算」同时成立时,两个共享读者(statusInputBaseline / effectiveTokenCount)降级为校准 billing 口径估算;单向、可证 legacy 不变。写侧与 kernel 未动。
  5. 是否有回归问题:见上方逐项清点,均 ✅。诚实记录一个已知边缘:无校准系数的未校准估算(chars/4 对 ASCII 最多高估 ~3.5×)叠加非上报 upstream 上温和增长时可能提前降级,meter 偏热——方向 fail-closed(早折不晚折),下次真实上报即自愈,严格优于修复前 meter 冻结。
  6. 是否破坏缓存:不涉及。不动 wire 字节、前缀、缓存键;前缀缓存行为零变化。
  7. 是否改了设计方向:无转向。首次落地 nudge: no-usage recovery leaves stale reference after network or 5xx failure #1595 承诺的读侧兜底路径,与双压缩模式设计一致;与 [PR] fix: stop stale session input baselines outliving their measurement context (#2683) #2725(写侧跨模型退役)互补关系不变。
  8. 是否引入了新的配置:无。STALE_ANCHOR_RATIO=0.25 是代码常量,非配置项;无新 env/config 字段。

判定:可合。 方向打到根因(读侧资格判定,不是症状层过滤)、机制覆盖两个出口(含 armFailureShrink 吞并次出口)、测试有牙(边界/负控/e2e freeze-breaker 全钉死)、CI 全绿、diff 干净(4 文件 +254/-5,CHANGELOG 已记行为变更 old→new)。当前 master(fd973ca)上 mergeable=true,可直接合并或先 rebase(behind 的 2 个提交均为 CI 基建,#4441 的 unused-exports 门禁在本 head 上也已绿)。

遗留一件事(上条已述):#4413 是本 issue 的重复 PR,建议由你关闭并保留本 PR——agent 无权关 PR。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

已在第三列车 #4558 上重做落地(与 cycle-stale 双守卫并集,测试适配 #4340 第二读者)。本 PR 关单收尾;回滚点为 #4558 单提交 revert。

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

Labels

bug Something isn't working p1 scope/kernel

Projects

None yet

1 participant