{"record":{"id":"8b1bd4f2959b14b4","repo":"odysseus-dev/odysseus","slug":"cleanup-preview-generation-failed","errorCode":null,"errorMessage":"Cleanup preview generation failed","messagePattern":"Cleanup preview generation failed","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"routes/cleanup/cleanup_routes.py","lineNumber":36,"sourceCode":"        APIRouter instance with cleanup routes\n    \"\"\"\n    router = APIRouter(prefix=\"/api/cleanup\")\n\n    @router.get(\"/preview\")\n    async def cleanup_preview(request: Request):\n        \"\"\"\n        Preview what would be cleaned up without making any changes.\n\n        Returns:\n            JSON response with lists of sessions that would be archived/deleted and estimated space savings\n        \"\"\"\n        user = get_current_user(request)\n        try:\n            preview = await get_cleanup_preview(owner=user)\n            return preview\n        except Exception as e:\n            logger.error(f\"Cleanup preview failed: {e}\")\n            raise HTTPException(500, \"Cleanup preview generation failed\")\n\n    @router.post(\"\")\n    async def cleanup_endpoint(request: Request):\n        \"\"\"\n        Perform cleanup operations:\n        1. Archive inactive sessions (not accessed for 7 days)\n        2. Delete old sessions (archived, not important, not accessed for 14+ days, with fewer than 10 messages)\n\n        Returns:\n            JSON response with counts of deleted and archived sessions, and space freed\n        \"\"\"\n        user = get_current_user(request)\n        try:\n            archived_count, deleted_count, space_freed_mb = await cleanup_sessions(session_manager, owner=user)\n            return {\n                \"archived_count\": archived_count,\n                \"deleted_count\": deleted_count,\n                \"space_freed_mb\": round(space_freed_mb, 2)","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/odysseus-dev/odysseus/blob/f9235ebbf13f693a6fd29ce70b097f6ec83705bf/routes/cleanup/cleanup_routes.py#L18-L54","documentation":"Raised as HTTP 500 by the cleanup preview endpoint when get_cleanup_preview(owner=user) throws any exception; the original exception is logged via logger.error before re-raising. It is a catch-all: the 500 tells you only that computing the dry-run preview failed, and the real cause is in the server log line 'Cleanup preview failed: <e>'.","triggerScenarios":"GET of the cleanup preview endpoint when the sessions directory is unreadable/deleted, session metadata is corrupt, disk stats fail, or the owner filter hits an unexpected state while scanning sessions.","commonSituations":"Sessions data dir moved or permission changed after a manual migration; a partially-written session file from an unclean shutdown; running as a different OS user than the one owning the data directory; disk-full conditions during stat() calls.","solutions":["Read the server log for the 'Cleanup preview failed' line — the underlying exception names the real problem.","Verify the server process has read access to the sessions storage directory and its files.","Remove or restore the corrupt session artifact the scan is choking on (often visible in the traceback path).","Free disk space if the error is an OSError during size/stat computation."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const resp = await fetch('/api/cleanup/preview');\nif (resp.status === 500) {\n  console.error('Preview failed — check server log for \"Cleanup preview failed\"');\n  return null; // degrade gracefully, do not offer cleanup\n}","typeGuard":null,"tryCatchPattern":"try {\n  preview = await api.getCleanupPreview();\n} catch (e) {\n  if (e.status === 500) { notify('Could not compute cleanup preview'); return; }\n  throw e;\n}","preventionTips":["Always run the preview endpoint before the mutating cleanup POST — it doubles as a health check.","Keep the sessions data directory readable by the service user and monitor disk space.","Correlate every 500 from these routes with the logged 'Cleanup preview failed' line to reach root cause."],"tags":["http-500","cleanup","catch-all","maintenance"],"backgroundTag":null,"analyzedSha":"f9235ebbf13f693a6fd29ce70b097f6ec83705bf","analyzedAt":"2026-08-14T21:47:48.359Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}