8000 fix(wal): replay WAL entries of more than 1,000,000 facts (#686) — backport by adityamukho · Pull Request #699 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

fix(wal): replay WAL entries of more than 1,000,000 facts (#686) — backport - #699

Merged
adityamukho merged 3 commits into
mainfrom
fix/686-wal-entry-cap-main
Oct 23, 2026
Merged

adityamukho merged 3 commits into
mainfrom
fix/686-wal-entry-cap-main

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Summary

v2.x backport of the v3 fix for #686 (data-integrity; the issue stays open until v2.0.10 is published).

On v2.x a transact, retract or WriteTransaction commit of more than 1,000,000 facts succeeded and wrote a WAL entry that replay took as damage. Replay stopped there, and the writer's tail cut at the next open (#513) truncated the WAL at that entry. After a crash, kill or close without a checkpoint, that transaction and every later one in the WAL were lost. Present since v0.5.0.

  • src/wal.rs scan_entries: the 1,000,000-fact cap is replaced by a byte bound. A count is damage only when the bytes left in the file cannot hold that many facts (4-byte length prefix each). The check runs on the raw u64 before the usize conversion. No new error code and no format change; WALs written by any v2.x release replay.

Tests

  • test_wal_entry_of_more_than_a_million_facts_replays: an entry of 1,000,001 facts and the entries after it replay, and reopening the writer keeps them.
  • test_wal_entry_with_more_facts_than_bytes_left_ends_replay (replaces the cap test): an impossible count (left/4 + 1, u64::MAX) ends replay at that entry, and reopening the writer cuts the WAL off there.
  • Full suite: 1,313 passed, 9 ignored (1,322). cargo clippy --all-features -- -D warnings is clean.

Docs

CHANGELOG (Unreleased → Fixed), docs/TEST_COVERAGE.md (counts and entry), CLAUDE.md test count.

🤖 Generated with Claude Code

https://claude.ai/code/session_0169pNQsLcCEn48te9X9WuZW

adityamukho and others added 3 commits October 23, 2026 09:47
…ckport

Replay took an entry of more than 1,000,000 facts as damage, and the
writer's tail cut at open removed it and every later entry, so a
transact, retract or WriteTransaction commit of that size, and every
later one, was lost after a crash or close without a checkpoint. A fact
count is now damage only when the bytes after it cannot hold that many
facts (each has at least its 4-byte length), checked before the count is
converted to usize.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0169pNQsLcCEn48te9X9WuZW
Take the entry's offset from valid_end rather than stream_position, and
fall back to no bound when the file length is unavailable (a corrupt
count still ends at EOF), so the coverage gate's branch floor holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0169pNQsLcCEn48te9X9WuZW
The byte bound now stops the truncated-entry tests before the fact
loop; cover the loop's two truncation exits directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0169pNQsLcCEn48te9X9WuZW
@adityamukho
adityamukho merged commit 47569c1 into main Oct 23, 2026
21 checks passed
@adityamukho
adityamukho deleted the fix/686-wal-entry-cap-main branch October 23, 2026 05:07
@codecov
codecov Bot commented Oct 23, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

0