Skip to content

fix(memory): reject self-loop edges in graph extractor#2221

Merged
bug-ops merged 1 commit intomainfrom
fix-2215-graph-self-loop-edges
Mar 27, 2026
Merged

fix(memory): reject self-loop edges in graph extractor#2221
bug-ops merged 1 commit intomainfrom
fix-2215-graph-self-loop-edges

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 27, 2026

Summary

  • Add three-layer defense against source_entity_id == target_entity_id edges in the knowledge graph
  • extract_and_store in semantic/graph.rs: skip self-loops after entity ID resolution with debug log
  • insert_edge_typed in graph/store/mod.rs: return MemoryError::InvalidInput for self-loops
  • Migration 044: DELETE existing self-loops + BEFORE INSERT trigger (SQLite lacks ALTER TABLE CHECK)
  • New MemoryError::InvalidInput(String) variant following existing thiserror patterns

Test plan

  • zeph-memory::semantic::graph::tests::extract_and_store_skips_self_loop_edges — mock returns self-loop, asserts 0 edges inserted
  • zeph-memory::graph::store::tests::insert_edge_typed_rejects_self_loop — asserts InvalidInput error
  • cargo nextest run --workspace --features full --lib --bins — 6638 passed

Closes #2215

@github-actions github-actions bot added documentation Improvements or additions to documentation memory zeph-memory crate (SQLite) rust Rust code changes bug Something isn't working size/M Medium PR (51-200 lines) labels Mar 27, 2026
Three-layer defense against source_entity_id == target_entity_id edges:
- extract_and_store: skip self-loops after entity ID resolution (debug log)
- insert_edge_typed: return InvalidInput error for self-loops
- migration 044: delete existing self-loops + BEFORE INSERT trigger

Adds MemoryError::InvalidInput(String) variant.
@bug-ops bug-ops enabled auto-merge (squash) March 27, 2026 08:33
@bug-ops bug-ops force-pushed the fix-2215-graph-self-loop-edges branch from 0bb6b5b to 0f959d7 Compare March 27, 2026 08:33
@bug-ops bug-ops merged commit 1e48a5a into main Mar 27, 2026
25 checks passed
@bug-ops bug-ops deleted the fix-2215-graph-self-loop-edges branch March 27, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation memory zeph-memory crate (SQLite) rust Rust code changes size/M Medium PR (51-200 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

graph: entity extractor creates self-loop edges (source == target)

1 participant