Skip to content

Label create_relationship writes by the stored edge (closes #3106) - #3176

Merged
malibio merged 2 commits into
mainfrom
issue-3106-inbound-evict-label
Sep 27, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-3106-inbound-evict-label

Conversation

@malibio

@malibio malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

Problem

A create_relationship write through an inbound (in-declaration) name is stored as the forward edge, and a later eviction's replaced entry names it in that forward form. The write's own label, though, echoed the call's inbound spelling. The two never matched, so "put it back on Alice" was refused as a duplicate of a write that no longer stood.

Changes

  • core: create_relationship / create_relationship_in_tx return CreatedRelationship { edge, replaced }, where edge is the stored forward edge. ReplacedEdge is renamed StoredEdge, since it now describes both.
  • rel_ops::CreateRelOutput reports the stored edge, not the input.
  • agent tool: the create_relationship result reports the stored edge as nodespace:// URIs, the same form as its replaced entries. (The CLI and Tauri responses also now show an inbound-name write in its forward form.)
  • daemon: the write label is built from the result. canonical_args still comes from the call's arguments, so the guard's identity for a write is unchanged. The edge_key scheme-stripping shim is deleted, since both sides now agree on one spelling.

Tests

  • core: write_through_in_name_reports_the_stored_edge: the rel_ops output is in forward form, and a later eviction names it identically.
  • daemon: an_edge_written_through_an_in_name_is_released_by_its_eviction: assign via the inbound name, evict, recreate. The recreation isn't refused, and its identity matches the original.
  • The existing guard tests pass, with fixtures moved to realistic tool results.

Ran: daemon local_agent_service tests (85 pass) and core relationship_in_name_normalization_test (18 pass). test:changed never ran: it sat queued behind other gates for the machine slot, so the full run is left to bun run merge.

🤖 Generated with Claude Code

@malibio

malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3176

Review Type: Initial review. No earlier reviews or comments on the PR. Head 8a1482a3.

Requirements Check (#3106)

  • ✅ A create_relationship write through an inbound name records its label in the stored forward form. create_relationship_in_tx shadows source_id/relationship_name/target_id through forward_endpoints before every Ok(...) return, including the idempotent already_exists path. So CreatedRelationship.edge is always the stored edge. rel_ops → exec_create_relationship → completed_writes_from (edge_label(&r.result)) passes it through unchanged. The builtin-only non-tx path returns plain(args), which is correct because builtins have no in declarations.
  • ✅ Test: assign via the inbound name, evict it, recreate it; the recreation is not refused. an_edge_written_through_an_in_name_is_released_by_its_eviction (daemon) covers it, and so does write_through_in_name_reports_the_stored_edge (core), which checks that the first write's reported edge equals the second write's replaced entry.
  • ✅ The canonical_args identity is unchanged. It is still derived from r.args. The existing guard tests pass. I ran them locally: relationship_in_name_normalization_test 18/18, and nodespace-daemon --lib local_agent_service 85/85.

Code Review Findings

🟡 The agent-layer seam has no test for an inbound write.
📁 packages/agent/src/local_agent/tools.rs:3521-3530 (existing test near 7415-7455)
The bug lived in the glue between core's result and the chat label. The glue that now produces the label is exec_create_relationship mapping output.source_id/target_id/relationship_name through node_uri, and it is only tested for a forward name (tasks). The daemon test builds its results by hand with rel_result(...), so it proves the label logic but not that the tool emits that shape.
Suggested fix: add a tools.rs test on the supersedes/superseded_by fixture that checks the first result's from_id/to_id/type are the stored forward edge and that the second write's replaced[0] equals them byte for byte. A cheap test that covers the actual integration point guards against regression at the exact seam that broke (test the contract, not the parts).

🟡 The daemon test's fixture reverses the shipped schema.
📁 packages/daemon/src/services/local_agent_service.rs:6071-6116
The doc comment says Alice takes the task "through the person-side tasks name, stored as task -[assignee]-> alice". In the shipped schema, tasks is the forward name on person (packages/core/src/models/core_schemas.rs:1328-1333, reverse_name: "assignee"). The neighbouring tests in this file, and the tools.rs test, use tasks as forward too. The test still passes because the results are synthetic, but it describes something impossible and will mislead the next reader.
Suggested fix: use the ADR superseded_by → supersedes pair, which the core test already uses as its real in declaration. Test fixtures should reflect real domain shapes, and this is also a readability issue.

🟢 Removing edge_key is safe.

  • The only producer of create_relationship completed-writes is completed_writes_from over ToolExecutionRecords from exec_create_relationship.
  • Both the edge and each replaced entry go through node_uri, applied to core ids that are bare (the input is strip_node_uri'd), so nothing gets double-prefixed.
  • The label and replaced are now built by one function (edge_label) from one shape, which removes a normalisation layer that only existed because the edge had two spellings. This is a good application of DRY and KISS.
  • Chats persisted before this change carry bare-id labels. Per CLAUDE.md, no compatibility shim is needed, and none was added.

🟢 The gRPC and CLI output now reports the stored edge (a contract change).
📁 packages/daemon/src/services/node_service.rs:1396-1413, packages/cli/src/commands/relationship.rs:106-109, packages/proto/proto/node_service.proto:723-730
CreateRelationshipResponse.{source_id, relationship_name, target_id} now come back in stored orientation. For example, nodespace relationship create old superseded_by new1 prints new1 --[supersedes]--> old. This is an improvement, because it now matches replaced. The Tauri command ignores these fields.
Nit: add one line to the proto message comment saying the fields are the edge as stored, swapped onto the forward name for an in write. API docs should state contract changes.

🟢 Nit: the model now sees the forward name for an inbound write.
📁 packages/agent/src/local_agent/tools.rs:3521-3530
A call to superseded_by now returns "type": "supersedes" with the endpoints swapped. The meaning is the same, and it matches what later-turn terse facts show. No change is needed now. If the golden or matrix evals ever show the model re-issuing the call because the result "doesn't match", this is the place to look.

🟢 Nit: playbook actions still echo their arguments.
📁 packages/core/src/playbook/actions.rs:1874-1878, 2282-2286
add_relationship still returns the call's source_id/target_id/relationship_type and ignores the now-available CreatedRelationship.edge. This is out of scope and harmless today, since no guard consumes it. It is worth folding in if Play outputs are ever compared against stored edges.

🟢 Standards and design. The ReplacedEdge → StoredEdge rename correctly generalises the type now that it describes both the created edge and the evicted ones, and the CreatedRelationship return is a clean single-responsibility result type. The change does one thing, has no backward-compatibility code, no #[allow], and no issue numbers in comments.

Recommendation: APPROVE

The fix is correct and minimal: it makes the store the only source of truth for how an edge is spelled. The two 🟡 items concern test fidelity, not correctness, and are cheap to address before merge.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (6f57a08)

✅ Addressed (3)

  • 🟡 Agent-seam test: added create_relationship_through_in_name_reports_the_stored_edge. It runs a real in declaration (superseded_by) through GraphToolExecutor and checks that the result's from_id/to_id/type are the stored forward edge and that the next write's replaced names it byte for byte. Before the fix, this fails: the result echoed from_id: "old".
  • 🟡 Daemon fixture direction: the inbound-eviction test used person tasks as if it were an in name, but it is the forward name. It now uses the ADR supersedes/superseded_by pair.
  • 🟢 Proto comment: CreateRelationshipResponse now documents that it reports the edge as stored.

⏭️ Skipped (2)

  • The model sees the forward name for an inbound write: the review said no change is needed, and it matches the later-turn facts. Worth revisiting only if evals show re-issued calls.
  • Playbook add_relationship echoes its arguments: out of scope, since no consumer compares that output against replaced.

🧪 Agent create_relationship tests 7/7, daemon local_agent_service 85/85.

Re-review: not needed. The changes are tests and one proto comment; no production logic changed.

malibio and others added 2 commits September 27, 2026 22:45
A write through an inbound (`in`-declaration) name is stored as the forward
edge, and a later eviction's `replaced` entry names it that way — but the
write's own label echoed the call's inbound spelling, so the two never
matched and restoring the evicted edge was refused as a duplicate.

- core: create_relationship(_in_tx) returns CreatedRelationship { edge,
  replaced }, where `edge` is the stored forward edge; ReplacedEdge is
  renamed StoredEdge
- rel_ops::CreateRelOutput reports the stored edge, not the input
- agent create_relationship result reports the stored edge as nodespace://
  URIs, the same form as its `replaced` entries
- daemon builds the write label from the result; canonical_args still
  comes from the call's arguments, so guard identity is unchanged; the
  edge_key scheme-stripping shim is gone since both sides now agree

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- agent: create_relationship_through_in_name_reports_the_stored_edge drives
  a real `in` declaration through GraphToolExecutor and checks the result's
  edge equals the later write's `replaced` entry byte-for-byte
- daemon: the inbound-eviction test used person `tasks` as an `in` name, but
  it is the forward name; switch to the ADR supersedes/superseded_by pair
- proto: document that CreateRelationshipResponse reports the stored edge

Skipped: the model seeing the forward name (the reviewer said no change
needed) and playbook add_relationship echoing its args (out of scope; no
consumer compares that output).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio
malibio force-pushed the issue-3106-inbound-evict-label branch from 6f57a08 to 587ea1d Compare September 27, 2026 20:51
@malibio
malibio merged commit 5030b7b into main Sep 27, 2026
@malibio
malibio deleted the issue-3106-inbound-evict-label branch September 27, 2026 20:51
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