[
https://issues.apache.org/jira/browse/CAMEL-27152?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen updated CAMEL-27152:
--------------------------------
Fix Version/s: 4.24.0
> camel-ai-tool - a tool call in flight fails when its route stops
> ----------------------------------------------------------------
>
> Key: CAMEL-27152
> URL: https://issues.apache.org/jira/browse/CAMEL-27152
> Project: Camel
> Issue Type: Bug
> Components: camel-ai
> Affects Versions: 4.22.0, 4.22.1, 4.22.2, 4.23.0
> Reporter: Serdar Gökay
> Priority: Minor
> Fix For: 4.24.0
>
>
> h2. Problem
> A tool call that is still inside an {{ai-tool}} route when the route stops,
> or the context shuts down gracefully, fails at its next step. On main and
> 4.23:
> {noformat}
> ExecutionError[message=Error executing tool 'held': The exchange cannot
> continue: its route is being stopped or reloaded,
> cause=org.apache.camel.RouteStoppingException: The exchange cannot continue:
> its route is being stopped or reloaded]
> at
> org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.runNotAllowed(RedeliveryErrorHandler.java:1026)
> {noformat}
> On 4.22.x the cause is a {{java.util.concurrent.RejectedExecutionException}}
> from the same place ({{RedeliveryErrorHandler.java:795}}).
> The shutdown strategy does wait for the call ({{Inflights per route: [held =
> 1]}}), but by then the route's processors are stopped.
> {{DefaultShutdownStrategy}} suspends a consumer that is {{Suspendable}} and
> defers one that is {{ShutdownAware}}; any other consumer is stopped at once,
> and {{DefaultConsumer.doStop}} stops the route processor. {{AiToolConsumer}}
> is neither.
> Found while reviewing CAMEL-27144 (PR 30317); it does not depend on that
> change. Reproduced with a plain route, no authorization option, on main
> (3d3b5185f1b8) and on camel-4.22.x (c6a6385c76b).
> h2. Proposal
> {{AiToolConsumer implements Suspendable}}, as {{HttpConsumer}},
> {{UndertowConsumer}} and {{CxfConsumer}} do. A route stop then suspends the
> consumer first, which deregisters the tool (its existing {{doSuspend}}),
> waits for the calls in flight, and stops it after.
> {{AiToolExecutor}} refuses a new call to a suspended tool: a caller can still
> hold the tool spec from before the suspend, and a suspended route keeps its
> processors started. The other suspendable request/reply consumers refuse in
> that state as well.
> A side effect, which I think is the intended behaviour: {{doSuspend}} and
> {{doResume}} of {{AiToolConsumer}} become reachable. Today {{suspendRoute}}
> falls back to stopping the route, because the consumer is not {{Suspendable}}.
> Test: a call held inside the route with a latch, the route stopped, the latch
> released, {{AiToolResult.Success}} expected. It fails without the change and
> passes with it; the module's tests pass.
> h2. Not in this issue's first PR
> {{AiPromptConsumer}} and {{AiResourceConsumer}} have the same shape (read,
> not tried). They follow in a second PR, so the first stays one module that
> exists on 4.22.x.
> PR: https://github.com/apache/camel/pull/30327
> _Claude Code on behalf of etzel-mes_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)