Skip to content

fix(memory): carry context (room) through consolidation, not session - #1704

Merged
joelteply merged 1 commit into
canaryfrom
fix/memory-context-not-session
Jun 20, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/memory-context-not-session

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Problem (latent data-loss — fixed before it ships)

The memory consolidation boundary dropped the room. ConsolidatedMemory carried only session_id, and to_corpus_memory() emitted "sessionId" into the memory's context bag — but recall.rs scores 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_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 absent.
  • recall.rs unchanged — 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 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 (sqlite 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.

🤖 Generated with Claude Code

…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]>
@joelteply
joelteply merged commit cd7d8b8 into canary Jun 20, 2026
4 checks passed
@joelteply
joelteply deleted the fix/memory-context-not-session branch June 20, 2026 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant