Repository navigation
feat: combined cache attribution stack — model-switch drops, unmeasured quarantine, non-streaming settle (#1557) - #1558
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1520-pr.1558.bf4c78bThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1558.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Review complete — verified head ① Issue direction (#1557 = #1535 + #1536 + #1547)All three root causes are fixed at the source, not masked:
② Regression audit (existing behavior on touched paths)
Behavior changes (old → new, intentional)
③ CodeClean. Restart detection via per-process ④ Test validityToothed, not tautological: pinned ⑤ Diff cleanliness8 files, every line on-purpose. One minor note: history carries one base-update merge commit ( Verification (head
|
…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.
…loop/plugin call sites (#1547) recordUsage (loop/core.ts) and applyUsageSample (plugin.ts) each inlined the same input-side stats update + recordCacheSample sequence with subtly drifted guards. Extract settleUsageReport into cache-ledger.ts (next to recordCacheSample, which it calls) so all three response shapes can settle through one path.
…#1547) The non-streaming JSON branch of forward() updated session.stats directly but never recorded a ledger sample, so stream:false sessions produced zero lines in /acp-cache and __bili/cache-report and were blind to every hit-rate / invalidation-attribution feature. Route its usage capture through settleUsageReport with protocol + targetOrigin, and give the branch the [acp-usage] log line and collapse watch the other two shapes already have.
…st not eat a pending fold (#1536) Mutation check: dropping the known-gate on the consumedFoldSeq advance leaves this red ('measured sample owns the fold compRepay'); clean tree 48/48.
3dc1358 to
fec8a2d
Compare
|
Conflict resolved (rebased onto current master, head README.md (the only real conflict): master's condensation deletions stand in full (owner's editorial intent). The branch's single genuinely-new doc block — the #1535 src/plugin.ts / src/server.ts: auto-merged cleanly across all 8 commits (no manual hunks — master's movement was disjoint). Gates run locally before push: cache-ledger + issue1547-nonstream + usage-observability + web-sessions(master state) + plugin-protocol = 63/63. Full suite on remote CI. Merge order unchanged: this PR → repoint #1560 to master → merge #1560 → close #1557. |
Supersedes PR #1560: its stacked base branch (2026-09-28_cache-attribution-combined) was squash-merged to master via #1558, leaving head cf81056 permanently CONFLICTING. This carries the byte-identical 5-file web delta (+230/-8, verified against stacked head a30ee8d) onto current master. The switch accounting it displays shipped in #1558.
Fixes #1557
Supersedes #1540 / #1545 / #1550 (mutually dependent stack — #1545 references #1540's attribution symbols 20×; three-in-one here per owner decision). Web UI portion split out for a separate PR by ework (tracked in #1557).
What's inside (semantics unchanged from the three originals, all deep-reviewed)
swline flag, both-sides-known gate, A→B→A,tr-only charging, legacy ledger normalization) — from feat: attribute model-switch cache drops in acp-cache report and web UI #1540.residual===0; wire/upstream/restart buckets, union-once,remaining >= 0) — from fix(cache): quarantine unmeasured cache reports + attribute invalidation causes (P0+P1, CLI) #1545.Review provenance
Verification (head
3dc1358)