docs(memory): document src/services/memory/index.js and fix save race condition

- Added JSDoc and inline comments to `src/services/memory/index.js` to clarify module flow and internal invariants.
- Fixed a race condition in `performSave` where `currentSavePromise` was cleared before the pending save was chained, potentially allowing concurrent writes.
- Created `docs/memory-service-index-overview.md` with high-level architecture.
- Verified changes with `npm test src/services/memory/index.js` and `npm run lint`.
- Updated `TEST_LOG` and `task-logs` to reflect the fix.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-02-27 04:34:02 +00:00
1 parent 802711f00c
commit c7b5a88d4b
14 files changed
+271 -9

No files matched your search

@@ -0,0 +1,23 @@
---
agent: docs-code-investigator
cadence: daily
run-start: 2026-02-27T03:12:00Z
---
# Decisions - docs-code-investigator - 2026-02-27T03-12-00Z
Prompt: src/prompts/daily/docs-code-investigator.md
## Decision: Document `src/services/memory/index.js`
### Context
`src/services/memory/index.js` is a large file (565 LOC) that serves as the main entry point for the memory service, orchestrating multiple sub-modules (`ingestor`, `retriever`, `pruner`). It has complex internal state (memory store caching, save serialization).
### Rationale
- High complexity: It manages async persistence with a manual lock/queue mechanism (`performSave`, `saveMemoryStore`).
- Critical path: All memory operations pass through here.
- Maintenance risk: Future refactors could easily break the save serialization or cache invalidation logic if not clearly documented.
### Implementation Details
- Will add comprehensive JSDoc for all public exports.
- Will add a detailed module-level comment explaining the flow and invariants.
- Will document the `performSave` / `saveMemoryStore` pattern specifically to prevent race conditions in future edits.