Fix model binding broken by Spring AI 2.0 options merge removal - #1818
Merged
Conversation
igordayen
requested review from
alexheifetz,
azanux,
jasperblues,
johnsonr and
simeshev
July 23, 2026 15:45
alexheifetz
reviewed
Jul 24, 2026
alexheifetz
left a comment
Contributor
There was a problem hiding this comment.
Decision needed on cohesiveness of semantics requireSpringAiLlm(llm).optionsConverter
vs requireSpringAiLlm(llm).buildXYZ
Contributor
Author
Addressed :
|
|
igordayen
pushed a commit
that referenced
this pull request
Jul 27, 2026
…#1828) * test: add regression test for Ollama configured model binding (#1735) Verifies that a registered Ollama LLM sends requests targeting the model it was registered for, rather than the OllamaChatOptions mistral fallback, by exercising the same SpringAiLlmService.convertOptions path that ChatClientLlmOperations uses to build per-request options. Complements the converter field-mapping tests added in #1818, which deliberately leave model stamping uncovered. Signed-off-by: sumin220 <173463176+sumin220@users.noreply.github.com> * test: resolve nested config classes via ClassUtils Addresses review feedback on #1828: use Spring's ClassUtils.forName with the config class's own loader instead of Class.forName, avoiding classpath issues in environments with non-default loader hierarchies. Signed-off-by: sumin220 <173463176+sumin220@users.noreply.github.com> * test: replace unguarded casts with assertIs Addresses review feedback on #1828: both casts now fail with a clear assertion message instead of a raw ClassCastException, and the bean lookup reports the registered bean names when the expected bean is missing (covering the null-from-map case as well). Signed-off-by: sumin220 <173463176+sumin220@users.noreply.github.com> --------- Signed-off-by: sumin220 <173463176+sumin220@users.noreply.github.com> Co-authored-by: sumin220 <173463176+sumin220@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



OVERVIEW
Problem
Spring AI 2.0 removed the implicit merge between per-request ChatOptions and the ChatModel bean's configured default options.
Every provider's OptionsConverter implementation omits .model() from the builder, relying on the old merge to stamp the correct model.
Example — Anthropic: AnthropicOptionsConverter.convertOptions() never calls .model(), so every call produces
AnthropicChatOptions with DEFAULT_MODEL = "claude-haiku-4-5" regardless of which model was selected. The
AnthropicChatModel bean had claude-sonnet-4-5 in its configured default properties options — in 1.x that won; in 2.0 it is never consulted.
Fix
Added buildChatOptions(llmOptions) to SpringAiLlmService that stamps this.name (the configured model ID) onto the
converted options after conversion:
This is provider-agnostic — name is the model ID set at SpringAiLlmService construction time, independent of whatever default any converter bakes in.
Applied at all call sites that build per-request options:
SpringAiLlmService alone is bypassed here)
Tests
path to ChatModel.call()
AnthropicChatOptions with the configured model, not DEFAULT_MODEL
Closes: #1815 , #1735 , #1816