Skip to content

refactor(client): replace session accumulators with derived recomputation (#308)#312

Merged
lis186 merged 6 commits into
mainfrom
worktree-refactor-308-derived-stats
Jul 20, 2026
Merged

refactor(client): replace session accumulators with derived recomputation (#308)#312
lis186 merged 6 commits into
mainfrom
worktree-refactor-308-derived-stats

Conversation

@lis186

@lis186 lis186 commented Jul 20, 2026

Copy link
Copy Markdown
Owner

摘要

  • addEntry 的 10 個 += 累加器全部移除,改為每次 push 後呼叫 recomputeSessionStats(sid) + recomputeProjectCost(projName) 衍生
  • Cold activation 簡化:不再需要 zero-then-replay + post-replay recompute
  • Dev-mode 冪等性斷言:startup 後對所有 session 跑兩次 recompute,assert 結果一致

Detail

Accumulators removed (10 fields)

# Field Before After
1-4 count/mainCount/subCount/retryCount ++ recomputeSessionStats
5 totalCost += derived
6-7 inputTokens/outputTokens += derived
8-9 toolCalls/toolCallTurns [name]+= / ++ derived
10 proj.totalCost += recomputeProjectCost

Data flow change

Before: classify → accumulate stats → compute displayNum → push → DOM
After:  classify → push(displayNum:null) → recomputeSessionStats → displayNum → patch entry → DOM

Cold activation simplification

Before: zero 10 fields → replay addEntry → recomputeSessionStats → recomputeProjectCost
After: replay addEntry (each call recomputes — last one is final)

Kept inline (not session stats)

_recentMainSpans, latestMainCtxPct, cacheBreaks, idleMs, compactCount — per-entry derived values, not session-level accumulators.

Test plan

Closes #308

🤖 Generated with Claude Code

Justin Lee and others added 6 commits July 20, 2026 12:29
…tion (#308)

addEntry 的 10 個 += 累加器改為每次 push 後呼叫 recomputeSessionStats/
recomputeProjectCost 衍生(冪等、結構性消滅雙重計數)。Cold activation
不再需要 zero-then-replay。Dev-mode 冪等性斷言在 startup 後自動跑。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
P1: batch 期間 (_loading) 跳過 recompute,用增量計數供 displayNum,
batch 結束後每 dirty session 跑一次 recomputeSessionStats(O(n) total)。
P2-1: session card re-render 移到 recompute 之後(stats 已更新)。
P2-2: cold session 用增量更新(entries 不在 allEntries),activation 時全量 recompute。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cold activation replay 保持 _cold=true 走增量路徑(避免 O(n²)),
replay 後一次 recomputeSessionStats + recomputeProjectCost。
Cold session 收到 live entry 時同步更新 project totalCost。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… on cwd migration

P1: cold activation replay 前 zero 10 個 session stats,避免
sessions.json seed 值與 addEntry 增量疊加造成雙重計數。
P2: cold session cwd 遷移時同步 recompute 舊 project cost。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Deep link 選中 session 後 recompute 更新了 stats 但 session card
DOM 未刷新。在 applyDeepLink 後補一次 renderSessionItem。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… cost

P2-1: deferred recompute (_dirtySessions) 跳過 _cold sessions,
避免清掉 sessions.json seed stats。
P2-3: cold replay 期間 (_coldActivating) 跳過 per-entry
recomputeProjectCost,post-replay 一次處理。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

refactor(client): replace session accumulators with derived recomputation

1 participant