Skip to content

The agent that grows with you

fix(stt): preserve subprocess error details

wangtaocb0cf7a19187
diff --git a/tests/tools/test_transcription_tools.py b/tests/tools/test_transcription_tools.py
index 2b181987a8c..d2938b0ea26 100644
--- a/tests/tools/test_transcription_tools.py
+++ b/tests/tools/test_transcription_tools.py
@@ -103,6 +103,37 @@ class TestGetProviderGroq:
from tools.transcription_tools import _get_provider
assert _get_provider({"provider": "groq"}) == "groq"
+
+class TestProcessErrorDetail:
+ """Subprocess diagnostics preserve the original STT helper failure."""
+
+ @staticmethod
+ def _detail(*, stderr=None, stdout=None):
+ from tools.transcription_common import _process_error_detail
+
+ error = subprocess.CalledProcessError(
+ 1,
+ ["ffmpeg"],
+ output=stdout,
+ stderr=stderr,
+ )
+ return _process_error_detail(error)
+
+ def test_prefers_stderr_over_stdout(self):
+ assert self._detail(stderr=" stderr detail \n", stdout="stdout detail") == "stderr detail"
+
+ def test_falls_back_to_stdout_when_stderr_is_missing(self):
+ assert self._detail(stdout=" stdout detail \n") == "stdout detail"
+
+ def test_falls_back_to_exception_when_output_is_missing(self):
+ detail = self._detail()
+
+ assert "returned non-zero exit status 1" in detail
+
+ def test_decodes_byte_output(self):
+ assert self._detail(stderr=b" bad \xff output \n") == "bad \ufffd output"
+
+
class TestGetProviderFallbackPriority:
"""Auto-detect fallback priority and explicit provider behaviour."""
diff --git a/tools/transcription_common.py b/tools/transcription_common.py
index 95b491e3ce3..3a0401e7a2b 100644
--- a/tools/transcription_common.py
+++ b/tools/transcription_common.py
@@ -70,7 +70,14 @@ def _lazy_ensure_quietly(dep: str) -> None:
def _process_error_detail(exc: "subprocess.CalledProcessError") -> str:
"""stderr > stdout > str(exc) for a failed helper binary."""
- return exc.stderr.strip() or exc.stdout.strip() or str(exc)
+ for output in (exc.stderr, exc.stdout):
+ if isinstance(output, bytes):
+ detail = output.decode("utf-8", errors="replace").strip()
+ else:
+ detail = str(output or "").strip()
+ if detail:
+ return detail
+ return str(exc)
def _log_prompt_unsupported(label: str) -> None: