{"record":{"id":"662c9997422e0b2e","repo":"infiniflow/ragflow","slug":"stderr-decode","errorCode":null,"errorMessage":"{stderr.decode()}","messagePattern":"\\{stderr\\.decode\\(\\)\\}","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"agent/sandbox/executor_manager/services/execution.py","lineNumber":242,"sourceCode":"\n        args_path = os.path.join(workdir, str(bundle[\"args_name\"]))\n        with open(args_path, \"w\", encoding=\"utf-8\") as f:\n            f.write(str(bundle[\"args_source\"]))\n\n        returncode, _, stderr = await async_run_command(\"docker\", \"exec\", container, \"mkdir\", \"-p\", f\"/workspace/{task_id}\", timeout=5)\n        if returncode != 0:\n            raise RuntimeError(f\"Directory creation failed: {stderr}\")\n\n        tar_proc = await asyncio.create_subprocess_exec(\"tar\", \"czf\", \"-\", \"-C\", workdir, code_name, runner_name, str(bundle[\"args_name\"]), stdout=asyncio.subprocess.PIPE)\n        tar_stdout, _ = await tar_proc.communicate()\n\n        docker_proc = await asyncio.create_subprocess_exec(\n            \"docker\", \"exec\", \"-i\", container, \"tar\", \"xzf\", \"-\", \"-C\", f\"/workspace/{task_id}\", stdin=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE\n        )\n        stdout, stderr = await docker_proc.communicate(input=tar_stdout)\n\n        if docker_proc.returncode != 0:\n            raise RuntimeError(stderr.decode())\n\n        start_time = time.time()\n        try:\n            arguments = req.arguments or {}\n            logger.info(\"Passed in args keys=%s size_bytes=%s\", list(arguments.keys()), len(json.dumps(arguments, ensure_ascii=False).encode(\"utf-8\")))\n            run_args = _build_container_run_args(language=language, task_id=task_id, container=container, runner_name=runner_name)\n\n            returncode, stdout, stderr = await async_run_command(\n                *run_args,\n                timeout=TIMEOUT + 5,\n            )\n\n            time_used_ms = (time.time() - start_time) * 1000\n\n            logger.info(\"----------------------------------------------\")\n            logger.info(f\"Code: {str(base64.b64decode(req.code_b64))}\")\n            logger.info(f\"{returncode=}\")\n            logger.info(f\"{stdout=}\")","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/sandbox/executor_manager/services/execution.py#L224-L260","documentation":"Raised when streaming a tarball into the container via `docker exec -i <container> tar xzf - -C /workspace/<task_id>` fails (non-zero returncode). The raw stderr bytes from the docker/tar pipeline are decoded directly into the message. Note the upstream host-side `tar czf` returncode is never checked, so a host tar failure surfaces here as a confusing container-side error.","triggerScenarios":"Executing staged code when: the target container does not have `tar` installed, the host `tar` failed (bad workdir/file names) producing an empty or corrupt stream, the container exited between the mkdir and extract steps, or disk is full inside the container.","commonSituations":"Alpine/minimal images without tar; host working directory deleted by a concurrent cleanup task; container OOM-killed mid-staging; filename with characters the host tar rejects; disk pressure in the container's writable layer.","solutions":["Read the decoded stderr: 'tar: not found' means the container image lacks tar — install it or use an image that has it.","Check the host-side tar exit: tar_proc.returncode is currently ignored; log and check it before feeding tar_stdout to docker.","Confirm the container is still running right before extraction (docker inspect).","Check container disk space (`docker exec <c> df -h /workspace`) if stderr mentions 'No space left on device'."],"exampleFix":"# before\ntar_proc = await asyncio.create_subprocess_exec(\"tar\", \"czf\", \"-\", \"-C\", workdir, code_name, runner_name, str(bundle[\"args_name\"]), stdout=asyncio.subprocess.PIPE)\ntar_stdout, _ = await tar_proc.communicate()\n\n# after: fail fast on host tar errors so the container-side message is trustworthy\ntar_stdout, tar_err = await tar_proc.communicate()\nif tar_proc.returncode != 0:\n    raise RuntimeError(f\"Host tar failed ({tar_proc.returncode}): {tar_err.decode()}\")","handlingStrategy":"validation","validationCode":"# Ensure tar exists inside the container before streaming the bundle\nreturncode, _, _ = await async_run_command(\"docker\", \"exec\", container, \"sh\", \"-c\", \"command -v tar\", timeout=5)\nif returncode != 0:\n    raise RuntimeError(f\"Container {container} has no tar; cannot stage code\")","typeGuard":null,"tryCatchPattern":"try:\n    await stage_and_extract(...)\nexcept RuntimeError as e:\n    stderr = str(e)\n    if \"tar:\" in stderr or \"No space left\" in stderr:\n        logger.error(\"Staging failed in container: %s\", stderr)\n    raise","preventionTips":["Bake tar into the sandbox image.","Check host-side tar returncode before piping into docker exec.","Alert on container disk usage; extraction fails when the writable layer is full.","Keep the host workdir alive until staging completes."],"tags":["docker","tar","sandbox","subprocess"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}