fix(MemoryGraph): first-wins on duplicate KNOWLEDGE slugs (drop UsageGraphError crash)#1408
Open
Luo0oo wants to merge 1 commit into
Open
fix(MemoryGraph): first-wins on duplicate KNOWLEDGE slugs (drop UsageGraphError crash)#1408Luo0oo wants to merge 1 commit into
Luo0oo wants to merge 1 commit into
Conversation
…GraphError crash)
buildGraph iterates KNOWLEDGE domains (People/Companies/Ideas/Research)
and derives each node's id from the bare filename via entry.replace(/\.md$/, '').
No domain prefix, so any two files sharing a basename across domains produce
identical ids and the second addNode throws:
UsageGraphError: Graph.addNode: the "synthesis" node already exist in the graph.
The crash blocks the whole build; the graph never renders and PATTERNS.md
never regenerates, silently breaking Pulse's /api/memory/graph route.
Guards graph.addNode with hasNode, matching the existing first-wins
semantics of the bareToId population two lines below. Emits console.warn
listing kept-path and skipped-path so users notice the data loss (this is
a report-generator tool, not a scriptable pipe — silent drop would hide
files they wrote).
Reproducer:
mkdir -p ~/.claude/LIFEOS/MEMORY/KNOWLEDGE/{Companies,Research}
printf '%s\n' '---' 'title: A' '---' 'body' > ~/.claude/LIFEOS/MEMORY/KNOWLEDGE/Companies/foo.md
printf '%s\n' '---' 'title: B' '---' 'body' > ~/.claude/LIFEOS/MEMORY/KNOWLEDGE/Research/foo.md
bun ~/.claude/LIFEOS/TOOLS/MemoryGraph.ts build # crashes without this fix
Orthogonal issues noticed but out of scope (worth separate PRs):
- KNOWLEDGE-first ordering in ingest() means WORK ISAs lose bare-slug
wikilink resolution when a KNOWLEDGE file shares the basename
- 'patterns' command rebuilds only on 60min cache age, never checks source
mtimes — user can edit a note and get stale patterns silently
- addEdge widens weight on collision but never upgrades kind (a later
'related' edge over an earlier 'tag' keeps kind 'tag' — provenance loss)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
buildGraphatLifeOS/install/LifeOS/TOOLS/MemoryGraph.ts:288iterates KNOWLEDGE domains (People/Companies/Ideas/Research) and derives node IDs from bare filenames:No domain prefix, so any two files sharing a basename across domains produce identical IDs. The second
graph.addNode(node.id, ...)throws:The crash blocks the whole build.
graph.jsonnever regenerates,PATTERNS.mdstays stale, Pulse's/api/memory/graphroute silently serves nothing.Fix
Guards
graph.addNodewithhasNode, matching the existing first-wins semantics of thebareToIdpopulation two lines below (if (!bareToId.has(bare)) bareToId.set(...)).Emits
console.warnlisting the kept-path and skipped-path so users notice the data loss.MemoryGraph.tsis a report-generator tool with multi-line human output, not a scriptable pipe; a silent drop would hide files the user wrote.Reproducer
Orthogonal issues noticed (out of scope — worth separate PRs)
ingest()means WORK ISAs lose bare-slug wikilink resolution when a KNOWLEDGE file shares the basenamepatternscommand rebuilds only on 60-min cache age, never checks source file mtimes — edit a note, get stale patterns silentlyaddEdgewidens weight on collision but never upgradeskind(a laterrelatededge over an earliertagkeeps kindtag— provenance loss)Verify
Reproducer above passes with this diff applied. Existing populated KNOWLEDGE trees without collisions are unchanged (the guard is a no-op path).