v0.9.14: Hand session history off as Arc snapshots (SessionUpdated + persistence)
- Dominant language
- Rust
- Stars
- 41k
- Forks
- 3.6k
- Avg merge
- 13h 59m
- Merged PRs (30d)
- 299
Description
From `codewhale-ops/PERF-OPPORTUNITIES-20260915.md` §3 (T2, T3). The structural fix both share: hand out `Arc` clones of session history and rebuild the Arc only on mutation, instead of deep-copying `Vec` per event/save. Repo precedent exists — `transcript.rs` already Arc-shares lines.
- [ ] **T2 [V]** — `core/engine.rs:3297`: `Event::SessionUpdated` carries `messages: self.session.messages.clone()` — a plain `Vec` deep copy fired after each user message, tool result, compaction, and model switch (~15 emit sites: `turn_loop.rs:1160,2444`, `engine.rs:1949,3418,4114`…). Fix: field becomes `Arc<[Message]>` (engine keeps one, bumps it on mutation), or send a revision counter and let the UI pull.
- [ ] **T3 [S]** — `session_manager.rs:2963–2985,1772–1806,3040–3055`: `build_session_snapshot` does `messages.to_vec()`, then `save_session` does `session.clone()` of the whole `SavedSession`, then `update_session` does an element-wise `messages[..old_len] == session.messages[..]` deep compare — all on the debounced flush path that fires during streaming. Multi-MB copies per save for long sessions. Fix: hand over `Arc>`/the journal instead of `to_vec()`; hydrate receipts in place instead of via `session.clone()`; compare by `(len, last leaf id/hash)` instead of element-wise equality.
Combined, T2+T3 mean several full-history copies per turn today. Doing them together keeps the `Arc` boundary coherent end-to-end (engine emit → UI consume → persistence hydrate).
Contributor guide
Research direction
Read the Arc-sharing precedent in transcript.rs, then trace Event::SessionUpdated in core/engine.rs and the snapshot, save, and update paths in session_manager.rs at the listed ranges. Follow the emit sites in turn_loop.rs and engine.rs to understand the mutation boundary; done means the engine, UI event, and persistence paths share session history without full-history copies while preserving hydration and change detection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend, performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100