Repository navigation
feat(web): model-switch cache drops column in web sessions view (split from #1557) - #1560
ranxianglei wants to merge 10 commits into
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.
…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.
…1557) Web UI portion of the #1535 model-switch attribution work, deliberately left at master state in the combined PR #1558 and delivered as its own PR per #1557. - sessions-data: WebSessionSummary gains modelSwitches / switchMissedTokens, sourced from the cache ledger agg (switches / switchMissed); omitted when the session never switched models. - client: new switch cell rendered between hit% and folds (count · dropped tokens, honest dash when none); empty-state colspan 12 -> 13. - page: both session tables gain the column + tooltip header. - i18n: zh/en strings for the new column. - test: executes the real client IIFE against live endpoints (node:vm DOM stubs) and pins 13-column alignment end to end.
[bot] 🏷 Review in progress. Initial checks done:
|
[bot] 🏷 Review complete — code is verified; mergeable once #1558 lands and the base is re-targeted to master. Duplicate screening: #1535 closed, stacked #1540 closed, no other open delivery of this content → not a duplicate. This is exactly the split-out #1557 requested ("Web UI split (owner: ework)"). ① Direction (original issue): #1535 asked for model-switch cache-drop attribution; #1557 deliberately kept the web part at master state in the combined PR and requested it as a separate PR branched off #1558's head. This PR delivers precisely that scope — nothing more, nothing less. ② Regression review (existing behaviors on touched paths):
③ Code review: omission semantics are right ( ④ Test validity: real teeth, not tautology — pins field-omission (asserts key absence, not zero), asserts 13 headers == 13 colgroup cols on both tables, forbids stale ⑤ Diff cleanliness: single linear commit on top of base head CI status & verification:
Behavior change flag: visible web change — sessions tables gain a 13th "switches" column and Merge guidance: mergeable from a code standpoint, with the sequencing constraint stated in the PR body — land after #1558, then re-target base to master (history is linear, will merge cleanly). Merging stays human-only per repo rules. 中文摘要:审核了 #1560(web 会话视图新增模型切换掉缓存列,从 #1557/#1558 拆出的交付)——diff 与声明完全一致(5 文件 +230/−8、与拆分前状态逐字节相同、单一线性提交),回归清点无意外变更,测试有牙且本地全量 3054/0/12 通过;#1558 合入 master 并把本 PR base 改回 master 后即可合并。 |
3dc1358 to
fec8a2d
Compare
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.
Refs #1557 (web UI split-out delivery; #1558 owns the close).
What this is
The Web UI portion of the #1535 model-switch attribution work — the part deliberately left at master state in the combined PR #1558 ("Web UI split (owner: ework)"). Delivered as its own PR branched off #1558's head (
3dc1358f), per the request in #1557. Content is byte-identical to what stacked PR #1540 shipped for these files (restored froma30ee8d1; verified as the exact +230/−8 delta, no other files touched).Base branch note
Base =
2026-09-28_cache-attribution-combined(#1558's head), not master — the web code reads the ledgeragg.switches/agg.switchMissedfields that #1558 introduces. After #1558 merges to master, re-target this PR's base to master; history is linear on top of the combined head, so it will merge cleanly.Changes (5 files, +230/−8)
src/web/sessions-data.ts:WebSessionSummarygainsmodelSwitches/switchMissedTokens, sourced from the cache-ledger agg (switches/switchMissed); fields omitted (not zero) when the session never switched models.src/web/client.ts: new switch cell between hit% and folds (count · dropped tokens, honest dash when none); empty-state colspan 12 → 13.src/web/page.ts: both session tables gain the column + tooltip header (72px colgroup slot).src/web/i18n.ts: zh/en strings for the new column.tests/web-sessions.test.ts: pins 13-column alignment end to end — data path (switch fields present only when switches actually happened), served HTML (13 headers == 13 colgroup cols on both tables, no stale colspan=12), and executes the real client IIFE against live endpoints via node:vm DOM stubs (every row renders exactly 13 cells; switch row shows1 · 8.0Kwith the attribution tooltip).Verification (head
cf810560)npm run typecheck✓npm run build✓ (dist-import-annotations OK)No config surface change. No version bump.