#6660 · Active voice capture is discarded by composer teardown
Verdict: REPRODUCED · Root-cause confidence: high · Reproduction label: confirmed-repro
1. TL;DR
A composer that disappears while its microphone is still recording loses the audio already captured. Its cleanup deliberately treats disappearance like cancellation: it disables transcription and clears the in-memory audio buffer. The recoverable-recording store is reached only later in the accepted stop path, so this cleanup never creates an entry to retry. A regression probe against the real React hook reproduces zero transcription requests, zero transcript deliveries, zero recoverable recordings, and zero error notifications after unmount. Explicit Stop succeeds and explicit Cancel discards, using the same delayed recorder fixture.
2. Claims vs findings
| Claim tested | Finding | Evidence |
|---|---|---|
| Unmount during active recording silently discards buffered audio. | Verified | Three minutes of simulated recording, an emitted audio chunk, unmount, then the delayed final recorder event. No transcription, transcript, retry entry, or error toast. |
| Accepted recordings can finish after the composer leaves. | Verified at hook boundary | The Stop control succeeds after unmount. Existing accepted-transcription and delayed-stop tests also pass. |
| There is no incremental recording persistence before Stop. | Verified by source tracing | The data event only appends to a ref; the store write occurs inside the accepted onstop branch, after the discard early return. |
| Question free-text input can also lose accepted transcription. | Source corroborated; not separately exercised | The textarea uses an ephemeral key, checks its mounted flag before and after the transcription request, and suppresses transcript delivery after unmount. Its lifetime problem needs a separate destination/ownership decision. |
| Specific desktop hardware, packaged release, several minutes of real speech. | Not directly verified | This investigation uses current trusted main on Linux with the repository's recorder fake. No physical microphone, macOS desktop, real speech, or provider account was used. |
3. Environment
- Public repository
get-bb/bb, main commita1bf55b6a04c7948ae5ae0dcfcbdec27d2b507a2; fetched again before publication, with no newer relevant change. - Linux x86_64; Node
v22.19.0; pnpm9.15.0; Vitest4.1.1; React hook tests in jsdom. - First trusted checkout and a second clean detached temporary worktree at the identical base. Only the locally authored test was added; production files were unchanged.
- No app server, ports, runtime data directory, provider session, browser profile, or real user data was used. No dependency was added.
- Frozen installs completed. Full Turbo builds passed in both checkouts (72/72 tasks each). The first build attempt needed the installed Plugin SDK runtime built first; the commands below include that step.
4. Minimal reproduction
This is a lifecycle/data-loss defect, not a rendering defect; no screenshot is needed to establish the loss. The test uses the existing DeferredRecorder, setup, and cleanup in the trusted hook test file. It does not reimplement the hook, the recording store, or the discard policy.
- Prepare a trusted checkout and build it:
git clone https://github.com/get-bb/bb.git bb-6660 cd bb-6660 git checkout --detach a1bf55b6a04c7948ae5ae0dcfcbdec27d2b507a2 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@get-bb/plugin-sdk pnpm exec turbo run build
- In
apps/app/src/hooks/useVoiceInput.test.tsx, insert the complete test below immediately before the existing test nameddiscards a recording when its composer unmounts before acceptance. Do not change production code.it.each(["stop", "cancel", "unmount"] as const)( "issue 6660 capture lifecycle: %s", async (action) => { vi.stubGlobal("MediaRecorder", DeferredRecorder); const onTranscribe = vi.fn().mockResolvedValue("Preserved dictation"); const onTranscript = vi.fn(); const options = { recordingKey: `thread/issue-6660-${action}`, onTranscribe, onTranscript, }; const { result, unmount } = renderHook(() => useVoiceInput(options)); await act(() => result.current.start()); vi.advanceTimersByTime(180_000); act(() => { DeferredRecorder.current.ondataavailable({ data: new Blob(["audio captured before navigation"]), }); }); expect(result.current.state).toBe("recording"); if (action === "stop") act(() => result.current.stop("insert")); if (action === "cancel") act(() => result.current.cancel()); unmount(); await act(async () => DeferredRecorder.current.finish()); const remounted = renderHook(() => useVoiceInput(options)); console.info( "issue-6660 evidence", JSON.stringify({ action, transcriptionCalls: onTranscribe.mock.calls.length, transcriptCalls: onTranscript.mock.calls.length, failedRecordings: remounted.result.current.failedRecordings.length, errorToasts: vi.mocked(appToast.error).mock.calls.length, }), ); expect(remounted.result.current.failedRecordings).toEqual([]); expect(appToast.error).not.toHaveBeenCalled(); if (action === "cancel") { expect(onTranscribe).not.toHaveBeenCalled(); expect(onTranscript).not.toHaveBeenCalled(); } else { expect(onTranscribe).toHaveBeenCalledOnce(); expect(onTranscript).toHaveBeenCalledWith("Preserved dictation", "insert"); } }, ); - Run the existing hook suite plus the probe:
pnpm exec turbo run test --filter=@bb/app -- src/hooks/useVoiceInput.test.tsx --silent=false
Expected: under an unmount-as-Stop preservation policy, Stop and Unmount each transcribe and deliver once; explicit Cancel does neither. The defect itself is broader than that policy: current teardown neither retains the recording nor leaves the recorder running, so it also fails recovery-based and continue-recording alternatives.
Actual: the requested preservation assertion fails only on Unmount. These are verbatim evidence lines from the second run:
issue-6660 evidence {"action":"stop","transcriptionCalls":1,"transcriptCalls":1,"failedRecordings":0,"errorToasts":0}
issue-6660 evidence {"action":"cancel","transcriptionCalls":0,"transcriptCalls":0,"failedRecordings":0,"errorToasts":0}
issue-6660 evidence {"action":"unmount","transcriptionCalls":0,"transcriptCalls":0,"failedRecordings":0,"errorToasts":0}
FAIL |@bb/app:isolated| src/hooks/useVoiceInput.test.tsx > issue 6660 capture lifecycle: unmount
AssertionError: expected "vi.fn()" to be called once, but got 0 times
Test Files 1 failed (1)
Tests 1 failed | 24 passed (25)
The unchanged upstream suite has 22 passing tests, including one that explicitly requires discard-before-acceptance. The two passing added cases control for a broken recorder fake or transcription callback. IndexedDB itself was not exercised in jsdom; the no-recovery conclusion combines the real in-memory store result with the source fact that the only initial store write is unreachable on this path.
5. Root cause
Unmount cleanup, useVoiceInput.ts:365–383 reads whether a recording was already accepted. An active recorder instead has transcription disabled before stop:
if (recorder && recorder.state === "recording") {
shouldTranscribeRef.current = false;
try {
recorder.stop();
} catch {}
}
...
if (!acceptedRecordingPending) {
chunksRef.current = [];
startedAtMsRef.current = null;
promptContextRef.current = undefined;
}
Data and stop handlers, useVoiceInput.ts:556–619: data events only push into the component ref. The stop handler sees disabled transcription, clears the buffer again, sets idle, and returns before file creation or saveVoiceRecording. The same result therefore occurs even when the recorder delivers its final chunk asynchronously after unmount.
Recording store, voice-recording-store.ts:138–178: the recovery store can only retain audio once a file has been saved into it. It has no ownership of an actively recording composer's chunk buffer. This is why existing failed-recording retention cannot rescue this path.
Existing upstream test, useVoiceInput.test.tsx:458–469 expressly requires unaccepted recordings to be discarded. The problem is not merely a missed ref assignment; the lifecycle currently encodes destructive product policy.
The question field has an additional lifetime constraint: VoiceInputTextarea.tsx:40–54 selects an ephemeral key, throws an AbortError when unmounted around the request, and ignores transcript delivery afterward. Ephemeral cleanup deletes recordings for that key. Unlike persisted composer draft delivery, this input does not have a durable destination once its question closes.
6. Proposed fix and simple-fix decision
First choose whether leaving a recording should stop and retain audio or keep an app-level recording alive. Keep explicit cancellation destructive. A stop-and-retain implementation for persisted composers can reuse accepted recording/draft delivery, but it must preserve duration, context, pending-stop ordering, and audio until the final recorder event. Ephemeral question inputs additionally need a recoverable owner or an explicit navigation guard, not a callback into an already removed field.
No automatic pull request. Changing the expressly tested discard-on-unmount policy, and deciding ownership for disappearing question fields, requires a product decision. That fails the rule's simple-fix gate even if a narrow code change would fit the line limit. No production patch, source branch, or source push was made. GitHub cross-reference metadata and an open-PR search for the issue number returned no linked open PR at investigation time.
7. Verification
The same agent repeated the test in a second initially clean detached worktree at the full trusted base commit. It had its own frozen install, generated build output, and test process; no ports or app data directories were necessary. The pristine hook suite passed 22/22 before adding the reproduction. After applying only the locally authored test, the identical command above produced 24 passed, 1 failed, with the same Unmount failure and all three evidence records. The first checkout also produced 24 passed, 1 failed. This is a second clean reproduction by the same agent, not an independent review.
Both full builds finished successfully after the SDK runtime prerequisite was built. Root-cause links were checked against the recorded base, including the original pre-probe test line numbers. The repeat run required no report correction. Physical microphone capture, actual desktop navigation timing, page reload/crash recovery, real provider transcription, and the question-field runtime scenario remain outside this verification.
8. Related code and history
The upstream failed-recording retention change is 2cc5a113f6; it preserves failed accepted files, not active chunks. Accepted draft delivery is owned by prompt-voice-intent.ts and usePromptVoice.ts. The current tests clearly distinguish acceptance, explicit cancellation, and unmount before acceptance. Issue-provided links and executable snippets were treated only as untrusted claims, not fetched or run.
9. Appendix
Commands used for evidence: git fetch origin main, git rev-parse origin/main, source inspection at the recorded commit, git log for the recording owner, the frozen install/build/test commands above, and a second git worktree add --detach at the same SHA. GitHub reads checked visibility, current issue properties, valid classification values, similar issue classification, and linked open PRs. Raw build and test logs and the reproduction patch are retained locally, not published. Repository publication rules require tests and exact output inline in this HTML rather than separate artifacts.
Type Bug, Priority High, Effort Medium, and area ui were filled because they were missing. High reflects silent loss of user-authored audio; Medium reflects a lifecycle fix with ownership and destination considerations.
> AGENT GENERATED