Skip to content

fix(server): resolve memory IDs to graph nodes in /graph/edge endpoints (#1180) - #1182

Merged
ajianaz merged 1 commit into
developfrom
fix/1180-graph-edge-memory-ids
Sep 5, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/1180-graph-edge-memory-ids

Conversation

@ajianaz

@ajianaz ajianaz commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

What

Fix POST /graph/edge always returning 500 for valid memory IDs (#1180), and align the graph edge family with the memory-ID contract:

  • POST /graph/edge: source/target are resolved to their graph node before insertion — memory-linked node first (via new GraphStore::node_id_for_memory), then an explicit node ID (clients may pass IDs from GET /graph), otherwise a node is ensured automatically via GraphStore::ensure_node_for_memory (label = memory_id, entity_type = "memory", memory_id link set). Response now returns {ok, source_node, target_node}.
  • DELETE /graph/edge: same dual-ID resolution; unknown IDs return 404 instead of leaking errors.
  • Both feat: HTTP graph mutation endpoints — POST /graph/edge and DELETE /graph/edge #542 memory-ID validation (acceptance criteria) and node-ID clients keep working.
  • API registry descriptions updated (incl. correcting the documented ?source=&target= params for DELETE, previously ?from=&to=); docs/api-reference.md regenerated via cargo run -p docgen.

Root cause: the handler validated IDs as memories (uteke.get_by_id) but inserted them straight into graph_edges, whose source_id/target_id FKs reference graph_nodes(id) — memory IDs almost never exist there, so every call hit FOREIGN KEY constraint failed → 500.

Why

#1180 — the documented contract ("Add a directed edge between two memories") was unusable: any call with two valid memory IDs 500'd on a clean v0.16.0 sandbox and on develop. Downstream impact: Corin's "add connection" feature was fully broken. Fix keeps the FK guarantee and adds automatic memory→node mapping instead of relaxing the schema.

Testing

  • 6 new unit tests in uteke-core/src/graph.rs: memory→node resolution (linked node preferred, legacy label fallback, absent → None), ensure-node idempotency + reuse, edge roundtrip through ensured nodes.
  • 8 new integration tests calling the router directly (handlers.rs tests, tiny_http::TestRequest, embedder-free via open_with_backend(None) so they run in CI without ONNX): memory-ID POST → 200 with node mapping verified in GET /graph; node-ID POST accepted; unknown memory → 404; self-loop → 400; DELETE by memory IDs / node IDs / unknown IDs; missing params → 400.
  • cargo fmt --all ✓ · cargo clippy --workspace --all-targets -- -D warnings ✓ · cargo test --workspace ✓ (543 core + 68 CLI + 19 server + 6 MCP + registry invariant test, 0 failures) · cora review --staged ✓ (No issues found) · docgen freshness check will validate the regenerated reference.

…ts (#1180)

POST /graph/edge validated source/target as memory IDs but inserted them
directly into graph_edges, whose FKs reference graph_nodes(id) — every
valid call violated the FK and returned 500. Both sides are now resolved
to their linked graph node (existing graph node IDs stay accepted), or a
node is ensured automatically before insertion. DELETE /graph/edge gains
the same dual-ID resolution. POST response now carries source_node and
target_node so clients can track the created nodes.
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit cbccebb into develop Sep 5, 2026
16 checks passed
@ajianaz
ajianaz deleted the fix/1180-graph-edge-memory-ids branch September 5, 2026 10:32
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.

1 participant