{"record":{"id":"1ad001e2386cd973","repo":"mem0ai/mem0","slug":"no-entities-to-delete","errorCode":null,"errorMessage":"No entities to delete","messagePattern":"No entities to delete","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"mem0-ts/src/client/mem0.ts","lineNumber":559,"sourceCode":"\n    if (userId) {\n      to_delete = [{ type: \"user\", name: userId }];\n    } else if (agentId) {\n      to_delete = [{ type: \"agent\", name: agentId }];\n    } else if (appId) {\n      to_delete = [{ type: \"app\", name: appId }];\n    } else if (runId) {\n      to_delete = [{ type: \"run\", name: runId }];\n    } else {\n      const entities = await this.users();\n      to_delete = entities.results.map((entity) => ({\n        type: entity.type,\n        name: entity.name,\n      }));\n    }\n\n    if (to_delete.length === 0) {\n      throw new Error(\"No entities to delete\");\n    }\n\n    for (const entity of to_delete) {\n      try {\n        // fetch() reuses the pooled connection; axios here defaulted to\n        // keepAlive: false, one handshake per entity.\n        await this._fetchWithErrorHandling(\n          `${this.host}/v2/entities/${encodePathSegment(entity.type)}/${encodePathSegment(entity.name)}/`,\n          {\n            method: \"DELETE\",\n            headers: this.headers,\n          },\n        );\n      } catch (error: any) {\n        throw new APIError(\n          `Failed to delete ${entity.type} ${entity.name}: ${error.message}`,\n        );\n      }","sourceCodeStart":541,"sourceCodeEnd":577,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/client/mem0.ts#L541-L577","documentation":"In the delete-users flow, when no specific userId/agentId/appId/runId is supplied the client fetches all entities via this.users() and builds a deletion list; if that list is empty it throws 'No entities to delete' rather than making zero API calls and reporting success. This prevents callers from believing a bulk wipe happened when there was nothing (or an auth/tenant mismatch meant nothing visible) to wipe.","triggerScenarios":"await client.deleteUsers({}) (or all-undefined scope) on an account/project whose users() call returns zero results — brand-new workspace, wrong org context, or an API key scoped to an empty project.","commonSituations":"Cleanup scripts run against the wrong environment; tests expecting seeded users that were never seeded; assuming entities exist without verifying; key scoped to a fresh project.","solutions":["If empty is acceptable, treat the error as a no-op: check the users list first and skip when empty.","Pass an explicit scope to avoid the bulk path: client.deleteUsers({ userId: 'alice' }).","Verify you are pointed at the right host/org — call client.users() and inspect the results before bulk delete."],"exampleFix":"// before\nawait client.deleteUsers({}); // throws 'No entities to delete' on empty workspace\n\n// after\nconst { results } = await client.users();\nif (results.length > 0) {\n  await client.deleteUsers({});\n}","handlingStrategy":"validation","validationCode":"const users = await client.users();\nif (users.results.length === 0) {\n  console.log('No entities to delete — skipping bulk delete');\n} else {\n  await client.deleteUsers({});\n}","typeGuard":"const hasEntities = (r: { results: Array<{ type: string; name: string }> }): boolean => r.results.length > 0;","tryCatchPattern":"try {\n  await client.deleteUsers({});\n} catch (e) {\n  if ((e as Error).message === 'No entities to delete') return { deleted: 0 }; // benign empty state\n  throw e;\n}","preventionTips":["Check users() count before any unscoped bulk delete.","Prefer scoped deletes (userId/agentId/appId/runId) over the wipe-all path.","Assert you are pointed at the intended environment before destructive bulk operations."],"tags":["delete","bulk-operations","empty-state"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}