Skip to content

fix: raise MiMo TTS legacy timeout default#6939

Open
1zzxy1 wants to merge 3 commits intoAstrBotDevs:masterfrom
1zzxy1:fix/mimo-tts-timeout
Open

fix: raise MiMo TTS legacy timeout default#6939
1zzxy1 wants to merge 3 commits intoAstrBotDevs:masterfrom
1zzxy1:fix/mimo-tts-timeout

Conversation

@1zzxy1
Copy link
Contributor

@1zzxy1 1zzxy1 commented Mar 25, 2026

Summary

  • raise the MiMo TTS default timeout from 20s to 60s for new configs
  • treat the legacy 20s default as a migration path at runtime so older configs do not keep timing out on long audio generation
  • add regression tests covering the legacy default upgrade and explicit custom timeout preservation

Closes #6841

Testing

  • uv run --group dev pytest tests/test_mimo_api_sources.py -q

Summary by Sourcery

Increase MiMo TTS default timeout and ensure legacy configurations transparently adopt the new default while preserving explicit custom timeouts.

Bug Fixes:

  • Prevent MiMo TTS requests from timing out prematurely on long audio generation when using the legacy 20-second default.

Enhancements:

  • Introduce a shared MiMo TTS timeout constant and update the provider to use it with a migration path from the legacy 20-second default.

Tests:

  • Add regression tests verifying automatic upgrade of the legacy 20-second timeout to 60 seconds and preservation of explicitly configured custom timeouts.

@auto-assign auto-assign bot requested review from Raven95676 and Soulter March 25, 2026 10:19
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 25, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 addresses an issue where MiMo TTS audio generation could time out, especially for longer outputs or older configurations. It increases the default timeout to 60 seconds and introduces a migration path to automatically update existing 20-second timeouts, ensuring smoother operation without requiring manual configuration changes for users. Comprehensive regression tests have been added to validate this behavior.

Highlights

  • Increased Default Timeout: The default MiMo TTS timeout was raised from 20 seconds to 60 seconds for new configurations.
  • Legacy Timeout Migration: Older configurations with the 20-second default timeout will now be automatically upgraded to 60 seconds at runtime to prevent audio generation timeouts.
  • Regression Tests: New tests were added to ensure the correct handling of both legacy default timeout upgrades and the preservation of explicitly set custom timeouts.
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.

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.

@dosubot dosubot bot added the area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. label Mar 25, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • The legacy migration logic hardcodes 20 as the old timeout; consider introducing a LEGACY_MIMO_TTS_TIMEOUT = 20 constant so the comparison stays in sync with any future changes and makes the intent clearer.
  • The tests manually call asyncio.run(provider.terminate()) in multiple places; factoring this into a small helper or fixture would reduce duplication and make it easier to adjust the termination behavior later.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The legacy migration logic hardcodes `20` as the old timeout; consider introducing a `LEGACY_MIMO_TTS_TIMEOUT = 20` constant so the comparison stays in sync with any future changes and makes the intent clearer.
- The tests manually call `asyncio.run(provider.terminate())` in multiple places; factoring this into a small helper or fixture would reduce duplication and make it easier to adjust the termination behavior later.

## Individual Comments

### Comment 1
<location path="astrbot/core/provider/sources/mimo_tts_api_source.py" line_range="41" />
<code_context>
+            provider_config.get("timeout", DEFAULT_MIMO_TTS_TIMEOUT)
+        )
+        # MiMo TTS often needs longer than the legacy 20s default for large outputs.
+        if timeout in (None, 20):
+            timeout = DEFAULT_MIMO_TTS_TIMEOUT
+        self.timeout = timeout
</code_context>
<issue_to_address>
**suggestion:** Using `20` as a magic number here makes the migration behavior harder to follow.

This condition bakes in `20` as a special legacy value tied to the old default. To improve maintainability, consider naming this value (e.g., `LEGACY_MIMO_TTS_TIMEOUT`) or deriving the check from the raw config/legacy default instead, so behavior stays clear if defaults change later.

Suggested implementation:

```python
        timeout = normalize_timeout(
            provider_config.get("timeout", DEFAULT_MIMO_TTS_TIMEOUT)
        )
        # MiMo TTS often needs longer than the legacy default for large outputs.
        # Treat `LEGACY_MIMO_TTS_TIMEOUT` as a special value so behavior stays clear if defaults change.
        if timeout in (None, LEGACY_MIMO_TTS_TIMEOUT):
            timeout = DEFAULT_MIMO_TTS_TIMEOUT
        self.timeout = timeout

```

To fully implement the change and avoid the magic number, you should also:

1. Define a `LEGACY_MIMO_TTS_TIMEOUT` constant near the other MiMo-related defaults in `mimo_tts_api_source.py`, e.g. close to where `DEFAULT_MIMO_TTS_TIMEOUT` is declared:

   ```python
   LEGACY_MIMO_TTS_TIMEOUT = 20  # seconds; previous MiMo TTS timeout default
   DEFAULT_MIMO_TTS_TIMEOUT = ...
   ```

   (Preserve the existing value and placement of `DEFAULT_MIMO_TTS_TIMEOUT`; only insert the new constant above or nearby.)

2. If this module is imported elsewhere via `*` or re-exported, no further changes are needed, since the constant is only used internally here.
</issue_to_address>

### Comment 2
<location path="tests/test_mimo_api_sources.py" line_range="139-144" />
<code_context>
     }


+def test_mimo_tts_raises_legacy_default_timeout_to_60_seconds():
+    provider = _make_tts_provider({"timeout": "20"})
+    try:
+        assert provider.timeout == 60
+    finally:
+        asyncio.run(provider.terminate())
+
+
</code_context>
<issue_to_address>
**suggestion (testing):** Add coverage for legacy timeout expressed as an integer and missing/None timeout values

This only exercises the legacy timeout when given as a string. Since `provider_config.get("timeout", ...)` may return an `int` or `str` and the migration logic checks `timeout in (None, 20)` after `normalize_timeout`, please also add tests for `{"timeout": 20}`, `{"timeout": None}`, and (if not already covered) the case where `timeout` is omitted. That will validate the migration behavior across all legacy configurations.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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 updates the default timeout for MiMo TTS operations from 20 seconds to 60 seconds. This change is implemented by introducing a new DEFAULT_MIMO_TTS_TIMEOUT constant, updating the default configuration, and modifying the MiMoTTSAPISource class to ensure that both unspecified timeouts and the legacy 20-second timeout are upgraded to 60 seconds. New unit tests have been added to confirm this behavior, ensuring that the legacy default is correctly raised while explicit custom timeouts are preserved. There are no review comments to provide feedback on.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Mar 25, 2026
provider_config.get("timeout", DEFAULT_MIMO_TTS_TIMEOUT)
)
# MiMo TTS often needs longer than the legacy 20s default for large outputs.
if timeout in (None, 20):
Copy link
Member

Choose a reason for hiding this comment

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

建议去掉这个if判断

# Conflicts:
#	tests/test_mimo_api_sources.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]TTS请求超时时间过短,导致一些比较大的语音无法通过钉钉发送

2 participants