mjolnir-strike opened a new pull request, #1457: URL: https://github.com/apache/flink-agents/pull/1457
Linked issue: #1440 ### Purpose of change After this change, `request_timeout=None`, and YAML `request_timeout: null`, is a validation error on all five Python model connections that take a `request_timeout`, as agreed in #1440. Omitting the argument still selects the default. Before this change the connections disagreed: - `OllamaChatModelConnection`, `OllamaEmbeddingModelConnection`, `DashScopeChatModelConnection` and `DashScopeEmbeddingModelConnection` declared `request_timeout: float | None` in `__init__`, but the pydantic field is `float`, so `None` already failed validation. Only the signature was wrong. - `OpenAIEmbeddingModelConnection` mapped `None` to the default with a `mode="before"` validator. `None` means "no timeout" to HTTP clients such as HTTPX, so accepting it as a second way to select the default is misleading. #### Runtime flow A connection is built either directly (`Connection(request_timeout=...)`) or by `PythonResourceProvider.provide`. The provider merges class-level config from `AgentConfiguration` (keys `<ClassName>.<field>`) with the descriptor's arguments, with the descriptor winning, and then calls the constructor. Pydantic validates the effective `request_timeout` against `float` when the connection is constructed. No validator rewrites it any more. #### Key decisions - **Reject `None` instead of mapping it to the default**, as wenjin272 chose in #1440. The alternative, adding a `None`-to-default validator to the four Ollama and DashScope connections, was rejected because it adds a second convention for selecting the default. - **Leave `max_retries` unchanged.** `OpenAIEmbeddingModelConnection` still maps `max_retries=None` to the default, because #1440 covers only `request_timeout`. This is open question 2 below. - **No Java change.** See open question 1 below. ### Behavioral Semantics #### Interaction decisions The effective value comes from class-level config and from the descriptor argument, and the descriptor argument wins: | Class-level config | Descriptor argument | Result | |---|---|---| | unset | unset | default | | `7` | unset | `7.0` | | `7` | `5` | `5.0` | | `null` | `5` | `5.0` | | `null` | unset | `ValidationError` | | `7` | `null` | `ValidationError` | #### Behavioral contracts 1. An omitted `request_timeout` uses the connection's `DEFAULT_REQUEST_TIMEOUT`. 2. A numeric `request_timeout` is used as given. 3. `request_timeout=None` passed to the constructor raises `pydantic.ValidationError` naming `request_timeout`. 4. YAML `request_timeout: null` raises the same error when the runtime provider builds the connection. 5. When both class-level config and a descriptor argument are present, the descriptor argument is the effective value, and contracts 1–3 apply to it. 6. `OpenAIEmbeddingModelConnection(max_retries=None)` still uses the default `max_retries`. #### Failure behavior An invalid `request_timeout`, including `None`, raises `pydantic.ValidationError` when the connection is constructed. On the runtime path that is inside `PythonResourceProvider.provide`, when the resource is first created. There is no fallback and no retry. Request-time behavior (timeouts, SDK errors) is unchanged. ### Tests | Contract | Tests | |---|---| | 1. Omitted uses the default | `test_omitted_request_timeout_uses_the_default` in `chat_models/tests/test_request_timeout_contract.py` (Ollama, DashScope) and `embedding_models/tests/test_request_timeout_contract.py` (Ollama, DashScope, OpenAI); `test_yaml_request_timeout_contract[omitted-*]` | | 2. A number is used as given | `test_numeric_request_timeout_is_used` (same two files); `test_yaml_request_timeout_contract[number-*]` | | 3. Constructor `None` is rejected | `test_none_request_timeout_rejected` (same two files) | | 4. YAML `null` is rejected via the provider | `test_yaml_request_timeout_contract[null-ollama-chat]`, `[null-openai-embedding]` in `plan/tests/test_resource_provider.py` | | 5. Config and descriptor composition | `test_request_timeout_from_config_and_descriptor` (6 cases) in `plan/tests/test_resource_provider.py` | | 6. `max_retries=None` keeps its default | `test_openai_embedding_model.py`, the updated `null_retries` assertion | **Coverage by risk:** the one behavior change, `OpenAIEmbeddingModelConnection` with `None`, is covered by the direct test and through the YAML and provider path. Against the old code only `test_none_request_timeout_rejected[OpenAI]` fails. The other new tests pass there too, as expected, since the Ollama and DashScope connections already rejected `None`. **Verified locally:** - `pytest flink_agents -k "not e2e_tests" -m "not integration"` on Python 3.12 with Flink 2.3: 3490 passed, 18 skipped. - The changed and new tests on Python 3.10 (Flink 2.3) and on Python 3.11 (Flink 1.20). - `ruff check --no-fix .` (ruff 0.11.13), `tools/check-license.sh`, `tools/check-agents-md.py` and `tools/check-skill-schema.py` all pass. **Not verified:** - The YAML and provider tests cover Ollama chat and OpenAI embedding only. Ollama embedding and the two DashScope connections are covered by the direct constructor tests. - Integration and e2e tests, which need live Ollama, DashScope or OpenAI services. Their request paths are unchanged. - Java tests, since no Java code changed. ### API **Compatibility impact:** - **Changes:** `OpenAIEmbeddingModelConnection(request_timeout=None)` and YAML `request_timeout: null` for it now raise instead of using the default (30 seconds). The public constructor annotations of the four Ollama and DashScope connections change from `float | None` to `float`. - **Unchanged:** runtime behavior for those four connections, every call that omits `request_timeout` or passes a number, `max_retries` handling, and all Java connections. Open questions for reviewers: 1. **Java parity.** The removed validator was documented as matching Java, where `parseRequestTimeout(null)` returns the default. The Java `OllamaChatModelConnection` does the same, since an explicit YAML `null` and an omitted argument both reach it as `null`. After this PR, Python rejects YAML `null` while Java still uses the default. Should Java be aligned in a follow-up, or is the difference acceptable? 2. **`max_retries`.** Should `max_retries=None` on `OpenAIEmbeddingModelConnection` follow the same rule? I left it unchanged to keep this PR to the scope agreed in #1440. ### Documentation - [ ] `doc-needed` - [x] `doc-not-needed` - [ ] `doc-included` ### Was this patch authored or co-authored using generative AI tooling? - [x] Yes - [ ] No Generated-by: Claude Code 2.1.330 (Claude Opus 5.5) 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
