refactor(client): replace session accumulators with derived recomputation (#308)#312
Merged
Merged
Conversation
…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>
This was referenced Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要
+=累加器全部移除,改為每次 push 後呼叫recomputeSessionStats(sid)+recomputeProjectCost(projName)衍生Detail
Accumulators removed (10 fields)
++recomputeSessionStats+=+=[name]+=/+++=recomputeProjectCostData flow change
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
CCXRAY_HOME=$(mktemp -d) npm test— 1391 pass, 0 failCloses #308
🤖 Generated with Claude Code