Skip to content

feat(voice): dictate without a Soniox key on a local speech model - #643

Open
cnYui wants to merge 3 commits into
simplexai-labs:mainfrom
cnYui:feat/voice-local-dictation
Open

cnYui wants to merge 3 commits into
simplexai-labs:mainfrom
cnYui:feat/voice-local-dictation

Conversation

@cnYui

@cnYui cnYui commented Nov 24, 2026 •

Copy link
Copy Markdown

What and why

Dictation (the Message box, Voice Mode and Pocket notes) needed a Soniox key. With none saved it now runs on a local speech model and a text rewrite of the person's choice, so a deployment with no speech key can still dictate.

  • Local recognition. SenseVoiceSmall int8 through sherpa-onnx, ported from SpeakMore (MIT; NOTICE and third_party/licenses/speakmore-MIT.txt updated). Node Services downloads the model (~230 MB) once into AGENT_HOME/models the first time it starts with no Soniox key (Hugging Face, or hf-mirror.com first for SIMPLEX_REGION=cn), resumable, pinned SHA-256. VOICE_LOCAL_ASR=0 turns it off; VOICE_LOCAL_ASR_THREADS caps CPU threads. Recording still needs Soniox for speaker labels and never uses it.
  • Streaming and turns. The model is offline, so the stream re-decodes the open segment for partials, cuts long speech at 30 s on the quietest 50 ms frame, and ends a turn after about a second of silence following speech. The pause is heard by loudness alone (no language list, no second model).
  • Rewrite. Each closed segment is rewritten (filler, recognition mistakes, punctuation; same language, never translated) before it lands, on either the owner's connected Claude CLI or an OpenAI-compatible API of the deployment's own (DeepSeek by default). A failed or slow rewrite keeps the recognized text. The choice is a deployment-wide voice_dictation_settings row; dictation without a Soniox key stays off until someone chooses.
  • UI. A Local model page in the existing voice key dialog (and a row in Settings > Security) reusing the dialog, Button, Select and Field components. CLI route: pick a model alias every Claude CLI takes (Haiku first, Sonnet, Opus), since the choice applies to everyone. API route: address, key, and a round button that lists the API's models so nobody types a model name.
  • CLI model. A new dictation_polish model-call kind carries the rewrite through the same queue as chat. It names its model, which overrides the Agent's configured one on a Claude Runtime, over the model field model_invoke already has on main; this PR adds no wire or daemon change.

How it was verified

  • Focused tests: voice-runtime (SenseVoice stream, segments, endpoint detector), node-services (voice service incl. model download, model-call), TeamHub (voicedictation incl. SSRF refusal and model listing; the dictation settings service incl. which key goes to which address; error codes; the cached readiness probe), Web (voice key dialog, controls, Pocket dictation, i18n catalog).
  • Fast checks on the rebased branch: contracts:verify, check-repository, check-docs, check-web, check-node-services, check-teamhub, check-voice-runtime (typecheck, lint, build), check-scripts-fast, TeamHub lint-go incl. doc comments, go test of every non-integration package, the layout test, sqlc verification.
  • Real end to end in the Docker stack through Chrome: model download and load, dictation with a pause sending the turn and Linger replying, the CLI model picker (Haiku), saving a DeepSeek key, listing its models, and the rejected-key path against the real API.
  • Contracts regenerated from contracts/openapi/.
  • The browser run above predates the review follow-up. After rebuilding the Docker stack on the follow-up commit (with main's 00893 applied), checked through Chrome: listing models with the saved key at its own address, a changed address disabling save and asking for its own key, and the CLI list offering only Haiku, Sonnet and Opus. The save-with-another-address refusal is covered by tests only.
  • Not run here: check-installer, the Python packaging tests of check-desktop, and the migration history script (my test container lacks python3 and PowerShell). The Desktop bundle change (sherpa-onnx-node in RUNTIME_PACKAGES) is untested. Failing only in my Linux container and unrelated to this change: a timezone-dependent realtime.test.ts, and install and dev-computer script tests that need jq, curl or python3.

Boundary

  • Docs: docs/voice.md (dictation without a key, rewrite choices, model listing, pause ends a turn), docs/model-scheduling.md, and the AGENTS.md of voice-runtime and node-services. New env vars are in .env.example and scripts/env-inventory.json.
  • Compatibility: migration 00894 adds one table. New API fields and routes are additive, and an old Web client ignores local_dictation_supported. A Computer too old to decode model keeps the Runtime's default; a Runtime other than Claude keeps the Agent's model.
  • User message to provider_ready path: typed messages are untouched. A dictated turn adds one rewrite call before it is posted, bounded to about 10 s on the CLI and 8 s on an API, with the raw text as the fallback; the audio goes to no speech service.
  • Security: an API key is sealed with TEAMHUB_SECRET_ENCRYPTION_KEY (without it a key cannot be saved), checked against /models on save, never returned, and the saved key is probed, stored again or used for a model listing only at the address it was saved for. TeamHub accepts https only, with no credentials, query or fragment, dials only public addresses (checked again at connect time) and follows no redirect. Dictated text goes to the chosen API from the server running TeamHub. The choice is deployment-wide and any signed-in Human can change it, which docs/voice.md states; there is no owner-only gate, since a deployment has one Account and TeamHub has no separate owner role.

🤖 Generated with Claude Code

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Request changes (1 P1, 2 P2, 3 P3)

Scope: base main, merge base ef6f06d5, 1 commit (eef2e280), 96 files reviewed at the requested head. Helper skills loaded: coderbook, ponytail-review, karpathy-guidelines. The review ran in a separate session.

Findings

P1

1. Saving the API settings with an empty key sends the saved key to any new address. apps/teamhub/internal/voice/dictation_settings.go:125-151

  • Problem: ListDictationModels correctly refuses to use the saved key unless config.BaseURL == baseURL, with the stated reason "otherwise a person could send it to a host of their choosing". SaveDictationAPI has no such check. When input.Key is empty and a ciphertext exists, it opens the saved key and runs s.dictationAPI.Probe(ctx, config) against the newly typed baseURL, which sends Authorization: Bearer <saved key> to <new base>/models (voicedictation/api.go:122-127).
  • Failure scenario: someone saves a DeepSeek key. Any signed-in Human then sends PUT /v0/voice-dictation-settings {"polish_source":"api","polish_api":{"base_url":"https://attacker.example","model":"x"}}. TeamHub sends the DeepSeek key to attacker.example. Any non-401/403/5xx answer also stores the attacker URL together with the old key. The Web page makes this easy to hit by accident: canSave in voice-local-model-page.tsx:158-164 accepts keySaved with any address, so changing the address to another provider without retyping the key leaks the old key to that provider.
  • Fix: in SaveDictationAPI, when the key is empty, reuse the saved key only if baseURL == existing.PolishApiBaseUrl.String; otherwise return ErrInvalidPolishAPI. Apply the same sameAddress rule to canSave on the Web page so it asks for a key once the address changes. Add a test for both cases.

P2

2. The settings logic in the voice service has no tests. apps/teamhub/internal/voice/dictation_settings.go

  • Problem: voicedictation/api_test.go covers the HTTP client: SSRF refusal and listing. The 238 lines that decide security and routing have no tests at all: key reuse on save, binding a listing to the saved address, opening a key sealed under another encryption key (Chosen=false), choosing API or CLI in PolishDictation, and the purpose and session checks. The same is true of the handlers in app/voice_dictation_settings.go. Finding 1 is the kind of bug those tests would have caught.
  • Fix: add table tests for SaveDictationAPI, ListDictationModels and PolishDictation with a fake DictationAPI that records which key went to which URL.

3. Any signed-in Human chooses where everyone's dictated text goes. apps/teamhub/internal/app/voice_dictation_settings.go:22-25

  • Problem: the row is deployment-wide, and the handler lets any session save it, "as for the voice provider keys". A Soniox key only changes which account pays. This setting changes the destination: once any user saves polish_source=api with an https URL they control and any key (the probe accepts a 404 or 200), every other user's dictated passages are POSTed to that URL. On a server shared by several tenants or teams, that is a quiet exfiltration path. The docs mention the setting is shared but not this consequence.
  • Fix: restrict saving to the deployment owner (internal/account/owner.go already has the concept), or make the API route per user. At least state the consequence in docs/voice.md.

P3

4. The voice policy now probes Node Services synchronously on every read. apps/teamhub/internal/app/voice_media_policy.go:37 → voice_local_asr.go:22

  • Once someone has chosen a rewrite, every getVoiceMediaPolicy and every dictation createVoiceSession makes an HTTP GET to /voice/health with a 1-second timeout. A slow or restarting Node Services adds up to 1 s to each page's policy read. The PR's critical-path note covers the rewrite call but not this round trip. A short cache of the state (a few seconds) would remove it.

5. One new table is built across two migrations. apps/teamhub/migrations/00893_voice_dictation_settings.sql, 00894_voice_dictation_polish_api.sql

  • Neither migration is on main yet, so 00894's ALTER TABLE can be folded into 00893's CREATE TABLE.

6. A CLI model picked from one person's catalog applies to everyone. apps/web/src/features/rooms/voice-control/voice-local-model-page.tsx:136-146

  • The options come from the saving user's own Computers, but PolishDictation runs on each dictating person's CLI. If someone picks a model id that only their Claude CLI offers, a colleague's claude --model <id> fails, and their dictation silently falls back to raw text with no sign why. Offer only the aliases (haiku, ...), or mention in the hint that the model must exist on every member's CLI.

Verified as fine

  • SSRF guard: NormalizeAPIBaseURL takes https only, refuses credentials, query, fragment and literal private IPs (voicedictation/api.go:47-57). The dialer's Control refuses non-public addresses after DNS resolution (api.go:80-91), which covers names that resolve inside the network and DNS rebinding. The custom http.Transport sets no Proxy, so no environment proxy bypasses the check. CheckRedirect returns ErrUseLastResponse. Response bodies are capped at 1 MiB.
  • The API key is never returned: the response has only key_saved (app/voice_dictation_settings.go:104-108). Polish errors report only the status, not the body (api.go:229-232).
  • CLI argument injection: the model must start with an alphanumeric character in TeamHub (voicedictation.go:69), node-services (model-call-http.ts MODEL_NAME), the contracts (node-services-internal/openapi.yaml, envelope.schema.json pattern) and the daemon (provider/model_invoke.go ValidModelName, checked in daemon/model_invoke.go:156). --model is added only when non-empty (claudeModelInvokeArgs).
  • Rolling deploy to Computers: model is sent only when runtimeType === "claude" and supportsModelInvokeModel (≥ 0.62.0, runner-connections.ts). apps/computer is bumped to 0.62.0. callId includes the model, so calls on different models are not deduplicated together (runtime-model-call.ts:607).
  • Polish failure paths: #rewrite falls back to the raw text on rejection, abort or a blank answer (sensevoice.ts #rewrite). The runtime aborts at 10.5 s (agent.ts), above TeamHub's 9 s CLI and 8 s API timeouts. Finals are emitted in segment order through the #emitting chain.
  • The internal polish route sits on the voice-runtime-authenticated group (routes_internal.go:111) and only serves chat_dictation sessions (dictation_settings.go:212). The CLI owner is the session's CreatedByActorID.
  • Model download: pinned revision and SHA-256, a .part file with Range resume and a fallback for hosts that ignore the range, rename only after the checksum passes (local-asr-model.ts). It starts only when no Soniox key is set and VOICE_LOCAL_ASR is not 0 (voice/service.ts apply). VOICE_LOCAL_ASR is in .env.example; VOICE_LOCAL_ASR_MODEL_DIR and VOICE_LOCAL_ASR_THREADS are in env-inventory.json.
  • Licenses: SpeakMore MIT text added; SenseVoice (FunASR model license) and sherpa-onnx (Apache-2.0) are noted in NOTICE.
  • No CJK outside the locale catalogs; no CJK in the commit message; no merge commits.

Not verified: contracts:generate && contracts:verify (no node_modules in this worktree); the Desktop bundling of sherpa-onnx-node's per-platform optional packages through RUNTIME_PACKAGES, which the PR also lists as untested; memory use with several concurrent local dictations (each LiveKit job process loads its own copy of the model, maxSessions = 16).

Process notes

  • The branch is one commit behind main (a3b6f44b), and main requires up-to-date branches, so it needs a rebase before merge.

CI

gh pr checks reports no checks on this branch, so nothing has run in CI. I ran no tests myself; the findings above come from reading the code.

Automated review by Claude Code


Automated review of eef2e28 by Claude Code.

cnYui and others added 2 commits November 25, 2026 08:50
With no Soniox key, chat and Pocket notes dictation now runs on the
SenseVoiceSmall int8 model (sherpa-onnx), ported from SpeakMore (MIT).
Node Services downloads it once into AGENT_HOME/models (Hugging Face, or
hf-mirror.com first in the cn region) with pinned checksums, and the voice
worker runs it on the CPU. The model is offline, so the stream re-decodes the
open segment for partials, cuts long speech at 30 s at the quietest frame, and
ends a turn after about a second of silence by loudness alone.

Each closed segment is rewritten (filler, recognition mistakes, punctuation)
before it lands, on either the owner's connected Claude CLI or an
OpenAI-compatible API of the deployment's own, such as DeepSeek. The choice is
a deployment-wide voice_dictation_settings row; an API key is sealed with
TEAMHUB_SECRET_ENCRYPTION_KEY and checked against /models on save. TeamHub
connects only to public addresses and follows no redirect. A failed or slow
rewrite keeps the recognized text.

The Local model page of the voice key dialog (and a row in Settings >
Security) offers both routes; for the API route a round button lists the
API's models, using the saved key only for the address it was saved for. The
Claude catalog picks the CLI model, Haiku by default.

To pass that model to the CLI, model_invoke gains an optional model sent only
to Computers from 0.62.0, which accept it as --model; older Computers keep
the Runtime's default. A new dictation_polish model-call kind carries the
rewrite through the same queue as chat.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Saving the API settings with the key left empty reused the saved key at
whatever address was typed, which sent it to a host of the saver's choosing.
Saving, probing and listing models now use the saved key only at the address
it was saved for, and the page asks for a new key once the address changes.

Also: table tests for the dictation settings service and its error codes; the
readiness probe of Node Services is reused for three seconds; the two new
migrations are one, numbered above main's latest; the CLI model list offers
only the aliases every Claude CLI takes, since the choice applies to everyone;
the docs say who can change where dictated text goes.

Upstream gained its own model field on model_invoke, so this change now uses
it: dictation's chosen model overrides the Agent's on Claude, and the
duplicate wire, daemon and gating code is gone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cnYui
cnYui force-pushed the feat/voice-local-dictation branch from eef2e28 to 59f338f Compare November 25, 2026 00:14

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approve with nits (1 P3)

Scope: base main, merge base 9be58b70, 2 commits, 82 files. This is a follow-up on eef2e28. The branch was rebased since then, so I read the new 59f338fb commit, compared the rebased feature commit with the old one (git range-diff), and re-checked the whole merge-base diff for P0/P1 issues. I loaded the review skills from the repo's review recipe (coderbook, ponytail-review sections 1–3, karpathy-guidelines sections 2–3) and ran the review alone in a separate session.

Previous findings

  • P1: an empty key on save sent the saved key to a new address. Resolved. SaveDictationAPI now uses the saved key only through savedAPIKey, which returns ErrInvalidPolishAPI unless the normalized address matches the saved one (apps/teamhub/internal/voice/dictation_settings.go:166-172). ListDictationModels uses the same check. The Web page asks for a new key once the address changes: savedKeyApplies gates canSave and canListModels in voice-local-model-page.tsx. TestSaveDictationAPIUsesASavedKeyOnlyAtItsOwnAddress and TestListDictationModelsUsesASavedKeyOnlyAtItsOwnAddress cover it.
  • P2: the dictation settings service had no tests. Resolved. apps/teamhub/internal/voice/dictation_settings_test.go covers key reuse, address binding, refusal without a store write, CLI model validation, Chosen=false for a key that can't be decrypted, and routing by source. TestVoiceDictationErrorsKeepTheirCodes covers the error-code mapping.
  • P2: any signed-in user can redirect everyone's dictation. Partially resolved. There is still no gate. The author says a deployment has one Account and no owner role. docs/voice.md now states the risk and says leaving TEAMHUB_SECRET_ENCRYPTION_KEY unset turns the API route off, and the handler comment (voice_dictation_settings.go:24-27) says the same. I accept this as documented intent.
  • P3: a synchronous Node Services probe on every policy read. Resolved. The answer is cached for 3 s (voice_local_asr.go:23-45), and TestLocalDictationStateIsReusedForAFewSeconds covers it. A small new issue in the cache is below.
  • P3: two migrations for one new table. Resolved. There is now a single 00894_voice_dictation_settings.sql, numbered after main's latest (00893_transcript_only_captures.sql).
  • P3: CLI model options came from one person's Computer catalog. Resolved. The page now offers only the haiku/sonnet/opus aliases (cliModelAliases), isHostDefaultModelId is removed as dead code, and the docs match.

Findings

P3

  • apps/teamhub/internal/app/voice_local_asr.go:42: the cache stores a failure caused by the caller's own context. probeLocalDictation uses the request context, and any error becomes Unavailable, which is then cached for 3 s for every caller. Example: a client navigates away while the probe is in flight, so the probe fails on the cancelled context and Unavailable is cached. For the next 3 s, localDictationEnabled returns false to everyone. Policy reads hide local dictation, and createVoiceSession for a chat dictation fails with ErrProviderUnavailable (handlers_voice_media.go:62-68). Concurrent readers also wait on the mutex while a probe runs (up to 1 s). Fix: probe with context.WithoutCancel(ctx). localASRClient's 1 s timeout already bounds the call.

Verified as fine

  • The saved key never leaves its address. dictationAPIConfig returns the stored, already-normalized URL (dictation_settings.go:198-207), and both entry points compare it against NormalizeAPIBaseURL output.
  • SSRF controls: the address must be https with no userinfo, query or fragment, and a literal private IP is refused (voicedictation/api.go:47-58). The dialer's Control re-checks every resolved address, including CGNAT (api.go:83-94), and redirects are not followed (api.go:106). An error body is not echoed back (api.go:228-231).
  • The CLI model override reaches the Claude CLI as --model <alias> (local-daemon/internal/provider/model_invoke.go:755-757). Node Services validates the name against a regex that must start with a letter or digit (model-call-http.ts MODEL_NAME), so it can't be read as a flag. Only a Claude Runtime uses the override (runtime-model-call.ts:938-944), and the model is part of callId, so dedupe keys stay distinct.
  • Model download: pinned revision plus SHA-256 per file. A partial file is checked before it is renamed into place, and a host that ignores Range gets a full rewrite (node-services/src/voice/local-asr-model.ts:106-160).
  • Migration: one table, CHECK constraints keep the API row complete, and goose Down drops it.
  • No CJK outside the locale catalogs, and no CJK in commit messages. No merge commits.

Process notes

  • 59f338fb fix(voice): address review of local dictation only patches 8ad60ec4. main takes rebase merges, so squash it into the feature commit before merging.
  • The branch is up to date with main. Merge state is BLOCKED because CI hasn't run (see below).

CI

  • The CI workflow for 59f338fb (and for eef2e28 before it) shows action_required: a maintainer has to approve the workflow run, so no checks have run on this head.
  • I ran these locally: go test -count=1 ./internal/voicedictation/ ./internal/voice/ -run 'Dictation|API|Normalize|Model|Polish' and go test -count=1 ./internal/app/ -run 'Dictation|LocalASR|LocalDictation'. All passed.
  • Not run here: Web, node-services and voice-runtime tests, and the Desktop native bundle with sherpa-onnx-node, which the PR also lists as untested.

Automated review by Claude Code


Automated review of 59f338f by Claude Code.

The probe of Node Services ran on the request's context, so a client that left
mid-probe made it fail, and "unavailable" was then cached for every caller for
a few seconds. The probe no longer inherits that cancellation; the client's
one-second timeout still bounds it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approve (0 findings)

Scope: follow-up on 59f338f, reviewing head de3a8db against base main (merge base 9be58b7). I read the incremental diff (2 files) and spot-checked the whole PR's merge-base diff (3 commits, 82 files) for P0/P1 risk. The helper skills (coderbook, ponytail-review, karpathy-guidelines) were not loaded for this follow-up; I worked from the linger-pr-review checklist directly. The review ran in a separate session.

Previous findings

  • P3 A failed probe from a cancelled request was cached for 3 s: Resolved. apps/teamhub/internal/app/voice_local_asr.go:44 now probes with context.WithoutCancel(ctx), and the 1 s localASRClient.Timeout (voice_local_asr.go:18) still limits how long the probe can take. TestLocalDictationStateIgnoresTheCallersCancellation (voice_local_asr_test.go:70) covers this. Without the fix, http.Client.Do fails on the cancelled context and the probe caches Unavailable, so the test does fail on the old code.

Findings

None.

Verified as fine

  • Readiness cache: the probe runs under a.localASR.mu, so at most one probe is in flight at a time. Each caller waits no more than about 1 s (the client timeout), and the result is cached for 3 s (voice_local_asr.go:36-47).
  • SSRF guard on the deployment's API route:
    • NormalizeAPIBaseURL accepts only https URLs with no userinfo, query, fragment or literal private address (apps/teamhub/internal/voicedictation/api.go:47-58).
    • The dialer's Control hook checks every resolved address against publicAddress, which covers loopback, private, link-local, multicast, unspecified and 100.64/10 (api.go:72-92, api.go:100).
    • Redirects are refused (api.go:107). The custom Transport leaves Proxy unset, so no environment proxy can bypass the dial check.
  • The API error path does not echo the response body, which may contain the prompt; it reports only the status (api.go:225-228). Response bodies are capped at 1 MiB (api.go:131, api.go:221).
  • CLI model names are checked against an anchored regex that requires a letter or digit first, so a model name cannot be read as a CLI flag (voicedictation.go:69).
  • Rewrite calls share one key per session, model and text digest (voicedictation.go:88), so a retried passage joins the call already running instead of starting another one.
  • No CJK appears in changed files outside the locale catalogs or in any commit message. There are no merge commits.

Process notes

  • 59f338f ("address review of local dictation") and de3a8db (the cancellation fix) only patch 8ad60ec. Squash them into it before the rebase merge.
  • mergeStateStatus is BLOCKED, and gh pr checks reports no checks for the branch, so CI still needs to run on this head.

CI

  • No checks are reported on the PR at de3a8db.
  • I ran go test -count=1 -run 'TestLocalDictation' ./internal/app/ in apps/teamhub locally, and it passed.
  • I did not run anything else. As the PR body notes, the Desktop bundle change (sherpa-onnx-node in RUNTIME_PACKAGES) is untested.

Automated review by Claude Code


Automated review of de3a8db by Claude Code.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant