{"record":{"id":"ac89a17655d784f8","repo":"langchain-ai/deepagents","slug":"could-not-write-the-complete-temporary-artifact","errorCode":null,"errorMessage":"could not write the complete temporary artifact","messagePattern":"could not write the complete temporary artifact","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/auto_mode.py","lineNumber":1029,"sourceCode":"        for file_path, artifact in _active_temp_artifacts(state).items()\n        if artifact[\"thread_key\"] == thread_key and artifact[\"turn_id\"] == turn_id\n    }\n\n\ndef _validate_temp_artifact_suffix(suffix: str) -> str:\n    if not _TEMP_ARTIFACT_SUFFIX_RE.fullmatch(suffix):\n        msg = \"suffix must be empty or a short extension such as .md\"\n        raise ValueError(msg)\n    return suffix\n\n\ndef _write_temp_artifact_bytes(file_descriptor: int, data: bytes) -> os.stat_result:\n    remaining = memoryview(data)\n    while remaining:\n        written = os.write(file_descriptor, remaining)\n        if written <= 0:\n            msg = \"could not write the complete temporary artifact\"\n            raise OSError(msg)\n        remaining = remaining[written:]\n    return os.fstat(file_descriptor)\n\n\ndef _allocate_temp_artifact(\n    content: str,\n    suffix: str,\n    *,\n    thread_key: str,\n    turn_id: str,\n    tool_call_id: str,\n) -> AutoTempArtifact:\n    data = content.encode(\"utf-8\")\n    temp_root = Path(tempfile.gettempdir()).absolute()\n    file_descriptor, raw_path = tempfile.mkstemp(\n        prefix=_TEMP_ARTIFACT_PREFIX,\n        suffix=suffix,\n        dir=temp_root,","sourceCodeStart":1011,"sourceCodeEnd":1047,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/auto_mode.py#L1011-L1047","documentation":"Raised by `_write_temp_artifact_bytes` in auto_mode.py when `os.write` returns 0 or a negative value, meaning the loop cannot make progress writing the remaining bytes of a temporary artifact to its file descriptor. The library throws this to guarantee a temp file allocated via `mkstemp` is fully written before it is handed to the model/tool, and the caller's `finally` block then unlinks the partial file.","triggerScenarios":"The underlying `os.write` call on a freshly `mkstemp`-created descriptor returns <= 0 bytes written — e.g. the disk filled up and the fd became invalid, the file was closed/replaced underneath the descriptor, or a exotic filesystem returned 0 instead of raising `BlockingIOError`/`OSError` directly.","commonSituations":"Full or quota-exhausted disk in the temp directory (`TMPDIR`/`/tmp`); a hostile or nonstandard `/tmp` (FUSE filesystems, containers with tiny tmpfs); resource exhaustion closing the descriptor out from under the loop; rare filesystem bugs where write(2) returns 0.","solutions":["Free disk space in the temp directory (`df -h $TMPDIR`) and raise any disk quota, then retry the operation","Check the filesystem backing the temp dir — if it is a small tmpfs or exotic FUSE mount, set `TMPDIR` to a normal local filesystem and retry","Check `dmesg`/system logs for I/O errors on the temp device and repair the disk if needed","If it reproduces reliably, report it — a write(2) returning 0 on a regular blocking fd indicates an environment bug"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import shutil, os\ntmp = os.environ.get(\"TMPDIR\", \"/tmp\")\nusage = shutil.disk_usage(tmp)\nif usage.free < 10 * 1024 * 1024:\n    raise RuntimeError(f\"temp dir {tmp} low on space: {usage.free} bytes free\")","typeGuard":null,"tryCatchPattern":"try:\n    artifact = create_temp_artifact(content=content, suffix=\".md\")\nexcept OSError as exc:\n    if \"could not write the complete temporary artifact\" in str(exc):\n        free_space_or_change_tmpdir_and_retry()\n    else:\n        raise","preventionTips":["Monitor free space on the TMPDIR filesystem before long agent runs","Point TMPDIR at a reliable local disk, not a tiny tmpfs or flaky network mount","Cap artifact content size so writes stay well within available space","Alert on disk-usage thresholds in containers/CI"],"tags":["filesystem","disk-full","temp-file","io"],"backgroundTag":"temp-file-write-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}