Skip to content

Backend: Implement idempotent DELETE for REST compliance #219

Closed as not planned

Description

@malibio

Problem

Current backend DELETE endpoint returns HTTP 500 error when attempting to delete a non-existent node. This violates REST/HTTP best practices for idempotent operations.

Current Behavior:

# First delete
DELETE /api/nodes/{id} → HTTP 200 OK

# Second delete (node already gone)
DELETE /api/nodes/{id} → HTTP 500 Internal Server Error
Error: "Node not found: {id}"

Expected Behavior (REST standard):

# First delete
DELETE /api/nodes/{id} → HTTP 204 No Content

# Second delete (idempotent)
DELETE /api/nodes/{id} → HTTP 204 No Content

Why This Matters

1. Network Reliability

  • HTTP timeouts may cause clients to retry DELETE requests
  • Double-DELETE scenario: request succeeds but client times out → retry fails with 500
  • Non-idempotent DELETE breaks retry logic

2. Distributed Systems (Future)

  • Distributed systems require idempotent operations for consistency
  • Multiple servers may issue same DELETE command
  • Current implementation causes errors in distributed scenarios

3. REST/HTTP Standards

  • HTTP RFC 7231 mandates DELETE idempotence
  • All standard HTTP libraries expect idempotent DELETE
  • Violating standards causes integration issues

4. Developer Experience

  • Developers expect standard REST behavior
  • Current behavior requires special error handling
  • Non-standard APIs are harder to learn and debug

Acceptance Criteria

  • DELETE /api/nodes/{id} returns HTTP 204 for existing nodes
  • DELETE /api/nodes/{id} returns HTTP 204 for non-existent nodes (idempotent)
  • No error thrown when deleting already-deleted node
  • Updated tests verify idempotence behavior
  • Documentation updated to reflect idempotent DELETE

Technical Implementation

Backend Changes Required

File: packages/desktop-app/src-tauri/src/dev_server/node_endpoints.rs

async fn delete_node(
    State(state): State<AppState>,
    Path(id): Path<String>,
) -> Result<StatusCode, HttpError> {
    // Try to delete node
    let result = state.node_service.delete_node(&id).await;
    
    match result {
        Ok(_) => {
            tracing::debug!("✅ Deleted node: {}", id);
            Ok(StatusCode::NO_CONTENT) // 204
        },
        Err(e) if is_not_found_error(&e) => {
            // Idempotent: node already deleted or never existed
            tracing::debug!("✅ Delete idempotent (node doesn't exist): {}", id);
            Ok(StatusCode::NO_CONTENT) // 204
        },
        Err(e) => {
            // Actual error (permissions, database issue, etc.)
            Err(HttpError::from_anyhow(e.into(), "NODE_SERVICE_ERROR"))
        }
    }
}

Related Issues

Priority

Medium - Not blocking current Phase 2 work, but should be fixed before Phase 3.

References

Activity

  1. malibio commented on Dec 4, 2025

    @malibio
    CollaboratorAuthor

    Test Baseline - Issue #219

    Frontend: 729 tests passed
    Rust: 54 tests passed

    Starting implementation for idempotent DELETE endpoint.

  2. self-assigned this
    on Dec 4, 2025
  3. malibio commented on Dec 4, 2025

    @malibio
    CollaboratorAuthor

    Issue Already Resolved

    After investigation, this issue has already been addressed through architectural changes:

    dev-proxy.rs (Browser Mode)

    • Lines 937-942: Returns HTTP 204 for non-existent nodes (idempotent)
    • Lines 955: Returns HTTP 204 for successful deletes

    Tauri Commands (Desktop App)

    • Uses delete_node_with_occ which returns DeleteResult { existed: bool }
    • No error thrown for non-existent nodes - returns existed: false

    NodeService Layer

    • delete_node() (line 2317-2320): Documented as idempotent
    • delete_node_with_occ() (line 2430): Returns DeleteResult { existed: false } for non-existent

    Tests

    • test_delete_node_cascade_atomic_idempotent in surreal_store.rs verifies behavior

    All acceptance criteria are met. Closing as already implemented.

  4. malibio commented on Dec 4, 2025

    @malibio
    CollaboratorAuthor

    Closing as already implemented - see comment above for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions