Mintplex-Labs/anything-llm · error

Failed to delete flow

Error message

Failed to delete flow

What it means

DELETE /agent-flows/:uuid maps any deleteFlow failure to this 500. AgentFlows.deleteFlow (server/utils/agentFlows/index.js:155) throws internally when the flow file does not exist or the resolved path escapes the flows dir ('Flow <uuid> not found'), catches it, and returns {success:false} — which the endpoint turns into a 500. So deleting a nonexistent flow yields 500, not 404; fs errors (EACCES/EBUSY) on rmSync produce the same response.

Source

Thrown at server/endpoints/agentFlows.js:147

  //       return response.status(500).json({
  //         success: false,
  //         error: error.message,
  //       });
  //     }
  //   }
  // );

  // Delete a specific flow
  app.delete(
    "/agent-flows/:uuid",
    [validatedRequest, flexUserRoleValid([ROLES.admin])],
    async (request, response) => {
      try {
        const { uuid } = request.params;
        const { success } = AgentFlows.deleteFlow(uuid);

        if (!success) {
          return response.status(500).json({
            success: false,
            error: "Failed to delete flow",
          });
        }

        return response.status(200).json({
          success,
        });
      } catch (error) {
        console.error("Error deleting flow:", error);
        return response.status(500).json({
          success: false,
          error: error.message,
        });
      }
    }
  );

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Call GET /agent-flows/list first and only DELETE a uuid that is present (idempotency guard on the client)
  2. Check server console for 'Failed to delete flow:' — it shows whether it was 'not found' vs an fs error like EACCES
  3. If it is an fs error, fix ownership/permissions of storage/plugins/agent-flows (e.g. chown the docker volume) and retry once

Example fix

// before (server): any deleteFlow failure becomes 500
const { success } = AgentFlows.deleteFlow(uuid);
if (!success) return response.status(500).json({ success:false, error:'Failed to delete flow' });

// after: distinguish not-found from real failures
const result = AgentFlows.deleteFlow(uuid);
if (!result.success && /not found/i.test(result.error || ''))
  return response.status(404).json({ success:false, error:'Flow not found' });
if (!result.success)
  return response.status(500).json({ success:false, error: result.error });
Defensive patterns

Strategy: validation

Validate before calling

async function safeDeleteFlow(uuid) {
  const res = await fetch('/api/agent-flows/list');
  const { flows } = await res.json();
  if (!flows.some(f => f.uuid === uuid)) return { skipped: true }; // avoids 500 for not-found
  const del = await fetch(`/api/agent-flows/${encodeURIComponent(uuid)}`, { method:'DELETE' });
  return { skipped: false, ok: del.ok };
}

Try / catch

try {
  const res = await fetch(`/api/agent-flows/${uuid}`, { method: 'DELETE' });
  if (res.status === 500) {
    const body = await res.json(); // 'Failed to delete flow' may mean already deleted
    console.warn('delete returned 500:', body.error);
  }
} catch (err) {
  console.error('network failure during delete:', err.message);
}

Prevention

When it happens

Trigger: DELETE with a uuid that was already deleted or never existed; double-click on the delete button in the UI firing two requests; uuid with traversal characters; the flow file locked or the storage directory read-only so fs.rmSync fails.

Common situations: Stale list in another tab after a delete; concurrent admins; docker bind-mount with wrong ownership making rmSync fail with EACCES.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/a88a0011c747bc40. Report an issue: GitHub.