fix: race condition in parallel PostToolUse hooks#14
Open
deiviuds wants to merge 2 commits intomemvid:mainfrom
Open
fix: race condition in parallel PostToolUse hooks#14deiviuds wants to merge 2 commits intomemvid:mainfrom
deiviuds wants to merge 2 commits intomemvid:mainfrom
Conversation
- Add file locking via memvid-lock.ts to prevent concurrent writes - Re-open memvid inside lock for every write to ensure fresh SDK state - Add cross-process deduplication (dedup.ts) to prevent duplicate observations - Add session persistence (session.ts) for consistent session IDs across hooks - Add source tracking to distinguish claude-code vs opencode observations - Add unit tests for dedup.ts and session.ts utilities Fixes memvid#13
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
Fixes #13 - Race condition where parallel PostToolUse hooks corrupt the mind.mv2 file.
Root Cause
When Claude Code makes parallel tool calls, multiple
post-tool-use.jsprocesses spawn simultaneously. Each process had its own memvid SDK handle with stale internal state, causing file corruption.Solution
memvid-lock.tsusing proper-lockfile to serialize writesdedup.tsto prevent duplicate observations from parallel hookssession.tsfor consistent session IDs across hook invocationsTesting
dedup.ts(5 tests)session.ts(13 tests)mind-lock.test.tswith concurrent write tests (4 tests)Changes
src/core/mind.ts- Re-open memvid inside lock for writessrc/hooks/post-tool-use.ts- Use dedup and session utilitiessrc/hooks/session-start.ts- Write session info at startsrc/utils/dedup.ts- Cross-process deduplication (new)src/utils/session.ts- Session persistence (new)src/__tests__/dedup.test.ts- Dedup tests (new)src/__tests__/session.test.ts- Session tests (new)