Skip to content

[PR] Fix: compression prompt permanently broken — after upstream stopped reporting usage, baseline frozen at stale value, nud | 修复:压缩提示永久失灵——上游停报 usage 后基准冻结在旧值,nudge 4小时不触发 (#4383) - #4413

Closed
ranxianglei wants to merge 2 commits into
masterfrom
2026-10-23_stale-usage-anchor

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #4383

什么坏了(人话)

会话里只要落过一次真实的 usage 上报(比如早期 4733 tokens),之后上游/网关不再回报 usage(有些网关不透传、模型切换后不再带 usage 字段),bili 的"上次实际用量"基准就永远冻结在那个旧值:上下文实际涨到 30 万 tokens,压缩提示的用量却一直显示 1%(4733/750000),增长量算出来是 0,连续 154 个请求 nudge 一次不响,4 小时 0 次折叠,上下文白白膨胀、成本暴涨。#4383 报告者的会话就是这条链:usage 基准 4733 冻结 → growth=0 < 触发门槛 22500 → 压缩能力整体停摆。

根因(机制链)

  1. settleUsageReport(src/cache-ledger.ts)在任何 total>0 的上报时把 lastInputTokens/lastUsageGradeTokens 标成 usage 级并打上 contextTokensSource="usage"。
  2. relay 发送必经点(src/server/relay.ts)每次主车道发送都会把 contextTokens/contextTokensSource 重新盖成 "estimate",只有下一次真实 usage settle 才会翻回 "usage"。
  3. 但 effectiveTokenCount(src/server.ts:2350)分支一只看 lastInputTokensSource==="usage" 就直接返回旧锚——它不知道 usage 流已经断了;statusInputBaseline(面板/状态面)同样。于是"最后一次上报时的真相"被当成了"现在仍然成立"。nudge: no-usage recovery leaves stale reference after network or 5xx failure #1595 承诺的"没有 usage 样本时 nudge 骑本地估算"在代码里从未兑现:一旦落过任何一个样本就再也不回退。

怎么修的

两种压缩模式都覆盖:relay 必经点注释明确 streaming/plugin pipe/非流式全部汇入,插件车道同样盖 estimate 章、同样被 settle 翻回——谓词对两车道语义一致。

测试

新增 tests/issue4383-stale-usage-anchor.test.ts 8 项,正反双向(#3617):冻结形状恢复估算、健康周期不误判、上报后恢复锚定、overflow-arm 保持权威、grade 分支同样旁路、无证据时保留旧锚、#728 车道不变、写入契约逐字段钉住。相邻回归 245 项全绿(cache-ledger×5、plugin-nudge-injection、issue1492/1569/1820/1839/2020/2029/2033/2117/2129/2366/3862/3900、fork-nudge×2、codex-compact、silent-backend-nudge 等),typecheck 干净。

config surface

无新增配置、无 env、无行为开关。

kernel

不涉及 kernel/(纯 src 侧)。

@ranxianglei ranxianglei changed the title 修复:压缩提示永久失灵——上游停报 usage 后基准冻结在旧值,nudge 4小时不触发 (#4383) [PR] Fix: compression prompt permanently broken — after upstream stopped reporting usage, baseline frozen at stale value, nud | 修复:压缩提示永久失灵——上游停报 usage 后基准冻结在旧值,nudge 4小时不触发 (#4383) Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-23_stale-usage-anchor (3cdf7dc)

Latest build — install this exact version

npm install -g billion-context@0.0.5342-pr.4413.3541d61

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
3cdf7dc billion-context@0.0.5342-pr.4413.3541d61 build
8166568 billion-context@0.0.5326-pr.4413.36caf7e build
1e8e5e9 billion-context@0.0.5302-pr.4413.8f04083 build
cfcf2a9 billion-context@0.0.5286-pr.4413.730d808 build
84e494e billion-context@0.0.5282-pr.4413.d853407 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei force-pushed the 2026-10-23_stale-usage-anchor branch from 1e8e5e9 to 8166568 Compare October 23, 2026 16:57
@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

状态说明:#4383 经核验为存量缺陷(机制在 v0.1.202 与 v0.1.204 逐字节一致),非 203/204 回归。按 owner 决定「非回归问题本版不合并」,本 PR 留待下个版本,保持 open、不阻塞发版。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

复核结论(本轮我独立核对了 CI 与 head 代码;回归分类沿用 floor 4 的逐版本核验,未重跑):

① CI 已转绿。 floor 3 报的 lock-sync / unused-exports 失败已在更新的 head 上修复——当前 head 8166568(晚于 floor 2 产物对应的 8b8f935)两者均 success。全量 0 失败:22 success / 15 skipped(门控 e2e)/ 4 仍在排队(mysql-contract、config-surface-guard、docs-coverage、lifecycle-ledger-guard,尚未跑完、非红)。当初转发给 ci-worker-r1 的那个卡点已闭环。

② 修复完好、单提交干净。 head 为单 commit 8166568「fix: ride the per-send estimate when the usage anchor is cycle-stale (#4383)」;新谓词 usageAnchorCycleStale(src/session.ts:728)接进 effectiveTokenCount(src/server.ts:2401)并镜像到 statusInputBaseline,tests/issue4383-stale-usage-anchor.test.ts 在位,无多余改动。

③ 维持 owner 决定,现状不变。 「存量缺陷、非 203/204 回归」的判定沿用 floor 4 的逐版本核验(v0.1.202 与 v0.1.204 机制逐字节一致),据此「非回归本版不合」。PR 现 mergeable=true / state=behind:下次发版窗口 rebase 到最新 master 后由人工合并即可,现在不需任何改动。

一句话:CI 绿、修复在位、可留待下版——本轮无待办。

…wo provably silent cycles

usageAnchorCycleStale only fires while lastInputTokensSource is "usage". An upstream failure arms the per-send estimate into lastInputTokens (source "estimate") without touching contextTokensSource or lastUsageGradeTokens — from that point the predicate is blind and the frozen stale grade resurrects through effectiveTokenCount branch 3 (and statusInputBaseline), re-blinding a healed session on every failure turn. Probe against this head: settle 4733 -> one send -> arm 1,108,494 => both readers serve {tokens:4733} at a real ~300K context. The issue body corroborates: 9 of 11 upstream failures armed estimates up to 1,108,494 yet the nudge kept reading 4733.

New gate gradeAnchorCycleStale: demotes the frozen usage-grade anchor when source is off {usage, overflow-arm} AND at least STALE_GRADE_MIN_SILENT_SENDS (=2) main-lane sends completed since the last settled report. Depth is the only discriminator: #1839 G1 proves a fresh small measurement (fake upstream reporting fixed input_tokens=5000) is field-indistinguishable from a stale sidecar sample by magnitude or by a binary flip, so one silent cycle keeps the anchor authoritative; two completed sends prove the flow is dead.

sendsSinceUsageSettle: new persisted stats counter (incremented in noteOutboundContextEstimates, zeroed in settleUsageReport, cleared at resetSessionCompression, restored with validation; legacy records absent = 0, self-heals within two sends). Overflow-arm authority untouched (#1839). CHANGELOG entry added for the PR.
@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

陈旧票清理(第三批动作①):同 issue 有更新 PR [4443]。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。

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

Labels

None yet

Projects

None yet

1 participant