Skip to content

fix: resolve stale lock and same-instance write contention (#622, #623)#625

Closed
jlin53882 wants to merge 2 commits intoCortexReach:masterfrom
jlin53882:fix/issue-622-623-lock-clean
Closed

fix: resolve stale lock and same-instance write contention (#622, #623)#625
jlin53882 wants to merge 2 commits intoCortexReach:masterfrom
jlin53882:fix/issue-622-623-lock-clean

Conversation

@jlin53882
Copy link
Copy Markdown
Contributor

Summary

Fix two related lock issues:

  1. [BUG] Windows: stale .memory-write.lock not released, blocks smart-extractor writes #622: Stale .memory-write.lock not released, blocking writes
  2. [BUG] Same-instance concurrent writes竞争 lock,导致 Lock file is already being held #623: Same-instance concurrent writes competing for lock

Changes

store.ts

  1. Add updateQueue for intra-instance write serialization

    • Prevents multiple writes within the same MemoryStore instance from competing for the file lock
  2. Use lockfilePath option with lock(dbPath)

    • Lock the database directory directly instead of the lock file
    • Specify lock file location via lockfilePath
  3. Proactive stale lock cleanup

    • Automatically clears lock artifacts older than 5 minutes
    • Fallback for legacy artifacts that proper-lockfile's built-in stale mechanism may miss
  4. Remove nested runSerializedUpdate in update()

    • The nested call caused deadlock because both used the same updateQueue
    • runWithFileLock already provides sufficient serialization

New Tests

  • test/lock-recovery.test.mjs: Tests for stale lock recovery
  • test/store-write-queue.test.mjs: Tests for intra-instance write serialization

Test Results

lock-recovery.test.mjs: 4 pass, 1 skip
store-write-queue.test.mjs: 3 pass

Why Both Issues Must Be Merged Together

If only #622 is merged without #623:

  • Same-instance concurrent writes can still compete for lock
  • May cause intermittent "Lock file is already being held" errors

If only #623 is merged without #622:

  • Stale locks from crashes may persist permanently
  • Cross-session lock contention remains unresolved

Both fixes are required for complete resolution.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

// test/store-write-queue.test.mjs

P1 Badge Re-encode newly added JS modules as UTF-8

This file (and the other files in this commit) was committed as UTF-16LE with NUL bytes, so Node’s ESM parser throws SyntaxError: Invalid or unexpected token at the first character (for example, running node --test test/store-write-queue.test.mjs fails immediately before any test logic runs). In practice this makes the added tests non-runnable and risks breaking tooling that expects UTF-8 source files.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jlin53882 jlin53882 force-pushed the fix/issue-622-623-lock-clean branch from db95602 to c9e98c0 Compare April 14, 2026 18:54
@jlin53882 jlin53882 closed this Apr 14, 2026
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