Skip to content

fix(tts): fall through to raw import when lazy_deps fails (#53259) - #67314

Closed
tusharui wants to merge 2 commits into
NousResearch:mainfrom
tusharui:fix/tts-lazy-import-fallthrough
Closed

fix(tts): fall through to raw import when lazy_deps fails (#53259)#67314
tusharui wants to merge 2 commits into
NousResearch:mainfrom
tusharui:fix/tts-lazy-import-fallthrough

Conversation

@tusharui

Copy link
Copy Markdown
Contributor

Problem

When TTS packages (edge-tts, elevenlabs, mistralai) are installed outside the venv but importable on sys.path (e.g. via PYTHONPATH, Docker layered filesystems), the TTS tool fails because lazy_deps.ensure() failures are re-raised as ImportError before the raw import line runs.

Fix

Replace raise ImportError(str(e)) with pass in the except Exception handler of all three lazy-import helpers, allowing execution to fall through to the raw import. Also fix the Mistral STT path in transcription_tools.py which only caught ImportError, not FeatureUnavailable.

Files changed

  • tools/tts_tool.py — 3 one-line changes (lines 93, 114, 137)
  • tools/transcription_tools.py — 1 one-line change (line 1436)
  • tests/tools/test_tts_pythonpath_fallback.py — new test file (6 tests)

Tests

Uses sys.modules fixtures (not builtins.__import__ patching) per reviewer feedback. Covers both fallback-on-FeatureUnavailable and clean-ImportError-when-truly-missing paths for all three providers.

Fixes #53259

…ch#53259)

Replace 
aise ImportError(str(e)) with pass in the except Exception
handler of _import_edge_tts(), _import_elevenlabs(), and
_import_mistral_client() so packages installed via PYTHONPATH or Docker
layered filesystems still work when lazy_deps.ensure() raises.

Also fix the Mistral STT path in transcription_tools.py which only
caught ImportError, not FeatureUnavailable.

Adds 6 regression tests using sys.modules fixtures (no
builtins.__import__ patching).
@alt-glitch alt-glitch added type/bug Something isn't working tool/tts Text-to-speech and transcription P3 Low — cosmetic, nice to have duplicate This issue or pull request already exists labels Jul 19, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #53289: the live patch applies the same lazy-dependency failure fallback across the same TTS and Mistral STT import paths. #53289 is the earlier open canonical with matching coverage.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the focused fallback fix. The premise remains present on upstream main: tools/tts_tool.py:93-95, 114-116, and 137-140 stop before raw imports when lazy installation raises, and tools/transcription_tools.py:1433-1438 only falls through on ImportError.

Problems

  • The changed STT branch at tools/transcription_tools.py:1436 has no regression coverage in this PR. tests/tools/test_tts_pythonpath_fallback.py exercises only the three TTS _import_* helpers.
  • As the member comment notes, this duplicates active canonical PR #53289. Its verified diff covers the same TTS and Mistral STT paths and includes an STT fallback regression.

Suggested changes

  • Add an isolated _transcribe_mistral() test where ensure("stt.mistral") raises FeatureUnavailable but the raw mistralai.client.Mistral import succeeds.
  • Reconcile any salvage with #53289 so the canonical implementation and its STT coverage are retained.

Automated hermes-sweeper review.

from tools.lazy_deps import ensure as _lazy_ensure
_lazy_ensure("stt.mistral", prompt=False)
except ImportError:
except Exception:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a regression test for this fall-through. The added test file exercises only the three TTS _import_* helpers, so _transcribe_mistral() is not covered when ensure("stt.mistral") raises but a raw mistralai import is available.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users labels Jul 19, 2026
…esearch#53259)

Add isolated test where ensure('stt.mistral') raises FeatureUnavailable
but the raw mistralai.client.Mistral import succeeds, verifying the
transcription_tools.py fallthrough path introduced in the same PR.
@teknium1

Copy link
Copy Markdown
Contributor

Merged into main via consolidated salvage PR #73510 (merge c0c5dac531). Your raw-import fallback when lazy_deps.ensure fails (PYTHONPATH installs) was cherry-picked with your authorship, covering both STT and TTS.

Your contribution is credited to you in git history. Thank you! Closing this PR as merged-via-salvage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users 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)

3 participants