Repository navigation
Reject extends/extended_by in remove_relationships - #2893
Merged
Merged
Conversation
update_schema's remove_relationships is a generic by-name removal over the same relationship-table-backed declaration list the extends edge is stored in, so a caller could pass remove_relationships: ["extends"] to silently clear it — contradicting UpdateSchemaParams::extends's own documented contract that the edge can only be re-targeted, never cleared. reject_reserved_relationship_names already blocked a hand-declared "extends"/"extended_by" relationship in add_relationships; apply the same rejection (built-in structural names too, for parity) to remove_relationships's name list before any mutation runs. Rewrite the two tests that previously asserted remove_relationships could clear extends (added alongside this back door's discovery in PR #2866) to assert the rejection instead, add reverse-name and built-in-name coverage, and correct the now-stale comments describing remove_relationships as a path that can drop the extends declaration. Co-Authored-By: Claude Sonnet 5 <[email protected]>
The pragmatic-code-review on PR #2893 found that closing the remove_relationships back door had a critical side effect: any schema ever given an extends parent became permanently undeletable, because count_schema_declaration_edges (packages/core/src/db/sqlite_store/relationships.rs) counted a schema's own extends declaration as a blocking relationship, and the only way to previously clear that declaration was the back door this PR closes. Fix: exclude a schema's own extends declaration (in_node = the schema being checked, i.e. it's the declaring/child side) from the blocking count, while still counting it when the schema is the target/parent another schema still extends (out_node = the schema being checked) — deleting a schema deletes its own extends row along with it, but deleting a schema other schemas still extend would silently strand those children. Adds deleting_an_extending_schema_succeeds_but_deleting_its_parent_is_still_blocked covering both directions. Also from review: shared the reserved-name classification between reject_reserved_relationship_names and reject_reserved_relationship_removal_names (both now call classify_reserved_relationship_name) instead of duplicating the built-in/type-system checks; corrected the TypeSystem doc comment to note extended_by was already an inert no-op pre-PR; and updated the DELETE_A_SCHEMA skill rule (packages/agent/src/skill_rules.rs) with an extends exception, regenerating packages/skill/references/cli.md and the prompt-assembly golden to match. Two lower-severity review findings intentionally left open, noted as follow-ups in the PR description: the new removal-name check runs before the schema-existence check (produces a misleading error for a nonexistent schema_id + remove_relationships:["extends"] — low severity, matches existing precedent for other early input-shape checks in this function); and a suggestion to make the reserved-name guard structural (e.g. via builtin_exclusion_sql) rather than a second name-based gate, which is an architecture-level change beyond this issue's scope. Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.
Summary
UpdateSchemaParams::extends's doc comment states theextendsedge can only be re-targeted, never cleared — butremove_relationshipsis a generic by-name removal over the same relationship-table-backed declaration listextendsis stored in, and nothing stopped a caller from passingremove_relationships: ["extends"]to silently clear it.reject_reserved_relationship_namesalready blocked a hand-declaredextends/extended_byrelationship inadd_relationships, but was never applied toremove_relationships's name list.Two tests added alongside this back door's discovery (PR #2866) actually asserted the opposite — that
remove_relationships: ["extends"]successfully cleared the edge — which confirmed the back door was real and exercised, not hypothetical.Changes
reject_reserved_relationship_removal_names(sharing aclassify_reserved_relationship_namehelper with the existingadd_relationshipsguard), applied toremove_relationshipsbefore any mutation runs inhandle_update_schema. Rejectsextends/extended_by(the type-system relationship, stored as an ordinary declaration) and, for parity withadd_relationships, built-in structural names likehas_child(never stored as declarations, so naming one was already a no-op — now it's a clear error instead of a silent one).remove_relationships: ["extends"]succeeded to assert it's now rejected, and that a rejected call leaves the extends edge untouched. Added coverage for the reverse spelling (extended_by) and a built-in structural name.remove_relationshipsas a path capable of dropping theextendsdeclaration.Fixed from
/pragmatic-code-reviewThe review caught a critical regression this fix would otherwise have introduced: closing the back door meant any schema ever given an
extendsparent would become permanently undeletable, sincecount_schema_declaration_edges(packages/core/src/db/sqlite_store/relationships.rs) counted a schema's ownextendsdeclaration as a blocking relationship, and the back door had been the only way to clear it before deletion.extendsdeclaration (where the schema being checked is the declaring/child side) from the blocking count, while still counting it when the schema is the target/parent another schema still extends — deleting a schema deletes its ownextendsrow along with it, but deleting a schema other schemas still extend would silently strand those children. Addeddeleting_an_extending_schema_succeeds_but_deleting_its_parent_is_still_blockedcovering both directions.DELETE_A_SCHEMAagent-skill rule (packages/agent/src/skill_rules.rs) with anextendsexception (the generic "remove_relationships then delete" recipe doesn't apply to it), regeneratingpackages/skill/references/cli.mdand the prompt-assembly golden snapshot to match.Follow-ups noted, not fixed inline (low severity / out of scope)
remove_relationshipsreserved-name check runs before the schema-existence check, soupdate_schema({schema_id: "nonexistent", remove_relationships: ["extends"]})reports the reserved-name rejection rather than "schema not found." Matches existing precedent — other early input-shape checks inhandle_update_schema(describe_malformed_fields,describe_missing_reverse_fields) already run before the existence check the same way.builtin_exclusion_sqlto also excludeTYPE_SYSTEM_RELATIONSHIP_NAMES) rather than a second explicit name-based gate, so a future by-name relationship-mutation path can't reintroduce this bug class by omission. Architecture-level change beyond this issue's scope.Why this direction
The doc comment on
UpdateSchemaParams::extendsandtest_update_without_extends_leaves_the_edge_untouchedboth already assert "there is no way to clear" the edge — closing the back door (rather than legalizing clearing and adding impact-analysis parity to the removal path) is the fix consistent with that existing, intentional contract. The issue's narrow-impact note (no normal schema-authoring flow namesextendsinremove_relationships) held up — the only prior reliance was the two just-discovered regression tests, not a real caller.Closes #2873
Test plan
cargo test -p nodespace-core --lib schema::/--test schema_relationship_declarations_test— all passing, including new/rewritten testscargo test -p nodespace-core --lib— 1667 passedcargo test -p nodespace-agent -p nodespace-cli— all passing, including the updated prompt-assembly golden andchecked_in_skill_md_is_up_to_datebun run quality:fix— clean (eslint, tsc, svelte-check, cargo fmt, cargo clippy -D warnings)test:all+cargo build --bin nodespaced+test:e2e) — all green, twice (once per push)🤖 Generated with Claude Code