This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 0cd932970c85 chore: camel-jbang - the AI panel shows and logs what
ends a turn, also an Error (#30003)
0cd932970c85 is described below
commit 0cd932970c855c12e3f8586c075db84688d5d3c2
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 15 09:56:02 2026 +0100
chore: camel-jbang - the AI panel shows and logs what ends a turn, also an
Error (#30003)
A turn of the built-in model that ended in an Error, not an Exception, was
over with nothing to see: no answer, no error in the panel, and nothing in the
AI log, as the agent thread caught Exception only. On Nov 14 2026 a plugin jar
built after the core jar it calls ended every answer in a NoSuchMethodError.
- The agent threads of the built-in model and of an ACP agent also catch an
Error, and report what ended the turn in the panel and in the AI log.
- AiTurnFailure (new) has the text of a failure: its message, or its class
name when it has none, and for a LinkageError that the jars of the Camel CLI do
not match.
- reportTurnError shows an error in the panel and writes it to the AI log,
replacing the same two lines on the error paths of a turn, so AiPanel does not
grow; its sizes in SourceSizeTest are lowered to 3197 lines and runAgentLoop to
156.
- AiPanelTest: a NoSuchMethodError from the model call is shown and logged,
and a failure with no message shows its class name.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../camel/dsl/jbang/core/commands/tui/AiPanel.java | 30 +++++-----
.../dsl/jbang/core/commands/tui/AiTurnFailure.java | 40 +++++++++++++
.../dsl/jbang/core/commands/tui/AiPanelTest.java | 66 ++++++++++++++++++++++
.../jbang/core/commands/tui/SourceSizeTest.java | 4 +-
4 files changed, 123 insertions(+), 17 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanel.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanel.java
index 02267a7c5765..2f44a1852b3e 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanel.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanel.java
@@ -1231,8 +1231,8 @@ class AiPanel {
runAgentLoop(systemPrompt, question);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
- } catch (Exception e) {
- conversation.add(new ConversationEntry(AiRole.ERROR,
e.getMessage()));
+ } catch (Exception | Error e) {
+ reportTurnError("Error", AiTurnFailure.describe(e));
} finally {
if (agentThread == Thread.currentThread()) {
thinking.set(false);
@@ -1245,6 +1245,12 @@ class AiPanel {
agentThread.start();
}
+ /** Shows what ended a turn in the panel and writes it to the AI log. */
+ private void reportTurnError(String logLabel, String message) {
+ conversation.add(new ConversationEntry(AiRole.ERROR, message));
+ log(LogLevel.ERROR, logLabel, message);
+ }
+
/**
* Tells the Ollama tab which question the panel is working on, so it
lists it as in progress from the moment it was
* asked until the turn ends: answered, failed or cancelled. Only for
Ollama; the tab is about that server.
@@ -1291,8 +1297,7 @@ class AiPanel {
turnAiMs += callLatency;
if (response == null) {
String err = "No response from LLM";
- conversation.add(new ConversationEntry(AiRole.ERROR, err));
- log(LogLevel.ERROR, "Error", err);
+ reportTurnError("Error", err);
return;
}
turnRequests++;
@@ -1308,8 +1313,7 @@ class AiPanel {
? "LLM request failed. Check API key and endpoint."
: "LLM request failed: " + detail
+ "\nCheck the endpoint and model (/model lists what
the provider offers).";
- conversation.add(new ConversationEntry(AiRole.ERROR, err));
- log(LogLevel.ERROR, "Error", err);
+ reportTurnError("Error", err);
return;
}
@@ -1414,8 +1418,7 @@ class AiPanel {
sb.append("\nSee F2 -> AI Log for the full results, then rephrase with
more detail (for example the exact ");
sb.append("endpoint URI or topic) or /retry.");
sessionTotalTokens += totalUsage.totalTokens();
- conversation.add(new ConversationEntry(AiRole.ERROR, sb.toString()));
- log(LogLevel.ERROR, "Error", sb.toString());
+ reportTurnError("Error", sb.toString());
// keep the history consistent: the turn ends without an answer, so
the next question starts fresh from here
messages.add(LlmClient.Message.assistantWithToolCalls(
"(no answer: the iteration limit was reached while calling
tools)", List.of()));
@@ -1450,8 +1453,7 @@ class AiPanel {
note == null ? shown : shown + "\n\n" + note);
} else {
String err = "Empty response from LLM.";
- conversation.add(new ConversationEntry(AiRole.ERROR, err));
- log(LogLevel.ERROR, "Error", err);
+ reportTurnError("Error", err);
}
messages.add(LlmClient.Message.assistantWithToolCalls(text,
List.of()));
compactHistoryAfterTurn();
@@ -1653,7 +1655,7 @@ class AiPanel {
agentThread = new Thread(() -> {
try {
runAcpTurn(wireQuestion);
- } catch (IOException | RuntimeException e) {
+ } catch (IOException | RuntimeException | Error e) {
reportAcpTurnFailure(e);
} finally {
if (agentThread == Thread.currentThread()) {
@@ -1671,14 +1673,12 @@ class AiPanel {
* gone anyway, so a JSON-RPC error from a healthy agent does not cost the
user the conversation context. An
* interrupted turn is already reported as "(cancelled)" by {@link
#interruptBusyOperation()}.
*/
- private void reportAcpTurnFailure(Exception e) {
+ private void reportAcpTurnFailure(Throwable e) {
AcpAgentClient.AcpException acp = e instanceof
AcpAgentClient.AcpException a ? a : null;
if (acp != null && acp.code() == AcpAgentClient.INTERRUPTED) {
return;
}
- String message = e.getMessage() != null ? e.getMessage() :
e.toString();
- conversation.add(new ConversationEntry(AiRole.ERROR, message));
- log(LogLevel.ERROR, "ACP error", message);
+ reportTurnError("ACP error", AiTurnFailure.describe(e));
AcpAgentClient agent = acpSession.client();
boolean dead = agent == null || !agent.isAlive()
|| (acp != null && (acp.code() == AcpAgentClient.CONNECTION ||
acp.code() == AcpAgentClient.TIMEOUT));
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiTurnFailure.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiTurnFailure.java
new file mode 100644
index 000000000000..238eb8e9fcbc
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiTurnFailure.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+/**
+ * The text the AI panel shows, and writes to the AI log, for what ended a
turn: of the built-in model or of an ACP
+ * agent, also an {@link Error} and a failure with no message. A plugin jar of
the CLI built after the core jar it calls
+ * ended each answer in a {@link NoSuchMethodError}: the turn was over with no
answer, no error and nothing in the AI
+ * log.
+ */
+final class AiTurnFailure {
+
+ private AiTurnFailure() {
+ }
+
+ /**
+ * The message of the failure, or its class name when it has none. A
{@link LinkageError} says that the jars of the
+ * Camel CLI do not match, as that is what it means here.
+ */
+ static String describe(Throwable e) {
+ if (e instanceof LinkageError) {
+ return "The jars of the Camel CLI do not match (built at different
times?): " + e;
+ }
+ return e.getMessage() != null ? e.getMessage() : e.toString();
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanelTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanelTest.java
index 00770014ff65..0d94b4999cdc 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanelTest.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanelTest.java
@@ -1297,6 +1297,72 @@ class AiPanelTest {
}
}
+ // ---- what ends a turn is shown and logged, also an Error and a failure
with no message ----
+
+ @Test
+ void aTurnThatEndsInAnErrorIsShownAndLogged() throws Exception {
+ // a plugin jar built after the core jar it calls (Nov 14 2026): each
answer ended with nothing shown or logged
+ AiPanel panel = askFailing(new NoSuchMethodError("'java.util.List
AnswerChecks.checkCode(java.lang.String)'"));
+
+ AiPanel.ConversationEntry last =
panel.conversationForTesting().get(panel.conversationForTesting().size() - 1);
+ assertEquals(AiRole.ERROR, last.role());
+ assertTrue(last.text().startsWith("The jars of the Camel CLI do not
match"), last.text());
+ assertTrue(last.text().contains("NoSuchMethodError"), last.text());
+ assertTrue(panel.getActivityLog().stream()
+ .anyMatch(e -> e.level() == AiPanel.LogLevel.ERROR &&
e.detail().contains("NoSuchMethodError")));
+ assertFalse(panel.isThinkingForTesting());
+ }
+
+ @Test
+ void aFailureWithNoMessageIsNotBlank() throws Exception {
+ AiPanel panel = askFailing(new IllegalStateException());
+
+ AiPanel.ConversationEntry last =
panel.conversationForTesting().get(panel.conversationForTesting().size() - 1);
+ assertEquals(AiRole.ERROR, last.role());
+ assertEquals("java.lang.IllegalStateException", last.text());
+ assertTrue(panel.getActivityLog().stream()
+ .anyMatch(e -> e.level() == AiPanel.LogLevel.ERROR &&
"java.lang.IllegalStateException".equals(e.detail())));
+ }
+
+ private static AiPanel askFailing(Throwable failure) throws Exception {
+ AiPanel panel = new AiPanel();
+ panel.setToolRegistryForTesting(new TuiToolRegistry(null));
+ panel.setClientForTesting(new FailingLlmClient(failure));
+ panel.open();
+ type(panel, "what does this app do");
+ panel.handleKeyEvent(KeyEvent.ofKey(KeyCode.ENTER, KeyModifiers.NONE));
+ await().atMost(10, TimeUnit.SECONDS).until(() ->
!panel.isAgentThreadRunningForTesting());
+ return panel;
+ }
+
+ /** Fails its first request with the given failure. */
+ private static final class FailingLlmClient extends LlmClient {
+
+ private final Throwable failure;
+
+ FailingLlmClient(Throwable failure) {
+ this.failure = failure;
+ withModel("test-model");
+ withApiType(ApiType.openai);
+ }
+
+ @Override
+ public boolean detectEndpoint() {
+ return true;
+ }
+
+ @Override
+ public ChatResponse chatWithTools(String systemPrompt, List<Message>
messages, List<ToolDef> tools) {
+ if (failure instanceof Error error) {
+ throw error;
+ }
+ if (failure instanceof RuntimeException rte) {
+ throw rte;
+ }
+ throw new RuntimeException(failure);
+ }
+ }
+
/** Always asks for the same tool call, like a model stuck on a failing
send. */
private static final class LoopingLlmClient extends LlmClient {
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceSizeTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceSizeTest.java
index 1ebcca7a9b16..b2750b61d8a7 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceSizeTest.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceSizeTest.java
@@ -56,8 +56,8 @@ class SourceSizeTest {
/** The files and the methods (class.method) over the limits, and the most
lines each may have. */
private static final String OVER_THE_LIMITS = """
- AiPanel.java 3200
- AiPanel.runAgentLoop 159
+ AiPanel.java 3197
+ AiPanel.runAgentLoop 156
AiUsageStats.render 166
CamelMonitor.java 2632
DiagramSupport.java 2360