Skip to content

fix(dashscope): preserve SSE error response body#2278

Open
zouyx wants to merge 2 commits into
agentscope-ai:mainfrom
zouyx:featrue/fix-dashscope-sse-request-id
Open

fix(dashscope): preserve SSE error response body#2278
zouyx wants to merge 2 commits into
agentscope-ai:mainfrom
zouyx:featrue/fix-dashscope-sse-request-id

Conversation

@zouyx

@zouyx zouyx commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.1-SNAPSHOT

Description

Fixes #2197.

DashScope SSE error events contain the model request_id, but DashScopeHttpClient.stream() previously discarded the raw error payload and constructed DashScopeHttpException with a null response body.

This change preserves the parsed response together with its raw SSE payload, then propagates that payload through DashScopeHttpException#getResponseBody(). Callers can therefore retrieve the DashScope request_id from the error response body.

A regression test verifies that a streaming error preserves request_id in the exception response body.

Checklist

  • Code formatting was verified by the Maven Spotless check.
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions (no public API added).
  • Related documentation has been updated (not required for this internal error-propagation fix).
  • Code is ready for review.

Copilot AI review requested due to automatic review settings July 18, 2026 16:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes DashScope streaming (SSE) error propagation so callers can access the original error payload (including request_id) via DashScopeHttpException#getResponseBody(), addressing #2197.

Changes:

  • Preserve the raw (post-decryption) SSE event payload alongside the parsed DashScopeResponse during streaming.
  • Populate DashScopeHttpException with the preserved response body when an SSE error event is received.
  • Add a regression test asserting request_id is present in the exception response body for streaming errors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-dashscope/src/main/java/io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java Wraps parsed SSE responses with their original payload and forwards that payload into DashScopeHttpException on error.
agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-dashscope/src/test/java/io/agentscope/extensions/model/dashscope/DashScopeHttpClientTest.java Extends the streaming error test to verify request_id is preserved in getResponseBody().

@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/extensions agentscope-extensions (general) labels Jul 19, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 AI Review

This is a clean, focused bug fix that addresses issue #2197. The streaming path in DashScopeHttpClient.stream() was discarding the raw SSE error payload and passing null as the response body to DashScopeHttpException, while the synchronous execute() path already correctly propagated it. The fix introduces a lightweight ParsedStreamResponse record to carry both the raw response string and the parsed DashScopeResponse through the reactive pipeline, making the streaming error path symmetric with the sync path. The regression test properly verifies that request_id is preserved in the exception's response body. No logical defects, concurrency issues, or architectural concerns found.

@@ -834,6 +837,8 @@ public DashScopeHttpClient build() {
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[praise] Clean use of a private record to thread the raw response body alongside the parsed response through the reactive pipeline. Minimal change surface, no side channels, and makes the streaming error path symmetric with the sync execute() path at line 215. Well done.

.equals("DashScope API error: " + errorMessage))
.equals("DashScope API error: " + errorMessage)
&& dashScopeHttpException
.getResponseBody()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[praise] Good regression test — asserting getResponseBody().contains("request_id") directly validates the fix for #2197 and guards against future regressions.

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 AI Review

This is a clean, focused bug fix that addresses issue #2197. The streaming path in DashScopeHttpClient.stream() was discarding the raw SSE error payload and passing null as the response body to DashScopeHttpException, while the synchronous execute() path already correctly propagated it. The fix introduces a lightweight ParsedStreamResponse record to carry both the raw response string and the parsed DashScopeResponse through the reactive pipeline, making the streaming error path symmetric with the sync path. The regression test properly verifies that request_id is preserved in the exception's response body. No logical defects, concurrency issues, or architectural concerns found.

@@ -834,6 +837,8 @@ public DashScopeHttpClient build() {
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[praise] Clean use of a private record to thread the raw response body alongside the parsed response through the reactive pipeline. Minimal change surface, no side channels, and makes the streaming error path symmetric with the sync execute() path at line 215. Well done.

.equals("DashScope API error: " + errorMessage))
.equals("DashScope API error: " + errorMessage)
&& dashScopeHttpException
.getResponseBody()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[praise] Good regression test — asserting getResponseBody().contains("request_id") directly validates the fix for #2197 and guards against future regressions.

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

This PR contains 91 lines of changes. Review in progress.


Automated review by github-manager-bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/extensions agentscope-extensions (general) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:sse请求模型,模型的requestid未返回

4 participants