langchain-ai/deepagents · error · OSError
could not write the complete temporary artifact
Error message
could not write the complete temporary artifact
What it means
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.
Source
Thrown at libs/code/deepagents_code/auto_mode.py:1029
for file_path, artifact in _active_temp_artifacts(state).items()
if artifact["thread_key"] == thread_key and artifact["turn_id"] == turn_id
}
def _validate_temp_artifact_suffix(suffix: str) -> str:
if not _TEMP_ARTIFACT_SUFFIX_RE.fullmatch(suffix):
msg = "suffix must be empty or a short extension such as .md"
raise ValueError(msg)
return suffix
def _write_temp_artifact_bytes(file_descriptor: int, data: bytes) -> os.stat_result:
remaining = memoryview(data)
while remaining:
written = os.write(file_descriptor, remaining)
if written <= 0:
msg = "could not write the complete temporary artifact"
raise OSError(msg)
remaining = remaining[written:]
return os.fstat(file_descriptor)
def _allocate_temp_artifact(
content: str,
suffix: str,
*,
thread_key: str,
turn_id: str,
tool_call_id: str,
) -> AutoTempArtifact:
data = content.encode("utf-8")
temp_root = Path(tempfile.gettempdir()).absolute()
file_descriptor, raw_path = tempfile.mkstemp(
prefix=_TEMP_ARTIFACT_PREFIX,
suffix=suffix,
dir=temp_root,View on GitHub (pinned to a1af029e6e)
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
Defensive patterns
Strategy: try-catch
Validate before calling
import shutil, os
tmp = os.environ.get("TMPDIR", "/tmp")
usage = shutil.disk_usage(tmp)
if usage.free < 10 * 1024 * 1024:
raise RuntimeError(f"temp dir {tmp} low on space: {usage.free} bytes free") Try / catch
try:
artifact = create_temp_artifact(content=content, suffix=".md")
except OSError as exc:
if "could not write the complete temporary artifact" in str(exc):
free_space_or_change_tmpdir_and_retry()
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- temporary artifact is not a regular file
- temporary artifact is not owned by this user
- temporary artifact permissions are too broad
- temporary artifact identity changed
- Could not read marketplace manifest {manifest_path}: {exc}
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/ac89a17655d784f8.
Report an issue: GitHub.