{"record":{"id":"3c0570b948e0ba5b","repo":"OpenBMB/ChatDev","slug":"session-directory-not-found","errorCode":null,"errorMessage":"Session directory not found","messagePattern":"Session directory not found","errorType":"exception","errorClass":"ResourceNotFoundError","httpStatus":null,"severity":"error","filePath":"server/routes/sessions.py","lineNumber":36,"sourceCode":"async def download_session(session_id: str):\n    try:\n        if not re.match(r\"^[a-zA-Z0-9_-]+$\", session_id):\n            logger = get_server_logger()\n            logger.log_security_event(\n                \"INVALID_SESSION_ID_FORMAT\",\n                f\"Invalid session_id format: {session_id}\",\n                details={\"received_session_id\": session_id},\n            )\n            raise ValidationError(\n                \"Invalid session_id: only letters, digits, underscores, and hyphens are allowed\",\n                field=\"session_id\",\n            )\n\n        dir_name = f\"session_{session_id}\"\n        session_path = WARE_HOUSE_DIR / dir_name\n\n        if not session_path.exists() or not session_path.is_dir():\n            raise ResourceNotFoundError(\n                \"Session directory not found\",\n                resource_type=\"session\",\n                resource_id=session_id,\n            )\n\n        with tempfile.NamedTemporaryFile(delete=False, suffix=\".zip\") as tmp_file:\n            zip_path = Path(tmp_file.name)\n\n        archive_base = zip_path.with_suffix(\"\")\n        try:\n            shutil.make_archive(str(archive_base), \"zip\", root_dir=WARE_HOUSE_DIR, base_dir=dir_name)\n        except Exception as exc:\n            if zip_path.exists():\n                zip_path.unlink()\n            logger = get_server_logger()\n            logger.log_exception(exc, f\"Failed to create zip archive for session: {session_id}\")\n            raise HTTPException(status_code=500, detail=\"Failed to create zip archive\")\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/OpenBMB/ChatDev/blob/4fb2db0ea90375ce1059f44fe03ffbd191a7a169/server/routes/sessions.py#L18-L54","documentation":"download_session builds WARE_HOUSE_DIR/session_{session_id} and raises ResourceNotFoundError when that directory is missing or not a directory. This becomes 404 via the outer handler (error 318).","triggerScenarios":"GET download for a session whose warehouse directory was never created, was deleted, or the server's WARE_HOUSE_DIR points elsewhere (different host/volume).","commonSituations":"Downloading right after creating a session before any files are written; warehouse on ephemeral container storage lost on restart; WARE_HOUSE_DIR env misconfiguration across deployments.","solutions":["Confirm the session produced files (run a workflow) before downloading","Check WARE_HOUSE_DIR on the server and volume mounts if containerized","Look for cleanup jobs that removed session directories","Re-run the session's workflow to regenerate the directory"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# server-side or via API: confirm the warehouse dir exists\n# dir = WARE_HOUSE_DIR / f'session_{session_id}'\nassert dir_exists_on_server(session_id), 'run the workflow first'","typeGuard":null,"tryCatchPattern":"except HTTPError as e:\n    if e.response.status_code == 404 and 'Session directory not found' in e.response.text:\n        rerun_workflow(session_id)  # regenerate, then retry download","preventionTips":["Only download after the session has produced output","Mount warehouse storage persistently in containers"],"tags":["http-404","session","filesystem"],"backgroundTag":"directory-not-found","analyzedSha":"4fb2db0ea90375ce1059f44fe03ffbd191a7a169","analyzedAt":"2026-08-27T14:35:29.622Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}