FoundationAgents/OpenManus · error · RuntimeError

Empty tar archive

Error message

Empty tar archive

What it means

Raised while unpacking a tar stream returned by the Docker API (get_archive): the archive opened successfully but tar.next() returned no member at all, i.e. the stream contains a valid but empty tar. This happens in the helper that converts a streamed archive back into file bytes, so the copy/read pipeline fails before any content is extracted.

Source

Thrown at app/sandbox/core/sandbox.py:417

        Args:
            tar_stream: Tar file stream.

        Returns:
            File content.

        Raises:
            RuntimeError: If read operation fails.
        """
        with tempfile.NamedTemporaryFile() as tmp:
            for chunk in tar_stream:
                tmp.write(chunk)
            tmp.seek(0)

            with tarfile.open(fileobj=tmp) as tar:
                member = tar.next()
                if not member:
                    raise RuntimeError("Empty tar archive")

                file_content = tar.extractfile(member)
                if not file_content:
                    raise RuntimeError("Failed to extract file content")

                return file_content.read()

    async def cleanup(self) -> None:
        """Cleans up sandbox resources."""
        errors = []
        try:
            if self.terminal:
                try:
                    await self.terminal.close()
                except Exception as e:
                    errors.append(f"Terminal cleanup error: {e}")
                finally:
                    self.terminal = None

View on GitHub (pinned to 52a13f2a57)

Solutions

  1. Check the source file exists and has size > 0 in the container before copying ('stat -c %s <path>').
  2. Log the number of chunks received from the tar stream before opening tarfile — zero chunks points at an upstream docker API failure, not a tar problem.
  3. Retry the copy once: transient container shutdown mid-stream can produce a truncated/empty archive.
  4. Upgrade the docker SDK — older versions had framing quirks when demuxing exec/archive streams.

Example fix

# before
for chunk in tar_stream:
    tmp.write(chunk)
# after
chunks = list(tar_stream)
if not chunks:
    raise RuntimeError("Empty tar archive: docker get_archive returned no data (is the container alive?)")
for chunk in chunks:
    tmp.write(chunk)
Defensive patterns

Strategy: retry

Validate before calling

chunks = list(sandbox.get_archive_stream(path))
if not chunks:
    raise RuntimeError('get_archive returned no data; container may have exited')

Try / catch

for attempt in range(2):
    try:
        return await extract_single_file_from_tar(stream_factory())
    except RuntimeError as e:
        if 'Empty tar archive' in str(e) and attempt == 0:
            continue  # transient mid-stream container exit
        raise

Prevention

When it happens

Trigger: The tar stream handed to this extractor is empty — most commonly when the docker get_archive response was consumed twice, when the stream errored before yielding the header frame, or when an upstream error produced zero chunks that still form a valid empty tar.

Common situations: Copying a file of length 0 in edge-case docker SDK versions; race where the container exits between stat and archive streaming; code that buffers the get_archive generator but swallows its first exception and passes an empty list on.

Related errors


AI-assisted analysis of FoundationAgents/OpenManus@52a13f2a57 (2026-08-15). Data as JSON: /api/errors/27a31c78a67678bc. Report an issue: GitHub.