fix: remove misdirected SemanticMsg enqueue causing O(n²) reprocessing#776
Open
chethanuk wants to merge 1 commit intovolcengine:mainfrom
Open
fix: remove misdirected SemanticMsg enqueue causing O(n²) reprocessing#776chethanuk wants to merge 1 commit intovolcengine:mainfrom
chethanuk wants to merge 1 commit intovolcengine:mainfrom
Conversation
volcengine#505) On every commit, session.py enqueued a SemanticMsg targeting the session URI (not a memory directory) with changes=None after the compressor had already enqueued correct messages with change-tracking dicts. This misdirected message bypassed the cache guard in _process_memory_directory() (which only loaded cached summaries when msg.changes was truthy), causing unconditional VLM API calls for every memory file — O(n²) reprocessing. Fix: - Remove the misdirected enqueue block in session.py (lines 309-324) - Harden cache loading in semantic_processor.py to always consult cached summaries regardless of msg.changes value (defense-in-depth) Impact: ~98.7% token reduction at 500 memories (100K+ tokens/day saved)
MaojiaSheng
approved these changes
Mar 19, 2026
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.
Summary
session.py(lines 309-324): After_flush_semantic_operations()already enqueued correct messages with change-tracking dicts,commit_async()was enqueuing a secondSemanticMsgtargeting the session URI (not a memory directory) withchanges=Nonesemantic_processor.py:_process_memory_directory()now always loads cached summaries from.overview.mdregardless ofmsg.changesvalue (defense-in-depth against otherchanges=Nonecallers likelock_manager.pyandsummarizer.py)Problem
On every commit,
session.py:309-324enqueued aSemanticMsgwithchanges=Noneafter the compressor had already correctly enqueued messages with proper change-tracking dicts. This misdirected message bypassed the cache guard in_process_memory_directory()(which only loaded cached summaries whenmsg.changeswas truthy), causing unconditional VLM API calls for every memory file — O(n²) reprocessing. At 500 memories this wasted 100K+ tokens/day.The timeline on each commit
Step 6-8 is waste. Removing lines 309-324 eliminates step 6, so step 8 never happens.
Fix
session.py: Removed 16-line block that enqueued the misdirectedSemanticMsg— the compressor's_flush_semantic_operations()already handles this correctlysemantic_processor.py: Removedif msg.changes:guard on cache loading so.overview.mdis always consultedCloses Memory extraction triggers O(n²) semantic reprocessing — token cost grows quadratically with memory count #505
Testing
test_fix_505_duplicate_semantic_enqueue.py)test_no_misdirected_semantic_enqueue_after_flush— verifiescommit_async()doesn't enqueue after compressor flushtest_process_memory_directory_loads_cache_when_changes_none— verifies cache is loaded even whenmsg.changes is NoneRelated Issue
Type of Change
Changes Made
Testing
Checklist
Screenshots (if applicable)
Additional Notes