Skip to content

fix(dictation): handle cloud dictation's 10-minute cap, stalled uploads and bad API keys - #39114

Merged
AmoabaKelvin merged 2 commits into
mainfrom
fix/cloud-dictation-timeout-and-cap
Nov 7, 2026
Merged

AmoabaKelvin merged 2 commits into
mainfrom
fix/cloud-dictation-timeout-and-cap

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

Cloud dictation (OpenAI) had three ways to go wrong:

  • If the upload got stuck, dictation sat on "Processing…" forever.
  • After 10 minutes of talking, everything you said after that was silently thrown away. On the phone, all 10 minutes were thrown away.
  • A wrong API key was saved without complaint. You only found out at your first dictation.

Now a stuck upload fails with a clear message. At 10 minutes, dictation stops on its own and inserts what you said. A wrong key is refused when you save it.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19
Prod 22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​154 $\color{#cf222e}{\Huge{\mathbf{−}}}$​56 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​98

What Changed

Stuck upload.

  • Before: OpenAiTranscriptionSession.finish() called fetch with only the cancel signal, so a stalled request never ended and the stop never finished.
  • Now: the request also has a deadline: 30 s, plus the time the WAV takes to upload at 1 Mbit/s (about 31 s for a short dictation, about 3 min for 10 minutes of audio). The deadline covers the response body too.
  • When it fires, the user sees "Speech error: OpenAI transcription timed out. Check your connection and try again." and dictation returns to idle. That goes through the existing error and then stopped path in stt-session-stop.ts.

10-minute cap.

  • Before: feedAudio() threw on every chunk past 10 minutes.
    • Desktop swallowed the error (use-audio-capture.ts), so the pill kept saying Listening while everything after the cap was dropped.
    • The phone treated the error as a failure and cancelled the session, so it threw away all 10 minutes.
  • Now: the session keeps audio up to exactly 10 minutes, drops anything later, and returns true once, on the chunk that reached the cap.
    • That boolean comes back through SttService.feedAudio and the existing speech:feedAudio invoke.
    • The capture hook calls a new onAudioLimitReached option. DictationController shows "Dictation stopped at the 10-minute cloud limit." and runs the normal stop, so the first 10 minutes are transcribed and inserted.
    • Phones ignore the return value. A phone keeps streaming, the host drops audio past the cap, and finish returns the first 10 minutes' text, with no RPC change.

API key.

  • Before: the key was stored without any check.
  • Now: saving from Settings, from orca speech openai-key set or through the speech.openAiKey.set RPC first sends the key to the transcription endpoint with an empty form (10 s limit).
    • OpenAI checks the key before it looks at the form, so this transcribes nothing and costs nothing.
    • Only a 401 refuses the key, with OpenAI's message cleaned up ("Incorrect OpenAI API key provided."). Any other answer, or no network, saves the key as before.
  • The Settings error toast no longer shows Electron's "Error invoking remote method…" prefix.

Why

  • Each fix is in the module that owns it. The session owns the upload and the cap. The save path that every route shares owns the key check.
  • The cap signal reuses the existing feed call. It rides on the speech:feedAudio reply instead of a new IPC event, preload listener and event type. That is about 20 fewer lines, and the renderer, preload and main always ship together.
  • The renderer stops through its normal path. That path already handles inserting the text, the waits and resetting state, so stopping at the cap reuses all of it.
  • Why the host doesn't stop the session itself. Phones need no change either way, and stopping from inside the feed path would start an async stop there.
  • Why the deadline grows with the recording. A fixed 60 s would fail long dictations on slower uplinks, and a fixed 3 min would leave short dictations stuck for minutes.
  • Why the key check uses the transcription endpoint. It checks the permission dictation actually needs. /v1/models would wrongly refuse restricted keys that have audio access but no model.read scope.
  • Why only a 401 refuses the key. Saving offline or during an OpenAI outage keeps working as before.
  • Ruled out: uploading in 10-minute pieces, which would remove the cap. That changes spend and belongs to a later dictation wave.

Linked Issue

None. This came from the dictation review (Wave 0). No GitHub issue exists for it.

Visual Proof

Recorded in a hidden dev build against a local fake OpenAI server. For the recordings only, the cap was shortened to 8 s and the endpoint pointed at the fake server; those edits were not committed. The toast text still says 10 minutes.

Before: the invalid key saves as "OpenAI API key saved". Dictation keeps showing Listening well past the cap, and after a manual stop it fails with the bad-key error.

before-cloud-dictation.mp4

After: the invalid key is refused with "Incorrect OpenAI API key provided." and the dialog stays open. Dictation stops by itself at the cap with "Dictation stopped at the 10-minute cloud limit.", and the transcript of the kept audio (exactly 8.0 s) is inserted.

after-cloud-dictation.mp4

There is no recording of the stuck upload because it is a 35 s wait. In the same build, with the fake server never answering, I stopped a 4 s dictation. The UI went from stopping to idle at 35 s with a single toast: "Speech error: OpenAI transcription timed out. Check your connection and try again."

Testing

On macOS:

  • Hidden dev build with a fake OpenAI server. This covers both the Settings save path and the desktop dictation path:

    • a bad key is rejected and no key file is written;
    • a good key saves;
    • dictation stops at the shortened cap, the toast shows, and the text is inserted;
    • a stalled endpoint ends with the error toast and returns to idle.
  • Node repro against the real OpenAiTranscriptionSession (local fake server):

    • On main: the stalled request was still pending after 20 s, and past 600 s every later chunk threw (60 of 660).
    • On this branch: the stalled request fails at 31.3 s, and so does a stalled response body. The 660 s feed throws nothing and uploads exactly 19,200,044 bytes (600 s).
  • Key check, saveVerifiedOpenAiSpeechApiKey run directly:

    • Against the real OpenAI API, a bogus key gets 401 invalid_api_key and is not saved.
    • Against the fake server: 503 saves, and a network failure saves.
  • Unit test. I added one test for the cap at its owner, openai-transcription-client.test.ts. It fails on main ("Cloud transcription is limited to 10 minutes per dictation").

  • Focused tests: openai-transcription-client, stt-service, ipc/speech, VoicePane.

  • Changed-file checks: check:code-quality:changed and localization extraction.

  • Not tested: I didn't test with a real valid key, so a valid key returning 400 for the empty form is taken from OpenAI's documented order (key first). I didn't run the phone path live; it needs no client change and its RPC is unchanged. Linux and Windows aren't platform-specific here.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

I didn't add a test for the deadline (it is timing) or for the key check (it needs network or mocks). Both were checked against real requests as described above.

Risk

  • Riskiest part: saving a key now makes a network call. A real 401 refuses the key, which is the point. Any other failure saves the key as before, and the save waits at most 10 s.
  • A slow, very long upload can now fail with a timeout instead of finishing much later. The deadline allows a 1 Mbit/s upload of the full 10 minutes plus 30 s.
  • Older paired phones behave better: they keep the first 10 minutes instead of losing everything, with no RPC change.
  • The speech:feedAudio invoke now returns a boolean instead of nothing. Renderer and main ship together.
  • To back out: a plain revert. Nothing is persisted.

Level: Low

AI Disclosure

Review

Two Claude review rounds; Codex is at its usage limit. Neither round found a P0 or P1.

  • Proxy (P2): the new key check, like the existing upload, uses Node's global fetch, so it ignores the network proxy set in Settings. Moving both speech calls to getMainHttpClient() is a follow-up. Doing it for the key check alone would validate a key for an upload that still can't reach OpenAI.
  • Hold mode (P3): an auto-repeating hold key can restart dictation after the cap stop. The existing mic-lost stop does the same.

Follow-ups:

  • the phone shows no notice when it hits the cap;
  • the phone's own 75 s finish timeout is shorter than the host deadline for very long uploads;
  • proxy support for cloud dictation.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: OpenAI error text is passed through the existing sanitizer, so an echoed key is never shown.
  • Remote / SSH / headless: the key check runs on the host that transcribes, through the shared save path. The CLI's 60 s request limit covers the 10 s check.
  • Mobile: no client change.
  • Cross-platform: nothing platform-specific.
  • Performance: one boolean per feed reply. Audio past the cap is dropped before resampling.

To try (dev build from /Users/kelvinamoaba/orca/workspaces/orca/dictation-cloud-limits):

  1. Settings > Voice > OpenAI Transcription > Add API key, enter sk-wrong, Save. A toast says "Incorrect OpenAI API key provided." and the dialog stays open.
  2. With a real key and a GPT-4o model selected, dictate a few seconds, then make the connection stall (Network Link Conditioner with 100% packet loss) and stop. After about 30 s, "OpenAI transcription timed out…" appears and the pill returns to idle. Before this PR it stayed on Processing.
  3. The cap needs 10 minutes of talking: dictation stops by itself with "Dictation stopped at the 10-minute cloud limit." and inserts the text.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 18 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 17248f19-67d4-490f-bee7-ce246524cd3d
Commits

Reviewing files that changed from the base of the PR and between e507dd7 and 54e99f7.

Files selected for processing: 23

  • src/main/ipc/speech.ts
  • src/main/runtime/speech/runtime-mobile-speech-catalog.ts
  • src/main/speech/openai-api-key-verification.ts
  • src/main/speech/openai-transcription-client.test.ts
  • src/main/speech/openai-transcription-client.ts
  • src/main/speech/stt-service.ts
  • src/preload/api/speech-api.ts
  • src/preload/api/speech-bridge.ts
  • src/renderer/src/components/dictation/DictationController.tsx
  • src/renderer/src/components/dictation/dictation-audio-limit-stop.ts
  • src/renderer/src/components/settings/voice/VoicePane.tsx
  • src/renderer/src/hooks/use-audio-capture.ts
  • src/renderer/src/i18n/locales/de.json
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/pt.json
  • src/renderer/src/i18n/locales/ru.json
  • src/renderer/src/i18n/locales/tr.json
  • src/renderer/src/i18n/locales/zh-Hant.json
  • src/renderer/src/i18n/locales/zh.json
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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