Repository navigation
Refuse deleting an extended or core schema (closes #2889) - #3095
Conversation
Pragmatic Code Review: PR #3095Review Type: Initial Review SummaryThis is a small, focused change that improves code health. I verified the bypass paths:
No legitimate flow needs to delete a core or extended schema. Requirements Check
Code Review Findings🟡 Improvements
🟢 Nits / Minor
Project rules: There is no backward-compat code, no issue numbers in code comments (ADR references only) and no lint suppressions. The error variant has a constructor that follows the existing pattern. Recommendation: APPROVEThis is a net positive and meets both maintainer decisions. Finding 1 (subtree bypass) is worth fixing in this PR or a quick follow-up, because it is the one remaining route to the exact corruption this PR prevents. Finding 2 is a two-line doc fix. Neither blocks merge. |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Addressed review (740085b)
core + daemon + agent + cli nextest: 3506 passed. Re-review needed: the guard's scope changed from the target to the whole subtree. |
Pragmatic Code Review: PR #3095 (re-review of 740085b)Review Type: Re-Review Previous Review Summary: 7 recommendations. 4 were addressed (#1, #2, #5, #6). 3 were skipped with a stated reason, and all 3 skips are justified (#3, #4, #7). This pass adds 1 new 🔴 issue, 2 new 🟡 issues and 3 new 🟢 issues. The 🔴 comes from an error in my previous review. Correction to the previous reviewFinding #2 said "I found no such guard: the
A third test asserts that the CLI surfaces this error: Verification of the new commit
Code Review Findings🔴 Must fix
🟡 Improvements
🟢 Nits / Minor
Recommendation: REQUEST CHANGESThe subtree logic in this commit is correct and well tested, and the PR as a whole is still a net positive. However, #1 is a documentation regression that I caused, and it tells agents the opposite of what the daemon does, so it should not merge as is. The fix is two lines. #2 does not block merge on its own: at minimum fix the stale |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (re-review): REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Addressed re-review (b532ca0)
Re-review needed: the design changed. |
Pragmatic Code Review: PR #3095 (re-review 2, of b532ca0)Review Type: Re-Review Previous Review Summary: Re-review 1 raised 1 🔴, 2 🟡 and 3 🟢. All are resolved:
The one deliberate trade-off is that the doomed-set exemption is dropped. A parent and child in the same subtree are now refused, which errs in the safe direction. I accept it. Deleting the child first is a clear, actionable path. Verification
Code Review Findings🟡 Improvements (non-blocking, follow-up)
🟢 Nits
Recommendation: APPROVEThe design is now right: one guard, at the store layer, which every delete path already passes through, extended to cover core schemas and the whole subtree. The previous 🔴 and 🟡 findings are resolved, the tests are targeted and green across all affected crates, and the skill docs are in sync. Finding 1 is a follow-up that fixes the root cause, not a blocker. |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (re-review 2): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Addressed re-review 2 (2df0b4c)
No re-review needed: the only change is a comment. |
delete_node now refuses a schema target with SchemaDeleteRefused when it is a core schema, or when another schema extends it — every extends-chain resolver skips a missing ancestor, so deleting a parent silently stripped its descendants of all inherited fields and relationships (ADR-078). Delete the extending schemas first. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- Run the schema guard over every node in the has_child subtree, not just the target: a schema moved under a text node was deleted along with it, bypassing the guard. A parent whose children are all in the same subtree stays deletable. Candidates are limited to core ids and extends parents, so an ordinary delete reads no extra nodes. - Document the pre-transaction TOCTOU window, same as the access gate. - Fix the stale `schema delete` CLI help (it described a relationship- declaration refusal that doesn't exist). - Tests: grandchild chain unwinds leaf-first; subtree holding an extended or core schema is refused; subtree holding the whole chain is allowed. Skipped: targeted out_node query (the subtree check needs the whole parent map anyway); FAILED_PRECONDITION status (would need a new OpsError variant; INVALID_ARGUMENT matches CollectionCycle today). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The store's assert_schema_deletable already refused deleting a schema another schema extends (the extends parent row counts as a declaration), on every delete path — so the service-level guard duplicated it. Removed it, and instead: - assert_schema_deletable refuses core schemas (`schema_is_core`). - delete_subtree_atomic runs the guard on every schema in the subtree, not just the target: move_node can put a schema under ordinary content, and deleting that container cascaded the schema away unchecked. - CLI `schema delete` help restored (it was accurate); agent skill rule and the generated cli.md mention the core-type refusal. - The core-schema reseed test now removes its fixture schema with the unchecked store delete. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…-only Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2df0b4c to
c073705
Compare
Summary
Closes the remaining gaps in schema deletion. The
extendscase in #2889 was already guarded: the store'sassert_schema_deletablecounts a live child'sextendsrow against the parent, so deleting an extended schema directly is refused withschema_has_declarationson every delete path. Two real holes remained, and this PR fixes both in that same store guard:assert_schema_deletablenow refusesisCoreschemas withschema_is_core. This was the maintainer decision on No guard against deleting a schema with extended_by children — descendants silently lose all inherited fields/relationships #2889.delete_subtree_atomiconly guarded the target.move_nodecan put a schema under ordinary content, and deleting that container cascaded the schema away, core or extended. The guard now runs on every schema in the subtree. A SQL filter finds them, so an ordinary content subtree reads no extra rows.The agent skill rule and the generated
references/cli.mdnow mention the core-type refusal. There is also one unrelated rustfmt hunk innode_service/mod.rsthatquality:fixinsists on.Tests
test_delete_core_schema_refusedtest_delete_refused_when_subtree_contains_an_extended_schematest_delete_refused_when_subtree_contains_a_core_schematest_delete_allowed_when_subtree_holds_an_unreferenced_schemaextendscases stay covered byschema_relationship_declarations_test.rs.🤖 Generated with Claude Code