Skip to content

Scope reverse-cardinality eviction by ownership equality (#2909) - #3282

Merged
mstomar125 merged 2 commits into
mainfrom
issue-2909-owner-equality
Sep 29, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-2909-owner-equality

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #2909

Root cause

Reverse-cardinality scoping decided whether an existing inbound edge belongs to the declaration being validated with type_satisfies(existing_source_type, declaring_type), an ancestor-chain membership check. If a nearer schema shadows an inherited relationship of the same name (only possible via the low-level set_schema_relationships, which skips cross-chain collision validation), the ancestor is still in the chain, so the shadowing schema's edges were misattributed to the ancestor's declaration and wrongly evicted/dropped.

Fix

New NodeService::source_resolves_relationship_to (relationship.rs) compares the existing source's own nearest-first owner (resolve_relationships owners map) for the relationship name against the declaring type: ownership equality. Used at both sites: create_relationship_in_tx and the merge re-point collision check. Chose the equality patch over the persisted-declaring-schema column (no DDL change / DB reset needed).

Tests

Not reachable today, so the state is constructed directly: shadow_child extends shadow_base, both declaring owns (reverse cardinality one); the child's shadow is written with set_schema_relationships after create_schema. Tests (relationship.rs, required_in_last_edge_tests):

  • reverse_cardinality_scope_ignores_edges_owned_by_a_shadowing_declaration (create path; also asserts same-declaration edges are still replaced)
  • merge_repoint_ignores_edges_owned_by_a_shadowing_declaration (merge path)

Mutation check: reverting each call site to type_satisfies individually makes its test fail (other passes).

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Review summary (pragmatic-code-reviewer, medium, static): CLEAN, no correctness findings. Checked both call sites (create_relationship_in_tx, merge re-point) and edge cases (self-owned type, non-shadowing subtype, missing/virtual types, extends exclusion); the only behaviour change is the intended shadowing case. Tests construct the shadow via set_schema_relationships and each was mutation-checked against type_satisfies.

Nits, not addressed: (1) helper re-resolves the chain per existing reverse edge inside the write tx (typically 0-1 edges; a per-call cache would suffice for merge); (2) other type_satisfies uses scope by target type, not declaration ownership, so left as is; (3) optional comment pointer to the helper at the merge site.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Merge queue: #3282 was taken out of the queue — the merge gate failed on it, rebased onto main. Reproduce with git rebase origin/main and bun run test:changed, fix, push, and re-run bun run merge 3282.

packages/agent/src/local_agent/agent_loop.rs:7864: /// The exact shape observed in #2281: two `create_node` calls actually ran
packages/agent/src/local_agent/agent_loop.rs:8136: // The #1937 shape: update_node ran, succeeded, persisted nothing, and
packages/agent/src/local_agent/agent_loop.rs:8758: /// #1943, the propagation half: the assistant turn persisted into history
packages/agent/src/local_agent/agent_loop.rs:11107: /// #1943: the verbatim payload from the issue's 3-of-3 reproduction, run
packages/agent/src/local_agent/agent_loop.rs:11198: /// #2182: verbatim shape from the golden-runner trace behind the issue —
packages/agent/src/local_agent/agent_loop.rs:11375: /// #1926: verbatim shape from the daemon.log trace behind the issue — a
packages/agent/src/local_agent/agent_loop.rs:11731: // #1909: route_multi re-enters retrieval once per intent rather than
packages/agent/src/local_agent/agent_loop.rs:12455: // here reproduces #1840's defect through a second door.
packages/agent/src/local_agent/agent_loop.rs:12667: // #1930: the structured question/options must reach the caller
packages/agent/src/local_agent/agent_loop.rs:13684: // #1909: an unlabeled blend of prior turns + current message read to
packages/agent/src/local_agent/tools.rs:508: /// hint (`render_resolve_query_field_line`) added in #1915: the hint reduces
packages/agent/src/local_agent/tools.rs:678: // #1943 splice (3 of 3 reps produced byte-identical
packages/agent/src/local_agent/tools.rs:684: // #2182 is the counter-example, and it cuts the
packages/agent/src/local_agent/tools.rs:5972: /// #1915: the decomposition prompt states the expected JSON encoding
packages/agent/src/local_agent/tools.rs:6039: JSON strings — the reverse-direction drift #1915 calls out; got:\n{prompt}"
packages/agent/src/local_agent/tools.rs:6670: // Reverse-direction drift (#1915's own motivating scenario): a
packages/agent/src/local_agent/routing.rs:1211: // The #2240 regression. `Node Deletion` was retrieved as a candidate on
packages/agent/src/local_agent/routing.rs:1796: // The regression case #1840 calls out explicitly: a Graph Editing
packages/agent/src/local_agent/routing.rs:2061: /// comment (#1846: two independently-maintained copies of this heading,
packages/agent/src/local_agent/routing.rs:2094: /// Measured 2026-07-31 for the duplication question in #1848: **4 copies
      at <anonymous> (/Users/mayanktomar/nodespace/core/.claude/worktrees/_gate/scripts/check-code-references.test.ts:219:67)
(fail) real-repo ratchet > current repo counts do not exceed the checked-in baselines [434.21ms]
scripts/eval/preflight.test.ts:
[preflight] Skill index not ready (0/8 retrievable). Embeddings run on a ~30s debounce; waiting so turns are not scored against an empty index.
[preflight] Skill index ready (8/8) after 0s.
[preflight] Skill index not ready (0/8 retrievable). Embeddings run on a ~30s debounce; waiting so turns are not scored against an empty index.
[preflight] Skill index not ready (8/9 retrievable). Embeddings run on a ~30s debounce; waiting so turns are not scored against an empty index.
[preflight] Skill index not ready (7/8 retrievable). Embeddings run on a ~30s debounce; waiting so turns are not scored against an empty index.
 729 pass
 1 fail
 1780 expect() calls
Ran 730 tests across 36 files. [21.78s]
error: script "test:scripts" exited with code 1
[stage exited with code 1]

  full output: /var/folders/3w/y9kj522n1_j9wqmt6vl_sb6r0000gp/T/nodespace-gate-logs/_gate-merge-2026-09-29T06-29-34-006Z/test-scripts-tooling.log

✗ test:scripts (tooling) failed — merge blocked.
  Fix the failure, push, and re-run: bun run merge <PR#>

@mstomar125

Copy link
Copy Markdown
Contributor Author

Removed the two issue references from doc comments (code-reference ratchet), rebased on origin/main; test:scripts, fmt and clippy pass.

@mstomar125
mstomar125 force-pushed the issue-2909-owner-equality branch from 6e8cbe0 to 357b32a Compare September 29, 2026 06:46
mstomar125 and others added 2 commits September 29, 2026 09:04
… not chain membership

create_relationship_in_tx and the merge re-point check decided whether an
existing inbound edge belonged to the declaration being validated with
type_satisfies (declaring type is somewhere in the source's chain). When a
nearer schema shadows an inherited relationship of the same name, that
misattributed the shadowing schema's edges to the ancestor's declaration.
Both sites now compare the existing source's own nearest-first owner for the
relationship name against the declaring type.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-2909-owner-equality branch from 357b32a to ebaed45 Compare September 29, 2026 07:05
@mstomar125
mstomar125 merged commit c420d7b into main Sep 29, 2026
@mstomar125
mstomar125 deleted the issue-2909-owner-equality branch September 29, 2026 07:05
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.

reverse-cardinality scoping uses ancestor-chain membership, not ownership equality (not reachable today)

1 participant