{"record":{"id":"82bc4a96455cc54c","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-toggle-flow","errorCode":null,"errorMessage":"Failed to toggle flow","messagePattern":"Failed to toggle flow","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/pages/Admin/Agents/AgentFlows/FlowPanel.jsx","lineNumber":84,"sourceCode":"            onClick={deleteFlow}\n            className=\"border-none flex items-center rounded-lg gap-x-2 hover:bg-theme-action-menu-item-hover py-1.5 px-2 transition-colors duration-200 w-full text-left\"\n          >\n            <span className=\"text-sm whitespace-nowrap\">Delete Flow</span>\n          </button>\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport default function FlowPanel({ flow, toggleFlow, enabled, onDelete }) {\n  const handleToggle = async () => {\n    try {\n      const { success, error } = await AgentFlows.toggleFlow(\n        flow.uuid,\n        !enabled\n      );\n      if (!success) throw new Error(error);\n      toggleFlow(flow.uuid);\n    } catch (error) {\n      console.error(\"Failed to toggle flow:\", error);\n      showToast(\"Failed to toggle flow\", \"error\", { clear: true });\n    }\n  };\n\n  return (\n    <>\n      <div className=\"p-2\">\n        <div className=\"flex flex-col gap-y-[18px] max-w-[500px]\">\n          <div className=\"flex w-full justify-between items-center\">\n            <div className=\"flex items-center gap-x-2\">\n              <FlowArrow size={24} weight=\"bold\" className=\"text-white\" />\n              <label htmlFor=\"name\" className=\"text-white text-md font-bold\">\n                {flow.name}\n              </label>\n            </div>","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/frontend/src/pages/Admin/Agents/AgentFlows/FlowPanel.jsx#L66-L102","documentation":"FlowPanel's toggle handler calls AgentFlows.toggleFlow(flow.uuid, !enabled) and throws when the response's success flag is false; the catch converts any failure into a 'Failed to toggle flow' toast. It fires when the backend rejects the enable/disable request for that flow uuid.","triggerScenarios":"Clicking the enable/disable switch for a flow whose uuid no longer exists server-side (deleted from another tab or by another admin), an expired or missing admin token returning 401/403, or a backend validation error for the flow being toggled.","commonSituations":"Stale admin page listing flows that were removed elsewhere; session token expired mid-session; backend restarting at the moment the switch is clicked.","solutions":["Reload the agent flows list and toggle again on the fresh uuid.","Inspect the Network tab response for the exact status: 401 means re-login, 404 means the flow is gone.","Re-authenticate if the request returned 401/403.","Check backend logs if a flow that visibly exists still fails to toggle."],"exampleFix":"// before\nconst { success, error } = await AgentFlows.toggleFlow(flow.uuid, !enabled);\nif (!success) throw new Error(error);\n\n// after — treat a vanished flow as a list-refresh, not a hard error\nconst { success, error } = await AgentFlows.toggleFlow(flow.uuid, !enabled);\nif (!success) {\n  showToast('Failed to toggle flow — refreshing list', 'error', { clear: true });\n  await loadFlows(); // re-sync uuids\n  return;\n}","handlingStrategy":"fallback","validationCode":"// Before toggling, confirm the flow still exists in the freshly loaded list\nconst flows = await loadAvailableFlows();\nif (!flows.some((f) => f.uuid === flow.uuid)) {\n  showToast('This flow no longer exists — list refreshed.', 'warning');\n  return;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const { success, error } = await AgentFlows.toggleFlow(flow.uuid, !enabled);\n  if (!success) throw new Error(error);\n  toggleFlow(flow.uuid);\n} catch (error) {\n  console.error('Failed to toggle flow:', error);\n  showToast('Failed to toggle flow', 'error', { clear: true });\n  await loadAvailableFlows(); // fallback: resync uuids, the old one may be stale\n}","preventionTips":["Reload the flows list when the admin tab regains focus so uuids stay fresh.","Optimistic UI should revert the switch position on failure.","Treat 404-shaped failures as 'flow removed elsewhere' and refresh rather than retry."],"tags":["agent-flows","toggle","api-error","stale-uuid"],"backgroundTag":"stale-resource-id","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}