Skip to content

feat(web): model-switch cache drops column in web sessions view (split from #1557) - #1560

Closed
ranxianglei wants to merge 10 commits into
2026-09-28_cache-attribution-combinedfrom
2026-09-28_web-ui-cache-attribution
Closed

ranxianglei wants to merge 10 commits into
2026-09-28_cache-attribution-combinedfrom
2026-09-28_web-ui-cache-attribution

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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 from a30ee8d1; 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 ledger agg.switches / agg.switchMissed fields 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: WebSessionSummary gains modelSwitches / 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 shows 1 · 8.0K with the attribution tooltip).

Verification (head cf810560)

  • npm run typecheck ✓
  • npm run build ✓ (dist-import-annotations OK)
  • Targeted: web-sessions 7/7 (incl. new acp-cache同时统计切换模型掉缓存归因 #1535 test) · cache-ledger 30/30 · issue1547-nonstream 4/4 · usage-observability 7/7
  • Full suite: 3054 pass / 0 fail / 12 skipped (default skips)
  • Remote CI runs the full suite.

No config surface change. No version bump.

ework-agent and others added 10 commits September 28, 2026 10:46
…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.
…eview of #1550)

The new non-streaming settle line lacked the imageUsageSuffix marker that
the loop and plugin settle sites already carry (#695 parity claimed in flag
e). imageUsageSuffix is a pure read (empty unless the session has saved
image tokens), so appending it changes no state.
…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.
…ed quarantine + invalidation buckets, non-streaming ledger settle (#1535 #1536 #1547, web UI split out)
…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.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review in progress. Initial checks done:

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[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):

  • src/web/sessions-data.ts — additive optional fields only (modelSwitches/switchMissedTokens); sessions that never switched omit both keys (not zero), so existing JSON consumers see byte-identical payloads for them. Reads agg.switches/agg.switchMissed, which base feat: combined cache attribution stack — model-switch drops, unmeasured quarantine, non-streaming settle (#1557) #1558 writes (src/cache-ledger.ts:318-319). No behavior change.
  • src/web/client.ts — non-compact rows go 12→13 cells (the intended feature); empty-state colspan follows (12→13); the compact=true row path is unchanged and has no callers anywhere in src/web/, so no table can render mismatched row widths. No colspan="12" remains in src/web/.
  • src/web/page.ts — both session tables gain exactly one <col style="width:72px"> + one <th> between hit% and folds; nothing else changed on those lines. The header's data-i18n-title is handled by the i18n applier (src/web/client.ts:103), so the tooltip switches correctly with locale.
  • src/web/i18n.ts — two new keys per locale; no renames/deletions.
  • tests/web-sessions.test.ts — pure addition.
    Conclusion: no unintended regressions found.

③ Code review: omission semantics are right (typeof switches === "number" && > 0 gate), honest dash via common.none ("—", present in both locales), tooltip only when data exists, fmtW formatting consistent with neighboring cells. No as any/@ts-ignore, no config surface touched, no version bump.

④ 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 colspan="12", and executes the actual WEB_CLIENT IIFE against live endpoints via node:vm DOM stubs asserting every row renders exactly 13 cells with 1 · 8.0K + attribution tooltip. A future column added in page.ts but forgotten in client.ts (or vice versa) would fail it.

⑤ Diff cleanliness: single linear commit on top of base head 3dc1358f; exactly 5 files, +230/−8; all five files byte-identical to their pre-split state at a30ee8d1 (empty diff verified). Every line relates to the column feature.

CI status & verification:

Behavior change flag: visible web change — sessions tables gain a 13th "switches" column and /__bili/sessions JSON gains two optional keys for switching sessions. Both are the intended, disclosed feature; no thresholds/defaults/timing/output-format drift elsewhere.

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 后即可合并。

@ranxianglei
ranxianglei force-pushed the 2026-09-28_cache-attribution-combined branch from 3dc1358 to fec8a2d Compare September 28, 2026 11:41
ranxianglei added a commit that referenced this pull request Sep 29, 2026
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.
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.

1 participant