Skip to content

B6: Exhaustive core→gRPC error mapping + parity tests (no catch-all to Status::internal) #1254

Closed

Description

@malibio

Spun off from architectural-audit tracking issue #1228, finding B6. Backend-only; no overlap with the in-flight frontend C-cluster work.

Background (from audit #1228)

B6 — Lossy core→gRPC error mapping 🟠
service_error_to_status() routes most variants through a generic OpsError pass-through; fetch_node() wraps everything as Status::internal(). Clients can't distinguish not-found / version-conflict / validation.
Action: map every NodeServiceError variant explicitly; ensure VersionConflict → aborted; add parity tests.

Verified current state — the audit OVER-states this; it's mostly done. Scope is now narrow.

After the B3/B4 work (#1244) routed the daemon through node_ops, the error path is:
NodeServiceError → From<NodeServiceError> for OpsError (packages/core/src/ops/mod.rs:42) → ops_error_to_status (daemon/src/services/node_service.rs:1387) → Status.

The important mappings ALREADY exist (verified):

  • NodeNotFound → OpsError::NotFound → Status::not_found ✅
  • VersionConflict → OpsError::VersionConflict → Status::aborted ✅ (the audit's specific ask is already satisfied — ops_error_to_status:1388-1393)
  • ValidationFailed / InvalidParent / InvalidRoot / CircularReference / HierarchyViolation → OpsError::ValidationFailed → Status::invalid_argument ✅
  • PlaybookValidationFailed → InvalidParams → invalid_argument; CollectionNotFound → NotFound → not_found ✅

So service_error_to_status is NOT a generic pass-through anymore — it delegates to a conversion that explicitly distinguishes not-found / version-conflict / validation. The audit's premise is stale.

The REAL remaining gaps (the actual scope of this issue):

  1. From<NodeServiceError> catch-all flattens several variants to Internal (ops/mod.rs, the other => OpsError::Internal(other.to_string()) arm). These collapse to Status::internal, losing client-actionable distinction:
    • DatabaseError, TransactionFailed → arguably Status::internal/unavailable is fine (genuinely internal) — but decide deliberately, don't leave them in a catch-all by accident.
    • InvalidUpdate(String) → should be invalid_argument, not internal (it's a client error).
    • QueryFailed, SerializationError, BulkOperationFailed → assess: client-actionable or genuinely internal? Map explicitly.
  2. fetch_node (daemon/src/services/node_service.rs:1265) wraps get_node failure as Status::internal(format!("get_node failed...")) and only returns not_found for the missing-row case. A NodeServiceError from get_node (e.g. a DatabaseError) is correctly internal, but verify it isn't swallowing a distinguishable variant. Low priority — confirm it's correct rather than rewrite.
  3. No parity tests asserting the variant→Status mapping. This is the main deliverable.

The task

  1. Make From<NodeServiceError> for OpsError exhaustive (ops/mod.rs:42): replace the other => Internal catch-all with explicit arms for every remaining variant. InvalidUpdate → a validation/invalid-params variant. Genuinely-internal variants (DatabaseError, TransactionFailed, SerializationError) map to Internal explicitly (named arms, no catch-all), so adding a new NodeServiceError variant later forces a compile error rather than silently becoming Internal.
  2. Confirm ops_error_to_status covers every OpsError variant explicitly (it currently does — NotFound/VersionConflict/ValidationFailed/InvalidParams/Internal). Keep it exhaustive (no _ =>).
  3. Add parity tests (the core deliverable): for each NodeServiceError variant, assert the resulting tonic::Status code. At minimum: NodeNotFound→NotFound, VersionConflict→Aborted, ValidationFailed/InvalidParent/CircularReference/HierarchyViolation/InvalidUpdate→InvalidArgument, DatabaseError/TransactionFailed→Internal. Table-driven test in the daemon crate.
  4. Audit Status::internal call sites in daemon/src/services/node_service.rs (e.g. the batch handlers at 711, 947; ExportMarkdown at 670) — confirm each is genuinely internal vs. a client error that should be invalid_argument/not_found. Fix the mis-categorized ones.

Acceptance criteria

  • From<NodeServiceError> for OpsError has no catch-all other => arm — every variant is mapped explicitly (compile-error on a new unmapped variant).
  • InvalidUpdate (and any other client-error variant) maps to invalid_argument, not internal.
  • ops_error_to_status remains exhaustive over OpsError (no _ =>).
  • Parity tests assert the variant→Status code for every NodeServiceError variant; VersionConflict → aborted explicitly covered.
  • Status::internal call sites in the daemon node_service are audited; client-errors re-mapped to the correct code.
  • No #[allow(...)], no lint suppression. cargo clippy --workspace --all-targets -- -D warnings clean.

Testing

  • New table-driven parity test in the daemon crate passes (cargo test -p nodespaced).
  • cargo test --workspace green.
  • An end-to-end check that a version-conflict RPC returns Aborted (the frontend conflict-resolution UI from Implement conflict resolution UI for concurrent edits #1231 depends on distinguishing this) and a missing node returns NotFound.

Coordination

Standard NodeSpace startup / PR sequence

EnterWorktree({name: "issue-<N>-explicit-grpc-error-mapping"}); bun install; baseline cargo test -p nodespaced; bun run gh:assign/gh:status. Before PR: cargo test --workspace + bun run test:all (no new failures), bun run quality:fix (revert unrelated cargo fmt churn via git status), bun run gh:pr <N>, /pragmatic-code-review, then ExitWorktree + gh pr merge --squash --delete-branch.


Spun off from #1228 (architectural audit), finding B6.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions