Skip to content

Fix validate_no_field_redeclaration blaming the wrong ancestor - #2906

Merged
mstomar125 merged 3 commits into
mainfrom
issue-2871-wrong-blame
Sep 23, 2026
Merged

mstomar125 merged 3 commits into
mainfrom
issue-2871-wrong-blame

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

  • validate_no_field_redeclaration (packages/core/src/schema/mod.rs) resolved the effective field set via resolve_effective_fields, which discards per-field ownership, and always named the immediate parent_id as the "already declared by" schema — even when the true declaring schema was a grandparent or further ancestor.
  • Switches to NodeService::resolve_field_owners's owner map (its second tuple element) to name the schema that actually declares the colliding field, mirroring the fix already applied to validate_no_relationship_redeclaration in Enforce ADR-078 field/relationship shadowing on more write paths #2866.
  • Cosmetic/diagnostic only: the redeclaration was already correctly rejected either way — only the "who owns this" detail in the error message was wrong.

Closes #2871.

Test plan

  • Added a blame assertion to test_redeclaring_a_field_inherited_from_a_grandparent_rejected (create_schema-with-extends path) confirming the error names the true declaring ancestor ("root"), not the immediate parent ("mid")
  • Added the same blame assertion to test_add_fields_only_call_rejects_a_field_inherited_from_a_grandparent (add_fields-only update path)
  • cargo test -p nodespace-core --lib schema:: — 170 passed
  • cargo clippy -p nodespace-core --lib -- -D warnings — clean
  • cargo fmt -p nodespace-core -- --check — clean
  • Full pre-push gate (bun run test:all + cargo build --bin nodespaced + e2e suite) — passed

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Review note (not acted on, recording for future reference): this fix moves `validate_no_field_redeclaration`'s ancestor-chain resolution onto the direct-column path (`resolve_field_owners` → `get_extends_parent_map`), matching what #2866 already did for `validate_no_relationship_redeclaration`. `validate_extends_target`'s cycle check (same file, unchanged, called in the same request) still uses the JSON-hydrated path (`load_parent_map`/`declared_parent`). Under a malformed `properties` JSON column on an extends-declaration row, `parse_declaration_row` could silently drop that edge from the JSON-hydrated path while the direct-column path still sees it — meaning the cycle check and the redeclaration check could theoretically disagree about the extends graph. This divergence between the two resolution mechanisms was introduced by #2866 (not by this PR); this PR just extends the same accepted pattern from relationships to fields. Low-probability edge case requiring data corruption to manifest, not a live bug — flagging for a possible future follow-up (e.g. unifying both call sites on one parent-map resolver) rather than fixing here, to keep this PR scoped to the blame-message bug in #2871.

mstomar125 and others added 3 commits September 23, 2026 11:55
validate_no_field_redeclaration resolved the effective field set via
resolve_effective_fields, which discards per-field ownership, and always
named the immediate extends parent as the "already declared by" schema
in its collision error — even when the true declaring schema was a
grandparent or further ancestor. Switch to
NodeService::resolve_field_owners's owner map, mirroring the fix already
applied to validate_no_relationship_redeclaration in #2866.

Adds a blame assertion to the two existing grandparent-collision tests
(create_schema-with-extends and add_fields-only) confirming the error
names the true declaring schema, not the immediate parent it's merely
inherited through.

Closes #2871.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…failure

validate_no_field_redeclaration's internal-error wrapper named parent_id
as though it were the schema whose lookup failed, even though the DB
failure inside resolve_field_owners can occur on any ancestor further up
the chain. The true failing schema id was still present (nested inside
the underlying NodeServiceError), just prefixed by a wrapper phrase that
read as if parent_id was the one that failed. Reword the wrapper to
describe the chain walk starting from parent_id, not the failing schema.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…nds re-target call site

The re-target call site's existing collision test only collided with the
immediate new parent, where declaring_schema == new_parent regardless of
whether the blame fix is present — it couldn't distinguish correct blame
from buggy blame at that specific call site. Add a grandparent-collision
test mirroring the ones already covering the create-schema and
add-fields-only call sites, confirming the error names the schema that
actually declares the field, not the immediate new parent.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-2871-wrong-blame branch from 63ca981 to 47d63ba Compare September 23, 2026 10:08
@mstomar125
mstomar125 merged commit 58e4bb4 into main Sep 23, 2026
@mstomar125
mstomar125 deleted the issue-2871-wrong-blame branch September 23, 2026 10:15
@mstomar125

Copy link
Copy Markdown
Contributor Author

Follow-up from a final confirmatory review pass (completed after merge, run in parallel with the merge decision — see below): no confirmed correctness bugs found. Two minor, non-blocking findings worth recording:

  1. Two divergent parent-resolution paths within one update_schema request: the add_fields collision check (now resolve_field_owners → resolve_type_chain → store.get_extends_parent_map(), direct SQL) and the neighboring, unchanged add_field_values inherited-field lookup (still resolve_effective_fields → load_parent_map → get_all_schemas(), JSON-hydrated) now read the ancestor chain via two different, non-transactional queries in the same call, where before this diff both went through the identical resolver. Under normal conditions both see identical committed data, so output is unaffected today; this is the same general class of issue as the validate_extends_target/resolve_field_owners divergence already noted in the comment above, extended to a second call site by this PR. Minor perf note too: the ancestor chain and its schemas are now fetched twice for that request shape instead of once.

  2. Doc-comment overclaim: the comment on the resolve_field_owners error wrapper in validate_no_field_redeclaration says the propagated error "already names whichever schema in the chain the underlying lookup actually failed on" — true for a per-schema get_schema_node failure, but not guaranteed if the failure originates in resolve_type_chain's bulk get_extends_parent_map() query, which doesn't name a particular schema. Not a behavioral bug (the real error text is always interpolated via {e}), just a doc-accuracy nit that could mislead a future reader.

Recording both since the review that surfaced them landed after merge (severe shared-machine load meant this pass took ~8.5 minutes to return); neither warrants reopening or a hasty follow-up PR, but both are fair candidates for a future consistency-cleanup pass on the extends-chain resolvers.

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.

validate_no_field_redeclaration always blames the immediate extends parent, not the true declaring ancestor

1 participant