Skip to content

fix(stt): strip Qwen3-ASR response prefix - #65534

Closed
LauraGPT wants to merge 5 commits into
NousResearch:mainfrom
LauraGPT:codex/fix-qwen3-asr-prefix-current-8773
Closed

fix(stt): strip Qwen3-ASR response prefix#65534
LauraGPT wants to merge 5 commits into
NousResearch:mainfrom
LauraGPT:codex/fix-qwen3-asr-prefix-current-8773

Conversation

@LauraGPT

@LauraGPT LauraGPT commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • strip the structured language ...<asr_text> prefix returned by Qwen3-ASR-compatible OpenAI transcription endpoints
  • apply the normalization after preserving the existing string, SDK .text, dictionary, and fallback response handling
  • add regression coverage for all three structured response shapes
  • preserve the current provider-aware STT configuration architecture

Context

This refreshes the valid fix from #8773 onto the maintained main line. The original branch is now reported as conflicting and also contains an unrelated rollback of the current STT model configuration behavior.

The implementation retains attribution to @malaiwah through the original author trailer.

Validation

  • rebased onto current main@56e2ba5e7; git range-diff confirms the one-commit patch is unchanged from prior head a6792ca4a
  • 235 passed across managed media gateways, transcription providers, plugin dispatch, and gateway STT configuration tests on exact head 113a0aa25
  • the three new response-shape tests were observed failing before the implementation and passing afterward
  • ruff check passed for both changed files
  • Python compilation and git diff --check passed
  • an extra whole-file ruff format --check probe reproduces the same pre-existing formatting result on current main; the two-file PR patch remains unchanged

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/tts Text-to-speech and transcription provider/qwen Qwen / Alibaba Cloud (OAuth) labels Jul 16, 2026
@LauraGPT
LauraGPT force-pushed the codex/fix-qwen3-asr-prefix-current-8773 branch 4 times, most recently from 1df2e19 to a6792ca Compare July 16, 2026 21:12
Normalize the structured <asr_text> marker after extracting text from string, SDK object, and dictionary transcription responses. Preserve the current provider-aware STT configuration architecture.

Refreshes NousResearch#8773 on current main.

Co-authored-by: angelos <angelos@oikos.lan.home.malaiwah.com>

Assisted-by: Codex:gpt-5.6
@LauraGPT
LauraGPT force-pushed the codex/fix-qwen3-asr-prefix-current-8773 branch from a6792ca to 113a0aa Compare July 17, 2026 01:21

@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 refreshing the Qwen3-ASR fix and preserving the current STT configuration work. The reported defect remains present: current main returns raw string transcription responses from tools/transcription_tools.py:1880-1881, and _transcribe_openai() forwards that value at tools/transcription_tools.py:1393.

Problems

  • The new marker condition matches any <asr_text> occurrence, while the documented Qwen envelope is language ...<asr_text>. Since this helper also serves Mistral and ElevenLabs (tools/transcription_tools.py:1447, 1630), it can truncate an otherwise legitimate transcript containing the literal marker. The new tests cover only stripping cases.

Suggested changes

  • Restrict the normalization to the start-anchored structured envelope and add a pass-through regression for a non-envelope string containing <asr_text>.

Automated hermes-sweeper review.

Comment thread tools/transcription_tools.py Outdated
@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 18, 2026
@LauraGPT
LauraGPT marked this pull request as ready for review July 18, 2026 21:33
@LauraGPT

Copy link
Copy Markdown
Contributor Author

Synced with current main and pushed exact head d59c2ca19ed9017ddbbf01adbf22c8c3602b713a; the branch is now 3 commits ahead / 0 behind and remains limited to tools/transcription_tools.py plus focused transcription tests.

Local validation on ind-gpu8 / Python 3.12.3:

  • python3 -m pytest tests/tools/test_transcription_tools.py::TestExtractTranscriptText tests/tools/test_managed_media_gateways.py::test_extract_transcript_text_strips_qwen3_asr_prefix -q (5 passed)
  • python3 -m pytest tests/tools/test_transcription_tools.py -q -k 'TranscribeOpenAI or TranscribeElevenLabs or TranscribeGroq or ExtractTranscriptText' (17 passed, 92 deselected)
  • python3 -m pytest tests/tools/test_managed_media_gateways.py -q -k 'qwen or transcription or asr_text or conflict' (4 passed, 13 deselected)
  • python3 -m compileall -q tools/transcription_tools.py tests/tools/test_transcription_tools.py tests/tools/test_managed_media_gateways.py
  • git diff --check

A broader tests/tools/test_transcription_tools.py -k 'qwen or asr_text or transcript' run still reaches 106 passed and then fails only on the 3 Mistral tests because this host's system Python blocks lazy mistralai==2.4.8 installation with PEP 668 (externally-managed-environment). That failure is outside the Qwen3-ASR transcript-prefix diff and matches the previously reported local environment boundary.

@LauraGPT

Copy link
Copy Markdown
Contributor Author

Addressed the sweeper review on the current PR head.

Change made:

  • restrict Qwen3-ASR cleanup to a start-anchored language <code> [<audio_language>...</audio_language>] <asr_text> envelope
  • preserve ordinary transcript text that merely contains <asr_text>, including text beginning with “Language ...”

Validation on ind-gpu8 / Python 3.12.3:

  • python3 -m pytest tests/tools/test_transcription_tools.py::TestExtractTranscriptText tests/tools/test_managed_media_gateways.py::test_extract_transcript_text_strips_qwen3_asr_prefix -q -> 6 passed
  • python3 -m pytest tests/tools/test_transcription_tools.py -q -k 'TranscribeOpenAI or TranscribeElevenLabs or TranscribeGroq or ExtractTranscriptText' -> 18 passed, 92 deselected\n- python3 -m pytest tests/tools/test_managed_media_gateways.py -q -k 'qwen or transcription or asr_text or conflict' -> 4 passed, 13 deselected\n- python3 -m compileall -q tools/transcription_tools.py tests/tools/test_transcription_tools.py tests/tools/test_managed_media_gateways.py\n- git diff --check\n

@LauraGPT

Copy link
Copy Markdown
Contributor Author

Current-head verification for 8e028103780c after the Qwen3-ASR prefix cleanup:

python -m pytest tests/tools/test_transcription_tools.py -q -k 'qwen or Qwen or managed_media or transcription_prefix or language'
python -m pytest tests/tools/test_managed_media_gateways.py::test_extract_transcript_text_strips_qwen3_asr_prefix -q
python -m py_compile tools/transcription_tools.py tests/tools/test_transcription_tools.py tests/tools/test_managed_media_gateways.py
git diff --check origin/main...HEAD
git rev-list --left-right --count origin/main...HEAD

Results:

  • focused transcription cleanup tests: 3 passed, 107 deselected;
  • managed-media Qwen3-ASR prefix cases: 3 passed;
  • compile and whitespace checks passed;
  • branch is 0 behind / 4 ahead of origin/main.

I also tried the broader two-file pytest selection. It reaches 117 passing tests, then fails only in unrelated lazy-dependency paths because this host's system Python is PEP 668 externally managed and cannot lazy-install mistralai / fal-client; the failures occur before those tests' mocks can exercise provider behavior. The Qwen3-ASR prefix path touched by this PR is covered by the focused tests above.

@LauraGPT

Copy link
Copy Markdown
Contributor Author

Synced this PR with current NousResearch/main after it had drifted behind. New head is 168b09ac8 (168b09ac8d9af39d5a8767df0117de8e7bfd479e). The merge was clean, and the final PR diff remains scoped to the Qwen3-ASR transcription envelope handling plus focused tests:

  • tools/transcription_tools.py
  • tests/tools/test_transcription_tools.py
  • tests/tools/test_managed_media_gateways.py

Fresh validation on the synced head:

python3 -m pytest -q tests/tools/test_transcription_tools.py::TestExtractTranscriptText tests/tools/test_managed_media_gateways.py::test_extract_transcript_text_strips_qwen3_asr_prefix
# 6 passed in 0.20s

git diff --check
# passed

I also ran the broader transcription/media-gateway test files; the Qwen-related tests passed, while unrelated optional-provider tests hit this runner's system-Python PEP 668 guard while trying to lazy-install mistralai / fal-client.

@teknium1

Copy link
Copy Markdown
Contributor

Merged into main via consolidated salvage PR #73510 (merge c0c5dac531). Your Qwen3-ASR language …<asr_text> envelope strip (3 commits, anchored regex) was cherry-picked with your authorship, with co-credit to @malaiwah (#8773, earliest report/fix).

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

@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

P2 Medium — degraded but workaround exists provider/qwen Qwen / Alibaba Cloud (OAuth) 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.

3 participants