Skip to content

fix(memory): enforce record-class storage for evidence memories#452

Merged
Aaronontheweb merged 2 commits into
devfrom
claude-wt-session-memory-records
Mar 27, 2026
Merged

fix(memory): enforce record-class storage for evidence memories#452
Aaronontheweb merged 2 commits into
devfrom
claude-wt-session-memory-records

Conversation

@Aaronontheweb

Copy link
Copy Markdown
Collaborator

Summary

Fixes #446 — distillation never produces record-class memories.

  • Policy override in MemoryProposalGate.BuildMemoryOperation(): memoryClass now determines storage kind instead of trusting the LLM's operation field. Evidence → Record + ImmutableRecord, Trace → Record + ConversationTrace, DurableFact → Document + MergeDocument.
  • Shared classification rules (MemorySidecarPromptBuilder.BuildClassificationRules()): strict operation-to-class mapping used by both the distillation and observation prompts to prevent drift.
  • Distillation prompt rewrite: added classification rules, concrete JSON examples for both upsert_document (durable_fact) and append_record (evidence), and explicit field specification.

Root Cause

The BuildDistillationSystemPrompt() listed both upsert_document and append_record as valid operations but never mapped which one to use for which memory class. The Qwen 27B model defaulted to upsert_document for nearly everything. Result: 32 documents (including 11 evidence incorrectly stored as merge-on-write documents) but only 1 record.

Test plan

  • dotnet build succeeds
  • All 693 tests pass (4 new tests added)
  • Post-deployment: monitor curation_create log events — evidence proposals should show "immutable record bypass" reason
  • Query SELECT COUNT(*) FROM memory_records should show records growing over time

@Aaronontheweb Aaronontheweb marked this pull request as ready for review March 27, 2026 01:32
Distillation never produced record-class memories because the prompt
listed both operations without mapping them to memory classes. The LLM
defaulted to upsert_document for everything, storing evidence as
mergeable documents instead of immutable records.

Two-layer fix:
- Policy override in MemoryProposalGate: memoryClass now determines
  storage kind regardless of the LLM's operation choice. Evidence and
  trace always become records; durable_fact always becomes a document.
- Prompt improvements: both distillation and observation prompts now
  include shared classification rules with explicit operation-to-class
  mapping and concrete examples of each type.
@Aaronontheweb Aaronontheweb force-pushed the claude-wt-session-memory-records branch from 7ee5e39 to 6744c95 Compare March 27, 2026 01:33
@Aaronontheweb Aaronontheweb enabled auto-merge (squash) March 27, 2026 01:40
@Aaronontheweb Aaronontheweb merged commit 31c9802 into dev Mar 27, 2026
3 checks passed
@Aaronontheweb Aaronontheweb deleted the claude-wt-session-memory-records branch March 27, 2026 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

investigate(memory): distillation never produces record-class memories

1 participant