Skip to content

Memory Module - #173

Merged
mstdokumaci merged 3 commits into
mainfrom
memory-module
Aug 1, 2026
Merged

mstdokumaci merged 3 commits into
mainfrom
memory-module

Conversation

@mstdokumaci

@mstdokumaci mstdokumaci commented Aug 1, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added thread-safe map support for synchronized reads and writes.
    • Improved document caching and cache-backed storage operations.
  • Bug Fixes
    • Improved cache reclamation and resilience during resource exhaustion.
    • Prevented stale cached documents after cache-update failures.
  • Tests
    • Added coverage for concurrent access, lifecycle management, eviction, reclamation, cleanup, and allocation failures.
    • Updated tests to reflect reorganized memory and caching components.
  • Documentation
    • Updated storage documentation to reflect revised primary-key tracking terminology.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f689f905-c7da-4fc0-a80d-282f7fd0f42d

📥 Commits

Reviewing files that changed from the base of the PR and between 1aed81f and 35b2327.

📒 Files selected for processing (3)
  • src/memory/lock_free_cache.zig
  • src/memory/strategy.zig
  • src/memory/strategy_test.zig
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/memory/strategy_test.zig

📝 Walkthrough

Walkthrough

The PR relocates memory modules into a directory structure, adds locked-map and lock-free-cache implementations with comprehensive tests, and refactors storage-engine workers to use document caches and locked-map based namespace, identity, and primary-key caches.

Changes

Memory and storage cache refactor

Layer / File(s) Summary
Memory module relocation and import updates
src/app_test_helpers.zig, src/authorization/session_resolver.zig, src/checkpoint_test_helpers.zig, src/connection/manager.zig, src/connection/send_queue.zig, src/logging_property_test.zig, src/memory_safety_property_test.zig, src/message_handler.zig, src/presence/worker.zig, src/presence/worker_test.zig, src/queues/*.zig, src/schema/test_helpers.zig, src/server.zig, src/storage_engine/write_queue.zig, src/storage_engine_test_helpers.zig, src/subscription/worker_pool.zig, src/subscription/worker_pool_perf_test.zig, src/subscription/worker_pool_test.zig, src/test_all.zig, specs/implementation/storage.md
Import paths change from root-level memory_strategy.zig to memory/strategy.zig. Test aggregation imports relocated memory test modules. Documentation updates PkSet reference to pk_set_type.
Lock-free cache simplification and test coverage
src/memory/lock_free_cache.zig, src/memory/lock_free_cache_test.zig, src/memory/lock_free_cache_leak_test.zig
Cache removes compile-time deinit validation, simplifies mutation results, handles pool exhaustion with fallible acquisition, and removes RefCountOverflow and CasFailed errors. Tests cover concurrent reads, reference counts, updates, eviction, value deinitialization, and reclamation tracking with CountingValue.
Memory strategy configuration and locked-map implementation
src/memory/strategy.zig, src/memory/strategy_test.zig, src/memory/locked_map.zig, src/failing_allocator_test_helper.zig
MemoryStrategy removes Config type and initWithConfig method, using fixed capacities and test-conditional arena preallocation. Locked map provides thread-safe hash-map wrapper with configurable locking and synchronized operations. FailNextAllocator test helper simulates allocation failures.
Storage cache type refactoring
src/storage_engine/cache.zig, src/storage_engine.zig, src/storage_engine/pk_set.zig
MetadataCacheKey becomes DocumentCacheKey. metadata_cache_type becomes document_cache_type. Namespace and identity caches change to lockedMap with Mutex locking. PkSet implementation is removed; pk_set_type uses lockedMap with RwLock. Public PkSet alias is removed from StorageEngine.
Storage engine initialization and wiring
src/storage_engine.zig, src/storage_engine/read_worker_pool.zig
StorageEngine.document_cache replaces metadata_cache. ReadWorker and ReadWorkerPool parameters change to document_cache. Initialization creates and wires document_cache. Primary-key sets allocate through storage_cache.pk_set_type. Namespace and identity caches initialize with empty values.
Read-path cache operations
src/storage_engine/read_worker_pool.zig, src/storage_engine/read_worker_perf_test.zig
Point lookups and database reads use and update document_cache. Version-gated cache population targets document_cache. Performance tests reclaim document_cache during teardown and cache-miss simulation.
Write-path cache operations and session resolution
src/storage_engine/write_worker.zig
Cache operations target document_cache. Failed updates evict and release the entry. Primary-key insertion calls put with error handling. Namespace and identity session resolution insert through namespace_cache.put and identity_cache.put.
Cache reset, bootstrap, and integration tests
src/storage_engine.zig, src/storage_engine_test.zig
Reset helper deinitializes primary-key sets. Setup SQL reset reinitializes document_cache and resets primary-key sets. Startup resets primary-key sets before bootstrapping. Tests verify cache population, retention, eviction, and post-commit allocation-failure handling with eviction and database validation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • mstdokumaci/zyncbase#157: Both changes modify StorageEngine.start and primary-key set bootstrapping alongside storage-engine cache and reader infrastructure changes.
  • mstdokumaci/zyncbase#159: Both changes modify storage_engine/write_worker.zig write-through cache update and eviction behavior, with corresponding storage-engine integration tests.
  • mstdokumaci/zyncbase#170: Both changes modify lock-free cache implementation and remove obsolete public error types and result structures.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately identifies the primary change as a memory module reorganization and related cache updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/storage_engine.zig (1)

26-27: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Update the storage specifications to remove or rename PkSet.

PkSet is no longer exported from src/storage_engine.zig, but both storage specifications still list it as an important type.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/storage_engine.zig` around lines 26 - 27, Update both storage
specifications to remove `PkSet` from their listed important types, or replace
it with its current exported name if it was renamed. Ensure the specifications
reference only types actually exported by `src/storage_engine.zig`.
🧹 Nitpick comments (2)
src/storage_engine.zig (1)

37-39: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use CamelCase for cache type aliases.

The same type-naming violation appears in both files. Rename the aliases and update their references consistently.

  • src/storage_engine.zig#L37-L39: Rename document_cache_type, namespace_cache_type, and identity_cache_type to CamelCase type aliases.
  • src/storage_engine/read_worker_pool.zig#L24-L24: Rename document_cache_type to the matching CamelCase alias.

As per coding guidelines, src/**/*.zig must use CamelCase for types and snake_case for functions and variables.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/storage_engine.zig` around lines 37 - 39, Rename the cache type aliases
in src/storage_engine.zig lines 37-39 to CamelCase and update every reference
consistently. Apply the corresponding document cache alias rename in
src/storage_engine/read_worker_pool.zig line 24 and its references; preserve
snake_case for functions and variables.

Source: Coding guidelines

src/storage_engine/cache.zig (1)

3-4: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Use snake_case for all affected Zig identifiers.

  • Rename the listed cache factories, helpers, aliases, APIs, and readerThread, including all references.
  • Also rename minActiveEpoch, cloneEntries, cowMutation, transformFn, releaseHandle, internalDefer, pushToDeferStack, reclaimLoop, readLock, readUnlock, writeLock, and writeUnlock.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/storage_engine/cache.zig` around lines 3 - 4, Rename all affected Zig
identifiers to snake_case and update every reference, including cache factories,
helpers, aliases, APIs, readerThread, minActiveEpoch, cloneEntries, cowMutation,
transformFn, releaseHandle, internalDefer, pushToDeferStack, reclaimLoop,
readLock, readUnlock, writeLock, and writeUnlock. Apply the changes in
src/storage_engine/cache.zig at ranges 3-4, 40-42, and 60-61, plus corresponding
references in src/memory/lock_free_cache_test.zig ranges 3-3 and 45-56 and
src/memory/lock_free_cache_leak_test.zig range 3-3.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/memory/lock_free_cache_leak_test.zig`:
- Around line 70-79: Update internalDefer and the cache update path exercised by
lock_free_cache_leak_test so a full deferred-node pool never silently drops
retired maps or entries: retain them using allocator-backed overflow nodes or
return an explicit backpressure error, and do not force reclamation while a
reader pins an epoch. Revise the test to release the pinned handle and then
assert that all deferred resources are eventually reclaimed.

In `@src/storage_engine_test.zig`:
- Around line 1027-1030: The failure branch in the cache lookup test must
release the live handle before returning. Update the .hit arm of getCachedRecord
to call hit.handle.release() before returning error.TestUnexpectedResult, while
preserving the existing .miss behavior.

In `@src/storage_engine.zig`:
- Around line 360-365: Reset all primary-key sets before each bootstrap scan by
calling the existing reset_pk_sets() in the startup flow after setup SQL and
before the bootstrap loop. Ensure failed attempts cannot leave IDs in the sets
used by documentExists and write-path duplicate checks, while preserving the
existing cache reset behavior around document_cache, namespace_cache, and
identity_cache.

In `@src/storage_engine/write_worker.zig`:
- Around line 870-874: Update the post-COMMIT pk_sets handling in the write
worker and StorageEngine.documentExists so a failed pk_sets.put does not make
committed rows appear absent. On insertion failure, either fall back to SQLite
for existence checks or mark the set degraded and rebuild it before use; ensure
StoreService.applySet receives authoritative existence results for
create/update, required-field, and authorization decisions.
- Around line 856-860: Update the document_cache.update error path in
commitBatchAndApply so a failed post-commit write invalidates or removes the
existing cache entry before deinitializing r, guaranteeing subsequent reads
produce a cache miss rather than stale data. Add failure-injection coverage that
prepopulates the cache entry and verifies it is absent after the update failure.

---

Outside diff comments:
In `@src/storage_engine.zig`:
- Around line 26-27: Update both storage specifications to remove `PkSet` from
their listed important types, or replace it with its current exported name if it
was renamed. Ensure the specifications reference only types actually exported by
`src/storage_engine.zig`.

---

Nitpick comments:
In `@src/storage_engine.zig`:
- Around line 37-39: Rename the cache type aliases in src/storage_engine.zig
lines 37-39 to CamelCase and update every reference consistently. Apply the
corresponding document cache alias rename in
src/storage_engine/read_worker_pool.zig line 24 and its references; preserve
snake_case for functions and variables.

In `@src/storage_engine/cache.zig`:
- Around line 3-4: Rename all affected Zig identifiers to snake_case and update
every reference, including cache factories, helpers, aliases, APIs,
readerThread, minActiveEpoch, cloneEntries, cowMutation, transformFn,
releaseHandle, internalDefer, pushToDeferStack, reclaimLoop, readLock,
readUnlock, writeLock, and writeUnlock. Apply the changes in
src/storage_engine/cache.zig at ranges 3-4, 40-42, and 60-61, plus corresponding
references in src/memory/lock_free_cache_test.zig ranges 3-3 and 45-56 and
src/memory/lock_free_cache_leak_test.zig range 3-3.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 77754089-3529-4974-b012-ad3969eed309

📥 Commits

Reviewing files that changed from the base of the PR and between 9d7f99e and 73a252d.

📒 Files selected for processing (34)
  • src/app_test_helpers.zig
  • src/authorization/session_resolver.zig
  • src/checkpoint_test_helpers.zig
  • src/connection/manager.zig
  • src/connection/send_queue.zig
  • src/logging_property_test.zig
  • src/memory/lock_free_cache.zig
  • src/memory/lock_free_cache_leak_test.zig
  • src/memory/lock_free_cache_test.zig
  • src/memory/locked_map.zig
  • src/memory/strategy.zig
  • src/memory/strategy_test.zig
  • src/memory_safety_property_test.zig
  • src/message_handler.zig
  • src/presence/worker.zig
  • src/presence/worker_test.zig
  • src/queues/mpsc_queue_test.zig
  • src/queues/mpsc_queue_thread_safety_test.zig
  • src/queues/spsc_queue_test.zig
  • src/schema/test_helpers.zig
  • src/server.zig
  • src/storage_engine.zig
  • src/storage_engine/cache.zig
  • src/storage_engine/pk_set.zig
  • src/storage_engine/read_worker_perf_test.zig
  • src/storage_engine/read_worker_pool.zig
  • src/storage_engine/write_queue.zig
  • src/storage_engine/write_worker.zig
  • src/storage_engine_test.zig
  • src/storage_engine_test_helpers.zig
  • src/subscription/worker_pool.zig
  • src/subscription/worker_pool_perf_test.zig
  • src/subscription/worker_pool_test.zig
  • src/test_all.zig
💤 Files with no reviewable changes (1)
  • src/storage_engine/pk_set.zig

Comment thread src/storage_engine_test.zig
Comment thread src/storage_engine.zig
Comment thread src/storage_engine/write_worker.zig
Comment thread src/storage_engine/write_worker.zig

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/storage_engine.zig (1)

26-27: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Update the storage specifications to remove or rename PkSet.

PkSet is no longer exported from src/storage_engine.zig, but both storage specifications still list it as an important type.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/storage_engine.zig` around lines 26 - 27, Update both storage
specifications to remove `PkSet` from their listed important types, or replace
it with its current exported name if it was renamed. Ensure the specifications
reference only types actually exported by `src/storage_engine.zig`.
🧹 Nitpick comments (2)
src/storage_engine.zig (1)

37-39: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use CamelCase for cache type aliases.

The same type-naming violation appears in both files. Rename the aliases and update their references consistently.

  • src/storage_engine.zig#L37-L39: Rename document_cache_type, namespace_cache_type, and identity_cache_type to CamelCase type aliases.
  • src/storage_engine/read_worker_pool.zig#L24-L24: Rename document_cache_type to the matching CamelCase alias.

As per coding guidelines, src/**/*.zig must use CamelCase for types and snake_case for functions and variables.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/storage_engine.zig` around lines 37 - 39, Rename the cache type aliases
in src/storage_engine.zig lines 37-39 to CamelCase and update every reference
consistently. Apply the corresponding document cache alias rename in
src/storage_engine/read_worker_pool.zig line 24 and its references; preserve
snake_case for functions and variables.

Source: Coding guidelines

src/storage_engine/cache.zig (1)

3-4: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Use snake_case for all affected Zig identifiers.

  • Rename the listed cache factories, helpers, aliases, APIs, and readerThread, including all references.
  • Also rename minActiveEpoch, cloneEntries, cowMutation, transformFn, releaseHandle, internalDefer, pushToDeferStack, reclaimLoop, readLock, readUnlock, writeLock, and writeUnlock.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/storage_engine/cache.zig` around lines 3 - 4, Rename all affected Zig
identifiers to snake_case and update every reference, including cache factories,
helpers, aliases, APIs, readerThread, minActiveEpoch, cloneEntries, cowMutation,
transformFn, releaseHandle, internalDefer, pushToDeferStack, reclaimLoop,
readLock, readUnlock, writeLock, and writeUnlock. Apply the changes in
src/storage_engine/cache.zig at ranges 3-4, 40-42, and 60-61, plus corresponding
references in src/memory/lock_free_cache_test.zig ranges 3-3 and 45-56 and
src/memory/lock_free_cache_leak_test.zig range 3-3.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/memory/lock_free_cache_leak_test.zig`:
- Around line 70-79: Update internalDefer and the cache update path exercised by
lock_free_cache_leak_test so a full deferred-node pool never silently drops
retired maps or entries: retain them using allocator-backed overflow nodes or
return an explicit backpressure error, and do not force reclamation while a
reader pins an epoch. Revise the test to release the pinned handle and then
assert that all deferred resources are eventually reclaimed.

In `@src/storage_engine_test.zig`:
- Around line 1027-1030: The failure branch in the cache lookup test must
release the live handle before returning. Update the .hit arm of getCachedRecord
to call hit.handle.release() before returning error.TestUnexpectedResult, while
preserving the existing .miss behavior.

In `@src/storage_engine.zig`:
- Around line 360-365: Reset all primary-key sets before each bootstrap scan by
calling the existing reset_pk_sets() in the startup flow after setup SQL and
before the bootstrap loop. Ensure failed attempts cannot leave IDs in the sets
used by documentExists and write-path duplicate checks, while preserving the
existing cache reset behavior around document_cache, namespace_cache, and
identity_cache.

In `@src/storage_engine/write_worker.zig`:
- Around line 870-874: Update the post-COMMIT pk_sets handling in the write
worker and StorageEngine.documentExists so a failed pk_sets.put does not make
committed rows appear absent. On insertion failure, either fall back to SQLite
for existence checks or mark the set degraded and rebuild it before use; ensure
StoreService.applySet receives authoritative existence results for
create/update, required-field, and authorization decisions.
- Around line 856-860: Update the document_cache.update error path in
commitBatchAndApply so a failed post-commit write invalidates or removes the
existing cache entry before deinitializing r, guaranteeing subsequent reads
produce a cache miss rather than stale data. Add failure-injection coverage that
prepopulates the cache entry and verifies it is absent after the update failure.

---

Outside diff comments:
In `@src/storage_engine.zig`:
- Around line 26-27: Update both storage specifications to remove `PkSet` from
their listed important types, or replace it with its current exported name if it
was renamed. Ensure the specifications reference only types actually exported by
`src/storage_engine.zig`.

---

Nitpick comments:
In `@src/storage_engine.zig`:
- Around line 37-39: Rename the cache type aliases in src/storage_engine.zig
lines 37-39 to CamelCase and update every reference consistently. Apply the
corresponding document cache alias rename in
src/storage_engine/read_worker_pool.zig line 24 and its references; preserve
snake_case for functions and variables.

In `@src/storage_engine/cache.zig`:
- Around line 3-4: Rename all affected Zig identifiers to snake_case and update
every reference, including cache factories, helpers, aliases, APIs,
readerThread, minActiveEpoch, cloneEntries, cowMutation, transformFn,
releaseHandle, internalDefer, pushToDeferStack, reclaimLoop, readLock,
readUnlock, writeLock, and writeUnlock. Apply the changes in
src/storage_engine/cache.zig at ranges 3-4, 40-42, and 60-61, plus corresponding
references in src/memory/lock_free_cache_test.zig ranges 3-3 and 45-56 and
src/memory/lock_free_cache_leak_test.zig range 3-3.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 77754089-3529-4974-b012-ad3969eed309

📥 Commits

Reviewing files that changed from the base of the PR and between 9d7f99e and 73a252d.

📒 Files selected for processing (34)
  • src/app_test_helpers.zig
  • src/authorization/session_resolver.zig
  • src/checkpoint_test_helpers.zig
  • src/connection/manager.zig
  • src/connection/send_queue.zig
  • src/logging_property_test.zig
  • src/memory/lock_free_cache.zig
  • src/memory/lock_free_cache_leak_test.zig
  • src/memory/lock_free_cache_test.zig
  • src/memory/locked_map.zig
  • src/memory/strategy.zig
  • src/memory/strategy_test.zig
  • src/memory_safety_property_test.zig
  • src/message_handler.zig
  • src/presence/worker.zig
  • src/presence/worker_test.zig
  • src/queues/mpsc_queue_test.zig
  • src/queues/mpsc_queue_thread_safety_test.zig
  • src/queues/spsc_queue_test.zig
  • src/schema/test_helpers.zig
  • src/server.zig
  • src/storage_engine.zig
  • src/storage_engine/cache.zig
  • src/storage_engine/pk_set.zig
  • src/storage_engine/read_worker_perf_test.zig
  • src/storage_engine/read_worker_pool.zig
  • src/storage_engine/write_queue.zig
  • src/storage_engine/write_worker.zig
  • src/storage_engine_test.zig
  • src/storage_engine_test_helpers.zig
  • src/subscription/worker_pool.zig
  • src/subscription/worker_pool_perf_test.zig
  • src/subscription/worker_pool_test.zig
  • src/test_all.zig
💤 Files with no reviewable changes (1)
  • src/storage_engine/pk_set.zig
🛑 Comments failed to post (1)
src/memory/lock_free_cache_leak_test.zig (1)

70-79: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Do not accept resource loss when the deferred-node pool is full.

A pinned reader prevents reclamation. internalDefer then returns when it cannot acquire a node. Each later update can lose a retired map or cache entry permanently.

Retain the resource until safe reclamation is possible. Use allocator-backed overflow nodes, or return a backpressure error. Do not force reclamation while a reader holds an epoch. Update this test to verify eventual cleanup after the pinned handle is released.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/memory/lock_free_cache_leak_test.zig` around lines 70 - 79, Update
internalDefer and the cache update path exercised by lock_free_cache_leak_test
so a full deferred-node pool never silently drops retired maps or entries:
retain them using allocator-backed overflow nodes or return an explicit
backpressure error, and do not force reclamation while a reader pins an epoch.
Revise the test to release the pinned handle and then assert that all deferred
resources are eventually reclaimed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/storage_engine.zig (1)

367-368: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Preserve a valid cache when reinitialization fails.

If document_cache.init fails, execSetupSQL returns while state remains .setup and document_cache has already been deinitialized. A later start, deinit, or setup retry can use an invalid cache.

Initialize a safe replacement before destroying the live cache. If the cache cannot support replacement, transition the engine to a state that blocks reuse after this failure.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/storage_engine.zig` around lines 367 - 368, Update the cache reset logic
in execSetupSQL to initialize a safe replacement document_cache before
deinitializing the currently valid cache; if replacement initialization fails,
transition the engine out of reusable setup state so later start, deinit, or
setup retries cannot access an invalid cache.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/storage_engine.zig`:
- Around line 367-368: Update the cache reset logic in execSetupSQL to
initialize a safe replacement document_cache before deinitializing the currently
valid cache; if replacement initialization fails, transition the engine out of
reusable setup state so later start, deinit, or setup retries cannot access an
invalid cache.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 91fc31f9-099c-4fa1-b5b3-341c3eed683d

📥 Commits

Reviewing files that changed from the base of the PR and between 73a252d and 1aed81f.

📒 Files selected for processing (7)
  • specs/implementation/storage.md
  • src/failing_allocator_test_helper.zig
  • src/memory/lock_free_cache.zig
  • src/memory/lock_free_cache_leak_test.zig
  • src/storage_engine.zig
  • src/storage_engine/write_worker.zig
  • src/storage_engine_test.zig
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/memory/lock_free_cache.zig
  • src/storage_engine/write_worker.zig

@mstdokumaci
mstdokumaci merged commit 843aea7 into main Aug 1, 2026
8 checks passed
@mstdokumaci
mstdokumaci deleted the memory-module branch August 1, 2026 19:48
@coderabbitai coderabbitai Bot mentioned this pull request Aug 6, 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