Skip to content

Let the pipeline gate survive a diffusers whose lazy submodule cannot import - #8227

Merged
danielhanchen merged 1 commit into
mainfrom
fix/lazy-diffusers-pipeline-guard
Aug 9, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix/lazy-diffusers-pipeline-guard

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

The bug

hasattr absorbs AttributeError and nothing else.

diffusers' top level is a lazy module, so in assert_pipeline_class_available the attribute probe is what actually imports the pipeline's submodule. When that submodule's own dependencies are unsatisfiable it raises RuntimeError("Failed to import diffusers.pipelines..."), which walks straight out of the guard.

That is precisely the escape the existing ImportError catch was written to prevent. The docstring already says it: the one thing that must not happen is a raise, because anything other than ValueError is not what the routes map to 400, so it leaves /images/download-plan as a bare 500 with the message lost. A partially usable diffusers install hit that path exactly the way a missing one used to.

Effect

Ten tests are red on main because of it. Same command, same tree, with only this guard swapped:

main's guard   10 failed, 204 passed
this branch             214 passed
FAILED tests/test_video_backend.py::test_validate_rejects_unknown_and_untrusted
FAILED tests/test_video_backend.py::test_validate_gates_base_repo_and_local_paths
FAILED tests/test_video_backend.py::test_validate_rejects_kind_extension_mismatch
FAILED tests/test_video_backend.py::test_validate_rejects_local_file_suffix_kind_mismatch
FAILED tests/test_video_backend.py::test_validate_rejects_windows_shaped_missing_checkpoint
FAILED tests/test_video_backend.py::test_validate_rejects_local_pipeline_without_model_index
FAILED tests/test_video_backend.py::test_validate_rejects_local_file_picked_as_pipeline
FAILED tests/test_video_backend.py::test_validate_rejects_local_base_repo_without_model_index
FAILED tests/test_cached_gguf_routes.py::test_pipeline_class_guard_passes_every_shipped_family

The eight test_video_backend.py ones have been carried as an environment problem for a while. They are not.

Change

Move the attribute probe inside the try and widen the catch, so the guard cannot raise anything but its own ValueError. Eight lines, plus a test that fails when either half is reverted.

… import

hasattr absorbs AttributeError and nothing else. diffusers' top level is a lazy
module, so the attribute probe is what actually imports the pipeline's submodule,
and when that submodule's own dependencies are unsatisfiable it raises
RuntimeError, which walks straight out of the guard.

That is the same escape the ImportError catch already existed to prevent: not the
ValueError the routes map to 400, so it leaves /images/download-plan as a bare 500
with the message lost. A partially usable diffusers install hit it exactly the way
a missing one used to.

Ten tests were red on main because of it, eight of them in test_video_backend.py.
They have been read as an environment problem for a while; they are not.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb86539fca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

import diffusers
except ImportError:
present = hasattr(diffusers, pipeline_class)
except Exception: # noqa: BLE001 -- see below: this check must never raise anything but its own ValueError

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not accept a pipeline whose lazy import failed

When diffusers imports but resolving the requested pipeline raises RuntimeError because its dependencies are unsatisfiable—the exact case added to the test—this catch now returns success even though the pipeline is unusable. Video has no native fallback: VideoBackend.validate_load_request therefore accepts the model, /video/download-plan advertises its potentially multi-GB files, and /video/load may acquire the GPU and evict the current model before getattr(diffusers, fam.pipeline_class) repeats the same failure in video.py. Convert this lazy-import failure into the route's expected ValueError (while retaining the separate fail-open behavior needed when diffusers is genuinely absent for native image loads), rather than treating it as availability.

Useful? React with 👍 / 👎.

@danielhanchen
danielhanchen merged commit 0d9e6bd into main Aug 9, 2026
40 of 45 checks passed
@danielhanchen
danielhanchen deleted the fix/lazy-diffusers-pipeline-guard branch August 9, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant