Skip to content

feat(memory): add cross-process locking and atomic writes for sqlite#3114

Open
yunasora wants to merge 1 commit into
docker:mainfrom
yunasora:feat/memory-atomic-writes
Open

feat(memory): add cross-process locking and atomic writes for sqlite#3114
yunasora wants to merge 1 commit into
docker:mainfrom
yunasora:feat/memory-atomic-writes

Conversation

@yunasora

Copy link
Copy Markdown

Fixes #3022

Implementation Details & Context

During the implementation, I aligned the changes with the existing codebase architecture and made a few adjustments based on the repository's current state:

  1. Database Configuration & Connection Pool:

    • The requested parameters (PRAGMA journal_mode=WAL, busy_timeout=5000, and SetMaxOpenConns(1)) are already centrally configured in sqliteutil/sqlite.go (which corresponds to the pkg/memory/database/sqlite/db.go mentioned in the checklist).
    • The memory SQLite DB utilizes this central entry point, so the concurrent state is natively guaranteed by the connection pool settings.
    • Separate read pools were not explicitly introduced because sqliteutil.OpenDB already enforces serialized writes via SetMaxOpenConns(1) while leaving read paths unlocked. WAL seamlessly handles the read/write concurrency.
  2. Cross-Platform File Lock:

    • Wrapped the entire write path (add/update/delete) inside the FileLock boundary across Linux, macOS, and Windows.
  3. Drift Guard Note:

    • Since the drift guard / generation mechanism is not yet present in the current codebase, the specific test case "drift guard fires correctly under contention" cannot be fully validated in isolation at this moment. However, because the write paths are now fully guarded by the FileLock boundary, the upcoming drift guard feature can be safely integrated into this perimeter later.

All cross-platform compilation checks and go test -race for memory/database modules have passed. Ready for review!

@yunasora yunasora requested a review from a team as a code owner June 15, 2026 02:14
@aheritier aheritier added area/sessions For features/issues/fixes related to session lifecycle (resume, persistence, export) kind/feat PR adds a new feature (maps to feat: commit prefix) area/agent For work that has to do with the general agent loop/agentic features of the app labels Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent For work that has to do with the general agent loop/agentic features of the app area/sessions For features/issues/fixes related to session lifecycle (resume, persistence, export) kind/feat PR adds a new feature (maps to feat: commit prefix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(memory): Atomic writes and cross-process locking for memory DB access

2 participants