invoke-ai/InvokeAI · error · ObjectNotFoundError

{name}

Error message

{name}

What it means

ObjectSerializerDisk.load(name) resolves `name` to a file under its on-disk base directory and deserializes it with torch.load. If the file is absent (FileNotFoundError), it re-raises as ObjectNotFoundError(name), so the message is the serialized-object name. This indicates the requested object was never saved, was deleted by cleanup/eviction, or the serializer's base directory differs from the one used to save it.

Source

Thrown at invokeai/app/services/object_serializer/object_serializer_disk.py:58

            # Remove dangling tempdirs that might have been left over from an earlier unplanned shutdown.
            for temp_dir in filter(Path.is_dir, self._base_output_dir.glob("tmp*")):
                shutil.rmtree(temp_dir)

        # Must specify `ignore_cleanup_errors` to avoid fatal errors during cleanup on Windows
        self._tempdir = (
            tempfile.TemporaryDirectory(dir=self._base_output_dir, ignore_cleanup_errors=True) if ephemeral else None
        )
        self._output_dir = Path(self._tempdir.name) if self._tempdir else self._base_output_dir
        self.__obj_class_name: Optional[str] = None

        torch.serialization.add_safe_globals(safe_globals) if safe_globals else None

    def load(self, name: str) -> T:
        file_path = self._get_path(name)
        try:
            return torch.load(file_path)  # pyright: ignore [reportUnknownMemberType]
        except FileNotFoundError as e:
            raise ObjectNotFoundError(name) from e

    def save(self, obj: T) -> str:
        name = self._new_name()
        file_path = self._get_path(name)
        torch.save(obj, file_path)  # pyright: ignore [reportUnknownMemberType]
        return name

    def delete(self, name: str) -> None:
        file_path = self._get_path(name)
        file_path.unlink()

    @property
    def _obj_class_name(self) -> str:
        if not self.__obj_class_name:
            # `__orig_class__` is not available in the constructor for some technical, undoubtedly very pythonic reason
            self.__obj_class_name = typing.get_args(self.__orig_class__)[0].__name__  # pyright: ignore [reportUnknownMemberType, reportAttributeAccessIssue]
        return self.__obj_class_name

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Guard with serializer.exists(name) (or os.path.exists on the path) before load, or catch ObjectNotFoundError and regenerate/re-save the object.
  2. Check the object_serializer base directory config matches where the object was saved.
  3. If the object is a transient intermediate (latents/images), re-run the generating operation instead of reloading.
  4. Make temp directories persistent (outside /tmp or excluded from cleanup) if objects must survive restarts.

Example fix

// before
obj = serializer.load(name)
// after
try:
    obj = serializer.load(name)
except ObjectNotFoundError:
    obj = regenerate_and_save(serializer)
Defensive patterns

Strategy: try-catch

Validate before calling

if not serializer.exists(name):
    raise LookupError(f"serialized object {name!r} missing on disk")
obj = serializer.load(name)

Type guard

import os
from pathlib import Path
def object_on_disk(serializer, name: str) -> bool:
    return Path(serializer._get_path(name)).exists() if hasattr(serializer, "_get_path") else False

Try / catch

try:
    obj = serializer.load(name)
except ObjectNotFoundError:
    obj = regenerate_and_save(serializer)  # recompute the object

Prevention

When it happens

Trigger: Calling load(name) with a name that was never produced by save(); the file was deleted (disk cleanup, OS temp cleaning, deleted DB row while files remain pruned); a different base directory/temp dir configured between save and load (e.g. RAM-disk path changed across restarts).

Common situations: Restarting InvokeAI with a different configured temp/object-serializer directory; tmpfiles/systemd cleaning /tmp between runs; referencing a serialized object stored in an older session; concurrent cleanup deleting files mid-session.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/b7c40e4a078d2d1e. Report an issue: GitHub.