Skip to content

Conversation

@CH3CHO
Copy link
Collaborator

@CH3CHO CH3CHO commented May 29, 2025

Ⅰ. Describe what this PR did

Support mixing line breaks in a single SSE response.

image

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@CH3CHO CH3CHO requested review from johnlanni and rinfx as code owners May 29, 2025 14:43
@lingma-agents
Copy link

lingma-agents bot commented May 29, 2025

修复SSE响应中混合换行符处理的兼容性问题

变更文件

文件路径 变更说明
plugins/​golang-filter/​mcp-session/​filter.go 将换行符检测逻辑重构为支持CR和LF混合格式,新增findNextLineBreak函数处理不同换行符组合,优化endpoint URL定位时的错误处理流程,移除旧的findSSELineBreak函数实现

时序图

Sequence diagram
    participant Filter as filter
    participant Buffer as buffer
    participant EndpointFinder as endpointFinder
    Filter->>Buffer: encodeDataFromSSEUpstream()
    Buffer-->>Filter: bufferBytes
    Filter->>Filter: findNextLineBreak(bufferData)
    Filter->>EndpointFinder: findEndpointUrl()
    EndpointFinder-->>Filter: endpointUrl
    Filter->>Filter: rewriteEndpointUrl()
Loading

💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @Lingma-Agent 分析这个方法的性能瓶颈并提供优化建议。

  • @Lingma-Agent 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @Lingma-Agent 请总结上述讨论并提出解决方案。

  • @Lingma-Agent 请根据讨论内容生成优化代码。

Copy link

@lingma-agents lingma-agents bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 代码评审报告

📋 评审意见详情

💡 单文件建议

✅ 未发现需要特别关注的代码问题。

🚀 跨文件建议

以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍 1. 函数拆分导致逻辑不一致性风险

在将findSSELineBreak拆分为findNextLineBreak并修改findEndpointUrl的参数后,存在逻辑不一致风险。原函数通过lineBreak参数传递换行符类型,而新逻辑直接调用findNextLineBreak获取换行符,可能导致以下问题:

  1. findEndpointUrl中两次调用findNextLineBreak可能返回不同换行符类型,但未验证其一致性
  2. 原先对非相邻CR/LF组合的错误处理(如旧代码第381行)被简化,可能导致兼容性问题
  3. 新增的findNextLineBreak未明确说明处理优先级规则(如同时存在\r和\n时的选择逻辑)

📌 关键代码:

func (f *filter) findNextLineBreak(bufferData string) (error, string) {
  // 新逻辑未完全继承原findSSELineBreak的错误处理逻辑

⚠️ 潜在风险: 可能导致:

  • 对混合换行符的SSE数据解析失败
  • 兼容旧换行符格式时出现意外错误
  • 新增未覆盖的异常场景(如\r\n\r混合情况)
🔍 2. 错误处理逻辑覆盖不完整

新增的findEndpointUrl函数在两次调用findNextLineBreak后,未处理lineBreak == ""时的缓冲重试逻辑。原findSSELineBreak在未找到换行符时会返回StopAndBuffer继续缓冲(旧代码第284行),但新逻辑直接返回空值导致流程中断,可能导致:

  • 部分数据未被正确缓冲处理
  • 对分片传输的SSE数据处理失败

📌 关键代码:

if lineBreak == "" {
  // No line break found, which means the data is not enough.
  return nil, ""
}

⚠️ 潜在风险: 可能导致:

  • 不完整SSE事件体被错误丢弃
  • 流式传输场景下的数据解析失败
🔍 3. 测试覆盖策略不足

PR中未添加针对混合换行符(如\r\n与\n共存)的测试用例,现有测试可能无法验证核心修复逻辑。特别是:

  1. 混合CR/LF的边界情况(如\r\n\r或\n\r组合)
  2. 多事件分片传输场景下的缓冲处理
  3. 非标准换行符组合(如单独出现的\n\r)的容错处理

⚠️ 潜在风险: 可能遗留:

  • 未被发现的解析错误
  • 新增兼容性问题
  • 压力场景下的稳定性风险
🔍 4. 架构模式变更未同步文档

函数参数变更(如findEndpointUrl移除lineBreak参数)和处理流程变化(从集中式换行符检测到分散调用)未在代码注释或架构文档中体现。可能导致:

  • 后续维护者难以理解设计变更动机
  • 其他依赖组件出现不兼容修改

⚠️ 潜在风险: 可能导致:

  • 未来代码重构时引入隐藏错误
  • 团队对架构演进方向理解偏差

💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @Lingma-Agent 分析这个方法的性能瓶颈并提供优化建议。

  • @Lingma-Agent 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @Lingma-Agent 请总结上述讨论并提出解决方案。

  • @Lingma-Agent 请根据讨论内容生成优化代码。

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.06%. Comparing base (ef31e09) to head (b86dcdd).
Report is 529 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2344       +/-   ##
===========================================
+ Coverage   35.91%   46.06%   +10.15%     
===========================================
  Files          69       81       +12     
  Lines       11576    13010     +1434     
===========================================
+ Hits         4157     5993     +1836     
+ Misses       7104     6671      -433     
- Partials      315      346       +31     

see 78 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@johnlanni johnlanni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@johnlanni johnlanni merged commit f3fbf7d into alibaba:main Jun 10, 2025
14 checks passed
@CH3CHO CH3CHO deleted the fix/mcp-session-crlf-compatibility branch June 10, 2025 13:23
ink-hz pushed a commit to ink-hz/higress-ai-capability-auth that referenced this pull request Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants