Repository navigation
fix(server): resolve memory IDs to graph nodes in /graph/edge endpoints (#1180) - #1182
Merged
Merged
Conversation
…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.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
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.
What
Fix
POST /graph/edgealways returning 500 for valid memory IDs (#1180), and align the graph edge family with the memory-ID contract:POST /graph/edge:source/targetare resolved to their graph node before insertion — memory-linked node first (via newGraphStore::node_id_for_memory), then an explicit node ID (clients may pass IDs fromGET /graph), otherwise a node is ensured automatically viaGraphStore::ensure_node_for_memory(label = memory_id,entity_type = "memory",memory_idlink set). Response now returns{ok, source_node, target_node}.DELETE /graph/edge: same dual-ID resolution; unknown IDs return 404 instead of leaking errors.?source=&target=params for DELETE, previously?from=&to=);docs/api-reference.mdregenerated viacargo run -p docgen.Root cause: the handler validated IDs as memories (
uteke.get_by_id) but inserted them straight intograph_edges, whosesource_id/target_idFKs referencegraph_nodes(id)— memory IDs almost never exist there, so every call hitFOREIGN 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
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.handlers.rstests,tiny_http::TestRequest, embedder-free viaopen_with_backend(None)so they run in CI without ONNX): memory-ID POST → 200 with node mapping verified inGET /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.