Skip to content

Add maximum dictation duration guard#47

Open
wpflueger wants to merge 1 commit intomainfrom
fix/max-dictation-duration
Open

Add maximum dictation duration guard#47
wpflueger wants to merge 1 commit intomainfrom
fix/max-dictation-duration

Conversation

@wpflueger
Copy link
Owner

Summary

  • Adds a configurable maxDurationSeconds setting (default: 60s) that auto-stops recording when reached, with an overlay notification
  • Adds a server-side max_audio_frames safety limit (5000 frames ≈ 100s) in the backend as a backstop against runaway clients
  • Prevents CUDA out-of-memory errors from unbounded audio accumulation during very long recordings

Test plan

  • Hold the hotkey for >60s and verify recording auto-stops with "Maximum duration reached" overlay
  • Change maxDurationSeconds in settings and verify the new limit applies
  • Verify normal short dictation (<60s) is unaffected
  • Verify backend logs warning when frame limit is hit

Closes #30

🤖 Generated with Claude Code

- 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>
Copilot AI review requested due to automatic review settings February 9, 2026 03:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 maxDurationSeconds audio setting (default 60s) that auto-stops recording and shows an overlay.
  • Adds a backend max_audio_frames cap (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.

Comment on lines +82 to +86
logger.warning(
f"Max audio frames ({max_frames}) reached, "
"stopping collection"
)
break
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
if (dictationActive) {
showOverlay("Maximum duration reached.", "processing");
sendToMain("backend:log", `Max dictation duration (${maxSeconds}s) reached, stopping.`);
stopDictation();
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
stopDictation();
void stopDictation().catch((error) => {
const message =
error instanceof Error ? error.message : "Error while stopping dictation after max duration.";
sendToMain("backend:log", message);
});

Copilot uses AI. Check for mistakes.

# Audio settings
sample_rate_hz: int = 16000
max_audio_frames: int = 5000 # Safety limit (~100s at 20ms/frame)
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.

Add maximum dictation duration guard

2 participants