perf(coding-agent): cache materialized session views behind mutation counter - #257
Conversation
SessionManager maintains running usage totals (input/output/cacheRead/ cacheWrite/cost/latestCacheHitRate) incrementally on assistant-message append and rebuilds them in _buildIndex()/newSession, exposed via getUsageTotals(). The footer no longer scans getEntries() every frame; rendering output is byte-identical (footer-width.test.ts green, and a new totals-equality test proves deep equality with the legacy loop, including latestCacheHitRate semantics and all-entries-not-branch-scoped behavior). Evidence: .omo/evidence/senpi-render-hotpath-and-startup-fixes/t2-vitest-red.txt, t2-vitest.txt
|
Todo 2 (incremental usage totals) landed in 40d98ec: SessionManager.getUsageTotals() maintained incrementally on assistant-message append, rebuilt in _buildIndex()/newSession; footer hot path no longer scans getEntries() per frame. TDD: totals-equality test (legacy loop vs getUsageTotals(), deep equality incl. latestCacheHitRate + all-entries semantics) captured RED then GREEN; footer-width.test.ts green with zero output diffs (125/125 tests passing across footer-width + session-manager suites). Evidence: .omo/evidence/senpi-render-hotpath-and-startup-fixes/t2-vitest-red.txt and t2-vitest.txt. |
…ageTotals in footer tests
CI failure root cause + fix (commit 9bc68d9)The 3 CI failures (footer-token-format, startup-session-name x2) traced to two gaps from the incremental-usage-totals change:
Verification
Environmental note (local full-suite flakiness, pre-existing)Local full-suite runs on a loaded parallel machine flake in spawn-heavy suites unrelated to this PR (app-server daemon/stdio CLI spawns, resource-loader, mcp). Confirmed pre-existing: plain Evidence: |
CI failures fixed (commit 9bc68d9)Root causes — two distinct issues behind the 3 failing tests:
Gate result: full gate green from worktree root — npm run check && CI=true npm run test exits 0. coding-agent: 462 passed / 4 skipped (466 files), 4006 passed / 31 skipped (4037 tests); all other workspace packages pass. (CI=true selects the repo's serialized forks pool per vitest.config.ts guidance for subprocess-heavy suites.) Note: local reruns were hampered by extreme machine load (loadavg ~180) which flaked pre-existing subprocess tests (app-server-daemon, app-server-stdio, skills-sidecar) — those pass standalone and are unrelated to this change. |
What
Bug A from the render-hotpath plan: the interactive footer re-materialized the entire session 3x per frame at ~60fps (getEntries/getBranch/getSessionName each deep-copying a 10 MB / 724-entry session via ResidentStringStore.materialize). Profiled at 33.4% self-time in transformJsonValue on a 17h session burning 50-86% CPU idle.
Fix
Measured evidence (real CLI, 10 MB session, tmux)
Evidence
Plan: .omo/plans/senpi-render-hotpath-and-startup-fixes.md
Plan: .omo/plans/senpi-render-hotpath-and-startup-fixes.md