Skip to content

fix(#2029): status readers share provenance-aware input baseline - #2056

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-04_status-baseline-provenance
Oct 4, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-04_status-baseline-provenance

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2029

Implements the owner-ruling scope from the #2029 thread (post-#2032 closure; #2032 not revived).

Change

New shared helper statusInputBaseline(session) in src/session.ts (beside the other session-stat helpers):

Wired into all four status-side readers:

  1. src/acp-status.ts — handleAcpStatus nudge recompute
  2. src/plugin.ts — handlePluginStatus live-nudge recompute
  3. src/plugin.ts — buildStatusPanel tokenCount
  4. src/stream.ts — postCompressTail recompute (evidence below)

Deliberately NOT touched (per ruling): plugin JSON contextTokens/contextTokensSource (#2017 merged observation contract — unknown is explicit null/"unavailable" there), failure arms, compression credits, wire bytes, configuration, persistence schema, accumulated billing, and the main request path (effectiveTokenCount unchanged).

Why postCompressTail is included (and its test companions)

Behavioral verification was recorded in the #2029 thread before wiring:

  • DRAIN state (all raw ranges folded, clean success): zero divergence across all provenance variants — the kernel's emergency-tier injection requires bestPending >= minPressureBenefit, which a drained state cannot satisfy, so the stop signal fires under both baselines.
  • TIER state (pending T2 distillation mass): divergence ONLY for estimate-grade stats — the raw phantom (174k vs 150k window) manufactured over-limit pressure that made T2 "actionable" and suppressed the stop signal (silence); the anchored baseline (60k → 40%) leaves T2 not-yet-actionable on the growth cadence, so the stop signal fires. Trusted sources (usage / overflow-arm) are identical under both.

Test companions per ruling item 3:

  • tests/compress-success-tail.test.ts case 3 (compress 成功输出缺剩余范围快照与停止提示(pi 侧 #420/#521 对齐) #1387 tier-suppression contract): fixture stats now stamp lastInputTokensSource: "usage" so the contract pins REAL over-limit suppression instead of relying on legacy-shape luck (unflagged values now fall back to anchor/unknown).
  • New case: estimate-grade baseline + pending T2 mass → stop signal fires — regression pin for the flip above; fails if the tail is rewired to the raw value.

Behavior changes (old → new)

Status reading Old New
estimate-grade baseline, real anchor exists (issue repro: 60k real / 174k est / 150k window) false emergency 116% in nudge + panel anchored 40%, no phantom pressure
estimate-grade baseline, no anchor estimate presented as measurement 0 (unknown sentinel; kernel goes growth-driven)
legacy session restored without source flag raw value presented as measurement real anchor if present, else 0
real over-window usage (source "usage") >100% shown unchanged, unclamped
bounded overflow-arm value passed through unchanged
post-compress tail, estimate-grade + pending T2 mass phantom-pressure silence stop signal (real over-limit suppression unchanged)
plugin JSON contextTokens/contextTokensSource #2017 observation contract untouched

Verification

  • typecheck clean; tsup build + dist-import-annotations OK
  • New suite tests/issue2029-status-baseline-provenance.test.ts (3 tests / 8-scenario matrix incl. credit-adjusted and trusted-drained-to-zero edges): unit provenance table; acp_status + plugin surfaces assert the EXACT tokenCount handed to processTurn (wrapped core, deepEqual), panel Context-line rendering, and stats/state read-only snapshots before/after each call
  • A/B regression proof: on unmodified master with only the helper added (no wiring), both reader-surface tests fail at the first repro scenario (observed 174000 vs expected 60000) and the new tail regression fails (phantom silence); unit table and all compress 成功输出缺剩余范围快照与停止提示(pi 侧 #420/#521 对齐) #1387 cases pass there
  • Targeted related suites on this head: 79/79 (acp-status, advisory-panel, acp-panel, issue404-restore-timestamps, issue532-panel-system-tokens, update-notes, ccr-v2, search-plan-aware, issue847-compress-failure-guards) + 5/5 compress-success-tail + 3/3 new file
  • Full regression delegated to remote CI

Config surface: none added (no new env/config/default values).

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-04_status-baseline-provenance (fa1dfa0)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2099-pr.2056.2e603fa

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-pr2056.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] 🏷 PR #2056 审查结论 — 方向正确,实现与 owner 裁决逐条吻合,独立复核全部通过。可合。

独立验证(全部在 PR head fa1dfa08 重跑,非采信报告):

  • typecheck 干净;定向 12 套件 89/89(新文件 + compress-success-tail + acp-status / acp-status-estimator / acp-panel / advisory-panel / ccr-v2 / issue404 / issue532 / issue847 / search-plan-aware / update-notes)。
  • A/B 回归证明(自跑):保留 helper、把三处接线还原为 raw lastInputTokens → 恰好 3 个失败:两个读者面测试在首个 repro 场景挂(observed 174000 vs expected 60000)+ 新 tail 回归挂(phantom 静默);单元 provenance 表与全部 compress 成功输出缺剩余范围快照与停止提示(pi 侧 #420/#521 对齐) #1387 用例在其上通过 → 新测试精确钉住修复面,不误伤既有契约。与 PR 正文声明一致。
  • CI:15/15 checks success @ fa1dfa08;mergeable: true(state=behind)。head 落后 master 的 2 个提交是 v0.1.182 版本同步(package.json/lock/release-notes),与本 PR 的 6 个文件零重叠——已用文件集交集验证,rebase/合并无冲突风险。
  • 裁决对照:owner ruling 点名的四处(src/acp-status.ts:63、src/plugin.ts:1114 live nudge、src/plugin.ts:1135 panel、src/stream.ts:264 postCompressTail)逐一核实全部接线到位;JSON 面未动——plugin.ts:1088-1090 仍走 currentContextObservation()(feat(plugin): expose isolated forks and attributed context observations #2017 observation 契约),diff 无触及;配套两件(case 3 fixture 打 source:"usage" + 新增「estimate-grade + 待蒸馏 mass → STOP-SIGNAL」)均完成。

逐关审查:

  • ① 原 issue 方向:Status readers still trust estimate-grade failure baselines after #1846 #2029 缺陷真实(A/B 独立复现);根因层次判断正确——读者层缺 gate,不是数据污染(lastUsageGradeTokens 锚点自 [OpenCode v2] Configured model context limit never reaches the proxy (x-bili-plugin-context-window not stamped) - silent registry-peek fallback suppresses proactive nudge and misfires emergency shrink #1569 起一直正确保留,arming 路径不碰它);方案打到核心(共享决策而非各面打补丁)。postCompressTail 的接线争议已有行为矩阵裁决(DRAIN 态零分歧;TIER 态仅 estimate-grade 翻转),本 PR 按裁决执行,无越界。
  • ② 回归审查(触碰路径既有行为清点):trusted 源(usage/overflow-arm)四读点 verbatim 透传、字节级不变;主请求路径 effectiveTokenCount(server.ts:3646)零 diff;failure arms、compression credits、累计计费、持久化 schema、配置面、wire bytes 均未动(processTurn 纯函数、返回 state 不被采纳,读边界成立);postCompressTail 唯一翻变 = estimate-grade 场景(即缺陷类本身),真实超窗抑制契约由 case 3 保真。未见无意回归。
  • ③ 代码审查:helper(src/session.ts:426-431)语义正确镜像 effectiveTokenCount 前两档(trusted verbatim → usage-grade anchor → 0/unknown),有意省略 estimate 档——那正是修复本体。一个值得注意的有意差异:trusted-zero 原值透传(不回退 stale anchor),与主路径 >0 guard 不同;文档注释给出理由(credit 调整后 drained 的会话不应被旧锚点虚增),scenario 8 钉住。放置于 session.ts(Session/stats 属主模块,三个消费方均已依赖,无新增 import 边)。
  • ④ 测试有效性:断言有牙——wrap core.processTurn deepEqual 断言传入 kernel 的精确 tokenCount、panel Context 行 regex(对 pinned kernel 渲染格式核实过)、EMERGENCY/无 phantom 双向断言、每次 status 调用前后 stats/state 只读快照(含 Map 字段稳定序列化)。8 场景矩阵覆盖 estimate±anchor / legacy±anchor / 真实超窗 / credit-adjusted / overflow-arm / trusted-drained-to-zero 全边缘。无恒真断言,非只测 mock。
  • ⑤ diff 整洁度:6 文件全部与本修复相关(helper + 4 接线 + 2 测试),无 lockfile/version/无关改动;单线性 commit,分支命名 2026-10-04_status-baseline-provenance、commit message fix(#2029) 合规。

结构化七问:

  1. 是什么问题:主请求路径自 fix: keep estimate-grade values out of context sizing denominators (#1839) #1846 起拒绝 estimate-grade failure baseline,但四个 status 侧读者(acp_status nudge、plugin live nudge、plugin panel、postCompressTail)仍把 raw lastInputTokens 直接喂给 kernel——estimate 抬高的 phantom 在 status 面造成虚假紧急压力(repro:60k 真实 / 174k estimate / 150k 窗 → 面板误报 116%)。
  2. 什么原因导致的:provenance gate 只建在主路径 effectiveTokenCount 里,status 读者层没有共享同一决策——读者缺 gate,不是数据污染。
  3. 怎么修复的:提炼共享只读函数 statusInputBaseline(session)(usage/bounded overflow-arm → 原值含 credit-drained 0;estimate/legacy 无 flag → 保留的真实锚点;无正锚点 → kernel unknown 哨兵 0;永不 clamp),四个 status 读点统一接入;纯读取侧改动,不碰任何写路径。
  4. 是否有回归问题:无无意回归(②逐项清点如上)。行为变更清单(old→new,均已在 PR 正文披露、我逐项核验):① estimate-grade 有锚点:status 显示 estimate(116% 假紧急)→ 显示锚点(40%);② estimate-grade 无锚点:estimate 当实测 → 0/unknown(growth-driven);③ legacy 无 flag:raw 呈现 → 有锚点用锚点否则 0;④ 真实超窗 usage:>100% 可见,不变(不 clamp,116% 断言钉住);⑤ overflow-arm:不变;⑥ tail estimate-grade+待蒸馏 mass:phantom 静默 → 停止信号(真实超窗抑制不变);⑦ plugin JSON contextTokens/contextTokensSource:不动(feat(plugin): expose isolated forks and attributed context observations #2017)。
  5. 是否破坏缓存:不涉及——纯只读 status 计算,不触碰 prefix cache/重试/增量游标/去重键/wire bytes;测试对每次 status 调用做了 stats/state 调用前后快照断言。
  6. 是否改了设计方向:无架构转向——fix: keep estimate-grade values out of context sizing denominators (#1839) #1846 provenance contract 向 status 面的既定补全;helper 置于 session.ts,无新增 import 边。
  7. 是否引入了新的配置:无——没有新 env/config/默认值。

review 未发现需顺手修的小问题;范围外无新发现,不立项。

判定:满足 §7.4 auto-merge 标准(单机制 scoped fix、A/B 回归测试钉住原始 bug、CI 15/15 绿、无 config/persistence/wire/cross-repo 变更、纯 fix、diff 干净、Closes #2029、不触 load-bearing infra)。唯一程序性事项:head 落后 master 2 个版本-only 提交(零文件重叠,无冲突)——建议 rebase 到 b1259d9b 后人工合并,或直接由 GitHub 处理 behind 状态。按规则我不执行 merge。

@ranxianglei
ranxianglei merged commit 3a9ec22 into master Oct 4, 2026
15 checks passed
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.22-master.3a9ec22 (rolling master tag).

npm install -g billion-context@0.0.22-master.3a9ec22  # 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.

Status readers still trust estimate-grade failure baselines after #1846

1 participant