Skip to content

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

Closed

Description

@currentbits

Code audit finding (memory-server): the 'edges' table (src/db.js:215) has no production writer — nothing in src/ inserts edges, only tests do (test/graph.test.js). Consequences: the graph retriever's 2-hop BFS (src/memory.js:495-630) degenerates to a direct mentions lookup, relation semantics are unused, and there is no memory_expand tool to traverse the graph.

Either wire a writer (entity co-occurrence within entries is free; LLM-extracted relations at write time is the stronger version, and write-time entity resolution is the consistent lesson from the memory-systems research) or remove the dead retriever leg. Note: entity extraction is also regex-only (wikilinks, file extensions, PascalCase; src/extract.js), and kinds repo/agent/tool are declared but never produced.

Activity

  1. added
    bug
    plan:todo
    plan:doing
    and removed
    plan:todo
    on Aug 17, 2026
  2. currentbits commented on Aug 17, 2026

    @currentbits
    OwnerAuthor

    Approach decided (grok worker a926f13d implementing):

    Wire the writer, not delete the leg. linkEntities() (src/memory.js:247) already resolves entities and writes mentions at store time — co-occurrence edges are ~10 lines in that same loop, and they bring the existing 130-line BFS in graphSearch() alive without touching it.

    • relation = 'co_occurs', pairs normalised src<dst so an unordered pair is one row, INSERT OR IGNORE on the existing PK.
    • One-shot backfill for existing DBs: edges derived from mentions via self-join, guarded by a janitor_state key.
    • Bounded for free — extractEntities() already caps at 15 entities/entry → ≤105 pairs.

    Deliberately out of scope:

    • memory_expand tool — that's a new feature, not the reported bug. File separately if an agent actually needs manual traversal.
    • LLM-extracted relations — adds a provider dep 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 unused repo/agent/tool kinds — harmless as-is, no consumer blocked.
  3. currentbits commented on Aug 17, 2026

    @currentbits
    OwnerAuthor

    Implemented and verified on coder/memory-graph-is-dead-in-production-edges-fba1f2 (65bbd70 + a63ea48). 131/131 memory-server tests pass.

     memory-server/src/db.js          |  44 +++++++
     memory-server/src/memory.js      |  19 +++-
     memory-server/test/graph.test.js | 205 +++++++++++++++++++++++++++++-
    
    • linkEntities() collects resolved entity ids and writes one co_occurs edge per unordered pair, src<dst normalised so a pair is never mirrored into two rows.
    • One-shot backfill derives edges from pre-existing mentions via self-join, guarded by janitor_state.edges_backfill_v1.
    • Tests cover: no mirrored duplicates; graphSearch() genuinely reaching a 2-hop entry (A mentions X+Y, B mentions Y+Z, query on X returns B); backfill populating and not double-running.

    Found on review, fixed separately (a63ea48): the edges PK indexes src as its leading column, so the UNION half of the BFS neighbour probe — WHERE dst = ? — was a full table scan, executed once per dequeued node. EXPLAIN QUERY PLAN confirmed SCAN edges. Free while the table was empty; not free now that each entry writes up to 105 rows. Added idx_edges_dst. No index on entry_id — that path is deleteEntry only, not a loop.

    Left open pending merge to main.

  4. added
    plan:done
    and removed
    plan:doing
    on Aug 17, 2026
  5. added a commit that references this issue on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugplan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions