refactor(storage): decode checkpoints incrementally#2
Merged
Conversation
Stream complete physical records through one shared checkpoint decoder so trajectory loading, append recovery, and future transcript sources agree on committed groups and byte offsets. Preserve exact raw lines while buffering at most one incomplete checkpoint. Keep append recovery bounded by counting committed records without collecting the full trajectory, and cover torn tails, malformed groups, arbitrary tail offsets, exact tool arguments, and large-log lazy reads.
Require every decoded physical line to begin exactly where the previous line ended so tail candidates cannot publish raw records with gaps or overlaps. Cover deterministic chunk boundaries, large declared counts, and multi-record checkpoints that complete across repeated EOF observations.
Owner
Author
|
Independent decoder review found one correctness gap in the reusable tail-candidate seam: CheckpointDecoder validated line_end underflow but not physical continuity, so direct callers could publish raw records with gap/overlap offsets. Draft PR #3 fixes this and adds multi-EOF group completion, deterministic chunk-boundary, large-count, and offset tests. Independent gates on the review commit: fmt/check/strict clippy green; cargo test --all-targets 276 passed, 0 failed, 0 ignored. Recommend merging #3 into this branch before #2. |
Validate the sequence after a complete checkpoint before retaining its first record. This prevents an unrepresentable next sequence from surfacing only after the checkpoint has reached its commit boundary. Keep commit_pending transactional as a defensive invariant and cover the boundary with a retry test that proves pending and byte offsets remain untouched.
fix(storage): validate checkpoint source offsets
siriusctrl
marked this pull request as ready for review
July 22, 2026 10:19
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.
Summary
load_trajectory()collect decoded records whileprepare_append()uses the same decoder without collecting the full historyWhy
Resume, append recovery, and the upcoming transcript viewer must agree on the exact committed boundary. The previous
tokio::fs::readimplementation materialized the whole file and embedded checkpoint validation inside one batch loader, which could not support lazy follow or reverse tail discovery without duplicating rules.This PR changes storage only. It does not add fmtview, inspect CLI behavior, or TUI code.
Validation
cargo fmt --checkcargo check --all-targetscargo clippy --all-targets -- -D warningscargo test --test message_log --test message_log_recovery(11 passed)cargo test --all-targets(272 passed, 0 failed, 0 ignored)messages.jsonl,events.jsonl,run.json,final.md, and the empty artifact directoryThe decoder tests cover every byte cut across a torn multi-record tail, malformed and inconsistent completed lines, arbitrary tail offsets, exact tool argument/raw-line preservation, follow completion after EOF, and first-checkpoint delivery without scanning a 20,000-record log.