This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new d4d8c6a40 fix(ai): keep a text-only engine's finished turn complete
(#6848)
d4d8c6a40 is described below
commit d4d8c6a4094f1d5bc6ab252b48416cdd16c1b9d5
Author: bai mengxuan <[email protected]>
AuthorDate: Fri Nov 27 12:25:33 2026 +0800
fix(ai): keep a text-only engine's finished turn complete (#6848)
---
.../studio/ops/ai/conversation/AiRunExecutor.java | 26 ++++++++++++++----
.../ops/ai/conversation/AiRunServiceTest.java | 32 ++++++++++++++++++----
2 files changed, 48 insertions(+), 10 deletions(-)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/ops/ai/conversation/AiRunExecutor.java
b/server/src/main/java/org/apache/rocketmq/studio/ops/ai/conversation/AiRunExecutor.java
index 369cb1e47..63fcd56b7 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/ops/ai/conversation/AiRunExecutor.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/ops/ai/conversation/AiRunExecutor.java
@@ -524,11 +524,12 @@ public class AiRunExecutor {
"llm.provider." + outcome.subtype,
"agent run ended with subtype: " + outcome.subtype,
outcome, false);
}
- if (!isHttpEngine(context.getEngine()) &&
!StringUtils.hasText(outcome.subtype)) {
- // The agent stream closed without ever delivering a result frame:
nothing was projected,
- // nothing failed with a frame of its own — the provider process
simply went away mid-turn.
- // A turn with no answer is not a successful one. HTTP completion
turns never carry a result
- // frame at all, so their fall through to COMPLETED stays correct
— that is the exclusion here.
+ if (expectsResultFrame(context.getEngine()) &&
!StringUtils.hasText(outcome.subtype)) {
+ // An engine whose stream carries a result frame closed without
ever delivering one: nothing
+ // was projected, nothing failed with a frame of its own — the
provider process simply went
+ // away mid-turn, and a turn with no answer is not a successful
one. Engines whose provider
+ // streams the completion as plain text never carry a frame at
all, so for them a missing
+ // frame proves nothing and must not be read as a lost process.
return new Terminal(RunStatus.FAILED, StopReason.PROVIDER_ERROR,
ERROR_CODE_NO_RESULT,
"agent stream ended without a result frame", outcome,
false);
}
@@ -665,6 +666,21 @@ public class AiRunExecutor {
||
LlmConfigVO.ENGINE_HTTP.equals(engine.trim().toLowerCase(Locale.ROOT));
}
+ /**
+ * Whether an engine's agent stream is expected to end with a result
frame, which is what makes a
+ * missing one evidence that the agent went away mid-turn.
+ *
+ * <p>Only {@code claude-code} streams the CLI's frame vocabulary and
resolves the terminal
+ * {@code result} frame from it ({@code ClaudeCodeStreamParser}). {@code
qoder} streams the
+ * completion as plain text — its provider inherits the default {@code
AgentProvider.streamEvents}
+ * adapter, which emits text deltas and nothing else — so a Qoder turn
that ended has no frame to
+ * end with, and the HTTP engine has no agent stream at all.
+ */
+ static boolean expectsResultFrame(String engine) {
+ return StringUtils.hasText(engine)
+ &&
LlmConfigVO.ENGINE_CLAUDE_CODE.equals(engine.trim().toLowerCase(Locale.ROOT));
+ }
+
/**
* Shuts the runs down before the JVM does.
*
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/ops/ai/conversation/AiRunServiceTest.java
b/server/src/test/java/org/apache/rocketmq/studio/ops/ai/conversation/AiRunServiceTest.java
index bfb734997..d794eed74 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/ops/ai/conversation/AiRunServiceTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/ops/ai/conversation/AiRunServiceTest.java
@@ -162,6 +162,8 @@ class AiRunServiceTest {
@Test
void admissionShouldQueueTheRunWithASnapshotOfTheEngineAndModelTest() {
provider.engineName = LlmConfigVO.ENGINE_QODER;
+ // The shape of a Qoder turn: the CLI's completion arrives as plain
text and nothing else.
+ provider.emit(new AgentEvent.TextDelta("broker b1 is lagging"));
service = serviceWith(AiRunTestSupport.directExecutor());
service.sendMessage(CONVERSATION_ID, new AiRunService.RunRequest(
@@ -177,11 +179,12 @@ class AiRunServiceTest {
// The worker picked the run up: QUEUED is a real state, not a label
the row keeps.
assertThat(runUpdates.get(0).getStatus()).isEqualTo(RunStatus.RUNNING.name());
assertThat(runUpdates.get(0).getStartedAt()).isNotNull();
- // ...and the run really did go on to execute and reach a terminal on
the queued engine —
- // a terminal, not specifically a success: this stub streams no
frames, so the turn ends
- // with the no-result failure instead of a success nothing projected.
- assertThat(lastRun().getStatus()).isEqualTo(RunStatus.FAILED.name());
-
assertThat(lastRun().getStopReason()).isEqualTo(StopReason.PROVIDER_ERROR.name());
+ // ...and the run really did go on to execute and finish on the queued
engine. Qoder's
+ // provider streams its completion as plain text and never reports a
result frame, so a
+ // finished turn without one is a success; the no-result failure
belongs to the engines whose
+ // stream carries a result frame.
+
assertThat(lastRun().getStatus()).isEqualTo(RunStatus.COMPLETED.name());
+ assertThat(lastRun().getStopReason()).isNull();
assertThat(emitters.get(0).timeoutMillis()).isEqualTo(AiRunExecutor.CLI_STREAM_TIMEOUT_MILLIS);
}
@@ -374,6 +377,25 @@ class AiRunServiceTest {
assertThat(registry.isLive(RUN_ID)).isFalse();
}
+ @Test
+ void aTextOnlyEngineTurnMustCompleteWithoutAResultFrameTest() {
+ // The other half of the no-result branch: it is scoped to the engines
whose agent stream
+ // carries a result frame. Qoder is not one of them — its provider
streams the completion as
+ // plain text (the default AgentProvider.streamEvents adapter) and
nothing in the qoder path
+ // ever emits a ResultMeta — so a finished Qoder turn has no frame to
end with. Failing it
+ // would report every successful Qoder answer as a provider error.
+ provider.engineName = LlmConfigVO.ENGINE_QODER;
+ provider.emit(new AgentEvent.TextDelta("group G is 1200 messages
behind"));
+ service = serviceWith(AiRunTestSupport.directExecutor());
+
+ service.sendMessage(CONVERSATION_ID,
+ new AiRunService.RunRequest("what is lagging", null,
LlmConfigVO.ENGINE_QODER, null, false, null));
+
+
assertThat(lastRun().getStatus()).isEqualTo(RunStatus.COMPLETED.name());
+ assertThat(lastRun().getStopReason()).isNull();
+ assertThat(lastRun().getErrorCode()).isNull();
+ }
+
@Test
void aBlankOrOversizedMessageShouldBeRefusedBeforeARowIsWrittenTest() {
assertThatThrownBy(() -> service.sendMessage(CONVERSATION_ID,
AiRunService.RunRequest.of(" ")))