Serdar Gökay created CAMEL-27152:
------------------------------------

             Summary: camel-ai-tool - a tool call in flight fails with 
RouteStoppingException 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.1, 4.22.0, 4.23.0, 4.22.2
            Reporter: Serdar Gökay


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:

{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}

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 on main 3d3b5185f1b8 with a plain route, no authorization 
option.

h2. Proposal

{{AiToolConsumer implements Suspendable}}, as {{DirectConsumer}} does. 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.

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 on main and passes with 
the change; the module's tests pass.

h2. Not in this issue

{{AiPromptConsumer}} and {{AiResourceConsumer}} have the same shape (read, not 
tried). Say if you want them in the same change.

I can send a PR.

_Claude Code on behalf of etzel-mes_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to