{"record":{"id":"f0bd783042ab10d0","repo":"Mintplex-Labs/anything-llm","slug":"memory-not-found","errorCode":null,"errorMessage":"Memory not found.","messagePattern":"Memory not found\\.","errorType":"http","errorClass":null,"httpStatus":404,"severity":"warning","filePath":"server/endpoints/memory.js","lineNumber":32,"sourceCode":"    return response.status(403).json({ error: \"Personalization is disabled.\" });\n  next();\n}\n\n/**\n * Loads the memory by :memoryId and, in multi-user mode, scopes the query to the requester's userId.\n * A memory owned by another user returns null here and is indistinguishable from \"not found\" — 404 either way.\n */\nasync function validateMemoryOwner(request, response, next) {\n  try {\n    const clause = { id: Number(request.params.memoryId) };\n    if (response.locals.multiUserMode) {\n      const user = await userFromSession(request, response);\n      clause.userId = user?.id ?? null;\n    }\n\n    const memory = await Memory.get(clause);\n    if (!memory)\n      return response.status(404).json({ error: \"Memory not found.\" });\n\n    next();\n  } catch (e) {\n    console.error(e);\n    return response.sendStatus(500);\n  }\n}\n\nfunction memoryEndpoints(app) {\n  if (!app) return;\n\n  app.get(\n    \"/workspaces/:slug/memories\",\n    [\n      validatedRequest,\n      flexUserRoleValid([ROLES.all]),\n      memoryFeatureEnabled,\n      validWorkspaceSlug,","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/memory.js#L14-L50","documentation":"404 from the validateMemoryOwner middleware. In multi-user mode the lookup adds clause.userId = user.id, so a memory owned by another user is deliberately indistinguishable from a missing one — both yield null from Memory.get and 404. Also fires for non-numeric ids (Number() → NaN never matches) and, subtly, when Memory.get swallows a DB error and returns null.","triggerScenarios":"Any /memories/:memoryId route where the id does not exist, was deleted, belongs to a different user (multi-user mode), is non-numeric, or the Prisma query errored (Memory.get's catch returns null).","commonSituations":"Stale UI after the memory was deleted from another tab/device; reusing an id captured under a different account; session switched mid-flow; DB outage masquerading as 404.","solutions":["Re-fetch the memory list (GET /memories / workspace memories) and use an id from the fresh response","Confirm you are authenticated as the owning user in multi-user mode","Treat 404 as 'gone or not yours' — do not blindly retry","If every id 404s at once, suspect DB connectivity: Memory.get masks errors as null, so check server logs"],"exampleFix":"// before\nawait fetch(`/memories/${memoryId}`, { method: 'PUT', ... });\n// after\nconst fresh = (await (await fetch('/memories')).json()).memories ?? [];\nif (!fresh.some((m) => m.id === Number(memoryId))) { refreshUI(); return; }\nawait fetch(`/memories/${memoryId}`, { method: 'PUT', ... });","handlingStrategy":"validation","validationCode":"// Only mutate ids present in the freshest list the caller can see\nconst fresh = await (await fetch('/memories')).json();\nconst mine = new Set((fresh.memories ?? []).map((m) => m.id));\nif (!mine.has(Number(memoryId))) throw new Error('Memory is gone or not owned by this user');","typeGuard":"function isOwnedMemoryId(list, id) {\n  return typeof id === 'number' && Number.isInteger(id)\n    && list.some((m) => m.id === id);\n}","tryCatchPattern":null,"preventionTips":["Never cache memory ids long-term; re-fetch before every mutation","In multi-user mode, remember 404 also means 'owned by someone else'","A sudden 404 across all ids suggests a DB issue (Memory.get masks errors as null) — check logs"],"tags":["memory","http-404","multi-user","authorization"],"backgroundTag":"resource-not-found","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}