Repository navigation
fix(cache): quarantine unmeasured cache reports + attribute invalidation causes (P0+P1, CLI) - #1545
Conversation
…attribute invalidation causes #1536: the ledger booked every sample whose provider omitted cache-hit tokens as cached=0, so a whole billed prefix landed in the unexplained ttlRepay residual and the hit rate read 0% even though nothing was wrong. P0 (measurement correctness): core.ts recordUsage normalizes undefined cachedTokens to null; cache-ledger.ts quarantines such samples out of the closure totals (own unknownSamples/unknownInput counters), drops them from the rendered line set, and skips the false-positive cache-collapse warning. The kernel identity still closes exactly over the measurable subset. P1 (attribution for the non-fixable causes), generalizing #1535's model-switch bucket to a full target identity (model | wire protocol | upstream origin) plus a proxy-restart/refork bucket (#499) via a process boot-id marker. Each cause charges only its sample's stable-prefix residual (tr) so compRepay stays booked to its fold and the closure never breaks. CLI (/acp-cache) gains a CACHE INVALIDATION breakdown section; the __bili/cache-report JSON gains wireSwitches/upstreamSwitches/restartDrops/ unmeasured/invalidation. Web UI is intentionally deferred to a separate PR. Behavior changes (disclosed): - [acp-usage] now logs "(no cache report)" instead of "cached=0 (cache hit 0%)" when the provider omits cache tokens (known samples unchanged). - warnCacheCollapse no longer fires for non-reporting providers (removes a false-positive collapse alert that was part of the same conflation). Tests: tests/cache-ledger.test.ts +5 regression tests (unknown quarantine, wire switch, upstream switch, restart, CLI breakdown). typecheck + full suite (3040 pass) + build green on this branch.
…lugin-pipe usage path (#1536) Review finding on this PR: the ledger has two entry points and only one was fixed. applyUsageSample (src/plugin.ts) — used by every plugin-mode pipe (pipePluginChatWithStrip / pipePluginResponsesWithStrip / pipePluginJson, the prepared.pluginMode branch of forward()) — still booked cachedTokens ?? 0, fed warnCacheCollapse with 0 for non-reporting providers, and passed no protocol/upstream identity. So P0 conflation and false-positive collapse warnings stayed live for all ACP-native agent sessions, and P1 wire/upstream attribution was blind there (only model + restart buckets worked). - applyUsageSample: normalize undefined -> null (mirrors recordUsage in loop/core.ts), gate warnCacheCollapse on a real report, pass cached/protocol/upstreamOrigin into recordCacheSample; log marker unified to '(no cache report)' across both paths (was 'cached=n/a' in plugin mode). - pipes take an optional trailing upstreamOrigin and forward it. - server.ts: hoist the fetched-origin computation above the plugin branch (targetOrigin) and share it between the three session-carrying pipe calls and the compress-loop ctx (removes the shadowing local). - tests: 3 regression tests (quarantine closure over the measurable subset, collapse-watch suppression, wire+upstream buckets via the plugin path); update the #695 log-text test to the unified marker.
[bot] 🏷 Reviewed #1545 against its stacked base (#1540 branch) — direction, regression surface, code, tests, diff. Found one real gap in the PR's own coverage, fixed it directly on the branch (commit ① Original issue (#1536) — direction ✓. The scoped plan (P0 measurement correctness → P1 attribution for the non-fixable causes → CLI first, Web deferred, stacked on #1540) matches the owner decision in #1536 verbatim. P0 root cause correctly identified and fixed at the producer: ② Regression audit — behaviors touched, verdicts:
③ Code — one gap found, fixed on branch ( ④ Test validity. The five new tests in the PR reproduce their bugs against the old code (teeth confirmed). My fix adds three more, each failing on the pre-fix path: quarantine closure over the measurable subset via the plugin pipe, collapse-watch suppression for non-reporting providers, wire+upstream buckets populated through ⑤ Diff cleanliness. Original delta tight and single-concern; my fix commit touches only the gap ( Behavior changes introduced by my fix commit (disclosed):
New issue filed (pre-existing, separate root cause): #1547 — the non-streaming rewriter branch of Verdict: mergeable once #1540 lands (base is that branch — merge order matters). Merging stays human-side. 中文摘要:审查了 #1545(P0 隔离未上报样本 + 失效归因),发现并直接在分支上修复了一个真实缺口——插件模式(ACP-native agent)的用量入口 |
[bot] 🏷 Follow-up on the pushed fix head
Nothing else outstanding from this review round. |
|
Deep review: ✅ mergeable — this is the load-bearing layer of the stack, and the math holds. What I verified (the two questions that matter)
Non-blocking observations
|
[bot] 🏷 Verified your deep-review points against the stack head, independently. One clarification up front: the commit you pushed ( Verified at stack head
Local pre-flight at #1547 status: left open — #1550's body carries Merge order when you're ready: #1540 → #1545 → #1550. 中文摘要:核对了你推的 fold-cursor 测试与 |
What
Follow-up to #1536 (compression cache hit-rate collapse). Implements the owner's scoped plan: P0 fix first → add attribution for what can't be fixed → CLI first, Web UI as a separate change. Generalizes and extends #1535's model-switch attribution.
P0 — stop conflating unmeasured with 0% (measurement correctness)
Providers that omit cache-hit tokens (
cachedTokens === undefined) were booked ascached=0, so their whole billed prefix landed in the kernel's unexplainedttlRepayresidual and the hit rate read 0% even when nothing was wrong. Such samples are now quarantined out of the closure totals (ownunmeasuredSamples/unmeasuredInputcounters), dropped from the rendered line set, and excluded from the false-positive cache-collapse warning. The kernel identity still closes exactly over the measurable subset.P1 — attribute the non-fixable causes (generalizing #1535)
#1535 added a model-switch bucket. This generalizes it to a full target identity and adds the other structural-invalidation causes found in the #1536 diagnosis:
Each cause charges only its sample's stable-prefix residual (
tr), socompRepaystays booked to its fold and the kernel closure never breaks. Upstream TTL/eviction stays the singleremainingresidual (deliberately not over-split into unmeasurable sub-causes).Surface (CLI-first, per owner decision)
/acp-cachetext gains a CACHE INVALIDATION breakdown section.__bili/cache-reportJSON gainswireSwitches/upstreamSwitches/restartDrops/unmeasured/invalidation.Behavior changes (disclosed)
[acp-usage]now logs(no cache report)instead ofcached=0 (cache hit 0%)when a provider omits cache tokens (known samples unchanged).warnCacheCollapseno longer fires for non-reporting providers (removes a false-positive collapse alert that was part of the same conflation).Verification
npm run typecheck✓npm test→ 3040 pass / 0 fail (12 skipped = gated e2e); +5 regression tests intests/cache-ledger.test.ts(unknown quarantine, wire switch, upstream switch, restart, CLI breakdown)npm run build✓cached; single-process so no false restart flag; feat: attribute model-switch cache drops in acp-cache report and web UI #1540's MODEL SWITCHES text unchanged)Fixes #1536