Skip to content

Reject extends/extended_by in remove_relationships - #2893

Merged
mstomar125 merged 2 commits into
mainfrom
issue-2873-remove-relationships-extends
Sep 23, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-2873-remove-relationships-extends

Conversation

@mstomar125

@mstomar125 mstomar125 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

UpdateSchemaParams::extends's doc comment states the extends edge can only be re-targeted, never cleared — but remove_relationships is a generic by-name removal over the same relationship-table-backed declaration list extends is stored in, and nothing stopped a caller from passing remove_relationships: ["extends"] to silently clear it. reject_reserved_relationship_names already blocked a hand-declared extends/extended_by relationship in add_relationships, but was never applied to remove_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

  • Added reject_reserved_relationship_removal_names (sharing a classify_reserved_relationship_name helper with the existing add_relationships guard), applied to remove_relationships before any mutation runs in handle_update_schema. Rejects extends/extended_by (the type-system relationship, stored as an ordinary declaration) and, for parity with add_relationships, built-in structural names like has_child (never stored as declarations, so naming one was already a no-op — now it's a clear error instead of a silent one).
  • Rewrote the two existing tests that asserted 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.
  • Corrected now-stale comments that described remove_relationships as a path capable of dropping the extends declaration.

Fixed from /pragmatic-code-review

The review caught a critical regression this fix would otherwise have introduced: closing the back door meant any schema ever given an extends parent would become permanently undeletable, since 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 back door had been the only way to clear it before deletion.

  • Fixed by excluding a schema's own extends declaration (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 own extends row along with it, but deleting a schema other schemas still extend would silently strand those children. Added deleting_an_extending_schema_succeeds_but_deleting_its_parent_is_still_blocked covering both directions.
  • Updated the DELETE_A_SCHEMA agent-skill rule (packages/agent/src/skill_rules.rs) with an extends exception (the generic "remove_relationships then delete" recipe doesn't apply to it), regenerating packages/skill/references/cli.md and the prompt-assembly golden snapshot to match.

Follow-ups noted, not fixed inline (low severity / out of scope)

  • The new remove_relationships reserved-name check runs before the schema-existence check, so update_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 in handle_update_schema (describe_malformed_fields, describe_missing_reverse_fields) already run before the existence check the same way.
  • Suggestion to make the reserved-name guard structural (e.g. extending builtin_exclusion_sql to also exclude TYPE_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::extends and test_update_without_extends_leaves_the_edge_untouched both 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 names extends in remove_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 tests
  • cargo test -p nodespace-core --lib — 1667 passed
  • cargo test -p nodespace-agent -p nodespace-cli — all passing, including the updated prompt-assembly golden and checked_in_skill_md_is_up_to_date
  • bun run quality:fix — clean (eslint, tsc, svelte-check, cargo fmt, cargo clippy -D warnings)
  • Pre-push gate (test:all + cargo build --bin nodespaced + test:e2e) — all green, twice (once per push)

🤖 Generated with Claude Code

mstomar125 and others added 2 commits September 23, 2026 09:35
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]>
@mstomar125
mstomar125 merged commit b48a687 into main Sep 23, 2026
@mstomar125
mstomar125 deleted the issue-2873-remove-relationships-extends branch September 23, 2026 09:16
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.

update_schema's remove_relationships can silently clear the extends edge

1 participant