Skip to content

Fix GraphResolver::is_declared_many_relationship to use merged extends-chain relationships - #2865

Merged
mstomar125 merged 3 commits into
mainfrom
issue-2837-graph-resolver-extends
Sep 23, 2026
Merged

mstomar125 merged 3 commits into
mainfrom
issue-2837-graph-resolver-extends

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

GraphResolver::is_declared_many_relationship (packages/core/src/playbook/graph_resolver.rs) looked up a relationship's cardinality via get_schema_node(node_type) — the type's own directly-declared relationships only, not merged across the ADR-078 extends chain. A relationship declared Many only on an ancestor schema and inherited by a subtype node (not redeclared) was misclassified as not-many when the subtype node currently has 0 or 1 related rows: the lookup returned false (nothing found on the bare subtype schema), so shape-inference fell through to count-based inference instead of forcing ResolvedValue::Collection — resolving the relationship as Missing or a bare Node instead of the correct List.

Same bug class as core#2769/core#2819, found in a third location during review of PR #2817.

Changes

  • is_declared_many_relationship now goes through NodeService::resolve_relationships (the effective, extends-chain-merged relationship set, added in PR Merge inherited fields into get_workflow_state's candidate enumeration #2817 / core#2769) instead of a raw single-schema get_schema_node + Schema::get_relationship lookup — the same pattern already used by workflow_state.rs and validation.rs for this exact bug class.
  • Added a regression test (inherited_many_relationship_with_zero_matches_resolves_to_empty_collection) covering a many-relationship declared only on an ancestor schema and inherited (not redeclared) by a subtype instance with zero current matches — before the fix this resolved to Missing, after the fix it correctly resolves to an empty Collection.

Test plan

  • bun run test — 262 test files / 5264 tests passed (baseline, frontend)
  • cargo test -p nodespace-core --lib playbook::graph_resolver — 39/39 passed, including the new regression test
  • bun run quality:fix — clean (0 lint/format errors)
  • Pre-push gate (bun run test:all + cargo build --bin nodespaced + bun run test:e2e) — all green

Closes #2837

🤖 Generated with Claude Code

…s-chain relationships (closes #2837)

is_declared_many_relationship looked up cardinality via get_schema_node's
own directly-declared relationships only, missing a "many" relationship
declared on an ancestor schema and inherited (not redeclared) by a subtype.
With zero or one currently-related rows this misclassified the relationship
as not-many, falling through to count-based inference and resolving it as
Missing or a bare Node instead of the required Collection.

Switch the lookup to NodeService::resolve_relationships, the same
extends-chain merge already used by workflow_state.rs and validation.rs for
this exact bug class (core#2769/#2819). Adds a regression test covering an
inherited many-relationship with zero current matches.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Review Type: Initial Review

Requirements Check (issue #2837):

  • ✅ is_declared_many_relationship now checks the effective (extends-chain-merged) relationship set via NodeService::resolve_relationships, not get_schema_node's own-schema-only lookup — this is the exact "suggested approach" the issue names.
  • ✅ A relationship declared many only on an ancestor and inherited (not redeclared) by a subtype is now correctly recognized, so a subtype instance with 0/1 current matches resolves to Collection instead of falling through to Missing/Node.
  • ✅ Scoped to the one lookup — no changes to GraphResolver's traversal/caching architecture, matching the issue's explicit non-goal.
  • ✅ Mirrors the established pattern from workflow_state.rs/validation.rs (core#2769/validate_play rejects a legitimate Play condition referencing an inherited (extends-chain) field as BrokenPath #2819) for this same bug class, rather than inventing a new approach.
  • ✅ Regression test added (inherited_many_relationship_with_zero_matches_resolves_to_empty_collection), built through handle_create_schema with a real extends chain (not the file's lighter create_schema test helper, which doesn't wire up extends), asserting the previously-broken case now resolves to an empty Collection via resolve_path end-to-end rather than unit-testing the private method directly.

Code Review Findings:

No Critical or Important findings.

🟢 Suggestion

  • The resolve_relationships call re-walks the full extends chain (one get_schema_node per ancestor) on every 0/1-match cardinality check, versus the prior single lookup. This is inherent to resolve_relationships itself, already accepted for the two existing callers, and out of scope per the issue's stated non-goals — not something this PR should fix — but worth keeping in mind if/when general GraphResolver caching work lands.
  • Nit: rels.iter().find(|r| r.name == segment).is_some_and(|r| ...) vs. a single .any(|r| r.name == segment && r.cardinality == Many) — purely stylistic, no behavior or performance difference worth blocking on.

Verified: resolve_relationships's discarded _owners map is correctly irrelevant here (only cardinality is needed, not which schema in the chain owns the declaration); the Err(_) case still conservatively resolves to false via matches!, preserving the documented "fail closed to existing row-count behavior" contract; the diff touches only packages/core/src/playbook/graph_resolver.rs (98/-14), matching the PR's stated scope.

Recommendation: APPROVE

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor 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.

mstomar125 and others added 2 commits September 23, 2026 07:20
…ny()

Combines the find().is_some_and() pair into one any() predicate that
checks name and cardinality together (Nit from PR#2865's
pragmatic-code-review) -- no behavior change.

Skipped the review's other suggestion (resolve_relationships re-walks
the full extends chain on every 0/1-match cardinality check): inherent
to resolve_relationships itself, already accepted for its two existing
callers, and out of this issue's stated non-goals; a general
GraphResolver caching pass is already tracked separately
(issue-2830-resolver-caching).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
probe_inherited_relationship_with_real_attached_data was scratch/debug
code (println! output, throwaway schema names) that ended up committed
alongside the previous address-review commit -- not part of this PR's
intended scope. Removed; the real regression coverage for this fix is
inherited_many_relationship_with_zero_matches_resolves_to_empty_collection,
already present.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Address-Review Summary

Addressed:

  • 🟢 Nit — combined rels.iter().find(...).is_some_and(...) into a single rels.iter().any(...) predicate checking name + cardinality together (no behavior change).

Skipped (with reasoning):

Incidental cleanup: a stray scratch/debug test (probe_inherited_relationship_with_real_attached_data, with println! output) ended up committed alongside the simplification commit — not part of this PR's intended changes. Removed in a follow-up commit; verified via git status --porcelain -uall that nothing else in the worktree was affected, and reran the full targeted test suite (39/39 pass) plus clippy clean afterward.

Separately: reviewing this PR surfaced a real, deeper bug in rel_ops::resolve_relationship_name (own-schema-only forward-name lookup, same bug class, different file) — filed as its own follow-up, #2868, rather than expanding this PR's scope.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The only change since the last review is a trivial, no-behavior-change style simplification (single-predicate .any() instead of .find().is_some_and()), plus removal of accidentally-included scratch code that was never part of the intended diff. Both are low-risk and straightforward per this repo's /address-review criteria.

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.

GraphResolver::is_declared_many_relationship uses own-schema-only lookup, misclassifying an inherited many-relationship

1 participant