Skip to content

refactor: make transcription and capture context-owned per run - #4674

Merged
dgageot merged 2 commits into
mainfrom
refactor/transcriber-run
Oct 20, 2026
Merged

dgageot merged 2 commits into
mainfrom
refactor/transcriber-run

Conversation

@dgageot

@dgageot dgageot commented Oct 20, 2026

Copy link
Copy Markdown
Member

Why

The old transcription/capture code relied on a global capture queue and
ad-hoc cleanup, making ordering and error handling around dictation
finalization easy to get wrong (e.g. dropped tail audio, lost transcripts
on finish vs abort).

What

  • Capturer.Run and Transcriber.Run are now configuration-only and own
    their per-run state (native C/cgo.Handle, WebSocket connection) instead
    of a global queue. Context cancellation aborts the run; a separate finish
    channel stops capture, flushes the tail, drains audio, commits and awaits
    ordered final transcripts with a ten-second network timeout.
  • The TUI now owns the speech run's lifecycle: nonblocking notifications,
    lossless pending text, a shared error-aware completion path, origin-tab
    scoped submission, and cancellation on replacement/shutdown.
  • Tests cover late/out-of-order VAD items and manual IDs, cleanup failures,
    blocked I/O/callbacks, finalization timeout, pending text vs Stop,
    cancellation, and tab routing.

Testing

task build/task test/task lint pass. go test -race ./pkg/audio/... ./pkg/tui passes, with the new finalization/race-sensitive
tests repeated 10x. no_audio build tag, Linux/Windows, and CGO-disabled
builds all pass. Live microphone/OpenAI transcription was not
exercised — only unit/race tests.

Capturer.Run now owns its C-side state and cgo.Handle per call instead
of a global queue, and Transcriber.Run owns the websocket connection,
cancellation, and worker joining for a single transcription run. The
TUI drives this through a speechRun that owns readiness/completion and
scopes handlers to the tab/editor that started it.

Assisted-By: docker-agent
Flush any native tail audio before disposing the capture queue so the
last chunk isn't dropped. Distinguish finish from abort during
dictation finalization and keep pending text/error state around
instead of discarding it, fixing VAD and completion handling to match.
Adds finish_test.go and extends transcribe/tui speak tests accordingly.

Assisted-By: docker-agent
@dgageot
dgageot requested a review from a team as a code owner October 20, 2026 21:15

@rumpl rumpl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I forgot that we have this feature

@dgageot
dgageot added this pull request to the merge queue Oct 20, 2026
@aheritier aheritier added area/docs Documentation changes area/tui For features/issues/fixes related to the TUI kind/refactor PR refactors code without behavior change labels Oct 20, 2026
Merged via the queue into main with commit 6016455 Oct 20, 2026
22 checks passed
@dgageot
dgageot deleted the refactor/transcriber-run branch October 20, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation changes area/tui For features/issues/fixes related to the TUI kind/refactor PR refactors code without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants