Skip to content

Conversation

@AllenDou
Copy link
Contributor

@AllenDou AllenDou commented Jan 6, 2026

when mode is 2pass and test audio is vad_example.wav, we should give more time to websocket connection to recv message, or funasr_wss_client.py's websocket.recv() will cause exception occasionally because connection has been closed.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @AllenDou, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an intermittent issue in the WebSocket client where the connection would sometimes close before all messages could be received, leading to exceptions. By strategically adding a short asynchronous delay before the connection closure, the change ensures that the client has ample time to process incoming data, thereby enhancing the stability and reliability of the WebSocket communication during specific test scenarios.

Highlights

  • WebSocket Connection Stability: Introduced a 5-second delay before closing the WebSocket connection in funasr_wss_client.py to prevent websocket.recv() exceptions. This addresses an issue where the connection might close prematurely, especially in '2pass' mode with 'vad_example.wav' audio.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 aims to fix a race condition in 2pass mode where the websocket connection is closed before the final message is received. It does so by adding a fixed 5-second sleep. While this may resolve the issue for the specific test case, it's not a robust solution. My review provides a more reliable synchronization mechanism using the existing offline_msg_done flag, which avoids both race conditions and unnecessary delays. This involves a small change in the message function to signal completion and replacing the hardcoded sleep with a conditional wait loop.

while not offline_msg_done:
await asyncio.sleep(1)

await asyncio.sleep(5)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Using a hardcoded sleep is not a robust way to handle synchronization. The time needed for the server to process and return the final message can vary based on server load, network conditions, and the length of the audio. This can lead to either unnecessary delays or race conditions if the sleep duration is too short.

A more reliable approach is to use an explicit synchronization mechanism. The offline_msg_done flag is already used for this in offline mode. You can extend this to 2pass mode.

First, you'll need to modify the message function to set offline_msg_done = True when it receives the final 2pass-offline result. This is the message that has is_final: False.

# In funasr_wss_client.py, message()
...
           else: # 2pass mode
               if meg["mode"] == "2pass-online":
                   ...
               else: # 2pass-offline
                   ...
                   print("\rpid" + str(id) + ": " + text_print)
                   # The final message in 2-pass mode will have 'is_final': False.
                   if not meg.get("is_final", True):
                       global offline_msg_done
                       offline_msg_done = True

Then, you can replace the hardcoded sleep with a loop that waits for offline_msg_done to be set when in 2pass mode, ideally with a timeout.

Suggested change
await asyncio.sleep(5)
if args.mode == "2pass":
# Wait for the final message. This requires a change in the `message` function.
timeout = 10 # seconds
while not offline_msg_done and timeout > 0:
await asyncio.sleep(1)
timeout -= 1
else:
await asyncio.sleep(5)

…more time to websocket connection to recv message, or funasr_wss_client.py's websocket.recv() will cause exception occasionally because connection has been closed.
@LauraGPT LauraGPT merged commit 36656aa into modelscope:main Jan 7, 2026
@AllenDou AllenDou deleted the bugfix branch January 8, 2026 02:59
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.

2 participants