Skip to content

A corrected name renames what it named; relationships through recalled facts; held turns say so - #232

Merged
joslat merged 3 commits into
mainfrom
phase38/names-periods-relations
Sep 28, 2026
Merged

joslat merged 3 commits into
mainfrom
phase38/names-periods-relations

Conversation

@joslat

@joslat joslat commented Sep 28, 2026

Copy link
Copy Markdown
Owner

What changes

  • A corrected name renames what it named, instead of leaving two of it. Controlled by ExtractionOptions.RenameOnCorrectedName, which is off by default and needs SupersedeReplacedFacts.
    • The bug: "It's Priya, not Pruya" closed the old naming fact, but left "Pruya" as a second person with "Pruya lives in Lisbon" still attached.
    • The trigger: a persist closes a naming fact (is named, is called, any subject: the user, a person, a pet) in favour of a new name.
    • The rename: the owner's entity with the old name is merged into the one with the new name, which is created if missing. Relationships and mentions move, the old name stays as an alias, and the old entity is closed.
    • The facts: live facts said about the old name are restated under the new one, each superseding its original.
    • Robustness: renames are found in the store after the write, so they apply on every write path (atomic, best-effort, replayed). Like supersession, the step is best-effort.
  • The people a recalled fact names bring their relationships (with RecallOptions.MaxRelationships set).
    • The bug: recall added relationships only between the recalled entities. So "what does my manager's husband do?" had "Daniel works as chef" but never the edge "Priya Nair married to Daniel".
    • The fix: the entities named in recalled facts (subjects and objects, by name or alias) now bring their relationships too, in the same single query.
    • API: new default interface methods ILongTermMemoryService.GetRelationshipsAroundAsync and IRelationshipRepository.GetLiveAroundAsync fall back to the id-only reads.
  • A held question turn says so. ExtractionResult.Deferred and the public ExtractionResult.DeferredMetadataKey let a host tell a held turn from an empty success. memory.ingestion.operations tags it status=Deferred.

Verification

  • Unit: all five non-integration test projects pass.
  • Integration (local Neo4j): 588 passed, 0 failed, 29 skipped (model-dependent).
  • New tests (each fails with its change reverted):
    • renaming your own name, a pet's name, and the switch off;
    • relationships reached through a fact with entity recall off;
    • the deferred status in the ingestion metric.
  • Perf gate: PASS on both the zero and remote latency profiles.
  • Samples: all build. MinimalAgent and AgentWithMemory run end to end on 45ba4aa4.
  • Live check with a real model: "Hi, I'm Pruya… it's Priya, not Pruya" left one person, Priya, with the alias "Pruya" and three restated facts.

🤖 Generated with Claude Code

https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9

joslat and others added 3 commits September 28, 2026 17:31
"It's Priya, not Pruya" closed the old naming fact but left "Pruya" as a second person,
with "Pruya lives in Lisbon" still on it. With ExtractionOptions.RenameOnCorrectedName
(off by default; needs SupersedeReplacedFacts), when a persist closes a naming fact
("is named", "is called", any subject) in favour of a new name, the owner's entity with
the old name is merged into the one with the new name (created if missing; relationships
and mentions move, the old name stays as an alias) and closed, and the live facts said
about the old name are restated under the new one, each superseding its original.

Found from the store after the write rather than threaded through it, so it holds on every
write path (atomic, best-effort, replayed); best-effort like supersession. Integration
tests on a real store with scripted extraction: your own name, a pet's name, and the
switch off (both fail without the change).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
…eferred in the ingestion metrics

A turn held for the next one that tells something returned an empty result that read as a
success with nothing in it. ExtractionResult.Deferred and the public DeferredMetadataKey
say what happened, and memory.ingestion.operations tags it status=Deferred, apart from
successes (a unit test on the metric fails without the change).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
Recall added the relationships between the recalled entities only, so "what does my
manager's husband do?" had "Daniel works as chef" and never the edge "Priya Nair married
to Daniel". With RecallOptions.MaxRelationships set, the entities the recalled facts name
(subjects and objects, by name or alias; not "user") bring theirs too, in the same one
query ($names empty: the id-only read, unchanged). New default interface methods
GetRelationshipsAroundAsync / GetLiveAroundAsync fall back to the id-only reads.
Integration test with entity recall off (the edge can only come through the fact); fails
without the change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
Copilot AI lite review requested due to automatic review settings September 28, 2026 15:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved correctness and concurrency issues remain in corrected-name persistence, along with documentation gaps.

Review effort: Lite
Findings: 2 High severity · 1 Low severity

Open (3)
What changed in this PR

Adds opt-in corrected-name renaming, fact-based relationship recall, and deferred extraction observability.

Changes:

  • Renames entities and restates affected facts.
  • Expands relationship recall through fact-mentioned names and aliases.
  • Adds deferred extraction metadata, metrics, tests, and documentation.
File Reviewed change
tests/​AgentMemory.Tests.Unit/​Observability/​InstrumentedMemoryServiceTests.cs Deferred metric tests
tests/​AgentMemory.Tests.Integration/​Services/​RelationshipsThroughFactsIntegrationTests.cs Fact-derived relationship recall tests
tests/​AgentMemory.Tests.Integration/​Extraction/​RenameOnCorrectedNameIntegrationTests.cs Corrected-name rename tests
src/​AgentMemory.Observability/​InstrumentedMemoryService.cs Deferred ingestion metrics
src/​AgentMemory.Neo4j/​Repositories/​Neo4jRelationshipRepository.cs Name-aware relationship reads
src/​AgentMemory.Neo4j/​Queries/​RelationshipQueries.cs Expanded relationship query
src/​AgentMemory.Core/​Services/​MemoryService.cs Deferred metadata wiring
src/​AgentMemory.Core/​Services/​MemoryContextAssembler.cs Fact-name relationship expansion
src/​AgentMemory.Core/​Services/​LongTermMemoryService.cs Relationship API implementation
src/​AgentMemory.Core/​Extraction/​PersistenceStage.cs Corrected-name rename workflow
src/​AgentMemory.Abstractions/​Services/​ILongTermMemoryService.cs New relationship service API
src/​AgentMemory.Abstractions/​Repositories/​IRelationshipRepository.cs New relationship repository API
src/​AgentMemory.Abstractions/​Options/​ExtractionOptions.cs Rename configuration
src/​AgentMemory.Abstractions/​Domain/​Extraction/​ExtractionResult.cs Deferred result contract
docs/​configuration/​memory-options.md Option documentation
CHANGELOG.md User-facing release notes

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

var from = since - TimeSpan.FromSeconds(1);
foreach (var named in naming)
{
var name = named.Object.Trim();
Comment on lines +272 to +275
var target = await _entityRepository.FindLiveByNameAsync(name, null, scope, cancellationToken).ConfigureAwait(false)
?? await _entityRepository.UpsertAsync(new Entity
{
EntityId = _idGenerator.GenerateId(),
/// superseding its original, so the history stays readable. Needs <see cref="SupersedeReplacedFacts"/> (which
/// closes the old naming fact). Owner-scoped: a shared (owner-less) write renames nothing.
/// </summary>
public bool RenameOnCorrectedName { get; set; }
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.

2 participants