You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "qiyu-lu (via GitHub)" <gi...@apache.org> on 2026/09/08 02:42:22 UTC

[I] [studio] AI 流式输出丢失独立的空格、换行和缩进片段 [rocketmq-dashboard]

qiyu-lu opened a new issue, #4108:
URL: https://github.com/apache/rocketmq-dashboard/issues/4108

   ## 问题
   
   AI 助手使用 HTTP 引擎接收 OpenAI-compatible SSE 响应时,如果模型把空格、换行或缩进单独放在一个 `choices[0].delta.content` 片段中,后端会丢弃该片段,导致单词粘连、Markdown 换行和代码缩进丢失。同样的内容是否出错取决于上游如何分片。
   
   ## 环境与复现
   
   - 分支:`rocketmq-studio`,基线提交:`d6dee7d7ccfcf4886f02466ec51452a6928b2cc8`。
   - 后端 Java 21;AI 设置中启用 HTTP 引擎,配置可用的 OpenAI-compatible API 地址、模型及所需凭据。
   
   1. 在 AI 助手中要求模型输出包含空行、列表或缩进代码块的 Markdown。
   2. 当上游返回独立的纯空白 content 片段时,页面输出会缺失对应的空白。真实模型的分片方式不固定,因此不是每次请求都会触发。
   3. 可在 `OpenAiCompatibleLlmClient.emitStreamEvent` 的 content 判断处设置条件断点 `token != null && !token.isEmpty() && token.isBlank()`,观察片段没有传递给下游。
   
   不依赖真实模型的最小示例:依次用 SSE `data:` 事件发送以下 content 片段(例如空格事件为 `data: {"choices":[{"delta":{"content":" "}}]}`),最后发送 `[DONE]`:
   
   ```json
   ["hello", " ", "world", "\n", "    ", "next"]
   ```
   
   预期拼接结果为 `"hello world\n    next"`,实际为 `"helloworldnext"`。
   
   ## 原因与预期行为
   
   `OpenAiCompatibleLlmClient.emitStreamEvent` 使用 `StringUtils.hasText(token)`,错误地过滤了合法的纯空白 content。`OpenAiCompatibleLlmGateway.emitEnhanceChunk` 也使用相同判断,提示词增强预览存在同类问题。
   
   应保留所有非空 content/chunk,包括空格、LF、CRLF、Tab、连续空格和空行;仍然忽略 null、空字符串和没有 content 的元数据事件,并保持 `[DONE]` 与错误事件行为不变。
   
   计划用一个小范围 PR 修复这两处判断,并增加客户端 SSE 与增强预览回归测试。
   


-- 
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: commits-unsubscribe@rocketmq.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [studio] AI 流式输出丢失独立的空格、换行和缩进片段 [rocketmq-dashboard]

Posted by "RockteMQ-AI (via GitHub)" <gi...@apache.org>.
RockteMQ-AI commented on issue #4108:
URL: https://github.com/apache/rocketmq-dashboard/issues/4108#issuecomment-5579038791

   Thank you for reporting this well-detailed issue.
   
   After code analysis, we have confirmed this is a real bug. The root cause is in `OpenAiCompatibleLlmClient.emitStreamEvent` where `StringUtils.hasText(token)` (line ~273) returns `false` for whitespace-only strings — it requires at least one non-whitespace character. This silently drops standalone space, newline, and indentation fragments from the SSE stream.
   
   **Classification:**
   - **Type:** Bug
   - **Confidence:** High
   - **Status:** Confirmed, under investigation for fix
   
   The fix direction you suggested is correct — the condition should preserve whitespace-only content fragments rather than filtering them out. We will prepare a fix.


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [studio] AI 流式输出丢失独立的空格、换行和缩进片段 [rocketmq-dashboard]

Posted by "qiyu-lu (via GitHub)" <gi...@apache.org>.
qiyu-lu commented on issue #4108:
URL: https://github.com/apache/rocketmq-dashboard/issues/4108#issuecomment-5578321139

   修复 PR:#4109,目标分支为 rocketmq-studio。改动限于两处空白片段判断及对应回归测试;本地 39 项后端测试、17 项前端 SSE API 测试和 Checkstyle 均通过。


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [studio] AI 流式输出丢失独立的空格、换行和缩进片段 [rocketmq-dashboard]

Posted by "lizhimins (via GitHub)" <gi...@apache.org>.
lizhimins commented on issue #4108:
URL: https://github.com/apache/rocketmq-dashboard/issues/4108#issuecomment-5581293214

   Resolved by #4109, merged into `rocketmq-studio` as 10a7b493.
   
   The two chunk filters were the only places dropping whitespace: `OpenAiCompatibleLlmClient.java:273` (`hasText(token)`) and `OpenAiCompatibleLlmGateway.java:211` (`!hasText(chunk)`). Both now use `hasLength`, so a delta whose content is only spaces, newlines or indentation is forwarded instead of discarded.
   
   Worth recording that the impact was slightly wider than this issue describes: `enhanceAndEmitHttp` accumulates inside the client's consumer (`OpenAiCompatibleLlmGateway.java:202-205`), so on trunk the whitespace was stripped from the prompt actually sent to the model, not only from the streamed preview.
   
   The guard was narrowed rather than removed. `parseDelta` returns `asText("")` and never null (`OpenAiCompatibleLlmClient.java:454`), and `hasLength("")` is still false, so role-only, `finish_reason` and `usage` deltas are still skipped, `[DONE]` termination is unaffected, and the non-streaming `parseCompletion` path correctly keeps `hasText`.
   
   Because this repository squash-merges against `rocketmq-studio` rather than the default branch, GitHub does not auto-close issues referenced in a PR body; closing manually.


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [studio] AI 流式输出丢失独立的空格、换行和缩进片段 [rocketmq-dashboard]

Posted by "lizhimins (via GitHub)" <gi...@apache.org>.
lizhimins closed issue #4108: [studio] AI 流式输出丢失独立的空格、换行和缩进片段
URL: https://github.com/apache/rocketmq-dashboard/issues/4108


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org