Fix `ImageGeneration` under `FallbackModel` and `dataclasses.replace`, and compare `Embedder` by identity

Merged
DS
1mo ago
+985-91

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

Why we make these changes

Post-merge follow-ups to #5357 (ImageGenerator), grouped into one PR. None changes what is sent to a provider API.

[!WARNING]
Compatibility impact: Two distinct Embedder instances no longer compare equal, even over the same model (on main any two with the same instrument did), and Embedder is now hashable. ImageGeneration(fallback_subagent_model=...).local and XSearch(fallback_subagent_model=...).local now read None instead of the derived subagent Tool. As a result, two identically configured ImageGenerations or XSearches with fallback_subagent_model now compare equal, and their repr no longer shows local=Tool(...). The dropped-settings warnings shipped in v2.41.0 now backtick setting names and quote model names, and the native-only one names the model it ran on after setting(s); their leading text is unchanged, except that native=False with your own local tool now gets one `ImageGeneration` ignored setting(s) notice instead of `ImageGeneration` ignored direct-only setting(s), whose advice to pass native=False didn't apply.

Why this can ship in a minor release: All three are bug fixes under the version policy's undocumented-behavior exception. Field equality compared only instrument, so Embedders over different models compared equal and the class was unhashable; a derived tool stored on local is what made dataclasses.replace raise (#8095); and the warning text is quoted nowhere in the docs.

Migration: Compare Embedders by identity (is); build the subagent tool with the public image_generation_tool(model=..., native_tool=...) or x_search_tool(model=..., native_tool=...) rather than reading .local; match a warning filter on the message's leading text rather than on the whole message, and on `ImageGeneration` ignored for the native=False notice.

  • Under a FallbackModel, ImageGeneration with a direct generator, the native tool left enabled (the default), and any dropped setting (dimensions, quality, ...) raised NotImplementedError: FallbackModel does not have its own model profile. on every run. The per-request notice read ctx.model.profile, while routing reads each inner model's profile.
  • With native=False, local=<your own tool>, that tool receives none of the capability's settings, yet only dimensions and a non-native aspect_ratio warned, with advice that didn't fit; every other setting was dropped silently.
  • dataclasses.replace on ImageGeneration / XSearch with fallback_subagent_model raised the fallback-versus-local UserError (#8095). replace(cap, fallback_model=...) still raises, since replace also passes the current fallback_subagent_model; use fallback_subagent_model=.
  • copy.deepcopy of WrapperModel / WrapperEmbeddingModel hit RecursionError; WrapperImageGenerationModel already had the guard.
  • Embedder compared equal across models and was unhashable (#8144).
  • #8285 (docs half only): no page showed how to get the generated image out of a capability-driven run, and the routing example's custom tool returned bytes, which reaches the model as base64 text and never lands in ToolReturnPart.files.

New public surface

None. gemini-3.1-flash-lite-image joins LatestGoogleModelNames and the four google KnownModelName blocks; the direct Gemini API, Vertex AI and the Gateway all serve it.

User-visible behavior

  • The notice reads the profile each request is prepared against: each of a FallbackModel's models, and a wrapper's own profile (so TemporalModel's using_model() choice counts). A TemporalModel whose current model is a FallbackModel, or a model of your own that routes without a profile of its own, gets no notice, since nothing public says which model a request reaches; on main such a model crashed the same way. It warns for, and names, each model whose path drops a setting (quality on the direct generator, dimensions on the native tool), also in a TemporalDurability workflow; a provider's native tool still ignores a setting it has no field for without a warning.
  • native=False with your own local tool now warns once at construction, naming every setting that tool won't receive.
  • The subagent tool is derived in get_toolset, like the direct generator's, so .local keeps what was declared (None) and replace is a plain field copy. Construction still rejects an image-only subagent model or a mistyped native.
  • Embedder compares and hashes by identity, like ImageGenerator.
  • New "Getting the Generated Image" section in docs/capabilities/image-generation.md; the routing example's custom tool returns BinaryImage.

Not in this PR, deliberately: a static native=ImageGenerationTool(...) instance's native-only settings, model and action='edit' are still dropped silently on the direct fallback, as on main. After dataclasses.replace, the native tool native=True resolves to looks the same as a declared one, so reading the instance would act on settings a copy no longer has. #9495 decides that distinction first.

Verification

  • tests/test_capability_image_generation.py: test_image_generation_dropped_settings_notice_reads_each_routed_model, test_image_generation_dropped_settings_notice_says_nothing_for_a_model_that_routes_itself (a model of your own without a profile, bare and wrapped), test_image_generation_native_false_with_a_custom_local_tool_warns_for_every_setting_it_ignores, test_image_generation_native_only_notice_keeps_its_shipped_prefix, test_image_generation_replace_clears_a_setting_from_the_direct_fallback
  • tests/test_fallback_native_factory.py: test_fallback_subagent_model_survives_dataclass_replace and test_native_capable_outer_model_skips_the_fallback_subagent (both capabilities)
  • tests/test_capability_native_or_local.py::TestXSearchCapability::test_xsearch_native_false_local_callable
  • tests/models/test_model.py::test_wrapper_model_deepcopy, tests/test_embeddings.py::test_wrapper_embedding_model_deepcopy, tests/test_embeddings.py::test_embedder_compares_by_identity
  • tests/durable_exec/temporal/test_agent.py: test_image_generation_prepare_function_reads_the_model_temporal_selected; test_image_generation_prepare_function_reads_the_model_inside_an_activity, which now pins unless_native and fails when the stamp is dropped; test_image_generation_notice_says_nothing_for_a_temporal_agent_fallback_model runs a TemporalAgent workflow over a FallbackModel and gets no notice
  • tests/durable_exec/temporal/test_durability.py: test_durability_image_generation_notice_meets_the_fallback_model_in_workflow_code runs the notice over a FallbackModel inside a TemporalDurability workflow; test_durability_image_generation_notice_names_the_fallback_member_that_drops_a_setting_in_workflow_code pins the warning that names the member dropping quality in workflow code

What changes for existing users

A run under a FallbackModel, or a model of your own without a profile, that crashed now completes, and some dropped settings now warn. The three compatibility impacts are in the warning above.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.