Repository navigation
[Feat]: Asynchronous write-back for hybrid memory sync #432
Description
Activity
- addedkeep-openPrevents the auto-close task from closing this issue.Prevents the auto-close task from closing this issue.
on Apr 22, 2026 MemMachine has made extensive use of
asyncoperations.Here's my analysis of this feature request against the current codebase relative to this issue.
✅ Already addressed (partially)
Request Where it's implemented Async write methods add_episodesinmemmachine.pyusesasyncio.gather(*tasks)to fan out to episodic + semantic memory concurrentlyBackground worker / asyncio task group ShortTermMemoryConsolidator.summarize()is explicitly non-blocking — it buffers episodes and runs a backgroundasyncio.create_taskloopBackground ingestion with retry/backoff SemanticService._background_ingestion_task()runs as a background loop with exponential backoff up to 60sAsync R/W locking AsyncRWLockinrw_locks.pyprovides full writer-priority async locking with context managers⚠️ Not yet fully addressedThe core concern — write operations blocking the API response until durable persistence completes — is still present. In
memmachine.py::add_episodes:await asyncio.gather(*tasks) return episode_ids
Writes to episodic and semantic storage are concurrent with each other (via
asyncio.gather), but the API handler still awaits full completion before returning. The issue's request for a "background write queue" at the ingestion layer — where the API acknowledges receipt and returns immediately while writes are drained asynchronously — is not implemented in the hot path.The
ShortTermMemoryConsolidatorachieves this pattern for summarization, andSemanticServicedoes it for background ingestion polling, but neither covers the primary durable-store write path.Conclusion
The existing async infrastructure (locks, task groups, background workers) is excellent groundwork. What remains is a targeted enhancement: introducing a write-back queue in the
add_episodeshot path so the REST handler can return episode IDs immediately and defer persistence. The issue's suggested ~25% latency improvement is a reasonable expectation given the background patterns already proven inShortTermMemoryConsolidator.- addedperformanceIssues relating to MemMachine performanceIssues relating to MemMachine performance
on Apr 22, 2026
Is your feature request related to a problem?
Write operations currently block while persisting to durable store. This slows down ingestion and increases API latency.
Describe the solution you'd like
Perform multiple memory insertions under load — throughput decreases linearly as concurrent requests increase.
Describe alternatives you've considered
Write-backs should be asynchronous with retry logic, reducing blocking time while maintaining consistency.
Additional context
Adding a background write queue or asyncio task group can cut write latency by ~25%.