Skip to content

fix(tts): fall back to raw imports after lazy install failure - #53289

Closed
jmeadlock wants to merge 2 commits into
NousResearch:mainfrom
jmeadlock:fix/53259-tts-lazy-import-fallback
Closed

fix(tts): fall back to raw imports after lazy install failure#53289
jmeadlock wants to merge 2 commits into
NousResearch:mainfrom
jmeadlock:fix/53259-tts-lazy-import-fallback

Conversation

@jmeadlock

Copy link
Copy Markdown

Summary

Fixes #53259.

This changes the TTS provider import helpers to continue to the normal Python import path when tools.lazy_deps.ensure() fails. That preserves valid deployments where TTS packages are supplied by PYTHONPATH, shared package directories, or container image layers instead of being installed directly into the Hermes venv.

Affected helpers:

  • _import_edge_tts()
  • _import_elevenlabs()
  • _import_mistral_client()

If the raw import is genuinely unavailable, the import statement still raises ImportError, so existing caller error handling remains intact.

Test plan

  • Verified regression test fails before the production fix with the expected ImportError failures.
  • uv run python -m pytest tests/tools/test_tts_lazy_import_fallback.py -v
  • uv run python -m pytest tests/tools/test_tts_*.py tests/agent/test_tts_registry.py -q
  • uv run ruff check tools/tts_tool.py tests/tools/test_tts_lazy_import_fallback.py

Notes

I also ran an independent review pass on the final diff. No security concerns or logic errors were found.

@alt-glitch alt-glitch added type/bug Something isn't working tool/tts Text-to-speech and transcription P3 Low — cosmetic, nice to have labels Jun 26, 2026
@harjothkhara

Copy link
Copy Markdown
Contributor

I checked this against the linked #53259 failure mode, and the patch looks aligned with the root cause: the helpers still try lazy install first, but no longer turn an install-target failure into a hard stop before Python's normal import path can see PYTHONPATH/container-layer packages.\n\nLocal proof using the repo wrapper:\n\nbash\nscripts/run_tests.sh tests/tools/test_tts_lazy_import_fallback.py tests/tools/test_tts_mistral.py tests/tools/test_voice_cli_integration.py\n\n\nResult: 103/103 passed. I also ran git diff --check origin/main...HEAD, clean. I did not find a blocker in the changed TTS helper paths.

@jmeadlock

Copy link
Copy Markdown
Author

Thanks for checking and for running the wrapper test suite — appreciated.

Allow TTS provider import helpers to continue to the normal Python import path when tools.lazy_deps.ensure() fails. This preserves setups where packages are supplied by PYTHONPATH or container image layers instead of the Hermes venv. Adds regression coverage for Edge TTS, ElevenLabs, and Mistral.
@jmeadlock
jmeadlock force-pushed the fix/53259-tts-lazy-import-fallback branch from fde29c2 to f2c9045 Compare July 14, 2026 14:23
@jmeadlock

Copy link
Copy Markdown
Author

Refresh (2026-07-13)

  • Rebased onto current main (46e87b14f).
  • Re-confirmed the [Bug]: TTS tool fails when packages are installed via PYTHONPATH (lazy_deps fallback missing) #53259 failure mode existed on main pre-rebase (raise ImportError(str(e)) at three sites in tools/tts_tool.py).
  • Local verification on the rebased branch: tests/tools/test_tts_lazy_import_fallback.py 3/3, full TTS subset (tests/tools/test_tts_*.py + tests/agent/test_tts_registry.py) 299 passed, ruff clean on touched files.
  • No scope change: edge / elevenlabs / mistral fall-through only.
  • Happy to adjust if review prefers a different fallback shape.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused regression fix. The three TTS helper changes match the failure still present on current main in tools/tts_tool.py:93-95, 114-116, and 137-139.

Problems

  • The identical Mistral SDK fallback remains absent from STT. In tools/transcription_tools.py:1397-1403, ensure("stt.mistral") only falls through on ImportError; another ensure() failure exits through the outer error handler at 1421-1423 before from mistralai.client import Mistral can run. tools/lazy_deps.py:131 confirms this is the corresponding lazy dependency.

Suggested changes

  • Extend the same fall-through behavior and regression coverage to _transcribe_mistral() so externally supplied mistralai packages work consistently for both TTS and STT.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 15, 2026
Extends the PR's TTS fix to _transcribe_mistral(): a non-ImportError
failure from lazy_deps.ensure("stt.mistral") no longer aborts before
the raw import can see PYTHONPATH/container-layer packages. Adds
regression coverage. Addresses sweeper review on NousResearch#53289.
@jmeadlock

Copy link
Copy Markdown
Author

Sweeper follow-up addressed (2026-07-16)

Extended the same fall-through to _transcribe_mistral() in tools/transcription_tools.py (5f5b6d695): a non-ImportError failure from ensure("stt.mistral") — e.g. FeatureUnavailable — no longer escapes to the outer error handler before the raw import can see PYTHONPATH/container-layer mistralai. Same shape as the three TTS sites (debug log + fall through).

  • Note: the sweeper's cited lines (1397-1403) have drifted on current main — the site is now at transcription_tools.py:1432-1438.
  • Regression test added to tests/tools/test_tts_lazy_import_fallback.py (reproduced the escape red-first, passes with the fix).
  • Local verification: scripts/run_tests.sh on all test_transcription* + the fallback suite — 229/229 passed; ruff clean on touched files; git diff --check clean.

No behavior change when mistralai is genuinely absent — the raw import's ImportError still routes through the existing outer handler.

@teknium1

Copy link
Copy Markdown
Contributor

The lazy-install recovery gap was fixed in #73510 via @tusharui's #67314 (raw-import fallback when lazy_deps.ensure fails). Thanks for the report-and-fix!

(Landed via #73510, merge c0c5dac531.) Closing.

@teknium1 teknium1 closed this Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/install-update Installer, updater, packaging, wheels, doctor P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades tool/tts Text-to-speech and transcription type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TTS tool fails when packages are installed via PYTHONPATH (lazy_deps fallback missing)

4 participants