fix(wal): fix concurrent corruption and torn-tail boot failure#58
Draft
pocky wants to merge 1 commit into
Draft
Conversation
- `AGENTS.md`: Add project instructions (extracted from CLAUDE.md) - `CLAUDE.md`: Replace inline content with @AGENTS.md reference - `README.md`: Update Zig requirement to 0.16.0 and docs URL - `src/cli/bootstrap.zig`: Degrade on restore error instead of failing boot - `src/persistence/manager.zig`: Fix archive reaping to match journal-<ts>.wal naming; add test - `src/persistence/wal.zig`: Replace cached fd with per-op re-open + flock serialization; add torn-tail truncate recovery; add concurrent-writer and rotate-strand tests - `src/tools/forget_fact.zig`: Update journal-write failure test to use directory collision - `src/tools/remember_fact.zig`: Update journal-write failure test to use directory collision - `src/tools/update_fact.zig`: Update journal-write failure test to use directory collision
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
O_APPENDre-opens guarded byflock(LOCK_EX), so concurrent writers from overlapping MCP sessions can no longer clobber each other's recordscleanArchivedWalswas matchingjournal.*.wal(which also matchedjournal.walitself andjournal.lock); update to match onlyjournal-*.walrotation archivesChanges
Persistence — WAL
src/persistence/wal.zig: Replace cachedfilefd with a stablelock_file(advisory flock target); everyappend/replay/rotatere-opensjournal.walby path underflock(LOCK_EX). Add torn-tail recovery inreplay: trackgood_bytes, truncate on first unparseable/unknown-op line. Use nanosecond-precision archive names to avoid same-second collisions. Update tests to match new semantics (concurrent writers, torn-tail truncation, rotate isolation)Persistence — Manager
src/persistence/manager.zig: FixcleanArchivedWalsprefix fromjournal.tojournal-and drop the redundantjournal.walguard (the suffix change already excludes it). Add test asserting activejournal.walandjournal.locksurvive a snapshot's reap passBootstrap
src/cli/bootstrap.zig: Catch non-OOM errors frompm.restore()and log a warning instead of propagating, matching the degraded-boot contract of mount-manifest failuresTool tests
src/tools/forget_fact.zig: Replace/dev/nullfd-swap trick with directory-in-place-of-file approach to forceO_WRONLYopen failure, compatible with the per-append re-open designsrc/tools/remember_fact.zig: Same fix asforget_fact.zigsrc/tools/update_fact.zig: Same fix asforget_fact.zigDocs / Config
AGENTS.md: New file — project instructions extracted fromCLAUDE.mdfor multi-agent runner compatibilityCLAUDE.md: Reduced to a single@AGENTS.mdreferenceREADME.md: Bump minimum Zig requirement to 0.16.0; simplify binary path in MCP config example; update docs URLTest plan
make testpasses with all inline WAL tests green, including the new concurrent-writer, torn-tail, and rotate-isolation testsmake functional-testcompletes without errors against the rebuilt binaryjournal.wal(append a truncated JSON fragment), restart the server, and verify it boots with the good records loaded and the torn tail removedzpm serveprocesses against the same data directory, issue concurrentremember_factcalls, then replay the WAL and confirm every record is present and parseableGenerated with awf commit workflow