Skip to content

Improve semantic memory reinforcement and contradiction recall#3

Open
coe0718 wants to merge 2 commits intoghostwright:mainfrom
coe0718:semantic-memory-reinforcement
Open

Improve semantic memory reinforcement and contradiction recall#3
coe0718 wants to merge 2 commits intoghostwright:mainfrom
coe0718:semantic-memory-reinforcement

Conversation

@coe0718
Copy link
Copy Markdown
Contributor

@coe0718 coe0718 commented Mar 31, 2026

What Changed

This PR improves semantic memory durability and contradiction visibility without introducing a new parallel memory system.

  • reinforces repeated semantic facts instead of storing near-duplicate current facts
  • tracks semantic contradiction lineage with superseded_by_fact_id
  • immediately supersedes lower-confidence contradictory facts so they do not remain current
  • surfaces relevant superseded facts back during semantic recall as contradiction notes
  • includes reinforcement and contradiction context in prompt formatting for known facts
  • adds focused tests for fact reinforcement, contradiction supersession, and contradiction-note recall

Why

This is a follow-up step on the memory strategy discussed in #1.

Phantom already stores semantic facts and invalidates contradicted ones, but repeated facts still behaved like separate observations, and changed beliefs were not surfaced clearly during later retrieval. This PR keeps the work in the TypeScript plumbing lane:

  • deterministic fact reconciliation
  • persistence and lineage tracking
  • retrieval shaping
  • prompt formatting

The agent and judges still handle the reasoning side. This change just makes the stored semantic memory behave more like a durable knowledge layer.

How I Tested

Commands run:

/home/coemedia/.bun/bin/bun test src/memory/__tests__/semantic.test.ts
/home/coemedia/.bun/bin/bun test src/memory/__tests__/semantic-reconciliation.test.ts
/home/coemedia/.bun/bin/bun test src/memory/__tests__/context-builder.test.ts
bash -lc 'export PATH="$HOME/.bun/bin:$PATH" && /home/coemedia/.bun/bin/bun test'
/home/coemedia/.bun/bin/bun run typecheck
/home/coemedia/.bun/bin/bun run lint

Notes:

  • Full test suite passes with Bun on PATH for subprocess-spawn tests.
  • Lint, typecheck, and the full test suite are all passing on the rebased branch.

Checklist

  • Tests pass (bun test)
  • Lint passes (bun run lint)
  • Typecheck passes (bun run typecheck)
  • No secrets or .env files included
  • Files stay under 300 lines
  • No Cardinal Rule violations (TypeScript does plumbing only, the Agent SDK does reasoning)
  • No default exports or barrel files added

Copy link
Copy Markdown
Member

@mcheemaa mcheemaa left a comment

Choose a reason for hiding this comment

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

#2 just landed on main. Can you rebase this on main when you get a chance? Will review once it's updated.

@coe0718 coe0718 force-pushed the semantic-memory-reinforcement branch from d4c955f to 407b067 Compare March 31, 2026 09:48
@coe0718
Copy link
Copy Markdown
Contributor Author

coe0718 commented Mar 31, 2026

Rebased this morning.

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.

3 participants