Repository navigation
fix(memory): carry context (room) through consolidation, not session - #1704
Merged
Merged
Conversation
…sion The memory consolidation boundary dropped the room: ConsolidatedMemory carried only session_id, and to_corpus_memory() emitted "sessionId" into the memory's context bag — while recall.rs scores the room bonus by reading "roomId". So a consolidated memory's room affinity NEVER matched: memory would orphan from its conversation (and on reconnect, key off a dead session). Per IDENTITY-SCOPE-PEER-LIVENESS-MODEL.md A.6 step 4, durable memory must be keyed by (identity, context), never session. The source already had the room: Thought.context_id existed but was ignored at the adapter. Carry it through: - ConsolidatedMemory gains context_id: Option<Uuid> (the room). - raw_adapter maps t.context_id -> memory.context_id (1:1, exact room). - to_corpus_memory emits the canonical "contextId" PLUS the "roomId" key recall already reads; sessionId stays as labelled session metadata (not a context substitute); room keys omitted (not nil) when there's no context. - recall.rs unchanged — it already reads "roomId"; the producer was wrong. All structs are plain (no #[derive(TS)]/Entity) so NO ts-rs binding or sqlite schema change — pure in-memory + JSON bag. Honest scope: the memory consolidation pipeline (run_consolidation_pass / to_corpus_memory) is not yet live-wired (only test callers; no production Thought producer), so this fixes a LATENT bug — the boundary now carries context correctly so the data-loss can never go live when the pipeline is wired. The Engram ORM context_id field (schema migration + ts-rs regen) is the separate deliberate follow-up (task #39 part b). Test: to_corpus_memory carries the room under both "roomId" (what recall reads) and "contextId". memory:: suite 71 pass. Co-Authored-By: Claude Opus 4.8 <[email protected]>
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.
Problem (latent data-loss — fixed before it ships)
The memory consolidation boundary dropped the room.
ConsolidatedMemorycarried onlysession_id, andto_corpus_memory()emitted"sessionId"into the memory's context bag — butrecall.rsscores its room bonus by reading"roomId". So a consolidated memory's room affinity never matched: memory orphans from its conversation, and on reconnect would key off a dead session.Per IDENTITY-SCOPE-PEER-LIVENESS-MODEL.md A.6 step 4: durable memory must be keyed by (identity, context), never session.
Fix
The source already had the room —
Thought.context_idexisted but was ignored at the adapter. Carry it through:ConsolidatedMemorygainscontext_id: Option<Uuid>(the room).raw_adaptermapst.context_id → memory.context_id(1:1, exact room).to_corpus_memoryemits the canonical"contextId"plus the"roomId"key recall already reads;sessionIdstays as labelled session metadata (not a context substitute); room keys omitted (not nil) when absent.recall.rsunchanged — it already reads"roomId"; the producer was wrong.All structs are plain (
#[derive(Debug, Clone)]) — no ts-rs binding or sqlite schema change (pure in-memory + JSON bag).Honest scope
The consolidation pipeline (
run_consolidation_pass/to_corpus_memory) is not yet live-wired (only test callers; no productionThoughtproducer). So this fixes a latent bug: the boundary now carries context correctly so the data-loss can never go live when the pipeline is wired. TheEngramORMcontext_idfield (sqlite schema migration + ts-rs regen) is the separate deliberate follow-up — task #39 part (b).Test
to_corpus_memorycarries the room under both"roomId"(what recall reads) and"contextId".memory::suite: 71 pass.🤖 Generated with Claude Code