Repository navigation
Surface access-gated cascade-delete refusal as a typed error + modal (nodespace-sync#413 core half) - #2029
Conversation
… + modal
The SubtreeAccessGate seam (ADR-041) already refused a cascade delete whose
subtree contains nodes the caller can't read, but mapped it to a generic
HierarchyViolation → INVALID_ARGUMENT, indistinguishable from ordinary
validation — so the frontend couldn't tell a refusal apart. Make it a
first-class, user-visible outcome:
- New NodeServiceError::SubtreeAccessDenied { inaccessible_count } (not the
shared bare-string HierarchyViolation); the gate's Denied branch returns it.
- New OpsError::SubtreeAccessDenied → maps to gRPC Status::failed_precondition
with the count in x-subtree-inaccessible-count metadata (mirroring how a
version conflict carries x-version-conflict), so the status is distinct from
validation and from OCC.
- Frontend: status_to_command_error → a SUBTREE_ACCESS_DENIED command code
carrying { inaccessibleCount }; an isSubtreeAccessDenied guard; a global
refusal modal ("N item(s) not visible — nothing was deleted").
- The delete is optimistic (the node is removed locally before the backend
call), so on a refusal the store restores exactly what the optimistic removal
stripped (node, version, persisted-set membership, subscriber notify) and
shows the modal. Descendants are only removed via post-commit events, which
never fire on a refusal, so restoring the target node is sufficient.
Community/no-Pro path is unchanged (AlwaysAllowGate never denies). This is the
core half of sync#413; the daemon-side gate that actually calls the cloud
subtree_inaccessible_count, and live validation, follow separately.
Part of #413.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…code Two real defects from review: - The optimistic restore lived only at the store layer, but the reactive view service owns `_rootNodeIds` (the top-level view's source of truth) and strips the node from it synchronously — so a refused top-level delete restored the store yet the node stayed gone from the UI. The store's deleteNode now takes an `onRefused` callback it invokes (after restoring its own state) so the view service restores `_rootNodeIds`/`_uiState` too. The store delete is fire-and-forget, so this callback is how the refusal (which lands async) reaches the view layer. Covered by store-level onRefused tests (fires on a refusal, not on success or a non-refusal error). - status_to_command_error branded EVERY FailedPrecondition as SUBTREE_ACCESS_DENIED, but the daemon returns FailedPrecondition from unrelated paths (node-create / schema failures). Now the code is assigned only when the x-subtree-inaccessible-count metadata is actually present; otherwise it falls through to GRPC_ERROR. Also (minor): renamed the version-conflict precedence test to say what it verifies (conflict reported when the gate allows) and added a genuine both-true test asserting the access refusal PRECEDES the version conflict — the gate runs before the OCC check, so we never leak version state on an access denial. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
APPROVE (self-review, mstomar125) Two-pass adversarial review of this security path. Core abort integrity confirmed first pass: the gate runs strictly before First pass found two real MAJORs the delegated build's own tests masked — (1) the optimistic restore lived only at the store layer, so a refused top-level delete restored the store but left the node gone from the UI ( Second pass verified all three fixes correct and complete, no new defects. Gate green on both pushes; core lib 1139, daemon, frontend 4557 tests; lint + svelte-check clean. Part of nodespace-sync#413 (core half). The daemon-side gate + core-pin bump + live Pro/RLS validation follow separately. |
Summary
The core half of sync#413. The
SubtreeAccessGateseam (ADR-041, core#1870) already refuses a cascade delete whose subtree contains nodes the caller can't read — but it mapped that refusal to a genericHierarchyViolation → INVALID_ARGUMENT, indistinguishable from ordinary validation, so the frontend couldn't tell a refusal apart to show anything useful. This makes the refusal a first-class, user-visible outcome, threaded end-to-end, and restores the optimistically-removed node when it happens.Changes
Backend
NodeServiceError::SubtreeAccessDenied { inaccessible_count }— a dedicated variant (not the shared bare-stringHierarchyViolation, which is also used for real hierarchy errors like "cannot move root"). The gate'sDeniedbranch indelete_nodereturns it.OpsError::SubtreeAccessDenied→ mapped in the daemon'sops_error_to_statustoStatus::failed_preconditionwith the count inx-subtree-inaccessible-countmetadata — mirroring exactly how a version conflict carriesx-version-conflict. Distinct fromINVALID_ARGUMENT(validation) andABORTED(OCC).Frontend
status_to_command_error→ aSUBTREE_ACCESS_DENIEDcommand code carrying{ inaccessibleCount }; anisSubtreeAccessDeniedtype-guard (mirroringisVersionConflict).subtree-access-denied-modal.svelte, mounted in+layout.sveltenext to the delete-confirmation modal), triggered via a small$statestore — "N item(s) not visible to you — nothing was deleted."Safety
AlwaysAllowGatenever denies, so none of this branch is reachable there.delete_subtree_atomic; aDeniedreturns the error with no mutation. Version-conflict still takes precedence (existing test preserved).Scope / what follows separately
This is the core half only. The daemon-side
ProSubtreeAccessGatethat actually calls the live cloudsubtree_inaccessible_countover PostgREST lives in nodespace-sync and is blocked on a core-pin bump there (the pinned rev predates theSubtreeAccessGateseam). That gate + a core-pin bump + live Pro/RLS validation are the remaining work on #413. The deployed cloud function is root-only (server-sidehas_childwalk; raises42501if the root itself is unreadable), so the gate passes just the root — no client-supplied id list (which also closes the count-fishing vector the threat model flagged).Tests
SubtreeAccessDenied { inaccessible_count }(and that version-conflict still wins; fully-readable/atomic/idempotent tests unchanged).cargo test -p nodespace-core --lib1138 pass.OpsError::SubtreeAccessDenied→failed_precondition+x-subtree-inaccessible-count.isSubtreeAccessDeniedguard cases + a restore test driving the realSharedNodeStore(vi.spyOnonbackendAdapter, no singletonvi.mock) — asserts restore + modal on refusal, and that a non-refusal error leaves the node deleted.bun run test4555 pass; lint + svelte-check clean.Part of #413.
🤖 Generated with Claude Code