{"record":{"id":"27a31c78a67678bc","repo":"FoundationAgents/OpenManus","slug":"empty-tar-archive","errorCode":null,"errorMessage":"Empty tar archive","messagePattern":"Empty tar archive","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"app/sandbox/core/sandbox.py","lineNumber":417,"sourceCode":"\n        Args:\n            tar_stream: Tar file stream.\n\n        Returns:\n            File content.\n\n        Raises:\n            RuntimeError: If read operation fails.\n        \"\"\"\n        with tempfile.NamedTemporaryFile() as tmp:\n            for chunk in tar_stream:\n                tmp.write(chunk)\n            tmp.seek(0)\n\n            with tarfile.open(fileobj=tmp) as tar:\n                member = tar.next()\n                if not member:\n                    raise RuntimeError(\"Empty tar archive\")\n\n                file_content = tar.extractfile(member)\n                if not file_content:\n                    raise RuntimeError(\"Failed to extract file content\")\n\n                return file_content.read()\n\n    async def cleanup(self) -> None:\n        \"\"\"Cleans up sandbox resources.\"\"\"\n        errors = []\n        try:\n            if self.terminal:\n                try:\n                    await self.terminal.close()\n                except Exception as e:\n                    errors.append(f\"Terminal cleanup error: {e}\")\n                finally:\n                    self.terminal = None","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/FoundationAgents/OpenManus/blob/52a13f2a57d8c7f6737eefb02ccf569594d44273/app/sandbox/core/sandbox.py#L399-L435","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the source file exists and has size > 0 in the container before copying ('stat -c %s <path>').","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.","Retry the copy once: transient container shutdown mid-stream can produce a truncated/empty archive.","Upgrade the docker SDK — older versions had framing quirks when demuxing exec/archive streams."],"exampleFix":"# before\nfor chunk in tar_stream:\n    tmp.write(chunk)\n# after\nchunks = list(tar_stream)\nif not chunks:\n    raise RuntimeError(\"Empty tar archive: docker get_archive returned no data (is the container alive?)\")\nfor chunk in chunks:\n    tmp.write(chunk)","handlingStrategy":"retry","validationCode":"chunks = list(sandbox.get_archive_stream(path))\nif not chunks:\n    raise RuntimeError('get_archive returned no data; container may have exited')","typeGuard":null,"tryCatchPattern":"for attempt in range(2):\n    try:\n        return await extract_single_file_from_tar(stream_factory())\n    except RuntimeError as e:\n        if 'Empty tar archive' in str(e) and attempt == 0:\n            continue  # transient mid-stream container exit\n        raise","preventionTips":["Never consume a docker stream generator twice; buffer it once and check it is non-empty.","Confirm the container is running before streaming archives from it.","Log chunk counts when debugging tar extraction."],"tags":["docker","tar","sandbox","empty-response"],"backgroundTag":null,"analyzedSha":"52a13f2a57d8c7f6737eefb02ccf569594d44273","analyzedAt":"2026-08-15T02:33:49.993Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}