Skip to content

fix(report): fold payback verdict uses the full post-fold window (#2044) - #2184

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-05_fold-economics-window
Oct 5, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-05_fold-economics-window

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

kernel-change: full-window fold payback verdict + new cadenceOk diagnostic field (#2044; owner-approved on the issue, host side cannot compute the kernel verdict window)

Ports the acp-kernel fix (PR ranxianglei/acp-kernel#507) into the vendored kernel/ tree now that the kernel lives in this repo (#2092 migration). kernel/package.json bumped 0.0.102 → 0.0.103 per version discipline.

What

  • paidBack = requestsAfter >= n* — same window as savedSoFar, so the verdict and the token figures on one row agree (billion-context#2044). The LAST fold is now evaluable instead of unobserved forever.
  • The original short-window verdict survives as the new cadenceOk field (interleave-cadence diagnostic; feat: price-aware compression triggering (dynamic threshold/frequency from window + cost weights) #1280 guard-signal candidate) — nothing is lost, semantics get names.
  • Summary explainer line updated to full-window semantics; n* printed with 2-decimal precision (fixes the 3 rounding display quirks).
  • savedSoFar / grossSaved / netTokens / GRAND LEDGER figures unchanged. Report-only: zero cache / wire / config impact. Golden pins untouched (no defaultConfig/prompt/tool/wire-marker surface changed).

Incident shape covered by regression tests

A fold that paid back long ago got NOT PAID BACK purely because the NEXT fold arrived in the same batch (k small) while savedSoFar on the same row kept growing. Live data: 383 NPB rows, 279 with k=0 (73%); counterfactual ≈38% flip to PB.

Tests

  • kernel suite npm --prefix kernel test: 22/22 (new: back-to-back fold PB+cadenceOk=false; last-fold flips to PB; evaluable NPB; instant payback at n*=0; S≤σ null; pi plugin /acp panel via ctx.ui.notify() — transient toast in web hosts (same class as billion-context-pi#255) #359 parity extended with k=0 variant)
  • tests/cache-ledger.test.ts: 37/37 (expectations flipped to the new verdict; cadenceOk added to the incremental/batch parity loop)
  • neighbors: cache-proof / cache-friendly-plugin / cache-friendly-proxy / acp-cache-diff 34/34; cache-seam-fuzz / seam-detector / key-switch / anthropic-cache-control 30/30
  • typecheck ✓ (kernel + root)

Closes #2044 (together with ranxianglei/acp-kernel#507 for the standalone repo, which the owner may merge or close as superseded).

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-05_fold-economics-window (ac0bcdb)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2254-pr.2184.479127a

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-pr2184.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei force-pushed the 2026-10-05_fold-economics-window branch from 480a4dd to 1a6c566 Compare October 5, 2026 14:43
- paidBack = requestsAfter >= n* (same window as savedSoFar; the last
  fold is now evaluable instead of unobserved forever)
- the original short-window verdict survives as the new cadenceOk field
  (interleave-cadence diagnostic, #1280 guard-signal candidate)
- summary explainer updated to full-window semantics; n* printed with
  2-decimal precision
- kernel/package.json 0.0.102 -> 0.0.103 (version discipline, #2092)

Tests: kernel/tests/cache-report.test.ts 22/22 (new: back-to-back fold
PB + cadenceOk=false regression; last-fold flips; evaluable NPB; instant
payback at n*=0; S<=sigma null; #359 parity + k=0 variant). Host side:
tests/cache-ledger.test.ts 37/37 (expectations flipped, cadenceOk in the
incremental/batch parity loop); cache neighbors 64/64; typecheck clean.

savedSoFar / netTokens / GRAND LEDGER figures unchanged; report-only,
zero cache/wire/config impact.
@ranxianglei
ranxianglei force-pushed the 2026-10-05_fold-economics-window branch from 1a6c566 to 2a324f5 Compare October 5, 2026 14:51
Not part of the approved port (acp-kernel#507 touched only src/cache-report.ts
and its test). Nothing consumes it: CI installs deps at the repo root and the
kernel's devDeps resolve through the root node_modules. Keeps the PR diff to
the fix itself.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成 — 代码层面可合,等 CI 全绿后由人合并(kernel 变更恒 human-gated)。

审核过程(审核先于实现):

  • 复现/查证:bug 真实存在——bug: fold economics verdict measures payback against turns-to-NEXT-fold, so folds that already paid back read NOT PAID BACK #2044 有 live data(383 NPB 行、73% k=0、≈38% 反事实翻转);我在本地把 PR 分支拉下来跑了定向验证:kernel tests/cache-report.test.ts 22/22 ✓、tests/cache-ledger.test.ts 37/37 ✓、root typecheck ✓。incident shape(back-to-back fold:k=1 而 requestsAfter=9≫n*≈3.6 → PB + cadenceOk=false)的回归测试确实钉住了原 bug——若把 paidBack 改回短窗口,该测试立即红。
  • 层次判断:根因在 kernel 判定表达式本身(computeFoldEconomics 自 给出缓存精确对账,增加新的命令/acp-开头 #800 起就用 turnsToNextFold 算 payback),不是渲染层问题——本 PR 修在源头 ✓。你拍板的方向 1(bug: fold economics verdict measures payback against turns-to-NEXT-fold, so folds that already paid back read NOT PAID BACK #2044 floor 5)与实现逐条核对一致:全窗口口径、cadenceOk 保留短窗口语义、summary 文案、n* 两位小数、ledger 数值不动。
  • CI 修复记录:首版 head 上 kernel-guard 因两条规则失败(缺 kernel-change: 声明 + kernel/src 改动未 bump 版本)。你在 14:44 的 force-push 已自行补上(声明行 + 0.0.102→0.0.103)✓。我另外发现并处理了一处 diff 整洁度问题:分支里混入了一个 2075 行的新文件 kernel/package-lock.json——acp-kernel#507 没有它、无任何 workflow 消费它(CI 在 repo root 装依赖,kernel devDeps 走 root node_modules 解析)、PR 正文也未提及,判定为开发时 npm 副产物。已推一个标注 commit ac0bcdb64 将其移除;如果它是你有意的(kernel 独立身份的一部分),revert 这一个 commit 即可,无功能影响。移除后最终 diff = 4 文件 +145/−11,每一行都与本 PR 目的相关。

结构化七问:

  1. 是什么问题:/acp-cache 报告里每个折叠的"回本判定"(paidBack)用错窗口——它数的是"到下一个折叠之间过了几轮"(k),而同行的节省金额(savedSoFar)数的是"该折叠之后至今的全部请求"(requestsAfter)。于是只要下个折叠来得紧(k 小),早就回本的折叠也显示 NOT PAID BACK;末次折叠则永远无法评估(null)。
  2. 什么原因导致的:kernel 的 computeFoldEconomics 从模块诞生(给出缓存精确对账,增加新的命令/acp-开头 #800)起就把一个节奏指标(到下一折叠的轮数)当成了回本判定在用,一行里混了两个口径——verdict 与 token 数字各说各话。
  3. 怎么修复的:判定改为与 savedSoFar 同窗口的 requestsAfter >= n*;原短窗口表达式一字不改地保留为新字段 cadenceOk(interleave 节奏诊断,feat: price-aware compression triggering (dynamic threshold/frequency from window + cost weights) #1280 护栏候选);summary 解释行同步改全窗口语义;n* 打印精度 1→2 位小数(顺带修掉 3 条取整显示瑕疵)。纯报告计算,零 wire 改动。
  4. 是否回归问题:逐项清点过触碰路径的既有行为——savedSoFar/grossSaved/netTokenDelta/oneTimeCostUnits/perTurnSavingUnits/breakevenTurns/GRAND LEDGER 全部不变(代码未碰);incremental/batch parity 循环已扩入 cadenceOk 并通过;golden pins 不受影响(未动 defaultConfig/prompts/tool schema/wire markers);src/、website/、tools/、scripts/ 无其他 paidBack/cadenceOk 消费者(grep 核实)。有意行为变更(均已在正文披露):末次折叠从 null(不可观测)变为可评估(requestsAfter<n* 时显示 NOT PAID BACK);unobservedCount 现在只计 S≤σ 的折叠;n*=0 的零成本折叠即时判为已回本。三项都是方向 1 的直接推论,非漂移。
  5. 是否破坏缓存:不涉及——纯报告计算,零缓存/wire/配置/持久化影响,不触碰任何重试/游标/去重键。
  6. 是否改了设计方向:不涉及——架构与数据流不变;FoldEconomics 增加一个纯附加诊断字段(cadenceOk)。
  7. 是否引入新配置:不涉及——无新 env/config/默认值。

收工判定:代码与测试就绪,diff 已收敛,方向与 owner 拍板一致;待新 head 的 CI 全绿(test matrix 还在跑)后由人合并——kernel 变更按 Kernel Boundary 恒 human-gated,我不代合。另:acp-kernel#507(standalone repo)按你的处置决定合并或关闭为 superseded 即可。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 全绿确认:最终 head ac0bcdb64 上 21/21 检查通过——kernel-guard ✓(声明 + 版本纪律)、test matrix 四格全过(ubuntu/windows × node 22/24:typecheck + kernel suite + bili suite + build)✓、全部 real-client e2e lane ✓、hermetic registry e2e ×2 ✓、version-guard / build-artifact / docs-sync / docs-coverage / lane-guard ✓。无失败、无取消。PR 就绪,按 Kernel Boundary 由人合并(kernel 变更恒 human-gated)。

@ranxianglei
ranxianglei merged commit ae44f38 into master Oct 5, 2026
21 checks passed
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.51-master.ae44f38 (rolling master tag).

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

bug: fold economics verdict measures payback against turns-to-NEXT-fold, so folds that already paid back read NOT PAID BACK

1 participant