Conversation
- Client: configurable maxDurationSeconds (default 60s) auto-stops recording when the limit is reached, with overlay notification - Backend: server-side max_audio_frames safety limit (5000 frames ≈ 100s) stops collecting frames if client misbehaves - Both limits prevent unbounded audio accumulation that could cause CUDA out-of-memory errors during transcription Closes #30 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds client- and server-side limits to prevent unbounded audio accumulation during dictation, reducing the risk of CUDA OOM errors from very long recordings.
Changes:
- Adds a client
maxDurationSecondsaudio setting (default 60s) that auto-stops recording and shows an overlay. - Adds a backend
max_audio_framescap (default 5000) that stops collecting streamed frames as a safety backstop. - Logs when the client/server duration/frame limits are hit.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| backend/src/parakey_backend/service.py | Enforces a maximum number of streamed audio frames before processing. |
| backend/src/parakey_backend/config.py | Introduces max_audio_frames config default for the backend safety limit. |
| apps/desktop/electron/settings.ts | Adds audio.maxDurationSeconds to settings schema and defaults. |
| apps/desktop/electron/main.ts | Implements the max-duration timer that auto-stops dictation and notifies the user. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| logger.warning( | ||
| f"Max audio frames ({max_frames}) reached, " | ||
| "stopping collection" | ||
| ) | ||
| break |
There was a problem hiding this comment.
There are existing unit tests for DictationService.StreamAudio (see backend/tests/test_service.py), but nothing currently verifies the new max_audio_frames cap. Please add a test that streams more than max_audio_frames frames and asserts the engine only receives up to the configured limit (and optionally that a warning is logged).
| if (dictationActive) { | ||
| showOverlay("Maximum duration reached.", "processing"); | ||
| sendToMain("backend:log", `Max dictation duration (${maxSeconds}s) reached, stopping.`); | ||
| stopDictation(); |
There was a problem hiding this comment.
stopDictation() is async, but it’s being invoked from setTimeout without await/error handling. If it throws/rejects, this can surface as an unhandled promise rejection in the main process. Consider using void stopDictation().catch(...) (or similar) to make the intent explicit and ensure failures are logged/handled.
| stopDictation(); | |
| void stopDictation().catch((error) => { | |
| const message = | |
| error instanceof Error ? error.message : "Error while stopping dictation after max duration."; | |
| sendToMain("backend:log", message); | |
| }); |
|
|
||
| # Audio settings | ||
| sample_rate_hz: int = 16000 | ||
| max_audio_frames: int = 5000 # Safety limit (~100s at 20ms/frame) |
There was a problem hiding this comment.
max_audio_frames is added to BackendConfig but load_config_from_env() doesn’t populate it from an environment variable, so the safety limit can’t actually be configured in the default server path. Consider adding something like PARAKEY_MAX_AUDIO_FRAMES (with int parsing + validation) or explicitly documenting that it’s fixed at the default unless BackendConfig is constructed manually.
Summary
maxDurationSecondssetting (default: 60s) that auto-stops recording when reached, with an overlay notificationmax_audio_framessafety limit (5000 frames ≈ 100s) in the backend as a backstop against runaway clientsTest plan
maxDurationSecondsin settings and verify the new limit appliesCloses #30
🤖 Generated with Claude Code