fix(memory): enforce identity singularity across scopes#133
Conversation
`encode()` routed profile engrams by declared scope, so `memorize(kind=profile)` with the default `scope=project` landed in `project/profile.md` — which no read path ever loads, silently dropping the data. Force `kind=profile` to `global_hc` regardless of scope, and add a one-time startup migration that merges any orphaned project identity into global then clears the project copy. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
EntelligenceAI PR SummaryFixes identity migration in
Confidence Score: 4/5 - Mostly SafeSafe to merge — the fix in Key Findings:
Files requiring special attention
|
There was a problem hiding this comment.
Fixes incorrect scoping of profile/identity engrams and adds migration logic for orphaned data, along with a method to clear stored identity.
cortex.py:encode()now unconditionally routeskind == 'profile'engrams toglobal_hc;__init__detects and migrates orphaned project-scoped identity entries viarewrite_identity()and clears them fromproject_hchippocampus.py: Newclear_identity()method deletes_profile_pathif presentbase.py: New abstract methodclear_identity()added to enforce interface contracttests/test_cortex.py: Added tests for correct global routing of profile engrams andTestOrphanedIdentityMigrationclass covering both migration and no-op scenarios
…ntity-scope-singular
The previous migration called `global_hc.rewrite_identity(orphaned)` which treats new entries as authoritative and strips existing global entries sharing the same key prefix. A stale `Name: Alec` in project scope could silently overwrite a fresh `Name: Alejandro` in global, corrupting data the user had explicitly corrected. Global wins on key conflicts now — only orphaned keys not already present globally are imported. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@Entelligence review |
|
Starting fresh pr review. This may take a few minutes |
|
New pr review completed! Check the pr for comments. |
|
@Entelligence review |
|
Starting fresh pr review. This may take a few minutes |
|
New pr review completed! Check the pr for comments. |
Summary
Cortex.encode()routed profile engrams by declared scope, somemorize(kind=profile)with the defaultscope=projectwrote toproject/profile.md— which no read path ever loads. The facts were silently lost.kind=profiletoglobal_hcregardless of declared scope, matching the existingbuild_memory_context()comment "identity is singular".Cortex.__init__merges any orphaned project identity into global and clears the project copy, so existing users recover data already written to the wrong place.clear_identity()toHippocampus(and toHippocampusProtocol) to support the migration without reaching into private paths.Notes
maybe_update_identity(only the last user message is scanned despite the every-5-turns cadence) is being handled separately in Fix: don't skip user messages to extract identity #125.Test plan
pytest tests/test_cortex.py tests/test_hippocampus.py— 55 passedkind=profile, scope=projectroutes to global, never writes projectprofile.md🤖 Generated with Claude Code