Repository navigation
feat(core): JSONL session storage layer (E1) - #14
Merged
Merged
Conversation
Implement the durable storage foundation per docs/architecture.md: - entry.rs: write-once tree entries with EntryType taxonomy - register.rs: namespaced mutable cells (lane/op/pending/fact) - state.rs: operation state machine (pc + seq CAS token) - storage.rs: Storage trait + JsonlStorage backend * one file per session, replay-on-open recipe format * strictly increasing global seq across all record kinds * atomic commit: validate-all-then-append single line * torn final line discarded whole (crash mid-append safe) * newer storageVersion = hard error, older replays cleanly * compaction rewrites header + live records, seq preserved * stale transition (CAS mismatch) rejected, never overwritten 11 integration tests cover all E1 acceptance criteria incl. roundtrip, compact, torn-tail, stale CAS, invalid commits, intra-commit parent chaining, and seq monotonicity.
Address cora review MAJOR: compact() renamed temp file over the live path without fsync, risking data loss on crash. Now: - append_line fsyncs after every commit line (committed records never lost; torn tail still discarded whole on open) - compact: write temp -> fsync -> rename -> fsync parent dir (POSIX; no-op on non-Unix targets)
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
CodeCora finding: commit() serialized usage records into the commit line but never pushed them to the in-memory list. Consequence: compact() rewrites the file from that list, silently dropping every usage row committed since open. Regression test now asserts usage rows survive compact and reopen. Also add Storage::usages() accessor (was missing from the trait).
CodeCora finding (valid): open() replayed around a torn final line but left the partial bytes on disk. The append handle then wrote the next commit line directly onto the fragment, permanently corrupting the file (the merged line is no longer the final line, so the next open fails with a hard Corrupt error). open() now tracks the end of the last complete line and truncates + fsyncs the torn bytes away before the writer is ever used. The torn-tail test now commits after reopening a torn file and reopens again to prove the file stays valid.
| serde_json::from_str::<Record>(&line).map(|r| vec![r]) | ||
| }; | ||
| let records = match parsed { | ||
| Ok(r) => r, |
CodeCora finding (valid): the replay loop's 'continue' for blank lines skipped the good_bytes increment, so a stray blank line made open() believe the file had a torn tail and truncate away the last valid commits — silent data loss. good_bytes now advances immediately after each complete physical line is read, before any skip logic. Regression test opens a file with an injected blank line and asserts both entries survive a double reopen.
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.
What
Implements Epic 1 (issue #1): durable JSONL session storage foundation per
docs/architecture.md.Model modules:
entry.rs— write-once conversation tree entries +EntryTypetaxonomyregister.rs— namespaced mutable cells (lane.leaf,op.state,pending,fact)state.rs— operation state machine (Pcprogram counter +seqCAS token)JSONL backend (
storage.rs):seqacross all record kindsstorageVersion= hard error; older replays cleanlyWhy
The storage layer is the durability foundation every later epic (provider loop, tools, approvals) commits through. It must guarantee: crash safety (torn tail tolerated, committed lines durable via fsync), monotonic seq, and CAS-protected state transitions — before any higher layer is built on it.
Testing
12/12 integration tests green (
cargo test -p cora-agent-core):dyn StorageCloses #1