Repository navigation
Gate cascade delete on subtree read access (ADR-041) - #1868
Conversation
Adds a pluggable pre-delete access check ahead of delete_subtree_atomic:
a SubtreeAccessGate trait injected into NodeService (AlwaysAllowGate by
default, matching today's behavior for community/local installs). A
synced Pro daemon can inject a real gate once the backing tenant RPC
lands (tracked separately in nodespace-cloud#103). The descendant id
set is computed once and shared between the gate check and the delete
itself so the two can never see different subtrees.
A denied gate aborts the whole delete — no node removed — and surfaces
NodeServiceError::InaccessibleDescendants{count} through OpsError, a
distinct gRPC FailedPrecondition status, and a new frontend refusal
modal state (terminal, no Delete button, count-only disclosure).
Closes #1736.
Co-Authored-By: Claude <[email protected]>
Review TypeInitial full-diff review (no prior review comments on this PR). Requirements CheckCross-referenced against issue #1736's acceptance criteria, applying both scope caveats from the issue comments (this PR is deliberately daemon-side-only plumbing; the authoritative RLS gate lands separately in
Code Review FindingsCritical Issues
In that optimistic path, Net effect: for a Pro-tenant actor whose target node's visible descendant count happens to be zero (because everything underneath is restricted), a refused delete still makes the node disappear from that actor's own UI, with no refusal modal, and no path back short of a full resync. This directly contradicts the stated design goal ("a refusal never causes nodes to flicker out of the UI and come back") for precisely the case the feature was built to protect — a node whose true subtree has inaccessible descendants the actor can't even see. The doc comment at This isn't disqualifying under Caveat 1 (it's not "the stub gate doesn't enforce anything," it's a real bug in the injection-point design that a live Pro daemon would hit), and Caveat 2 doesn't cover it either — it doesn't require a live tenant to see; it's reachable today by constructing a stub Suggested Improvements
Nitpicks
Architectural AssessmentThe
Disclosure Rule (count-only, no identifying information)Traced every point the inaccessible descendant set touches:
No leak found anywhere in the diff. This is clean end-to-end. Security AssessmentReviewed as access-control-adjacent code per instructions, despite the real predicate being explicitly out of scope here:
Recommendation: REQUEST CHANGESThe backend plumbing (gate trait, injection pattern, error propagation chain, disclosure discipline, OCC/precedence correctness) is well-designed and thoroughly tested — this is a strong PR on the server/daemon side. The blocking issue is narrower: the frontend's optimistic-delete shortcut (triggered when the actor's own visible descendant count is zero) bypasses the non-optimistic/refusal-aware path entirely, which can show a node as deleted in the acting user's own UI even when the backend correctly refused the delete — precisely in the "invisible restricted descendant" scenario this feature exists to protect. Given this is access-control-adjacent, user-facing-correctness code, recommend fixing this before merge rather than as a fast-follow: either make cascade deletes with descendants unconditionally non-optimistic (simplest), or add refusal handling to the optimistic path's error catch. Everything else in the PR — architecture, error chain, disclosure rule, OCC precedence, test coverage — is solid and requirement-complete for the stated (and correctly caveated) scope. |
malibio
left a comment
There was a problem hiding this comment.
Review posted above (GitHub does not allow self-authored PRs to request changes) — recommendation is REQUEST CHANGES per the full report: one Critical finding (optimistic-delete path can hide a UI-visible refusal for actors whose visible descendant count undercounts the true subtree), everything else solid.
…tion Critical fix: deleteNode conditioned the non-optimistic (await-before-mutate) path on the locally-visible descendant count. On a synced Pro tenant, RLS silently filters getDescendants to what the actor can already see — a node whose entire child set is restricted-and-invisible reported descendantCount === 0, so the delete fell through to the old optimistic path and could vanish from the deleting actor's own UI before the backend's refusal was known. Now the backend call is always awaited first, regardless of the locally-visible count; this is free on community/local installs where the gate is AlwaysAllowGate and resolves immediately. Also addresses two suggestions: propagate get_node's real error instead of swallowing it via .ok().flatten() in delete_node's early exists-check, and debug_assert a Denied decision always carries inaccessible_count > 0 so a buggy real gate can't surface a "0 items" refusal message. Skipped: HTTP/dev-proxy adapter's plain-Error-on-non-OK gap (isVersionConflict has the same pre-existing gap; out of scope for this PR, worth a follow-up). Addresses reviewer recommendations from PR #1868 review. Co-Authored-By: Claude <[email protected]>
Addressed review feedback🔴 Critical (fixed): 🟡/🟢 addressed:
Skipped: the HTTP/dev-proxy adapter's plain- All tests pass ( Re-Review DecisionRE-REVIEW NEEDED — the critical fix changed core delete-flow control logic (removed the |
Review TypeRe-Review — delta only. Last reviewed at Previous Review Summary
Verification of the Critical Fix(a) Is there any remaining path that mutates local state before the backend resolves? Traced
I confirmed this empirically rather than by reading alone. Temporarily extending the test file's (b) Does removing the conditional break the leaf-node case? No, on all three sub-questions:
(c) Are the two minor fixes correct and regression-free?
(d) Tests against current HEAD — all green:
Code Review Findings🔴 Critical IssuesNone. The prior Critical is closed and independently verified. 🟡 Suggested Improvements
🟢 Nitpicks
New Issues IntroducedNone. Specifically checked for: local-state mutation reachable before the await (none), double-persistence on the leaf path (none — verified empirically), dead code from the removed conditional (none — Recommendation: APPROVEThe Critical is properly closed — not narrowed or worked around, but removed at the root by deleting the conditional entirely, which eliminates the whole "locally-visible count lies about the true subtree" bug class rather than patching one instance of it. I verified the fix empirically rather than by inspection: a refused leaf delete now leaves the UI untouched, and a successful leaf delete still writes exactly once. The two minor fixes are correct, the The one 🟡 — the missing |
malibio
left a comment
There was a problem hiding this comment.
Re-Review Recommendation: APPROVE
(GitHub does not allow approving your own pull request, so this is filed as a COMMENT review — the recommendation is APPROVE.)
The prior Critical is closed at the root: the descendantCount > 0 conditional is removed entirely, so the backend delete is always awaited before any local-state mutation. Verified empirically, not just by inspection — a refused delete on a leaf node now leaves the node in the store and does not fire nodeDeleted, and a successful leaf delete still issues exactly one backendAdapter.deleteNode call (no double-write via skipPersistence). Both minor fixes are correct, and the absent-target idempotency contract survives the crud.rs error-propagation change.
All checks green: 1075 Rust lib tests, 4116 frontend tests, clippy clean, eslint + svelte-check clean (1869 files, 0 errors).
One non-blocking 🟡: the test mock for delete-confirmation.svelte omits showInaccessibleDescendantsRefusal, so the refusal path has no repo test covering it. Worth a small follow-up commit as a regression guard. Full report in the comment above.
Follow-up to the prior commit: the re-review confirmed the fix is correct but noted the test mock for delete-confirmation.svelte didn't export showInaccessibleDescendantsRefusal, so the exact scenario the fix protects against (a refused delete must leave local state untouched, not just cascades) had no test coverage in the repo. Adds the missing mock export plus two tests: a leaf-node delete calls backendAdapter.deleteNode exactly once (no double-write), and a leaf-node delete refused with INACCESSIBLE_DESCENDANTS leaves the node in the store and never fires nodeDeleted — the regression guard for the bug just fixed. Co-Authored-By: Claude <[email protected]>
Follow-up: added the regression test coverage the re-review flaggedRe-review approved the critical fix and confirmed it's correctly closed, but noted (🟡) the test mock for Added the missing mock export plus two tests in
All 116 tests in that file pass; full This is additive test coverage only, no production code changed — no further re-review needed. PR is ready for merge at your discretion. |
PR #1868 landed the full vertical slice: SubtreeAccessGate trait + AlwaysAllowGate default, plus a complete error-propagation chain (NodeServiceError::InaccessibleDescendants, an OpsError variant, a dedicated gRPC FailedPrecondition status, a Tauri CommandError code, and a terminal frontend refusal modal) for a Denied state no caller in this codebase can produce today. Keeps the generic, already-wired seam: SubtreeAccessGate trait, AlwaysAllowGate, the NodeService injection point, and the collect_subtree_ids/delete_subtree_atomic refactor. Removes the product-surface plumbing built only against a synthetic test gate: the typed error, gRPC status mapping, Tauri command code, and frontend refusal modal/state. The delete_node call site keeps invoking the gate, but a Denied decision now maps to the existing HierarchyViolation error as a placeholder until a real Pro gate lands with its own typed error and UI treatment. reactive-node-service.svelte.ts's deleteNode reverts to optimistic-for-leaf-nodes behavior (no unconditional await), since the non-optimistic path existed solely to protect the now-removed refusal UX. Co-authored-by: Claude <[email protected]>
Summary
delete_subtree_atomic: aSubtreeAccessGatetrait injected intoNodeService, defaulting toAlwaysAllowGate(matches today's unconditional-cascade behavior for community/local installs — no access model exists there).SqliteStore::collect_subtree_ids) and shared between the gate check and the delete itself, so they can never disagree on what's being checked vs. deleted.NodeServiceError::InaccessibleDescendants { inaccessible_count }throughOpsError→ a distinct gRPCFailedPreconditionstatus (x-inaccessible-descendantsmetadata) → a newINACCESSIBLE_DESCENDANTSTauriCommandErrorcode → a terminal frontend refusal modal (no Delete button, count-only disclosure — never ids/names/types).reactive-node-service'sdeleteNodeis non-optimistic for any node with descendants: it now awaits the backend response before touching local state, so a refusal never causes nodes to flicker out of the UI and come back.Scope note
This repo (
nodespace-core) is the local daemon and has no access-control concept of its own — the real enforcement authority is the Pro tenant schema innodespace-cloud(ADR-041). That authoritative subtree-read-check RPC doesn't exist yet; a companion issue is open to add it: NodeSpaceAI/nodespace-cloud#103. Until that lands and a Pro daemon (nodespaced-pro, built innodespace-sync) injects a real gate viaNodeService::set_subtree_access_gate, community installs are unaffected —AlwaysAllowGateis the only gate in play, matching current behavior exactly.Test plan
bun run test:all— full workspace (frontend 171 files/4113+ tests, all Rust crates) — 0 failuresbun run quality:fix— clean, unrelated formatting drift reverteddeletes_a_node_and_confirms_it_is_absent(existing single-node delete path unaffected)Closes #1736.