Skip to content

memory: write co-occurrence edges so the graph retriever has data to walk (#307) - #327

Merged
currentbits merged 12 commits into
mainfrom
coder/memory-graph-is-dead-in-production-edges-fba1f2
Aug 17, 2026
Merged

currentbits merged 12 commits into
mainfrom
coder/memory-graph-is-dead-in-production-edges-fba1f2

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Fixes #307.

The bug

memory-server declares an edges table (src/db.js:215) that nothing in src/ ever wrote to — only test/graph.test.js did. So Memory.graphSearch()'s 2-hop BFS always terminated at hop 0 and silently degenerated into a plain mentions lookup. ~130 lines of retriever running against a permanently empty table.

What changed

Wire the writer, not delete the leg. linkEntities() already resolves entities and writes mentions at store time, so co-occurrence edges cost ~10 lines in that same loop and bring the existing BFS alive without touching it.

  • linkEntities() (src/memory.js) collects the resolved entity ids and writes one co_occurs edge per unordered pair, normalised src < dst so a pair never becomes two mirrored rows. INSERT OR IGNORE on the existing PK.
  • Bounded for free: extractEntities() already caps at 15 entities/entry, so ≤105 rows per entry. No new cap.
  • One-shot backfill (backfillCoOccurrenceEdges in src/db.js) derives edges from pre-existing mentions via a self-join, guarded by janitor_state.edges_backfill_v1 so it runs at most once per database. Existing installs get a populated graph without a re-index.

Found on review

The edges PRIMARY KEY (src, dst, relation, entry_id) indexes src as its leading column, so the UNION half of the BFS neighbour probe — WHERE dst = ? — fell back to a full table scan, executed once per dequeued node. EXPLAIN QUERY PLAN confirmed SCAN edges. That cost nothing while the table was permanently empty; fixing the writer is exactly what makes it expensive. Added idx_edges_dst. No index on entry_id — that path is deleteEntry only, not a loop.

Verification

131/131 memory-server tests pass. New coverage in test/graph.test.js:

  • storing an entry with 2+ extractable entities produces the expected co_occurs edges, src<dst, with no mirrored duplicate
  • graphSearch() genuinely reaches a 2-hop entry — entry A mentions X+Y, entry B mentions Y+Z, a query seeded on X returns B
  • the backfill populates edges from pre-existing mentions and does not double-run

deleteEntry() and the janitor's orphan-edge cleanup already handled edges; both still hold with real edge data.

Deliberately out of scope

  • memory_expand tool — a new feature, not the reported bug. The existing retriever is what was broken, and it now works. File separately if an agent needs manual traversal.
  • LLM-extracted typed relations — adds a provider dependency and network latency to a write path that has neither. Co-occurrence is the free version; typed relations are the upgrade path if relation semantics ever get a consumer.
  • extract.js regex-only extraction, and the declared-but-unused repo/agent/tool kinds — harmless as-is, no consumer blocked.

🤖 Generated with Claude Code

  • PR created by the Claude Code agent

Willem and others added 12 commits August 17, 2026 15:26
… Named agent profiles (provider + model + effort + permission
DigestRun/DigestResult in shared/ipc plus the pure ranking in src/digest.ts:
main collects evidence, the renderer decides merge-ready / needs-you /
discard, so the receipt can be re-ranked without re-walking git.

Co-Authored-By: Claude Opus 5 <[email protected]>
Types and a green seam so backend and UI can land in parallel:
GcCandidate/GcScanResult/GcCleanResult, ProjectInfo.worktreeRetention,
and git.gcScan/gcClean across preload, wireClient and devCoder.
worktrees.gcScan/gcClean are placeholders returning empty scans until
the real engine lands.

Co-Authored-By: Claude Opus 5 <[email protected]>
entries.source column migration and src/trust.js: the trust multiplier both
halves of #309 build on. Provenance plumbing and the DB aggregation land on
top of this.

Co-Authored-By: Claude Opus 5 <[email protected]>
Add the coffee-time receipt: ranked merge-ready / needs-you / discard
with cost, check evidence and risk flags. Wasted spend stays visible.
Main gathers facts only: windowed threads, usage, git stats, and
scraped test/build evidence. Ranking stays in src/digest.ts.
linkEntities now inserts unordered co_occurs pairs (src < dst) at store
time. Existing DBs get a one-shot mentions self-join backfill guarded by
janitor_state edges_backfill_v1.
The edges PK indexes src as its leading column, so the UNION half of
graphSearch's neighbour query (WHERE dst = ?) fell back to a full scan --
once per dequeued node. Free while the table was empty; now that entries
write up to 105 co-occurrence rows each, it is not.

Co-Authored-By: Claude Opus 5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit 63cf192 into main Aug 17, 2026
1 check failed
@currentbits
currentbits deleted the coder/memory-graph-is-dead-in-production-edges-fba1f2 branch October 3, 2026 16:07
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.

Memory graph is dead in production: edges table has no writer

1 participant