Skip to content

CausalMemoryGraph.addCausalEdge() silently creates orphan edges when NodeIdMapper.getNodeId() returns undefined #7

@ruvnet

Description

@ruvnet

Summary

In CausalMemoryGraph.addCausalEdge() (bundled agentdb@3.0.0-alpha.16), when NodeIdMapper.getNodeId() returns undefined for a numeric memory id that was never registered, the code constructs a fallback string ${memoryType}-${memoryId} (e.g. episode-123) and silently creates the edge — even if no node with that id exists in the graph. Surfaced by ruvnet/ruflo#2246 §3.

Where (per the reporter's read of alpha.16's dist)

// dist/controllers/CausalMemoryGraph.js — addCausalEdge()
const mapper = NodeIdMapper.getInstance();
const fromNodeId = typeof edge.fromMemoryId === 'string'
  ? edge.fromMemoryId
  : (mapper.getNodeId(edge.fromMemoryId) || `${edge.fromMemoryType}-${edge.fromMemoryId}`);
// ...same for toNodeId, then createCausalEdge(graphEdge)

The || ... fallback path runs with no console.warn, no validation, no rejection. The edge is created against an id the graph never registered → dangling/orphan edge.

Impact (from the reporter)

"We hit this as recurring causal-edge deprecation noise with no actionable guidance about required id formats (e.g. entity: / mem: prefixes)."

Silent orphans corrupt graph topology — pagerank, shortest-path, and similar traversals will encounter dangling endpoints with no diagnostic trail.

Reproduction

Call addCausalEdge() with a numeric fromMemoryId that was never registered via NodeIdMapper.register(). Observe: edge created against episode-<id> with no warning. Run a graph traversal: orphan endpoint encountered.

Suggested fix (any one)

  1. Reject the edge when the mapper returns undefined, with an actionable error message naming the missing id + the registration call.
  2. Emit console.warn documenting what id format was expected and how to register it (e.g. NodeIdMapper.register(rawId, 'entity:foo')).
  3. Validate at the end of addCausalEdge that both endpoints actually exist as nodes in the graph; reject otherwise.

Reporter's preference (#2246): "emit one actionable warning ... or reject the edge, instead of constructing an unvalidated id."

Cross-references

  • Upstream report: ruvnet/ruflo#2246 (§3 of a 4-finding bug report)
  • Bundled version that hit this: agentdb 3.0.0-alpha.16

Happy to PR if useful — start a thread.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions