Skip to content

fix(audio): importing the Whisper ASR module no longer loads torch - #4662

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/fix-smoke-getuid-memory-recall
Oct 4, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/fix-smoke-getuid-memory-recall

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Every open PR shows these two failures; this clears them. The macOS one is fixed here; the Windows one is fixed by #4585, so the smoke jobs go green once both merge.

The macOS failure dates from #4061 (Sep 28), which added the recall test after the torch-loading audio test from #3616. The smoke job runs with -x, so earlier failures hid it until #4562 fixed those on Oct 2.

Test plan

  • New test_importing_whisper_asr_does_not_load_torch fails on main and passes here
  • Locally on macOS, all audio and memory tests in CI order: 433 passed, test_memory_turn_recall included
  • Locally on macOS, every unit test up to and including the recall test: torch never loads, and recall passes. The 13 failures are local env noise (CLI binaries not on PATH, pip frontends); none import the audio module
  • CI: "Unit Tests (macOS smoke)" passes test_memory_turn_recall.py

Importing gaia.audio.whisper_asr pulled in torch at module load. On macOS
torch's bundled libomp then sits beside faiss's, and memory recall refuses
every faiss search for the rest of the process. In the unit suite a
mocked-sounddevice test imported the module, so test_memory_turn_recall
failed on the macOS smoke job for every PR.

torch and whisper are now imported when a WhisperAsr is constructed, the
only point that needs them. A subprocess test pins that the import stays
torch-free.
@github-actions github-actions Bot added audio Audio (ASR/TTS) changes tests Test changes labels Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve

Importing the Whisper speech-to-text module no longer loads torch as a side effect. That side effect broke memory recall for the rest of a macOS test run. torch and whisper are now imported only when someone actually creates a speech recognizer, so the user-facing behaviour is unchanged. A new test fails if the module ever starts loading torch again. The change is small and well targeted. I found no blocking issues.

One thing to keep in mind: another audio test file still imports whisper at the top of the file. CI's macOS smoke environment doesn't install whisper, so CI is fine. On a dev machine that has the voice extras installed, though, a full local run can still load torch before the recall test runs.

Real-world evidence

N/A: this is an internal import-timing change and its test. It touches no CLI, API, MCP or Agent UI surface, and no evidence bundle was produced. The verdict rests on static review plus the author's local macOS run described in the PR.

🔍 Technical details

Issues found

🟢 tests/unit/test_asr.py:15-18 still loads torch at collection time. It imports whisper and WhisperAsr at module level. pytest collects every module before running any test, so wherever openai-whisper is installed, torch is in the process before test_memory_turn_recall runs. The macOS smoke job installs only .[api], so CI isn't affected. A full pytest tests/unit/ on a dev box with talk extras is affected. The fix is a follow-up: move those imports into the test classes' setUp, or check for whisper with importlib.util.find_spec("whisper").

Correctness checks

  • Every module-level torch. reference has moved over: the __init__ block (lines 79-85) uses the local name, and _process_audio uses self._torch (line 241). No other whisper./torch. uses remain outside __init__.
  • Nothing in src/, tests/ or hub/ patches gaia.audio.whisper_asr.torch or .whisper, so moving the imports doesn't silently break any mocks.
  • The missing-dependency error path is unchanged: it still names torch/openai-whisper when either import fails.

Strengths

  • The regression test checks the real invariant ('torch' in sys.modules) in a fresh subprocess, so imports left over from other tests can't hide a failure. It also skips cleanly when torch isn't installed.
  • The fix removes the cause instead of skipping the recall test the way ci(unit): give the macOS and Windows smoke jobs time to finish #4580 does.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 4, 2026
Merged via the queue into amd:main with commit 32e4ffa Oct 4, 2026
@kovtcharov-amd
kovtcharov-amd deleted the kalin/fix-smoke-getuid-memory-recall branch October 4, 2026 15:26
kovtcharov added a commit to kovtcharov/gaia that referenced this pull request Oct 4, 2026
…md#4662

amd#4585 now patches only the uninstall module's platform, and its autouse
fixture never tree-kills a fake sidecar pid, which is the only path that
ran taskkill. amd#4662 fixed the torch import that broke faiss recall on
macOS, so the recall test no longer needs a skip. This PR keeps only the
smoke-job timeouts.
aksh8b pushed a commit to aksh8b/gaia that referenced this pull request Oct 5, 2026
)

The macOS and Windows unit-test smoke jobs hit their 30-minute limit
before the suite finishes, so even with every test fixed they can't go
green. This raises the limits to fit a full run: 45 min on macOS (a full
run takes ~33) and 60 on Windows (15 min reached 6,873 of ~18,000
tests).

The test fixes this PR first carried now live elsewhere: the Windows
`os.getuid` teardown and the sidecar taskkill in amd#4585, and the macOS
recall failure in amd#4662 (merged; it removes the torch import at its root
instead of skipping the test). Merge amd#4585 first; this PR no longer
touches any test file, so the two don't conflict.

## Test plan
- [ ] CI: after amd#4585, "Unit Tests (macOS smoke)" and "Unit Tests
(Windows smoke)" run to the end inside the new limits
- [x] Locally (macOS): `test_memory_turn_recall.py`,
`test_agent_sidecar_manager.py`, `installer/test_uninstall_command.py`
at main's versions: 148 passed, 4 skipped

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
aksh8b pushed a commit to aksh8b/gaia that referenced this pull request Oct 5, 2026
…op (amd#4585)

The Windows smoke job stops at the first failing test, so every fix so
far has only revealed the next Windows-only failure. This clears all the
ones known so far in one go so the job can finally reach the end. One is
more than a Windows problem: the sidecar tests' fake process (pid 4242)
reached the real tree-kill, so on Linux and macOS each run sent SIGTERM
to whatever real process group held that id, and the error was
swallowed.

- **Uninstall shebang tests:** they fake Linux only inside the uninstall
module, so pyfakefs teardown no longer calls `os.getuid` on Windows.
Installer-leftover paths are built the way the platform prints them.
- **Sidecar manager tests:** only real child processes reach the
tree-kill (and so `taskkill` on Windows); `os.killpg`/`os.getpgid` fakes
no longer error on Windows, where they don't exist.
- **CLI refusal test:** the subprocess gets `USERPROFILE`/`SYSTEMROOT`
(Windows finds its home and starts Python from them) and reads its
output as UTF-8 (the refusal prints an emoji).
- **Dev-anchor tests:** expected paths are built the way the platform
prints them.
- **Reap tests:** the two that assert a process-group kill skip on
Windows, where the code deliberately skips that kill (a documented gap).

Test-only change. Merge this before amd#4580, which now only raises the
smoke-job timeouts. The macOS smoke failure was fixed by amd#4662.

## Test plan

- [x] `pytest tests/unit/test_agent_sidecar_manager.py
tests/unit/installer/test_uninstall_command.py
tests/unit/test_cli_refusal_exit_codes.py
tests/unit/test_daemon_cli_dev_anchor.py
tests/unit/test_daemon_agents_routes.py tests/unit/test_project_map.py`
on macOS after merging main: 298 passed, 4 skipped
- [ ] `Unit Tests (Windows smoke)` gets past these files on this PR's
run
- [ ] With amd#4580 also merged, `Unit Tests (Windows smoke)` is green on
main

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audio Audio (ASR/TTS) changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants