Skip to content

refactor(storage): decode checkpoints incrementally#2

Merged
siriusctrl merged 4 commits into
mainfrom
agent/checkpoint-decoder
Jul 22, 2026
Merged

refactor(storage): decode checkpoints incrementally#2
siriusctrl merged 4 commits into
mainfrom
agent/checkpoint-decoder

Conversation

@siriusctrl

Copy link
Copy Markdown
Owner

Summary

  • replace whole-file message-log reads with a shared synchronous checkpoint decoder and a lazy async forward reader
  • publish only complete logical checkpoints while retaining a torn physical line and at most one pending checkpoint
  • preserve each committed record's exact raw bytes including LF, source offset, and committed byte end
  • make load_trajectory() collect decoded records while prepare_append() uses the same decoder without collecting the full history
  • allow validation to start from an arbitrary sequence and byte offset so the follow-up tail-first transcript source can reuse the same checkpoint definition

Why

Resume, append recovery, and the upcoming transcript viewer must agree on the exact committed boundary. The previous tokio::fs::read implementation 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 --check
  • cargo check --all-targets
  • cargo clippy --all-targets -- -D warnings
  • cargo test --test message_log --test message_log_recovery (11 passed)
  • cargo test --all-targets (272 passed, 0 failed, 0 ignored)
  • echo-provider headless smoke on the rebased commit; inspected messages.jsonl, events.jsonl, run.json, final.md, and the empty artifact directory

The 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.

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.
@siriusctrl

Copy link
Copy Markdown
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
siriusctrl marked this pull request as ready for review July 22, 2026 10:19
@siriusctrl
siriusctrl merged commit 116dce4 into main Jul 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant