refs(#2264): Phase 4 — replace Session.messages: Vec<Message> with AppendLog
Refs #2264 (Phase 4 — AppendLog backing store).
Summary
Replaces Session.messages: Vec<Message> with AppendLog, the
append-only wrapper introduced in Phase 1. AppendLog now implements
Deref<Target=Vec<Message>> + DerefMut + From/Into, making
it a transparent drop-in — all existing .len(), .iter(),
.push(), .remove(), .clone() calls work without change.
AppendLog changes
- Add
Deref/DerefMutfor transparent Vec access - Add
From<Vec<Message>>andInto<Vec<Message>>for conversions - Add
into_inner()for explicit unwrapping - Remove explicit
iter()/len()/is_empty()/as_slice()— Deref providesstd::slice::Iter(not opaqueimpl Iterator)
Files
| File | Change |
|---|---|
prompt_zones.rs |
+28/−25: Deref + From impls |
session.rs |
+2/−2: messages: AppendLog |
engine.rs |
+8/−8: .into() on assignments |
turn_loop.rs |
+2/−2: .into() + .into_inner() |
capacity_flow.rs |
+1/−1: .into() |
tests.rs |
+2/−2: &* deref for assertions |
Testing
- 37 prompt_zones + prefix_cache tests pass
- cargo check: clean (6 pre-existing schema_migration warnings)
Greptile Summary
This PR wires AppendLog (from Phase 1) as the backing store for Session.messages, replacing the raw Vec<Message>. The conversion is kept transparent by adding Deref<Target=Vec<Message>>, DerefMut, From/Into, and into_inner(), so all existing call sites continue to compile with minimal mechanical changes.
AppendLoginprompt_zones.rsgainsDeref,DerefMut, and theFrom/Intopair; the redundant explicit methods (len,is_empty,iter,as_slice) are removed in favour of slice auto-deref.Session.messagesinsession.rsis retyped toAppendLog; eight assignment sites inengine.rs,capacity_flow.rs, andturn_loop.rsadd.into()to convertVec<Message>results intoAppendLog.- Two test assertions are updated to use
&*to explicitly derefAppendLogto&Vec<Message>for comparison.
Confidence Score: 4/5
Safe to merge — the mechanical conversions are all correct and cargo check is clean. The only concern is a design gap in prompt_zones.rs that future contributors should be aware of.
All Vec
crates/tui/src/prompt_zones.rs — the DerefMut implementation and its interaction with the append-only doc-comment.
Important Files Changed
| Filename | Overview |
|---|---|
| crates/tui/src/prompt_zones.rs | Adds Deref/DerefMut, From/Into, and into_inner() to AppendLog; removes the explicit iter/len/is_empty/as_slice methods. DerefMut fully exposes the inner Vec for arbitrary mutation, undermining the append-only invariant the type is named and documented for. |
| crates/tui/src/core/session.rs | Changes Session.messages field from Vec |
| crates/tui/src/core/engine.rs | Updates eight assignment sites from direct Vec assignment to .into() conversions; all existing .remove(), .truncate(), .len(), and .iter() calls continue to work via DerefMut/Deref. |
| crates/tui/src/core/engine/turn_loop.rs | Converts one assignment site to .into() and changes messages_with_turn_metadata() to use clone().into_inner(); the latter allocates an unnecessary intermediate AppendLog. |
| crates/tui/src/core/engine/capacity_flow.rs | Single assignment converted to .into(); no other changes. |
| crates/tui/src/core/engine/tests.rs | Updates two assertions to use &* deref to compare Vec |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["result.messages: Vec<Message>"] -->|".into()"| B["AppendLog"]
B -->|"Deref"| C["&Vec<Message> (read-only callers)"]
B -->|"DerefMut"| D["&mut Vec<Message> (remove / truncate / clear / last_mut)"]
B -->|".clone().into() or .clone().into_inner()"| E["Vec<Message> (SessionUpdated / API calls)"]
B -->|"into_inner()"| F["Vec<Message> (consumed)"]
G["Session.messages: AppendLog"] --- B
Reviews (1): Last reviewed commit: "refs(#2264): Phase 4 — replace Session.m..." | Re-trigger Greptile
Greptile also left 2 inline comments on this PR.
[!WARNING] You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!
Thanks @encyc for taking the time to contribute.
This repository is currently observing a maintainer-managed contribution gate in dry-run mode, so this pull request is staying open. When enforcement is enabled, pull requests from contributors who are not listed in .github/APPROVED_CONTRIBUTORS will be closed automatically.
Please read CONTRIBUTING.md for the expected contribution shape. A maintainer can grant PR access by commenting /lgtm on a pull request.
Thanks @encyc — this is useful v0.9 cache-architecture work and a good concrete follow-up to #2264. I rechecked it during the current stewardship pass.
I’m leaving the PR open rather than merging or harvesting it as-is because GitHub now reports the branch as conflicting/dirty against current main, and the current approach makes AppendLog a transparent Vec<Message> via DerefMut. That keeps the mechanical migration small, but it also means the type no longer enforces the append-only invariant that made the design valuable in the first place. Future callers could still remove/truncate/clear history through the Vec API without the compiler noticing.
The direction I’d be comfortable landing for v0.9 is narrower and stricter:
- keep
Session.messagesmigration scoped and well-tested; - avoid unrestricted
DerefMutforAppendLog; - add explicit mutation methods for the current legitimate paths (
push, controlled truncation/compaction/reset), with names that make cache-impact obvious; - preserve the focused checks from this PR, plus current
cargo check/test -p codewhale-tui --lockedcoverage after rebasing.
If we harvest this later, I’ll keep your contribution credited. The implementation here clarified the exact tradeoff between a drop-in migration and a real append-only contract.
@Hmbown thanks for the detailed review — the tradeoff between a drop-in migration and a real append-only contract was exactly the right call. I've pushed an update that addresses all three points:
1. Removed DerefMut
Deref (immutable) is kept for read access; DerefMut is gone. Callers can no longer reach Vec::remove / Vec::clear / Vec::truncate through the wrapper.
2. Explicit, cache-impact-named mutation methods
| Method | Cache semantics |
|---|---|
push(msg) |
extends prefix ✅ |
push_batch(batch) |
fewer cache invalidations than repeated push |
truncate_to(new_len) |
discards oldest → cache loss ⚠️ |
trim_front(count) |
removes from head → shared-prefix loss 🔴 |
clear() |
full reset 🔴 |
last_mut() |
mutable access to last message only |
3. Rebased on latest main (v0.8.53)
Merged upstream and fixed 8 Vec<Message> → AppendLog conversion sites introduced post-v0.8.50. All conflicts resolved.
Tests
cargo check -p codewhale-tui: cleanprompt_zonestests: 16 passed, 0 failedengine::tests: 120 passed, 0 failed, 1 ignored
@encyc — this Phase 4 of the #2264 AppendLog series is next in line from our side, and your earlier review-feedback fixes look good. It's currently conflicting with main (which has moved a lot this week, including v0.8.55). Could you rebase onto current main? We'd like to keep the series moving — thanks for staying with this multi-phase work.
/lgtm
@encyc is already approved for pr contributions in .github/APPROVED_CONTRIBUTORS.
@Hmbown — rebased onto current main (v0.8.57). Conflicts in engine.rs, turn_loop.rs, and tests.rs were mechanical — upstream had added messages_revision tracking and a few new assignment sites since the last rebase, all resolved.
cargo check -p codewhale-tui: ✅ cleancargo test -p codewhale-tui: ✅ 4362 passed, 0 failed
Ready for the next step whenever you are. Thanks for the /lgtm and for keeping this series moving.