perf: async batched edit-log writer with unified flush path#134
Merged
XuPeng-SH merged 1 commit intomatrixorigin:mainfrom Mar 25, 2026
Merged
perf: async batched edit-log writer with unified flush path#134XuPeng-SH merged 1 commit intomatrixorigin:mainfrom
XuPeng-SH merged 1 commit intomatrixorigin:mainfrom
Conversation
6c7e40a to
403ccce
Compare
Replace synchronous per-operation sql.log_edit() calls with an async EditLogBuffer that collects entries via a bounded channel (4096) and flushes as multi-row INSERTs every 2s or when 64 entries accumulate. Key changes: - EditLogFlusher trait abstracts flush target (SqlMemoryStore in prod, InMemoryFlusher in unit tests) so the full batching path is testable - Bounded channel with try_send for backpressure, retry-once on flush failure, oneshot-based flush() for deterministic test assertions - All edit-log write paths unified: store/correct/purge/store_batch/ purge_batch/purge_by_topic in MemoryService, governance quarantine/ cleanup in MCP tools + API routes, and GovernanceStore::log_edit via SqlMemoryStore.edit_log_tx sender propagation to background pools - MemoryService::new() returns Self (clean API); new_with_test_entries() for tests that need to assert on edit-log writes - Comprehensive e2e test suite (18 tests) verifying all 9 columns of mem_edit_log against the real database for every mutation path Additional improvements: - Deduplicate shutdown_signal() into memoria-service (shared by CLI/MCP/API) - Graceful shutdown: signal handling + edit-log drain + flusher drain - Background flusher tasks (AccessCounter, LastUsed, ToolUsage, CallLog) now have shutdown signals via watch channel + JoinHandle await - Graph + entity link cleanup on correct/purge (hot path + governance fallback) - cleanup_orphan_graph_data() surfaces partial failures instead of swallowing - Batch optimizations: N+1 → batch entity/graph queries, tokio::join for hybrid search, get_stats_batch combines access_count + feedback - Moka caches: active_table (5s), cooldown, node_count (2min) - find_near_duplicate: single query with app-layer same-type preference - Test SQL injection hardening: parameterized queries + enum whitelist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes
Fixes #
What this PR does / why we need it
Replace synchronous per-operation sql.log_edit() calls with an async EditLogBuffer that collects entries via a bounded channel (4096) and flushes as multi-row INSERTs every 2s or when 64 entries accumulate.
Key changes:
Additional improvements: