Assertive-xxh opened a new pull request, #1388: URL: https://github.com/apache/flink-agents/pull/1388
Linked issue: #1387 A committer has not confirmed the direction on #1387 yet. I opened this so the diff and tests are easy to look at, and I'm happy to change the approach. ### Purpose of change Python `load_yaml` could leave part of a failing file registered. When a shared chat model and a shared model router have the same name, the resources committed before the clash stayed on the environment, and loading the corrected file then failed with `Duplicate shared ...`. Such a file now registers nothing, as in Java `loadYaml` for a clash with the environment. The pre-check in `load_yaml` only compared names within one resource type. The chat model / model router rule was enforced by `env.add_resource`, which runs during the commit. #### Runtime flow `load_yaml` handles each file in three steps: build its state without touching the environment, pre-check the shared resource names, then commit. The pre-check now also calls the existing `check_model_name_collision` for each shared resource name, against `env.resources` and against the file's own shared resources. Build and commit are unchanged. #### Key decisions - The pre-check now covers everything `env.add_resource` rejects: a duplicate within the resource type, and a chat model / model router clash. The commit can no longer fail halfway. - The existing helper is reused, so the error is the one programmatic registration raises. It has no `(loading <path>)` suffix. - The in-file check is in the `load_yaml` pre-check, not in `_build_in_file_state`. `build_agents` registers nothing, so it has no partial state to protect, and it keeps accepting the files it accepts today. ### Behavioral Semantics #### Interaction decisions | Where the two names meet | Result | |---|---| | shared chat model in the file, model router on the environment | `ValueError`, the file registers nothing | | shared model router in the file, chat model on the environment | `ValueError`, the file registers nothing | | shared chat model and shared model router in the same file | `ValueError`, the file registers nothing | | chat model and model router on the same agent | unchanged: rejected while the file is built | | shared chat model and agent-level model router | unchanged: accepted | #### Behavioral contracts 1. A file whose shared chat model has the name of a model router on the environment raises `ValueError` and registers none of its shared resources. 2. A file whose shared model router has the name of a chat model on the environment raises `ValueError` and registers none of its shared resources. 3. A file that declares a shared chat model and a shared model router with the same name raises `ValueError` and registers none of its shared resources. 4. After such a failure, the corrected file loads into the same environment. 5. The message is the one programmatic registration raises: `Resource '<name>' cannot name both a chat model and a model router.` #### Failure behavior All three cases raise `ValueError` from the pre-check. Nothing falls back, retries, or is swallowed. Errors raised while the file is built are unchanged and still come first. The duplicate check and the clash check run per name, in resource-type order. A file with both problems on different names now reports whichever name comes first. Before, it always reported the duplicate. ### Tests | Contract | Test | |---|---| | 1 | `test_load_yaml_chat_model_clashing_with_registered_router_registers_nothing`, the counterpart of Java's `sharedChatModelNameClashWithRouterLeavesFailedFileUnregistered` | | 2 | `test_load_yaml_router_clashing_with_registered_chat_model_registers_nothing` | | 3 | `test_load_yaml_chat_model_and_router_clashing_within_file_registers_nothing` | | 4 | the test of contract 2, which then renames the router and loads the file again | | 5 | all three match on the message | All three fail on `main`. Without the environment check the first two fail; without the in-file check the third fails. `ruff check --no-fix .` passes. `pytest flink_agents/api/yaml/tests`: 167 passed. The unit selection of `tools/ut.sh -p` on Python 3.12: 3216 passed, 18 skipped, 20 failed. The 20 are in `test_output_type_utils.py` and `test_remote_execution_environment.py`. They need a JVM, which is not installed here, and fail the same way on `main`. Not verified: - The Java lane was not run. This diff does not touch Java. - Java may still register part of a file whose own chat model and model router clash (contract 3): `validateSharedResourceNames` compares only with the environment. I read the code but did not run it. - No test pins that files loaded earlier in the same `load_yaml` call stay registered when a later file fails. That behavior is unchanged. - Python 3.10 and 3.11 were not run. ### API No signature change. `load_yaml` rejects the same files as before, with the same exception type and message. What changes for a caller: a failing file leaves the environment untouched, and a file with two problems may report the other one (see Failure behavior). `build_agents` and Java are unchanged. ### Documentation - [ ] `doc-needed` - [x] `doc-not-needed` - [ ] `doc-included` The `load_yaml` docstring now states this guarantee, as the Java doc comment does. ### Was this patch authored or co-authored using generative AI tooling? - [x] Yes - [ ] No Generated-by: Claude Code 2.1.308 (Claude Fable 5.2) 🤖 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]
