Skip to content

[PR] fix(anthropic): enforce shared 4-breakpoint cache budget and harvest message-level controls - #7615

Open
feriaref wants to merge 4 commits into
ranxianglei:masterfrom
feriaref:fix/anthropic-shared-cache-budget
Open

feriaref wants to merge 4 commits into
ranxianglei:masterfrom
feriaref:fix/anthropic-shared-cache-budget

Conversation

@feriaref

Copy link
Copy Markdown
Contributor

Fixes #7607

kernel-change: harvest message-level and raw-block cache_control in kernel/src/wire/anthropic.ts so coreToAnthropic honors the shared 4-breakpoint Anthropic cache budget (WC-010/WC-016); bumps acp-kernel 0.0.206 -> 0.0.207 with synced lockfiles.

Summary

  • Harvest message-level and raw-block cache_control in anthropicToCore and apply marks cleanly in coreToAnthropic (kernel/src/wire/anthropic.ts).
  • Skip unmarkable trailing reasoning blocks in computeAnthropicMessageMarks and extract stampSystemWithinAnthropicBudget (src/loop/cache-control.ts) as the single 4-breakpoint budget source of truth across src/server/prepare-anthropic.ts and src/loop/adapter-anthropic.ts.
  • Preserves pre-fold sticky prefix anchors when clients mark only trailing blocks, without exceeding WC-010 (4 breakpoints) or violating WC-016 (global-scope ordering).

Verification

  • npm run typecheck: pass
  • npm run check:unused-exports: clean
  • npm run check:test-import-graph: ok
  • npm --prefix kernel run test: 1,661/1,661 pass
  • tests/anthropic-shared-cache-budget.test.ts, tests/cache-control.test.ts, tests/wire-contract.test.ts: 28/28 pass

@ranxianglei ranxianglei changed the title fix(anthropic): enforce shared 4-breakpoint cache budget and harvest message-level controls [PR] fix(anthropic): enforce shared 4-breakpoint cache budget and harvest message-level controls Nov 23, 2026
ranxianglei pushed a commit to feriaref/billion-context that referenced this pull request Nov 23, 2026
…ianglei#7615)

Rebase onto master picked up ranxianglei#6751, which already consumed 0.0.207.
This PR's kernel/src/wire/anthropic.ts change therefore no longer
carries a version bump and kernel-guard would fail. Bump to the next
free version and sync the kernel + root lockfiles.
ranxianglei pushed a commit to feriaref/billion-context that referenced this pull request Nov 23, 2026
…anxianglei#7615 review)

The module header still described the pre-PR discipline: 'Cap = 3 message
marks + 1 system breakpoint' and 'client-managed caching suppresses our
stamps entirely'. Under the shared 4-breakpoint budget the message-mark cap
is dynamic (min(3, budget left after client marks + non-message
breakpoints)), and full suppression now holds only in proxy mode — plugin
mode counts client marks against the shared budget and keeps the system
stamp plus a supplemental anchor on active folds. Comment-only fix found
during review; no behavior change.
@ranxianglei
ranxianglei force-pushed the fix/anthropic-shared-cache-budget branch from ae06e09 to 8538ffd Compare November 23, 2026 18:31
@ranxianglei ranxianglei added bug Something isn't working p2 scope/wiring labels Nov 23, 2026
ranxianglei pushed a commit to feriaref/billion-context that referenced this pull request Nov 23, 2026
…anxianglei#7615 review)

The PR's new message-level harvest (kernel/src/wire/anthropic.ts
clientMessageControls) had no test coverage. This pins:
- message-level marks re-emit on the last non-reasoning block
- trailing thinking blocks stay unmarked (signature-safe)
- message-level + block-level marks share the WC-010 4-breakpoint
  budget with the system stamp (3 client marks + 1 system stamp = 4)
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重 (duplicate screening): not a duplicate. Searched open+closed for cache_control breakpoint / WC-010 / 4-breakpoint. Related-but-distinct: #5525 (fork-adoption ladder seeding), #4234 (string-content system-message marks), #7323 (incremental-lane retouch marks), #6869 (closed — the pinClientMessageMarks / #6861 foundation this PR builds on), #2515 (closed — round-2 client marks, #2499). #7614 (same author, kernel instance-reid.ts + prune.ts) has no file overlap with this PR's kernel change; it has the same post-rebase version-bump issue, handled in its own thread.

What I did to this PR (all pushed to your fork branch, force-pushed ae06e09 → 97171b52c):

  1. Rebased onto master (045228c) — clean, no conflicts.
  2. f7ad285 — kernel bump 0.0.207 → 0.0.208: master's [PR] kernel: compress length-rejection advice must match the failure direction (#6730) #6751 already consumed 0.0.207, so without this this PR's kernel/src change would have failed kernel-guard (version discipline, Kernel Boundary rule 2). Kernel + root lockfiles synced.
  3. 8538ffd — fixed the stale header comment in src/loop/cache-control.ts: it still said "Cap = 3 message marks + 1 system breakpoint" and "client-managed caching … suppresses our stamps entirely" — both now wrong (the budget is dynamic/shared, and full suppression only applies in proxy mode).
  4. 97171b5 — added a test pinning message-level harvest (the PR's headline kernel feature had zero test coverage): message-level marks re-emit on the last non-reasoning block, trailing thinking stays unmarked, and message-level + block-level marks share the WC-010 budget with the system stamp (3 client marks + 1 system stamp = 4).
  5. Labeled the PR bug + p2 + scope/wiring (judged from the PR's own diff: wire-protocol cache-budget fix, narrow trigger surface — clients must actively mark; not p1).

Verification (targeted, local, on the final head): typecheck clean; host tests anthropic-shared-cache-budget + cache-control + anthropic-cache-control + wire-contract 37/37 (incl. the 3 tests in the new file); kernel wire subset (9 files) 114/114; round-2 seam suites (issue2499-anthropic-round2-cache + round2-stream + round2-thinking-hold) 11/11 → round-2 behavior preserved. Full-suite verdict = CI on the pushed head: static gates were already green on the prior head (incl. kernel-guard, lock-sync, version-guard), test shards on the final head are still running.

One drive-by finding → filed as #7622 (bug/p3/scope/ci): the WC-010 fake validator (tests/wire-contract-fakes.ts) counts breakpoints over system + tools + message content blocks but NOT message-level cache_control — a test-fidelity gap only (zero production impact: bili egress normalizes message-level → block-level; the passthrough path forwards the client's own marks as-is). Options A (verify against the real API, then update validator + ledger) / B (ledger note) are in the issue; I recommend A if you have API access.


8问 review:

  1. 是什么问题: Anthropic 每请求最多 4 个 cache_control 断点(WC-010),global-scope 标记另有顺序约束(WC-016)。本 PR 之前,三个独立的标记生产者(kernel harvest、prepare-anthropic 稳态 stamp、adapter-anthropic 二轮 stamp)各算各的预算、公式不一致,且 kernel 在 harvest 时静默丢弃 message-level 与 raw-block(thinking/image/redacted_thinking/unknown)上的 cache_control。后果:(a) 客户端主动标记时总数可超 4 → 上游 400;(b) 客户端 global-scope 标记 + bili 再 stamp system → WC-016 顺序违规 → 400;(c) message-level 标记在往返中丢失。
  2. 什么原因导致的: kernel anthropicToCore 只 harvest text-block 上的标记;host 侧预算逻辑有两份拷贝(prepare-anthropic 与 adapter-anthropic)且公式不同;"client-managed wins" 回退是全有全无、不分模式(不区分 proxy/plugin,不识别 global scope)。
  3. 影响范围与严重程度: p2。触发面窄——客户端必须主动发送 cache_control 标记;失败模式是这些特定请求 400,不是整体不可用。proxy + global-scope 场景是真修复(之前可能 400);plugin + 客户端标记:之前安全但浪费预算,现在在预算内 stamp(效率提升)。
  4. 怎么修复的: 单一事实源——stampSystemWithinAnthropicBudget(src/loop/cache-control.ts:283)同时被稳态(src/server/prepare-anthropic.ts:630)与二轮(src/loop/adapter-anthropic.ts:264)使用;kernel 把 message-level 标记 harvest 进独立的 clientMessageControls map(重放时落在该消息最后一个非 reasoning block 上——KDD release v0.1.3 #10 签名安全),raw-block 标记进 cacheControls(同 id 冲突时 block-level 优先,prepare-anthropic.ts:250-253);message 标记数 = min(3, 剩余预算);模式感知的回退;global-scope 存在时两种模式都抑制 bili 的标记与 stamp。
  5. 是否有回归问题: 逐项审过——无客户端标记的稳态路径不变(3+1,字节一致);proxy + global-scope system 的整请求 passthrough([Bug][claude MITM] 注入 ACP 工具破坏宿主请求:scope:"global" 缓存前缀 400 + Threads continue 指纹不符(thread_fingerprint_mismatch) #2648,prepare-anthropic.ts:173 早退)不变;F2 seam anthropic lane: buildSystem 将客户端多块 system 合并为单块,破坏下游按块形状的 CC 识别(如 sub2api billing-block 前缀检查) #1876 字节一致性保持(src/server/inject.ts 零 cache_control → 注入工具无标记 → 二轮标记数 == 稳态标记数);bili claude: every request rewrites mid-history, breaking the prefix cache (cache hit falls to 8.7% on one request, 119K tokens re-billed, no fold or switch attribution) #6861 客户端标记钉存不变(现在在共享预算内);thinking 字节不动(KDD release v0.1.3 #10 已验证:无标记 thinking 字节一致重放)。有意行为变更(披露):① plugin 模式 + 客户端标记:system 现在在预算剩余时会被 stamp(旧:不 stamp)——效率提升,不超 WC-010;② plugin + global-scope system:bili 的 message 标记被丢弃(旧:3 个标记)——更保守,与 [Bug][claude MITM] 注入 ACP 工具破坏宿主请求:scope:"global" 缓存前缀 400 + Threads continue 指纹不符(thread_fingerprint_mismatch) #2648 一致;③ proxy + global-scope 在 tools/message 标记上:bili 不再 stamp system(旧:可能 stamp → WC-016 400——这就是修复本身)。
  6. 是否破坏缓存: 不——相反,是让缓存在预算内正常工作。标记是粘性/累积的;新测试钉死了 fold 前后字节一致前缀(wire2.slice(0,3) deepEqual wire1.slice(0,3))。
  7. 是否改了设计方向: 无转向——按既有 single-applier 原则收敛;kernel wire harvest 增加的是附加保真度(message-level + raw-block 标记从丢弃变为保留)。
  8. 是否引入了新的配置: 无。

测试缺口(如实说明): 函数级逻辑已钉死(新文件 3/3 + 我补的 message-level 测试);pureClientManaged/hasActiveFold 的 handler 级接线没有集成测试(3 行组合,组合的函数本身已钉死)——可接受的残留,e2e/CI 兜底。

Kernel Boundary 状态: PR 已声明 kernel-change ✓;版本纪律 ✓(rebase 后 0.0.208);但 #7607 里没有人工 owner 对 kernel 变更的批准记录(该 issue 两条评论都是 agent 发的)→ kernel 部分待 owner 批准(Kernel Boundary rule 1;mechanical-bug 豁免不适用——这是设计变更)。无论如何,human-only merge tier 适用(rule 3)。

结论: host 侧逻辑验证成立;待 (a) owner 批准 kernel 变更 + (b) 最终 head 的 CI 绿,即可合并。

标签: PR #7615 = bug/p2/scope/wiring(wire 协议缓存预算修复,触发面窄); 新 issue #7622 = bug/p3/scope/ci(测试保真缺口,无用户影响)。

@ranxianglei
ranxianglei force-pushed the fix/anthropic-shared-cache-budget branch from 97171b5 to c61b12d Compare November 24, 2026 06:11
ranxianglei pushed a commit to feriaref/billion-context that referenced this pull request Nov 24, 2026
…anxianglei#7615 review)

The module header still described the pre-PR discipline: 'Cap = 3 message
marks + 1 system breakpoint' and 'client-managed caching suppresses our
stamps entirely'. Under the shared 4-breakpoint budget the message-mark cap
is dynamic (min(3, budget left after client marks + non-message
breakpoints)), and full suppression now holds only in proxy mode — plugin
mode counts client marks against the shared budget and keeps the system
stamp plus a supplemental anchor on active folds. Comment-only fix found
during review; no behavior change.
ranxianglei pushed a commit to feriaref/billion-context that referenced this pull request Nov 24, 2026
…anxianglei#7615 review)

The PR's new message-level harvest (kernel/src/wire/anthropic.ts
clientMessageControls) had no test coverage. This pins:
- message-level marks re-emit on the last non-reasoning block
- trailing thinking blocks stay unmarked (signature-safe)
- message-level + block-level marks share the WC-010 4-breakpoint
  budget with the system stamp (3 client marks + 1 system stamp = 4)
ranxianglei pushed a commit to feriaref/billion-context that referenced this pull request Nov 24, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI-fix run: merge conflict resolved, PR is now mergeable (clean).

What I did this run (rebase + conflict resolution + version discipline + verify + push):

  1. Rebased the PR onto current master fc7ddee4f95 (the PR's base had been 045228c; master advanced in between). PR head was 97171b52c (4 commits).
  2. Resolved the one real conflict — the import block in src/loop/adapter-anthropic.ts: master added lastIterationContext to the util import (its stop-sequence / context-tokens work), and this PR swapped the cache-control import to stampSystemWithinAnthropicBudget. I took the union — kept master's lastIterationContext + the PR's stampSystemWithinAnthropicBudget, and dropped stampAnthropicSystemCacheControl (now unreferenced after the PR's round-2 rebuild change). Every other file auto-merged cleanly.
  3. Re-bumped the kernel version 0.0.208 → 0.0.209 (+ the acp-kernel version line in both lockfiles). The rebase dropped the original bump commit (f7ad285, 0.0.207 → 0.0.208) because that patch was already upstream (master's Batch compression should not fail entirely; protected messages should be automatically excluded. | 批量压缩不应该全部失败,保护消息应该自动剔除 #7596 consumed 0.0.208) — but this PR's kernel/src/wire/anthropic.ts change is a NEW kernel change sitting ON TOP of master's 0.0.208, so it needs its own version number or kernel-guard (Kernel Boundary rule 2, version discipline) would fail.
  4. Verified locally (targeted, on the final head c61b12d7b35): npm run typecheck clean (kernel + pi-subagents build + tsc --noEmit); host tests anthropic-shared-cache-budget + cache-control + wire-contract = 29/29; kernel wire/anthropic subset = 99/99; round-2 seam suites (issue2499-round2-cache + anthropic-cache-control + round2-stream + round2-thinking-hold + fold-round2-shape) = 20/20.
  5. Force-pushed the rebased head to feriaref/billion-context fix/anthropic-shared-cache-budget (97171b52c → c61b12d7b35). Fetched first; no concurrent move (remote head was still 97171b52c).

Result: PR merge state is now mergeable: True (conflict cleared), base = current master fc7ddee4f95. merge_state: blocked only because of the pending owner approval + the new head's CI still running — not a conflict. Prior head's CI was fully green (30/30, 0 failed) per the mirror cache.

Remaining (not mine to satisfy): the kernel change still needs owner approval (Kernel Boundary rule 1 — #7607 has no human approval record; the mechanical-bug exemption doesn't apply since this is a design change). Human-only merge tier applies (rule 3). Note the PR body's kernel-change line still reads "0.0.206 → 0.0.207" (stale from the original authoring); the actual kernel version on this head is 0.0.209 — I left the body untouched per lane rules.


8问:

  1. 是什么问题: PR [PR] fix(anthropic): enforce shared 4-breakpoint cache budget and harvest message-level controls #7615 与 master 合并冲突(merge state dirty)——master 在 PR 基线 045228c 之后又前进了(stop-sequence/context-tokens 改动落在 adapter-anthropic.ts,kernel 版本被 Batch compression should not fail entirely; protected messages should be automatically excluded. | 批量压缩不应该全部失败,保护消息应该自动剔除 #7596 推到 0.0.208),与 PR 的 4 个提交在同一文件、同一版本行上撞车,PR 无法合并。
  2. 什么原因导致的: 两条线并行改同一处——(a) adapter-anthropic.ts 的 import 块相邻行:master 加 lastIterationContext,PR 换 stampSystemWithinAnthropicBudget,git 无法自动合并;(b) kernel 版本:PR 的 bump 提交(0.0.207→0.0.208)rebase 时被判定「patch 已在上游」而丢弃,但 PR 的 kernel/src 改动是叠在 master 0.0.208 之上的新变更,需要独立版本号。
  3. 影响范围与严重程度: 仅本 PR 分支的合并状态,不影响任何已发布行为。解决前 PR 卡住(dirty 无法合并),解决后 mergeable=True。严重度:调度阻塞,无用户面影响。
  4. 怎么修复的: rebase 到当前 master fc7ddee4f95;import 冲突取并集(保留 master 的 lastIterationContext + PR 的 stampSystemWithinAnthropicBudget,删掉已无引用的 stampAnthropicSystemCacheControl);kernel 版本重新 bump 到 0.0.209(kernel/package.json + 两个 lockfile 的 acp-kernel 版本行),保证 kernel-guard 版本纪律通过。
  5. 是否有回归问题: 无——冲突解决是纯机械的(import 并集 + 版本号),未改动任何 PR 逻辑语义;master 的 stop-sequence/context-tokens 与 PR 的 cache-budget 改动在不同函数/不同行,自动合并后两者完整保留(已 grep 验证 stopSequence/contextTokens: roundContext/effectiveMarks/stampSystemWithinAnthropicBudget 均在位);本地定向测试全绿(见上)。
  6. 是否破坏缓存: 不涉及——本次只动 import 与版本号,不触碰任何缓存/重试/游标/去重键逻辑。
  7. 是否改了设计方向: 不涉及——纯 rebase + 冲突解决 + 版本纪律,无架构/边界/数据流转向。
  8. 是否引入了新的配置: 不涉及——无新 env/config/默认值。

收工判定: 冲突已解决并推送,PR 现为 mergeable(clean);待 (a) owner 批准 kernel 变更 + (b) 新 head c61b12d7b35 的 CI 绿,即可进入人工合并。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei
ranxianglei force-pushed the fix/anthropic-shared-cache-budget branch from c61b12d to 17ef7c7 Compare November 25, 2026 00:11
ranxianglei pushed a commit to feriaref/billion-context that referenced this pull request Nov 25, 2026
…anxianglei#7615 review)

The module header still described the pre-PR discipline: 'Cap = 3 message
marks + 1 system breakpoint' and 'client-managed caching suppresses our
stamps entirely'. Under the shared 4-breakpoint budget the message-mark cap
is dynamic (min(3, budget left after client marks + non-message
breakpoints)), and full suppression now holds only in proxy mode — plugin
mode counts client marks against the shared budget and keeps the system
stamp plus a supplemental anchor on active folds. Comment-only fix found
during review; no behavior change.
ranxianglei pushed a commit to feriaref/billion-context that referenced this pull request Nov 25, 2026
…anxianglei#7615 review)

The PR's new message-level harvest (kernel/src/wire/anthropic.ts
clientMessageControls) had no test coverage. This pins:
- message-level marks re-emit on the last non-reasoning block
- trailing thinking blocks stay unmarked (signature-safe)
- message-level + block-level marks share the WC-010 4-breakpoint
  budget with the system stamp (3 client marks + 1 system stamp = 4)
ranxianglei pushed a commit to feriaref/billion-context that referenced this pull request Nov 25, 2026
…ianglei#7615)

master consumed 0.0.209 (ranxianglei#7614) and 0.0.210 (mega-turn gap bridging) since the
previous rebase; this PR's kernel/src/wire/anthropic.ts change is new on top,
so it takes the next version to satisfy kernel-guard (Kernel Boundary rule 2).
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI-fix run 2: merge conflict resolved again — master moved under the PR.

Why it went dirty again: since the previous rebase, master advanced ~60 commits (fc7ddee4f95 → 85afa7b212c) and itself consumed two kernel versions — accbec4bfbf bumped 0.0.208 → 0.0.209 (#7614) and 356209602bc bumped 0.0.209 → 0.0.210 (mega-turn gap bridging). My PR head was sitting on a 0.0.209 bump, so the version line collided and the merge went dirty.

What I did this run (rebase + version discipline + verify + push):

  1. Rebased the PR onto current master 85afa7b212c. The fix/docs/test commits all applied cleanly (no code conflicts — master's changes to prepare-anthropic.ts/server.ts/util.ts didn't overlap the PR's hunks). The only conflict was the kernel version line (my 0.0.209 vs master's 0.0.210), resolved to master's 0.0.210 — the old bump commit became a no-op and was auto-skipped.
  2. Re-bumped the kernel 0.0.210 → 0.0.211 (+ the acp-kernel version line in both lockfiles). This PR's kernel/src/wire/anthropic.ts change is new on top of master's 0.0.210, so it takes the next version to satisfy kernel-guard (Kernel Boundary rule 2, version discipline).
  3. Reinstalled deps (the workdir node_modules had been cleaned between runs) and verified locally on the final head 17ef7c72a0d: npm run typecheck clean (kernel + pi-subagents build + tsc --noEmit); host tests anthropic-shared-cache-budget + cache-control + wire-contract = 29/29; kernel wire/anthropic subset = 99/99; round-2 seam suites (issue2499-round2-cache + anthropic-cache-control + round2-stream + round2-thinking-hold + fold-round2-shape) = 20/20.
  4. Force-pushed the rebased head to feriaref/billion-context fix/anthropic-shared-cache-budget (c61b12d7b35 → 17ef7c72a0d). Fetched first (from the GitHub remotes — the local mirror was 502); no concurrent move (remote head was still c61b12d7b35, master still 85afa7b212c).

Result: PR merge state is now mergeable: True (conflict cleared), base = current master 85afa7b212c. merge_state: blocked only because of the pending owner approval + the new head's CI still running — not a conflict.

Remaining (not mine to satisfy): the kernel change still needs owner approval (Kernel Boundary rule 1 — #7607 has no human approval record; the mechanical-bug exemption doesn't apply since this is a design change). Human-only merge tier applies (rule 3). Note the PR body's kernel-change line still reads "0.0.206 → 0.0.207" (stale from the original authoring); the actual kernel version on this head is now 0.0.211 — I left the body untouched per lane rules.


8问:

  1. 是什么问题: PR [PR] fix(anthropic): enforce shared 4-breakpoint cache budget and harvest message-level controls #7615 再次与 master 合并冲突(merge state dirty)——上一次 rebase 之后 master 又前进了约 60 个提交,且 master 自己连续 bump 了两次 kernel 版本(0.0.209、0.0.210),与 PR 分支上的 0.0.209 bump 在同一版本行上撞车,PR 再次无法合并。
  2. 什么原因导致的: 两条线并行改 kernel 版本号——master 侧 [PR] fix(kernel): prevent covered reasoning leak across thinking drops #7614(accbec4bfbf,0.0.208→0.0.209)和 mega-turn gap bridging(356209602bc,0.0.209→0.0.210)先后消费了两个版本;PR 侧的 bump 提交停在 0.0.209。rebase 时版本行冲突,且 PR 的 kernel/src/wire/anthropic.ts 改动是叠在 master 0.0.210 之上的新变更,必须再取下一个版本号。
  3. 影响范围与严重程度: 仅本 PR 分支的合并状态,不影响任何已发布行为。解决前 PR 卡住(dirty 无法合并),解决后 mergeable=True。严重度:调度阻塞,无用户面影响。
  4. 怎么修复的: rebase 到当前 master 85afa7b212c;fix/docs/test 三个提交干净应用(无代码冲突);版本行冲突取 master 的 0.0.210(旧 bump 提交变空被自动跳过);再新增一个提交把 kernel bump 到 0.0.211(kernel/package.json + 两个 lockfile 的 acp-kernel 版本行),保证 kernel-guard 版本纪律通过。
  5. 是否有回归问题: 无——冲突解决是纯机械的(版本行 + 版本号),未改动任何 PR 逻辑语义;master 的 ~60 个提交与 PR 的 cache-budget 改动在不同 hunk,自动合并后两者完整保留;本地定向测试全绿(typecheck clean + host 29/29 + kernel 99/99 + round-2 seam 20/20)。
  6. 是否破坏缓存: 不涉及——本次只动 kernel 版本号,不触碰任何缓存/重试/游标/去重键逻辑。
  7. 是否改了设计方向: 不涉及——纯 rebase + 冲突解决 + 版本纪律,无架构/边界/数据流转向。
  8. 是否引入了新的配置: 不涉及——无新 env/config/默认值。

收工判定: 冲突已解决并推送,PR 现为 mergeable(clean);待 (a) owner 批准 kernel 变更 + (b) 新 head 17ef7c72a0d 的 CI 绿,即可进入人工合并。若 master 再前进并再次消费 kernel 版本,本车道会按同样流程再 rebase + bump。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

No action needed — the PR is already clean; the "dirty" wake is a stale mirror reading.

I verified the LIVE state in this run (not from memory):

  • GitHub (authoritative): mergeable: True — no merge conflict. base 85afa7b212c, head 17ef7c72a0d.
  • master is still at 85afa7b212c (unchanged since the last rebase — the rebase target is still valid).
  • PR branch head is 17ef7c72a0d (the head pushed in the previous run; no concurrent move).
  • The final head 17ef7c72a0d does not carry the [ework:ci-held] marker (it is the unmarked final head — correct).

The "merge state: dirty" in the wake is a stale mirror reading from before the previous run's push. There is no conflict to resolve, so I did not rebase or push anything this run — re-pushing the identical head would only waste the branch's one full CI pass.

Status: the PR is mergeable (clean). merge_state: blocked is only the pending owner approval (kernel change, Kernel Boundary rule 1) + the new head 17ef7c72a0d's CI still running. The mirror cache currently shows the prior head's checks all green (30/30, 0 failed); the new head's run is in flight.

Remaining (not mine to satisfy): owner approval of the kernel change + green CI on 17ef7c72a0d, then human merge. No new decision needed this run.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei
ranxianglei force-pushed the fix/anthropic-shared-cache-budget branch from 17ef7c7 to 77d7561 Compare November 29, 2026 00:03
ranxianglei pushed a commit to feriaref/billion-context that referenced this pull request Nov 29, 2026
…anxianglei#7615 review)

The module header still described the pre-PR discipline: 'Cap = 3 message
marks + 1 system breakpoint' and 'client-managed caching suppresses our
stamps entirely'. Under the shared 4-breakpoint budget the message-mark cap
is dynamic (min(3, budget left after client marks + non-message
breakpoints)), and full suppression now holds only in proxy mode — plugin
mode counts client marks against the shared budget and keeps the system
stamp plus a supplemental anchor on active folds. Comment-only fix found
during review; no behavior change.
ranxianglei pushed a commit to feriaref/billion-context that referenced this pull request Nov 29, 2026
…anxianglei#7615 review)

The PR's new message-level harvest (kernel/src/wire/anthropic.ts
clientMessageControls) had no test coverage. This pins:
- message-level marks re-emit on the last non-reasoning block
- trailing thinking blocks stay unmarked (signature-safe)
- message-level + block-level marks share the WC-010 4-breakpoint
  budget with the system stamp (3 client marks + 1 system stamp = 4)
ranxianglei pushed a commit to feriaref/billion-context that referenced this pull request Nov 29, 2026
…ianglei#7615)

master consumed 0.0.211..0.0.214 (v0.1.217 release + egress plane + cross-lane
switching ranxianglei#7684) since the previous rebase; this PR's kernel/src/wire/anthropic.ts
change is new on top, so it takes the next version to satisfy kernel-guard
(Kernel Boundary rule 2).
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI-fix run: merge conflict resolved — master moved significantly and this rebase required a semantic merge in the kernel wire file (thinking relay), which I resolved and verified with the full kernel + host suites.

Why it went dirty (bigger than the last two runs): master advanced 85afa7b212c → 24ba3ad09e8 — the v0.1.217 release + the egress plane + cross-lane model/protocol switching (#7684). Master consumed kernel versions up to 0.0.214 (was 0.0.210), and — critically — master rewrote the same case "reasoning": block in coreToAnthropic (kernel/src/wire/anthropic.ts) that this PR also rewrites. So this wasn't just a version-line collision; the two changes overlap in the thinking-relay path.

What I did this run (rebase + semantic merge + version discipline + verify + push):

  1. Rebased the PR onto current master 24ba3ad09e8. The fix/docs/test commits applied; the kernel file hit two conflicts:
    • Hunk 1 (anthropicToCore reasoning): clean union — kept master's anthropicThinking: true flag + the PR's safer typeof b.signature === "string" check + the PR's rawAnthropicBlock capture.
    • Hunk 2 (coreToAnthropic reasoning) — the semantic merge: master's version is a 3-branch decision (signed → thinking+sig / same-lane unsigned via anthropicThinking → thinking / foreign unsigned → degrade to text); the PR's version adds a rawAnthropicBlock verbatim re-emit + ...cc(m.id) cache_control restoration + the safer signature check. These are orthogonal: master decides thinking-vs-text, the PR restores cache_control. I combined them — the PR's rawAnthropicBlock branch first (it's only set for same-lane Anthropic blocks, so re-emitting it verbatim is consistent with master's same-lane logic and strictly more faithful), then master's 3-branch decision, with ...cc(m.id) added to every emitted block (thinking and the degraded text) so cache_control is restored in all cases.
  2. Re-bumped the kernel 0.0.214 → 0.0.215 (+ both lockfiles) — the PR's wire/anthropic.ts change is new on top of master's 0.0.214, so it takes the next version for kernel-guard (Kernel Boundary rule 2).
  3. Verified locally on the final head 77d756130a4: npm run typecheck clean; kernel suite 159/159 (incl. crosslane-egress-fidelity — master's [PR] egress plane: cross-lane model/protocol switching — render fidelity + wire-granularity pinning #7684 test — + wire-reasoning-echo/wire-demoted-thinking/wire-bili-message-roundtrip/issue3939-wire-byte-stability); host suite 73/73 (incl. the PR's anthropic-shared-cache-budget + anthropic-cache-control + wire-contract + issue5495-unsigned-thinking-replay/issue5998-unsigned-thinking-egress/issue1960-thinking-verbatim + the round-2 seam suites).
  4. Force-pushed 17ef7c72a0d → 77d756130a4 to feriaref/billion-context. Fetched first (GitHub remotes); no concurrent move (master still 24ba3ad09e8, PR branch still 17ef7c72a0d).

Result: PR merge state is now mergeable: True (conflict cleared), base = current master 24ba3ad09e8. merge_state: blocked only because of the pending owner approval + the new head's CI still running — not a conflict.

⚠️ Reviewer note (kernel change): the hunk-2 merge is a semantic combination in the thinking-relay path (KDD #10 territory). I judged it well-defined (orthogonal concerns, not an approach choice) and the full kernel + host suites confirm it, but it is a kernel wire change — it sits at the human-only review tier (Kernel Boundary rule 3) and the PR still needs owner approval (rule 1; #7607 has no human approval record). The PR body's kernel-change line still reads "0.0.206 → 0.0.207" (stale); the actual kernel version on this head is 0.0.215 — I left the body untouched per lane rules.


8问:

  1. 是什么问题: PR [PR] fix(anthropic): enforce shared 4-breakpoint cache budget and harvest message-level controls #7615 第三次与 master 合并冲突——这次 master 大幅前进(v0.1.217 发版 + egress 平面 + 跨车道模型切换 [PR] egress plane: cross-lane model/protocol switching — render fidelity + wire-granularity pinning #7684),不仅消费了 kernel 版本(到 0.0.214),还重写了与本 PR 相同的 coreToAnthropic 里 case "reasoning": 代码块,两处在 thinking 中继路径上真正重叠。
  2. 什么原因导致的: 两条线改同一代码块——master 的 [PR] egress plane: cross-lane model/protocol switching — render fidelity + wire-granularity pinning #7684 把 reasoning 渲染改成三分支判决(有签名→thinking+sig / 同车道无签名→thinking / 外来无签名→降级为 text);PR 给同一块加了 rawAnthropicBlock 原样重发 + ...cc(m.id) 缓存控制恢复。git 无法自动合并,需要语义级合并。
  3. 影响范围与严重程度: 仅本 PR 分支的合并状态,不影响已发布行为。解决前 PR 卡住(dirty),解决后 mergeable=True。严重度:调度阻塞 + 一次高风险 kernel 语义合并(已用全套测试验证)。
  4. 怎么修复的: rebase 到 24ba3ad09e8;kernel 文件两处冲突——hunk1 取并集(master 的 anthropicThinking + PR 的更安全签名判断 + PR 的 rawAnthropicBlock);hunk2 语义合并:PR 的 rawAnthropicBlock 分支置顶(仅同车道 Anthropic 块才有,原样重发比 master 重建更忠实),其后接 master 三分支判决,每个发出的块(thinking 和降级 text)都加 ...cc(m.id) 恢复缓存控制。kernel 版本 bump 到 0.0.215。
  5. 是否有回归问题: 无——本地全套验证绿:typecheck clean + kernel 159/159(含 master 的 [PR] egress plane: cross-lane model/protocol switching — render fidelity + wire-granularity pinning #7684 crosslane-egress-fidelity 与 wire 字节稳定性/推理回显)+ host 73/73(含 PR 的 cache-budget 测试、thinking replay、round-2 seam)。master 的跨车道降级逻辑与 PR 的缓存恢复都完整保留。
  6. 是否破坏缓存: 不涉及——本次是合并既有改动,不改变任何缓存/重试/游标策略;PR 本身的缓存预算逻辑经 anthropic-shared-cache-budget 测试钉住。
  7. 是否改了设计方向: 不涉及——纯 rebase + 语义合并 + 版本纪律,无架构/边界转向。
  8. 是否引入了新的配置: 不涉及——无新 env/config/默认值。

收工判定: 冲突已解决并推送,PR 现为 mergeable(clean)。本次含一处 kernel thinking 中继路径的语义合并,已用全套 kernel+host 测试验证,但仍属 kernel 变更——待 (a) owner 批准 kernel 变更(Kernel Boundary rule 1)+ (b) 新 head 77d756130a4 的 CI 绿 + (c) 人工 review(human-only tier),方可合并。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

feriaref and others added 4 commits November 30, 2026 03:58
…anxianglei#7615 review)

The module header still described the pre-PR discipline: 'Cap = 3 message
marks + 1 system breakpoint' and 'client-managed caching suppresses our
stamps entirely'. Under the shared 4-breakpoint budget the message-mark cap
is dynamic (min(3, budget left after client marks + non-message
breakpoints)), and full suppression now holds only in proxy mode — plugin
mode counts client marks against the shared budget and keeps the system
stamp plus a supplemental anchor on active folds. Comment-only fix found
during review; no behavior change.
…anxianglei#7615 review)

The PR's new message-level harvest (kernel/src/wire/anthropic.ts
clientMessageControls) had no test coverage. This pins:
- message-level marks re-emit on the last non-reasoning block
- trailing thinking blocks stay unmarked (signature-safe)
- message-level + block-level marks share the WC-010 4-breakpoint
  budget with the system stamp (3 client marks + 1 system stamp = 4)
…ianglei#7615)

master consumed 0.0.215..0.0.217 (v0.1.218 release + mixed-tier auto-split ranxianglei#7770 + crush tool-result rewriter removal) since the previous rebase; this PR's kernel/src/wire/anthropic.ts change is new on top, so it takes the next version to satisfy kernel-guard (Kernel Boundary rule 2).
@ranxianglei
ranxianglei force-pushed the fix/anthropic-shared-cache-budget branch from 77d7561 to cd3efed Compare November 29, 2026 20:02
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI-fix run 4: merge conflict resolved again — master moved under the PR and consumed two more kernel versions.

Why it went dirty (same recurring class as runs 2–3): master advanced 24ba3ad09e8 → 5bb3eb2cd9a — the v0.1.218 release plus the egress rid rework, the close-object-guard CI gate, and two more kernel version consumptions: f20fc4ab20e (mixed-tier auto-split, #7770) bumped 0.0.215 → 0.0.216 and 3128090997c (crush tool-result rewriter removal) bumped 0.0.216 → 0.0.217. My PR head sat on the 0.0.215 bump from run 3, so the version line collided and the merge went dirty. Unlike run 3, no code overlap this time: master did not touch kernel/src/wire/anthropic.ts, adapter-anthropic.ts, or cache-control.ts since the last rebase — the only shared files were the three version files plus src/server.ts / src/server/prepare-anthropic.ts (non-overlapping hunks, auto-merged).

What I did this run (verified live first, then rebase + version discipline + verify + push):

  1. Verified the live state (not from memory): GitHub API mergeable: false, mergeable_state: "dirty"; master 5bb3eb2cd9a; fork branch head 77d756130a4 (no concurrent move). The mirror check cache was 24h stale, so I used a single live PR GET for the merge state.
  2. Rebased the PR onto master 5bb3eb2cd9a: the fix/docs/test commits all applied cleanly (no code conflicts). The only conflicts were the three version lines (my 0.0.215 bump vs master's 0.0.217) — resolved to master's 0.0.217, which made the old bump commit a no-op and it was skipped.
  3. Re-bumped the kernel 0.0.217 → 0.0.218 (+ the acp-kernel version line in both lockfiles) as a new commit. This PR's kernel/src/wire/anthropic.ts change is new on top of master's 0.0.217, so it takes the next version to satisfy kernel-guard (Kernel Boundary rule 2, version discipline).
  4. Verified locally on the final head cd3efedfef8: npm run typecheck clean (kernel + pi-subagents build + tsc --noEmit); host tests anthropic-shared-cache-budget + anthropic-cache-control + wire-contract = 37/37; round-2 seam + client-mark suites (issue2499-round2-cache + round2-stream + round2-thinking-hold + fold-round2-shape + issue6861-client-cache-marks-pinned + opencode-rolling-cache-marks) = 29/29; full kernel suite 1660/1660 (upgraded from the wire subset — master's crush-removal and mixed-tier changes are covered too).
  5. Force-pushed 77d756130a4 → cd3efedfef8 to feriaref/billion-context fix/anthropic-shared-cache-budget. Fetched immediately before the push; no concurrent move (master still 5bb3eb2cd9a, fork head still 77d756130a4).

Result: PR merge state is now mergeable: True (conflict cleared), base = current master 5bb3eb2cd9a. merge_state: blocked only because of the pending owner approval + the new head's CI still running — not a conflict. The run-3 semantic merge in the thinking-relay path (rawAnthropicBlock verbatim re-emit + ...cc(m.id) cache_control restoration) is intact and re-verified by the full kernel suite.

Remaining (not mine to satisfy): the kernel change still needs owner approval (Kernel Boundary rule 1 — #7607 has no human approval record; the mechanical-bug exemption doesn't apply since this is a design change). Human-only merge tier applies (rule 3). Note the PR body's kernel-change line still reads "0.0.206 → 0.0.207" (stale from the original authoring); the actual kernel version on this head is 0.0.218 — I left the body untouched per lane rules.

Pattern note (4th occurrence): every time master consumes a kernel version, this PR's bump commit collides on the same version line. Until the PR merges, each master kernel bump will dirty it again; this lane will keep rebase + bump in the same flow.


七问:

  1. 是什么问题: PR [PR] fix(anthropic): enforce shared 4-breakpoint cache budget and harvest message-level controls #7615 第四次与 master 合并冲突(merge state dirty)——上一次 rebase 之后 master 又前进了(v0.1.218 发版 + egress rid 重构 + close-object-guard CI 门禁),并连续消费了两个 kernel 版本(0.0.216、0.0.217),与 PR 分支上停在 0.0.215 的 bump 提交在同一版本行上撞车,PR 无法合并。
  2. 什么原因导致的: 两条线并行改 kernel 版本号——master 侧 f20fc4ab20e([Bug][kernel] mixed-tier block merge leaves two active blocks owning the same messages (duplicate summaries on the wire) | 混合层级合并留下双覆盖与两份摘要 #7770 mixed-tier auto-split,0.0.215→0.0.216)和 3128090997c(crush 重写器移除,0.0.216→0.0.217)先后消费了两个版本;PR 侧的 bump 提交停在 0.0.215。rebase 时版本行冲突,且 PR 的 kernel/src/wire/anthropic.ts 改动是叠在 master 0.0.217 之上的新变更,必须再取下一个版本号。与第 3 次不同:本次 master 没有触碰 PR 的任何代码文件,纯版本行冲突。
  3. 影响范围与严重程度: 仅本 PR 分支的合并状态,不影响任何已发布行为。解决前 PR 卡住(dirty 无法合并),解决后 mergeable=True。严重度:调度阻塞,无用户面影响。
  4. 怎么修复的: rebase 到当前 master 5bb3eb2cd9a;fix/docs/test 三个提交干净应用(无代码冲突);三处版本行冲突取 master 的 0.0.217(旧 bump 提交变空被自动跳过);再新增一个提交把 kernel bump 到 0.0.218(kernel/package.json + 两个 lockfile 的 acp-kernel 版本行),保证 kernel-guard 版本纪律通过。
  5. 是否有回归问题: 无——冲突解决是纯机械的(版本行 + 版本号),未改动任何 PR 逻辑语义;master 的 v0.1.218 变更与 PR 的 cache-budget 改动在不同文件/不同 hunk,自动合并后两者完整保留;本地验证绿:typecheck clean + host 37/37 + round-2 seam 29/29 + kernel 全套 1660/1660(含 master 的 crush 移除与 mixed-tier 变更的覆盖)。
  6. 是否破坏缓存: 不涉及——本次只动 kernel 版本号,不触碰任何缓存/重试/游标/去重键逻辑;PR 本身的缓存预算逻辑经 anthropic-shared-cache-budget 测试钉住。
  7. 是否改了设计方向: 不涉及——纯 rebase + 冲突解决 + 版本纪律,无架构/边界/数据流转向;无新配置/env/默认值。

收工判定: 冲突已解决并推送,PR 现为 mergeable(clean);待 (a) owner 批准 kernel 变更 + (b) 新 head cd3efedfef8 的 CI 绿,即可进入人工合并。若 master 再前进并再次消费 kernel 版本,本车道会按同样流程再 rebase + bump。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

This branch has not been deployed

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

Labels

bug Something isn't working p2 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anthropic cache_control: enforce shared 4-breakpoint budget across tools/system/messages and harvest message-level controls

2 participants