OpenBMB/ChatDev · error · HTTPException

Failed to create zip archive

Error message

Failed to create zip archive

What it means

shutil.make_archive threw while zipping the session directory; the partial zip is unlinked, the failure is logged, and HTTP 500 'Failed to create zip archive' is returned.

Source

Thrown at server/routes/sessions.py:53

        if not session_path.exists() or not session_path.is_dir():
            raise ResourceNotFoundError(
                "Session directory not found",
                resource_type="session",
                resource_id=session_id,
            )

        with tempfile.NamedTemporaryFile(delete=False, suffix=".zip") as tmp_file:
            zip_path = Path(tmp_file.name)

        archive_base = zip_path.with_suffix("")
        try:
            shutil.make_archive(str(archive_base), "zip", root_dir=WARE_HOUSE_DIR, base_dir=dir_name)
        except Exception as exc:
            if zip_path.exists():
                zip_path.unlink()
            logger = get_server_logger()
            logger.log_exception(exc, f"Failed to create zip archive for session: {session_id}")
            raise HTTPException(status_code=500, detail="Failed to create zip archive")

        logger = get_server_logger()
        logger.info(
            "Session download prepared",
            log_type=LogType.WORKFLOW,
            session_id=session_id,
            archive_path=str(zip_path),
        )

        def cleanup_zip():
            if zip_path.exists():
                zip_path.unlink()

        return FileResponse(
            path=zip_path,
            filename=f"{dir_name}.zip",
            media_type="application/zip",
            headers={"Content-Disposition": f"attachment; filename={dir_name}.zip"},

View on GitHub (pinned to 4fb2db0ea9)

Solutions

  1. Check the logged exception 'Failed to create zip archive for session' for the root cause
  2. Verify read permissions on all files under the session directory
  3. Free disk space on the temp/warehouse volume
  4. Avoid deleting the session while a download is in flight
Defensive patterns

Strategy: retry

Validate before calling

# pre-flight checks before download
assert disk_space(temp_dir, estimate=session_size(session_id))
assert readable(session_dir_on_server(session_id))

Try / catch

except HTTPError as e:
    if e.response.status_code == 500 and 'zip' in e.response.text:
        wait_for_no_concurrent_cleanup(); retry_download(session_id)

Prevention

When it happens

Trigger: GET download when the session directory contains unreadable/permission-restricted files, disappears mid-zip, or disk space for the temp zip is exhausted.

Common situations: Concurrent deletion of the session dir during download; permission mismatches when files were written by another user; full /tmp or warehouse volume.

Related errors


AI-assisted analysis of OpenBMB/ChatDev@4fb2db0ea9 (2026-08-27). Data as JSON: /api/errors/935028ad53af7d0f. Report an issue: GitHub.