fix: clean up Foundry transcribe failures

This commit is contained in:
millionart committed 2026-05-07 11:15:12 +08:00
1 parent 5c92e87bc6
commit 593cf766a2
2 files changed
+14 -1

No files matched your search

@@ -80,7 +80,7 @@ impl FoundryLocalWhisperAsr {
if self.cancel_generation.load(Ordering::SeqCst) != cancel_generation {
anyhow::bail!("Foundry Local Whisper transcription cancelled");
}
if result.is_ok() {
if foundry_transcribe_attempt_consumes_buffer(&result) {
self.buffer.lock().clear();
}
result
@@ -238,6 +238,11 @@ fn trim_transcript_text(text: &str) -> String {
text.trim().to_string()
}
fn foundry_transcribe_attempt_consumes_buffer<T>(result: &Result<T>) -> bool {
let _ = result;
true
}
#[cfg(test)]
mod tests {
use crate::recorder::AudioConsumer;
@@ -308,6 +313,13 @@ mod tests {
assert_eq!(super::trim_transcript_text(" hello\r\n"), "hello");
}
#[test]
fn foundry_transcribe_attempt_consumes_buffer_even_on_error() {
let result: anyhow::Result<()> = Err(anyhow::anyhow!("transient runtime error"));
assert!(super::foundry_transcribe_attempt_consumes_buffer(&result));
}
#[test]
fn foundry_provider_cancel_clears_buffer() {
#[cfg(target_os = "windows")]
@@ -2537,6 +2537,7 @@ async fn end_session(inner: &Arc<Inner>) -> Result<(), String> {
return Ok(());
}
log::error!("[coord] Foundry Local Whisper transcribe failed: {e:#}");
schedule_foundry_local_asr_release(inner, current_session_id);
emit_capsule(
inner,
CapsuleState::Error,