Skip to content

The agent that grows with you

fix(qqbot): test the STT timeout at the HTTP call-site; share the 60s default and number parsing

teknium1aa5038303041
diff --git a/gateway/platforms/qqbot/adapter.py b/gateway/platforms/qqbot/adapter.py
index b4890438555..d77a4770650 100644
--- a/gateway/platforms/qqbot/adapter.py
+++ b/gateway/platforms/qqbot/adapter.py
@@ -81,7 +81,6 @@ def check_qq_requirements() -> bool:
_VOICE_EXTENSIONS = (".silk", ".amr", ".mp3", ".wav", ".ogg", ".m4a", ".aac", ".speex", ".flac")
-_STT_DEFAULT_TIMEOUT = 60.0 # seconds; matches stt.openai.timeout's default
_STT_PROVIDER_BASE_URLS = {
"zai": "https://open.bigmodel.cn/api/coding/paas/v4",
# Aliases that target direct REST APIs not modeled as first-class providers in PROVIDER_REGISTRY. Used
@@ -1203,15 +1202,13 @@ class QQAdapter(OwnAccessPolicyMixin, BasePlatformAdapter):
vars; None when unconfigured (QQ's built-in ASR still works). ``timeout`` (seconds,
default 60) follows the shared STT client default so a self-hosted model's cold start
is not cut off at 30s (#112939)."""
+ from tools.transcription_common import DEFAULT_STT_TIMEOUT, _config_number # lazy: keep adapter light
stt_cfg = (self.config.extra or {}).get("stt")
if isinstance(stt_cfg, dict) and stt_cfg.get("enabled") is not False:
base_url = stt_cfg.get("baseUrl") or stt_cfg.get("base_url", "")
api_key = stt_cfg.get("apiKey") or stt_cfg.get("api_key", "")
model = stt_cfg.get("model", "")
- try:
- timeout = float(stt_cfg.get("timeout", _STT_DEFAULT_TIMEOUT))
- except (TypeError, ValueError):
- timeout = _STT_DEFAULT_TIMEOUT
+ timeout = _config_number(stt_cfg, "timeout", DEFAULT_STT_TIMEOUT)
if base_url and api_key:
return {"base_url": base_url.rstrip("/"), "api_key": api_key, "model": model or "whisper-1",
"timeout": timeout}
@@ -1228,7 +1225,7 @@ class QQAdapter(OwnAccessPolicyMixin, BasePlatformAdapter):
base_url = _resolve_qq_secret("QQ_STT_BASE_URL", _STT_PROVIDER_BASE_URLS["zai"])
model = _resolve_qq_secret("QQ_STT_MODEL", "glm-asr")
return {"base_url": base_url.rstrip("/"), "api_key": qq_stt_key, "model": model,
- "timeout": _STT_DEFAULT_TIMEOUT}
+ "timeout": DEFAULT_STT_TIMEOUT}
return None
async def _call_stt(self, wav_path: str) -> Optional[str]:
diff --git a/tests/gateway/test_qqbot.py b/tests/gateway/test_qqbot.py
index 69d77a4d1aa..e73ebdfa1ce 100644
--- a/tests/gateway/test_qqbot.py
+++ b/tests/gateway/test_qqbot.py
@@ -287,14 +287,25 @@ class TestResolveSTTConfig:
with mock.patch.dict(os.environ, {}, clear=True):
assert adapter._resolve_stt_config() is None
- def test_timeout_defaults_to_60_and_honours_config(self):
- """The STT request timeout is configurable and no longer a fixed 30s (#112939)."""
+ def test_call_stt_posts_with_configured_timeout(self, tmp_path):
+ """The configured ``stt.timeout`` reaches the STT HTTP request; default 60s, not the
+ old fixed 30s (#112939). Drives ``_call_stt`` so a regression at the call-site is caught."""
+ wav = tmp_path / "v.wav"
+ wav.write_bytes(b"RIFF")
+ posted = []
+
+ class _FakeClient:
+ async def post(self, url, **kwargs):
+ posted.append(kwargs)
+ return httpx.Response(200, json={"text": "hi"}, request=httpx.Request("POST", url))
+
with mock.patch.dict(os.environ, {}, clear=True):
- adapter = self._make_adapter(app_id="a", client_secret="b", stt={"apiKey": "k", "provider": "zai"})
- assert adapter._resolve_stt_config()["timeout"] == 60.0
- adapter = self._make_adapter(app_id="a", client_secret="b",
- stt={"apiKey": "k", "provider": "zai", "timeout": "95"})
- assert adapter._resolve_stt_config()["timeout"] == 95.0
+ for stt, expected in (({"apiKey": "k", "provider": "zai"}, 60.0),
+ ({"apiKey": "k", "provider": "zai", "timeout": "95"}, 95.0)):
+ adapter = self._make_adapter(app_id="a", client_secret="b", stt=stt)
+ adapter._http_client = _FakeClient()
+ assert asyncio.run(adapter._call_stt(str(wav))) == "hi"
+ assert posted[-1]["timeout"] == expected
# ---------------------------------------------------------------------------
diff --git a/tools/transcription_cloud.py b/tools/transcription_cloud.py
index 97c87c23f55..f01635ec370 100644
--- a/tools/transcription_cloud.py
+++ b/tools/transcription_cloud.py
@@ -45,13 +45,13 @@ def _with_openai_client(api_key: str, base_url: Optional[str], file_path: str, l
subclass) so timeouts report as connection errors, as they always have."""
try:
from openai import OpenAI
- from tools.transcription_common import _config_number
+ from tools.transcription_common import DEFAULT_STT_TIMEOUT, _config_number
from tools.transcription_tools import _load_stt_config
openai_config = _get_stt_section(_load_stt_config(), "openai")
client = OpenAI(
api_key=api_key,
base_url=base_url,
- timeout=_config_number(openai_config, "timeout", 60.0),
+ timeout=_config_number(openai_config, "timeout", DEFAULT_STT_TIMEOUT),
max_retries=_config_number(openai_config, "max_retries", 1, cast=int),
)
try:
diff --git a/tools/transcription_common.py b/tools/transcription_common.py
index 3a0401e7a2b..94b5c1a7bdb 100644
--- a/tools/transcription_common.py
+++ b/tools/transcription_common.py
@@ -19,6 +19,9 @@ DEFAULT_STT_MODEL = os.getenv("STT_OPENAI_MODEL", "whisper-1")
DEFAULT_GROQ_STT_MODEL = os.getenv("STT_GROQ_MODEL", "whisper-large-v3-turbo")
DEFAULT_MISTRAL_STT_MODEL = os.getenv("STT_MISTRAL_MODEL", "voxtral-mini-latest")
DEFAULT_ELEVENLABS_STT_MODEL = os.getenv("STT_ELEVENLABS_MODEL", "scribe_v2")
+# Seconds for one STT HTTP request; shared by the OpenAI-SDK path and the QQ adapter so a
+# self-hosted model's cold start is not cut off at the old fixed 30s (#112939).
+DEFAULT_STT_TIMEOUT = 60.0
LOCAL_STT_COMMAND_ENV = "HERMES_LOCAL_STT_COMMAND"
LOCAL_STT_LANGUAGE_ENV = "HERMES_LOCAL_STT_LANGUAGE"
COMMON_LOCAL_BIN_DIRS = ("/opt/homebrew/bin", "/usr/local/bin")