{"record":{"id":"e4f57812c8c928fd","repo":"langchain-ai/deepagents","slug":"failed-to-write-credential-file-auth-path-ex","errorCode":null,"errorMessage":"Failed to write credential file {auth_path()}: {exc}. Check available disk space and the permissions on the parent directory.","messagePattern":"Failed to write credential file (.+?): (.+?)\\. Check available disk space and the permissions on the parent directory\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/auth_store.py","lineNumber":298,"sourceCode":"    store failures, so translate here with a remediation hint instead of\n    leaking a raw traceback to the caller (CLI or TUI). The message never\n    includes the credential value.\n\n    Returns:\n        The chmod-warning tuple from `_write_raw` on success.\n\n    Raises:\n        RuntimeError: If the underlying write fails with an `OSError`.\n    \"\"\"\n    try:\n        return _write_raw(data)\n    except OSError as exc:\n        msg = (\n            f\"Failed to write credential file {auth_path()}: {exc}. \"\n            \"Check available disk space and the permissions on the parent \"\n            \"directory.\"\n        )\n        raise RuntimeError(msg) from exc\n\n\ndef load_credentials() -> dict[str, StoredCredential]:\n    \"\"\"Return all stored credentials keyed by provider name.\n\n    Returns:\n        Mapping of provider name to its stored credential. Empty when no\n        credentials are persisted yet.\n\n    Raises:\n        RuntimeError: If the file exists but is corrupt or has an unsupported\n            schema version. Caller is expected to surface a remediation hint.\n    \"\"\"  # noqa: DOC502 - re-raised from `_read_raw`\n    data = _read_raw()\n    if data is None:\n        return {}\n    creds_raw = data.get(\"credentials\")\n    if not isinstance(creds_raw, dict):","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/auth_store.py#L280-L316","documentation":"Raised by `_write_raw_or_raise` in auth_store.py when an `OSError` occurs while persisting the credential file — the atomic write could not complete. It is re-raised as a `RuntimeError` with the resolved `auth_path()` embedded so the user knows exactly which file failed and gets pointed at disk space / parent-directory permissions as the likely causes.","triggerScenarios":"Calling set_stored_key() or delete_stored_key() when the write fails due to a full disk, read-only filesystem, missing or unwritable state directory, permission errors (e.g. another user owns the file), or quota limits.","commonSituations":"Disk quota exceeded on a CI runner or container; HOME directory mounted read-only; the state directory was created by root and is now unwritable by the current user; tmpfs full; file owned by a different UID.","solutions":["Free up disk space (check `df -h` for the filesystem containing the credential file's directory).","Check and fix permissions on the parent directory (`ls -la` on the state dir; `chown`/`chmod` as needed).","Ensure the state directory exists and is writable: `mkdir -p $(dirname $(auth_path)) && chmod 700 $(dirname ...)`.","If migrating containers/users, copy or recreate the credential file with correct ownership.","Retry after fixing the underlying resource issue — no data was written."],"exampleFix":"// before: set_stored_key fails on full disk\nset_stored_key(\"anthropic\", key)  # RuntimeError: Failed to write credential file ...\n// after: ensure the state dir is writable first\nstate_dir = pathlib.Path(auth_path()).parent\nstate_dir.mkdir(parents=True, exist_ok=True)\nstate_dir.chmod(0o700)\nset_stored_key(\"anthropic\", key)","handlingStrategy":"retry","validationCode":"# pre-check writability before calling the API\ndef _state_dir_writable() -> bool:\n    d = pathlib.Path(auth_path()).parent\n    return d.is_dir() and os.access(d, os.W_OK) and shutil.disk_usage(d).free > 1024 * 1024","typeGuard":"def _is_writable_dir(path: pathlib.Path) -> TypeGuard[pathlib.Path]:\n    return path.is_dir() and os.access(path, os.W_OK)","tryCatchPattern":"for attempt in range(3):\n    try:\n        set_stored_key(\"anthropic\", key)\n        break\n    except RuntimeError as exc:\n        if \"Failed to write credential file\" not in str(exc) or attempt == 2:\n            raise\n        time.sleep(2 ** attempt)  # transient pressure: retry after backoff","preventionTips":["Ensure the state directory exists with 0700 permissions and correct ownership before first use.","Monitor disk space/quota on the volume holding the state directory (containers, CI runners).","Avoid running as a different user than the one that created the credential file.","Mount HOME/state directories read-write in containers."],"tags":["auth","filesystem","permissions","disk-space"],"backgroundTag":"file-write-permission-denied","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}