Skip to content

Dev/issue#135

Closed
luk384090-cloud wants to merge 12 commits into
mainfrom
dev/issue
Closed

Dev/issue#135
luk384090-cloud wants to merge 12 commits into
mainfrom
dev/issue

Conversation

@luk384090-cloud

Copy link
Copy Markdown
Collaborator

Description

[Describe what this PR does and why]

Related Issue: Fixes #[issue_number] or Relates to #[issue_number]

Security Considerations: [Check if API keys or sensitive credentials are exposed in code/logs]

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactoring

Component(s) Affected

  • Model
  • Application
  • Common
  • Documentation
  • Tests
  • CI/CD

Checklist

  • Pre-commit hooks pass
  • Tests pass locally
  • Documentation updated (if needed)
  • Ready for review

Testing

[How to test these changes]

Additional Notes

[Optional: any other context]

kevin added 10 commits June 9, 2026 13:53
- Add detailed exception logging for sync and async HTTP streaming requests
- Include request context such as url, method, stream, timeout, status code, and request id
- Handle SSE done events consistently across streaming parsers
- Avoid swallowing stream read failures while preserving original exception behavior
- Fix pylint warning by avoiding redefinition of built-in id

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces several enhancements and bug fixes to the DashScope SDK. Key changes include adding support for wait_timeout_seconds in asynchronous task polling, introducing the AioTextReRank class for asynchronous text reranking, respecting the trust_env configuration in HTTP client sessions, improving SSE stream handling to properly reset event types on empty lines, and robustly resolving local file URIs. Additionally, connection lifecycle management for real-time TTS was enhanced with threading events. The code review feedback highlights two opportunities for improvement: first, ensuring that the sync version of call() in base_api.py copies kwargs to prevent losing custom configurations during polling; second, refactoring the session creation wait logic in qwen_tts_realtime.py into a polling loop to avoid timeout accumulation and unnecessary blocking when the websocket closes.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread dashscope/client/base_api.py Outdated
Comment on lines +653 to +655
wait_kwargs = {}
if wait_timeout_seconds is not None:
wait_kwargs["wait_timeout_seconds"] = wait_timeout_seconds

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.

medium

In the sync version of call(), wait_kwargs is initialized as an empty dictionary ({}), which means any additional keyword arguments (such as headers or base_address) passed to call() are lost and not forwarded to cls.wait(). In contrast, the async version (BaseAsyncAioApi.call()) correctly copies kwargs using kwargs.copy().

To ensure consistency and prevent custom configurations from being ignored during the polling phase, wait_kwargs should be initialized as a copy of kwargs.

Suggested change
wait_kwargs = {}
if wait_timeout_seconds is not None:
wait_kwargs["wait_timeout_seconds"] = wait_timeout_seconds
wait_kwargs = kwargs.copy()
if wait_timeout_seconds is not None:
wait_kwargs["wait_timeout_seconds"] = wait_timeout_seconds

Comment on lines 168 to 172
if not self.session_created_event.wait(timeout):
raise TimeoutError(
"websocket session could not be created within 5s. "
f"{self._build_connection_state_message()}",
)

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.

medium

There are two issues with using self.session_created_event.wait(timeout) here:

  1. Timeout Accumulation: Since timeout (5 seconds) is passed directly to wait(), the total potential wait time can be up to 10 seconds (5s for the connection loop + 5s for the session event), which contradicts the error message stating it could not be created within 5s.
  2. Unnecessary Blocking on Close: If the websocket connection is closed (e.g., due to a handshake/auth failure) while waiting for the session to be created, wait() will still block for the remaining duration because it does not monitor self.websocket_closed_event.

Using a polling loop that checks both events and respects the overall start time solves both issues.

Suggested change
if not self.session_created_event.wait(timeout):
raise TimeoutError(
"websocket session could not be created within 5s. "
f"{self._build_connection_state_message()}",
)
while (
not self.session_created_event.is_set()
and not self.websocket_closed_event.is_set()
and (time.time() - start_time) < timeout
):
time.sleep(0.1)
if not self.session_created_event.is_set():
raise TimeoutError(
"websocket session could not be created within 5s. "
f"{self._build_connection_state_message()}",
)

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.

1 participant