etzel-mes opened a new pull request, #30327: URL: https://github.com/apache/camel/pull/30327
# Description https://issues.apache.org/jira/browse/CAMEL-27152 Found in the review of #30317; it does not depend on that change. A tool call that is still inside an `ai-tool` route when the route stops, or Camel shuts down gracefully, fails at its next step, while the shutdown strategy is waiting for it (`Inflights per route: [held = 1]`): - `DefaultShutdownStrategy` suspends a consumer that is `Suspendable` and defers one that is `ShutdownAware`; any other consumer is stopped at once. - `DefaultConsumer.doStop` stops the route processor, so the error handler of the next step refuses the exchange: `RouteStoppingException` on main and 4.23, `RejectedExecutionException` on 4.22.x. The change: - `AiToolConsumer implements Suspendable`, as `HttpConsumer`, `UndertowConsumer` and `CxfConsumer` do. A route stop suspends the consumer first, which deregisters the tool (its existing `doSuspend`), waits for the calls in flight, and stops it after. `ShutdownAware` with a deferred shutdown would keep the tool registered during the wait, and the exchanges are already counted by the inflight repository. - `AiToolExecutor` refuses a new call to a suspended tool with an `ExecutionError`. A caller can still hold the `AiToolSpec` from before the suspend, and the suspended route keeps its processors started; the other suspendable request/reply consumers refuse in that state as well. One behaviour change beyond the fix: `doSuspend`/`doResume` of `AiToolConsumer` were not reachable, because `suspendRoute` and `context.suspend()` fall back to a stop for a consumer that is not `Suspendable`. They now suspend: the tool is deregistered and resuming registers the same spec again. The registry ends in the same state as before and the listener events are the same. Upgrade guide entry added. Tests: `AiToolRouteStopInFlightTest` holds a call inside the route, stops the route and expects `AiToolResult.Success`; without the change the call fails. `AiToolExecutorTest` covers the refused call on a suspended tool and the call after resume. camel-ai-tool, camel-mcp-server-api and camel-mcp-server unit tests pass. The failure was reproduced on main and on `camel-4.22.x` (c6a6385c76b). Not in this PR: `AiPromptConsumer` and `AiResourceConsumer` have the same shape. I left them out so this change stays one module that exists on 4.22.x, and will send them as a follow-up under the same issue unless you prefer them here. 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 module 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]
