Skip to content

fix: release microphone when voice recorder setup fails - #1425

Open
MrPunyapal wants to merge 1 commit into
dev-null-sh:productionfrom
MrPunyapal:fix/release-microphone-when-recorder-setup-fails
Open

MrPunyapal wants to merge 1 commit into
dev-null-sh:productionfrom
MrPunyapal:fix/release-microphone-when-recorder-setup-fails

Conversation

@MrPunyapal

@MrPunyapal MrPunyapal commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem

If voice recorder setup fails after acquiring a microphone stream, one or more audio resources can remain active.

Change

Cleans up the recorder, microphone tracks, and audio context across synchronous and asynchronous setup failures. Cleanup attempts each resource even if another resource throws while stopping.

Tests

The full JavaScript unit suite passed (228 tests). Focused failure-path tests cover recorder, track, and audio-context cleanup. Type checks and lint passed.

Summary by CodeRabbit

  • Bug Fixes
    • Improved voice recording reliability when setup or recording encounters an error. Audio recording resources are now cleaned up more consistently, including when recording is stopped or canceled.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fb6c295a-55ec-4ca6-92e8-812044248b3a
Commits

Reviewing files that changed from the base of the PR and between d5af71f and da7fdf7.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

startVoiceRecording now uses shared cleanup during setup failures, stop, and cancellation. New unit tests cover failures in recorder and audio-meter setup and verify cleanup of the recorder, microphone tracks, and audio context.

Changes: Voice recording cleanup

Layer / File(s) Summary
Shared cleanup lifecycle
resources/js/lib/voice-notes.ts, tests/Unit/VoiceNoteSetup.test.ts
Setup failures invoke cleanup before the error is rethrown. Stop releases resources in a finally block, and cancellation delegates recorder shutdown to cleanup. Tests inject five setup failures and check cleanup counts.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: nunomaduro, xheaven

Merge Risk: Minimal · previous review 34d8c

No actionable issue is established for this change; it is mergeable after normal checks.

Security architecture risk: Minimal · up to 34d8c

The change strengthens microphone cleanup without expanding recording permissions or access. The reviewed lifecycle paths show no material security risk introduced or worsened by this PR.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed authority remains limited to resources acquired for an individual browser recording. The inspected change does not add recording callers, cross-user access, server privileges, or a new data destination.

Trust Boundaries and Controls

  • observed — Microphone acquisition still uses the browser's getUserMedia permission boundary with unchanged audio constraints. The cleanup changes neither bypass that boundary nor request additional capture capabilities.

Resilience and Maintainability Implications

  • observed — Cleanup isolates recorder-stop and individual track-stop exceptions so other microphone tracks still receive stop attempts. Audio-context closure is requested afterward, with promise rejection ignored as before; closure completion is not awaited.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title matches the main change. The PR makes startVoiceRecording release the microphone tracks, recorder, and audio context when setup fails, which the title states directly. The summary and obje…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title matches the main change. The PR makes startVoiceRecording release the microphone tracks, recorder, and audio context when setup fails, which the title states directly. The summary and objectives both describe this cleanup, and the added tests cover the failure paths. The title is a single, concise sentence in conventional commit form.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f98cc09f-71b2-4bec-ba30-f5e3d7db0c11
Commits

Reviewing files that changed from the base of the PR and between c934501 and 34d8c4e.

Files selected for processing: 2
  • resources/js/lib/voice-notes.ts
  • tests/Unit/VoiceNoteSetup.test.ts

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

@MrPunyapal
MrPunyapal force-pushed the fix/release-microphone-when-recorder-setup-fails branch from 3e5aba9 to 34d8c4e Compare November 3, 2026 05:55
@MrPunyapal
MrPunyapal marked this pull request as ready for review November 3, 2026 06:02
@nunomaduro

Copy link
Copy Markdown
Member

@CodeRabbit By the way, Code Rabbit, can you memorize that it's actually fine not to have doc strings that are really not super important right now? So it's fine to have them or not to have them

@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@nunomaduro Understood. Docstrings are optional when they add little value. Missing nonessential docstrings alone should not prompt a change request.

The automated docstring coverage check is separate and needs a configuration change to stop its warnings.


Learnings added
Learnt from: nunomaduro
URL: https://github.com/dev-null-sh/dev-null.sh/pull/1425

Timestamp: 2026-11-03T20:05:14.888Z
Learning: Within repository "dev-null-sh/dev-null.sh": When reviewing this repository, treat nonessential docstrings as optional. Do not request docstrings solely because they are absent or to increase coverage when they would not explain important behavior.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

@MrPunyapal
MrPunyapal force-pushed the fix/release-microphone-when-recorder-setup-fails branch 2 times, most recently from b9ea03b to d5af71f Compare November 4, 2026 11:04
@MrPunyapal
MrPunyapal force-pushed the fix/release-microphone-when-recorder-setup-fails branch from d5af71f to da7fdf7 Compare November 4, 2026 20:27
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.

2 participants