Wait for final results from Whisper before completing

<details>
<summary>Prompts Used</summary>
User: This checkout corresponds to https://github.com/jimrandomh/faceclaw/pull/27. Review this branch.

GPT-6 Astra:
> Found one issue:
>
> - **[P2] Wait for Whisper’s final result before completing dictation** — [FaceclawVoiceController.java:729](/Users/jbabcock/repositories/g2/faceclaw/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java:729). Skipping partial decodes leaves short utterances without text until release, but the dialog still finalizes after its existing timeout. If decoding exceeds roughly 2.7 seconds (native stop’s 1.5-second wait plus the dialog’s 1.2-second timeout), auto-send can abandon a short command or send an incomplete longer one. Continue can append the late editing instruction literally instead of refining the message. I reproduced these outcomes with delayed transcript events. These flows should await recognition completion.
>
> Validation: TypeScript and a clean Android build passed. All 21 test failures also occur on `main`. Actual Whisper latency was not tested on hardware.

<hr>

User: Thanks, let's fix that issue.

GPT-6 Astra:
> Fixed. Dictation now waits for native recognition to finish before fallback timers run. Auto-send, Continue, and AI Chat preserve delayed Whisper results; cancellation ignores late transcripts.
>
> TypeScript and Android builds pass. All 11 new regression tests pass. The full suite still has the same 21 pre-existing failures.
</details>
This commit is contained in:
James Babcock committed 2026-09-17 22:12:33 -07:00
1 parent 91890a25ac
commit 25c398d60f
11 files changed
+385 -28

No files matched your search

+14 -3
View File
@@ -89,11 +89,22 @@ export class VoiceDraft {
}
private stopAndFinalize(): void {
// Install fallback first: stop may synchronously deliver the final.
this.timer = setTimeout(() => this.finish(), 1500);
const generation = this.generation;
const afterStop = () => {
if (generation !== this.generation || !this.isFinishing()) return;
this.timer = setTimeout(() => this.finish(), 1500);
};
if (this.started) {
this.started = false;
void Promise.resolve(this.actions.stopVoiceCapture()).catch((error) => this.cancel(String(error)));
// Native recognition can take longer than the synchronous stop join.
// Its final callback may finish the draft before this promise resolves.
const stopped = this.actions.stopVoiceCapture();
if (!stopped) { afterStop(); return; }
void stopped.then(afterStop, (error) => {
if (generation === this.generation) this.cancel(String(error));
});
} else {
afterStop();
}
}