etzel-mes opened a new pull request, #30336: URL: https://github.com/apache/camel/pull/30336
# Description https://issues.apache.org/jira/browse/CAMEL-27152 Follow-up to #30327, as agreed there: the same fix for `camel-ai-prompt` and `camel-ai-resource`. In #30327 I had only read that `AiPromptConsumer` and `AiResourceConsumer` have the shape of `AiToolConsumer`. Now tried on main (e1bdcd5aaa6): a prompt request or resource read held inside the route fails when the route stops, with the same `RouteStoppingException` from `RedeliveryErrorHandler$SimpleTask.runNotAllowed`, while the shutdown strategy waits for it. The change, the same as for ai-tool: - `AiPromptConsumer` and `AiResourceConsumer` implement `Suspendable`. A route stop suspends the consumer first, which deregisters the prompt, resource or resource template (their existing `doSuspend`), waits for the calls in flight, and stops it after. - `AiPromptExecutor` and `AiResourceExecutor` refuse a new call while the consumer is suspending or suspended, in each executor's own form for its "No consumer available" error. A resource template read goes through `AiResourceExecutor` and is refused the same way. Behaviour change beyond the fix, as for ai-tool: `suspendRoute` and `context.suspend()` now suspend these routes instead of stopping them. The registries end in the same state and notify once for each transition, so an MCP client gets the same `list_changed` notifications. The upgrade guide entry of #30327 now names camel-ai-resource too; camel-ai-prompt is new in 4.24, so it has nothing to migrate. On the suggestion in the review of #30327, to add `|| consumer.isStoppingOrStopped()` to the check: I did not, here or in ai-tool. `BaseService.isStoppingOrStopped()` is `status < STARTING || status > SUSPENDED`, so it is also true for a consumer that has not started yet, and the check would refuse every tool, prompt and resource that is registered early. A call on a spec held after the route has fully stopped fails at the stopped processor, as before. Say if you want that case refused in the executors with a narrower condition. Tests: `AiPromptRouteStopInFlightTest` and `AiResourceRouteStopInFlightTest` hold a call inside the route, stop the route and expect a result; without the change they fail. The executor tests cover the refused call on a suspended prompt, resource and resource template, and the call after resume. Unit tests of camel-ai-prompt, camel-ai-resource, camel-ai-tool, camel-mcp-server-api and camel-mcp-server pass; the integration tests were not run. cc @davsclaus @oscerd # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. Not from the root folder: I built the two modules with the formatter and import sort. The change touches no generated file. # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. _Claude Code on behalf of etzel-mes_ 🤖 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]
