Skip to content

Add configurable voice context to reduce Qwen3-ASR memory - #15810

Merged
danielhanchen merged 12 commits into
unslothai:mainfrom
Imagineer99:feat/voice-context-settings
Nov 9, 2026
Merged

danielhanchen merged 12 commits into
unslothai:mainfrom
Imagineer99:feat/voice-context-settings

Conversation

@Imagineer99

@Imagineer99 Imagineer99 commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Qwen3-ASR currently lets llama-server allocate its full 64K context even for short recordings. Add a Voice context setting with Auto and fixed limits from 1K to 64K. In a local RTX 5070 Ti check with Qwen3-ASR-0.6B Q8_0, the same 11-second recording used roughly 8.7 GiB at 64K versus 2.0 GiB at 4K.

Auto uses native audio/prompt token counts plus transcript headroom, starting at 4K and growing or shrinking for each recording. The saved setting reaches dictation, uploads, source transcription and reference audio. Active recordings are protected during changes and resizing.

Oversized recordings and token-limited responses now produce actionable errors instead of successful partial transcripts. Older supported runtimes without native token counting retain the previous 64K capacity in Auto, including through the public OpenAI-compatible API; fixed limits remain available to reduce memory.

Validation

  • 805 backend tests covering STT engines, context limits, concurrency, cancellation, device preferences, API routes and streaming.
  • 844 frontend tests across 91 files, with no failures or skips; application and test typechecks pass.
  • Ten API-to-model checks with real Qwen inference on Linux/WSL, including Auto 4K → 16K → 4K, manual 1K, input overflow, streaming truncation and public API requests. Missing-counter compatibility used a protocol shim with real allocation and inference.
  • Eight browser checks with a mocked API verified default/hydrated settings, persistence, model visibility and safe unloading.

UI before / after

Settings > Voice with Local transcription and Qwen3-ASR 0.6B selected, base 91935a1 vs head f41e7ee (two isolated Studio installs). Before: no Voice context row. After: a Voice context row between Load into and Microphone, defaulting to Auto (recommended).

Voice settings before and after

The Voice context menu offers Auto plus fixed limits from 1,024 to 65,536 tokens.

Voice context options before and after

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T12:39:10.788180Z e92df90 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member

Frontend build + bundle sanity fails the strict locale check on this PR: the five new Voice settings strings exist only in en.ts.

Missing keys (will fall back to en): 5
  - settings.voice.dictation.sttContextLabel
  - settings.voice.dictation.sttContextAuto
  - settings.voice.dictation.sttContextAutoDescription
  - settings.voice.dictation.sttContextFixedDescription
  - settings.voice.dictation.sttContextTokens
Missing keys above. Add them to every overlay, or run without --strict to accept the English fallback.

Adding them to every locale overlay (ar, de, es, fr, he, hi, it, ja, ko, pt-br, ru, sv, zh-CN) clears it. The bundle-budget part of the same job is fixed on main by #15822.

danielhanchen added a commit that referenced this pull request Oct 28, 2026
`(Python 3.13, rest)` on #15810 failed `test_legacy_sandbox_is_migrated`
with a log line that gives the cause away:

```
Moved 1 chat sandbox folder(s) from .../test_legacy_sandbox_is_migrate0/userprofile/studio_sandbox
  to .../test_sandbox_lives_under_the_s0/custom_studio_home/sandbox
```

The legacy folder of one test was moved into the sandbox root of the
test that ran before it on the same xdist worker.

## Cause

Since #15628, `get_sandbox_workdir` starts a background
`sandbox-migrate` thread. That thread captures `sandbox_root()` when it
starts, but reads the legacy root (`HOME/studio_sandbox`) only once it
gets scheduled. `test_sandbox_lives_under_the_studio_home` never waits
for its mover. On a busy worker the mover was still pending when
`test_legacy_sandbox_is_migrated` switched `HOME` and reset
`_legacy_sandbox_migrated`. It then moved the new test's folder into the
old root. The new test's own `get_sandbox_workdir` found that mover
still alive and reused it, so nothing ever moved the folder to where the
test looks.

The product is fine: in a real process `HOME` never changes under the
mover. This is test isolation.

There is a second hazard with the same root. The conftest does not
isolate `HOME`, so a mover that outlives a test's `monkeypatch` reads
the real `~/studio_sandbox`.

## Fix

A conftest autouse fixture joins any live `sandbox-migrate` thread
before and after every backend test. It raises if a mover does not
finish in 30s instead of letting it leak. The fixture requests
`monkeypatch`, so the drain runs before the test's `HOME` is restored
and a late mover can never read the real home directory.

## Verification

- Repro: a tiny plugin delays the mover by 1s, the way a loaded worker
deschedules it. Running `test_sandbox_lives_under_the_studio_home` and
then `test_legacy_sandbox_is_migrated`:
- main `3db711acb5`: `1 failed, 1 passed`, with the same misplaced move
as CI
  - this branch: `2 passed`
- `test_sandbox_files_and_storage_roots.py` on its own: 321 passed.
- The 10 backend test files that start a mover, under `-n 8`: 887
passed, 3 skipped.
- Only `conftest.py` and `test_sandbox_files_and_storage_roots.py` drive
the mover directly, and nothing holds one open across tests, so the
drain cannot stall an unrelated test.

Copy link
Copy Markdown
Member Author

Fixed in 0e96760: all five Voice context strings are translated in all 13 locale overlays, preserving the {count} placeholder. Merged current main, including #15822 and #15830.

The startup bundle still exceeded the updated budget by 319 bytes. A comparison against main with the same Node version and dependencies measured this feature's growth at 978 bytes raw / 474 bytes compressed, with 85 startup chunks unchanged. Commit 91cebe8 adjusts the budget by exactly that growth, preserving main's headroom.

Locally verified npm run i18n:check:strict, npm run typecheck, npm run build, npm run bundle:check, the built-bundle sanity checks, and all 43 bundle-checker tests.

@danielhanchen danielhanchen self-assigned this Nov 7, 2026
# Conflicts:
#	studio/backend/tests/test_transcribe_source_route.py
#	studio/frontend/scripts/check-bundle-budget.ts
@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown
Member Author

Checked head e92df90. The Windows Composer failure appears to be a shared CI fixture problem: it times out waiting for window.__threadWeight in playwright_long_thread_gate.py:188, before seeding the chat or measuring typing performance. The same exact timeout occurs in run 42593587286 and run 42570323837 on unrelated branches. This PR does not change that fixture or workflow; its Linux and macOS lanes passed. I requested a rerun of the failed Windows job.

Local validation on the pinned head: 294 targeted backend tests and 45 frontend tests passed, covering context sizing and limits, active-request safety, cancellation, missing-counter compatibility, request propagation, and explicit truncation errors. Safety and merge-aware worktree checks were clean. No product change was needed for this CI failure. A fresh Codex review is running.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: e92df90c1c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 9, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 9, 2026
@danielhanchen
danielhanchen merged commit 9092900 into unslothai:main Nov 9, 2026
danielhanchen added a commit that referenced this pull request Nov 9, 2026
…gs store (#17293)

## Summary

`main` is red in the frontend unit tests (`Frontend build + bundle
sanity` and `Frontend unit tests (Windows)`) since #16976 merged:

```
# Error: no stub for import "./stt-context" in .../features/settings/stores/voice-settings-store.ts
not ok 888 - tests/mic-target.test.ts
```

#15810 (merged at 15:43 UTC) moved the voice context settings into
`stores/stt-context.ts` and made `voice-settings-store.ts` import it.
#16976 (merged about an hour later) added `tests/mic-target.test.ts`,
which loads that store through `loadWithStubs` with a stub list written
before that import existed. `loadWithStubs` throws on any unstubbed
import, so the whole file fails at load, and every PR based on current
`main` inherits the red. #16976's own code is fine; only its test's stub
list is out of date.

The fix passes the real `stt-context` module, the same way
`voice-settings-storage-sync.test.ts` already does after #15810.

## Changes

- `studio/frontend/tests/mic-target.test.ts`: add `"./stt-context":
sttContext` to the store's stubs.

## Testing

- `node --test tests/mic-target.test.ts`: 20 passed. On `main` the same
file fails to load (0 passed, 1 failed).
- `npm test` (whole frontend unit suite): 15450 tests, 0 failed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants