Repository navigation
Let a realtime finish that beats start open the socket itself - #422
Merged
Merged
Conversation
…n it RealtimeTranscriber described one lifecycle with three variables: `phase` (idle/open/closed), an `isFinishing` flag that was really a fourth phase, and a `task` whose nil-ness repeated `phase` — the kind of split state 2c7e640 had to fix a race in. `Phase` now has `finishing`, and the WebSocket task lives in the `open` and `finishing` cases, so it can't be set without the phase that owns it or outlive `close`. `send`, `finish` and `waitForTermination` switch on the phase; `isFinishing` and `task` are gone. Every transition maps 1:1 onto the old one: no behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DS5B1Vp9Andd7LBEDhGKeC
finish() on a session not yet started closed it and dropped the audio queued for it, so the Record button's Stop worked around it: 73ae910 added an `opened` task, a `Recording.opened` field, an `applyTurns(opened:)` parameter and an `await recording.opened.value` before finish(), and finish()'s doc told callers to do the same. The fix now lives in the transcriber. Its turn stream exists from init (`turns`), so it can be read before the socket opens, and whichever of start() and finish() comes first opens it: finish() on an idle session with audio queued opens the socket, sends the audio, and waits for Termination as usual; start() after that is a no-op. With nothing queued it still just closes. start() no longer returns the stream; callers read `turns`. The app drops the `opened` task, field, parameter and await. Behaviour change: a finish() before start() no longer loses the queued audio — it is sent and its turns arrive. A new test covers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DS5B1Vp9Andd7LBEDhGKeC
finishBeforeStart repeated audioBeforeStart's setup and session's expected turns closely enough for jscpd to count two clones. A queued(on:) helper and a helloTurns constant now hold them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DS5B1Vp9Andd7LBEDhGKeC
alexkroman
changed the base branch from
claude/realtime-finishing-phase
to
main
November 25, 2026 20:49
One conflict: #410 made RealtimeTranscriber conform to LiveTranscriptionSession on the same line this PR documents Phase under. Kept both; this PR's API is unchanged, so the conformance still holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DS5B1Vp9Andd7LBEDhGKeC
#410 put the Record button's live session behind LiveTranscriptionSession, whose start() returned the turn stream, and gave the UI tests an offline double built the same way. This PR moves the stream to a `turns` property that exists from init, so: - LiveTranscriptionSession now requires `turns` and a start() that returns nothing, the shape RealtimeTranscriber has here. - UITestLiveSession builds its stream in init and yields each scripted turn straight into it. The `owed` count and `isClosed` flag, which covered a Next Turn or a Stop arriving before start, go: a stream that exists from the start buffers the one and has already ended for the other. - applyTurns takes any LiveTranscriptionSession and reads its `turns`. - The stream's init locals are renamed so they don't shadow the stored properties (variable_shadowing, which #410 also hit). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DS5B1Vp9Andd7LBEDhGKeC
…der) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DS5B1Vp9Andd7LBEDhGKeC
alexkroman
enabled auto-merge
November 25, 2026 21:11
alexkroman
pushed a commit
that referenced
this pull request
Nov 25, 2026
… CI run Recent multi-commit PRs (#410, #413, #414, #416, #420, #422, #423, #425, #426) mostly spent their extra ~37-minute runs on things nothing caught before CI: - scripts/check-swift-lint-lite.sh: a toolchain-free text match for the opt-in SwiftLint/swift-format rules it can see (modifier_order, no_empty_block, NoBlockComments, swift-format's `catch where`). Run by check.sh (so --portable and --lint-only) and the swift-budgets edit hook; would have flagged the pre-fix files of #414, #422 and #425. - .claude/hooks/push-gate.sh: a PreToolUse hook that runs `check.sh --portable` (~20 s) before any `git push` and blocks a red one — jscpd clones (#420, #422) and post-merge size overruns (#363, #378) were pushes that skipped the documented portable run. - AGENTS.md / CLAUDE.md: a "Rules only CI catches" list for the rest (variable_shadowing, one_declaration_per_file, type_contents_order, multiline_function_chains, MemberImportVisibility, one argument per line), and the new hook and script in the hooks table and permissions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DS5B1UDUZXyuF6g7GUmmNu
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 25, 2026
alexkroman
enabled auto-merge
November 25, 2026 21:44
#421 landed as a squash of the commits this branch was built on, so git saw its RealtimeTranscriber, LiveTranscriptionSession and tests changed twice. main's copies of those three files are exactly #421's, and this branch's are #421's plus this PR's change, so they are kept from here; a plain merge would have left two start() functions in the transcriber. #398's import and TextReader lines come in unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DS5B1Vp9Andd7LBEDhGKeC
Collaborator
Author
|
The Generated by Claude Code |
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 25, 2026
alexkroman
pushed a commit
that referenced
this pull request
Nov 25, 2026
Three conflicts: - DictationLog.swift: #431 moved the log-removal sweep to DictationLog+Removal.swift and made the logger internal for it; this PR had moved the withheld placeholders to DictationLog+Withholding.swift. Each now lives once, in its own file. - DictationSession+Pipeline.swift: this PR's DictationLog.loggable call, followed by #431's sentPrompt for the log. - DESIGN.md: main's table (#431 renamed SyncSTTLimits), with this PR's HopReturn row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DS5B1Vp9Andd7LBEDhGKeC
alexkroman
pushed a commit
that referenced
this pull request
Nov 26, 2026
#422 rewrote the Record button's live-session double inside TranscriptsModel+UITest.swift; this branch had moved that double to UITestLiveSession.swift, so the rewrite lands there and the model file keeps only its factory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DS5B1VPQPwfs6KaTp1BQKW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Today,
finish()on a session that hasn't started yet closes it and drops the audio queued for it. The Record button's Stop worked around this in 73ae910 with four pieces: anopenedtask, aRecording.openedfield, anapplyTurns(opened:)parameter, andawait recording.opened.valuebeforefinish().finish()'s doc also told callers to do the same.This PR fixes it in the transcriber instead:
init. It is a newpublic nonisolated let turns, so it can be read before the socket opens. Whichever ofstart()andfinish()comes first opens the socket.finish()on an idle session with audio queued opens the socket itself. It then sends the audio and waits forTerminationas before; a laterstart()does nothing. With nothing queued,finish()still just closes.start()no longer returns the stream. Callers readturns.LiveTranscriptionSession(from Drive the Record button in the Mac UI suite, on offline doubles for its capture and live session #410) follows: it requiresturnsand astart()that returns nothing. The UI tests'UITestLiveSessionbuilds its stream ininitand yields each scripted turn into it, which drops itsowedcount andisClosedflag: a turn released before the recording reads any waits in the stream, and a session ended beforestarthas already ended its stream.TranscriptsModel+Recording.swift,TranscriptsModel.swift): theopenedtask, field, parameter and await are gone.applyTurns(from:)readsrealtime.turnson anyLiveTranscriptionSession.finish()'s doc is rewritten to describe the new behaviour.Behaviour change: calling
finish()beforestart()no longer loses the queued audio. The socket opens, the audio is sent, and the final turn still arrives onturns. In the app, a Stop that lands before the socket has opened finishes the recording without waiting on a separate task.How it was tested
New test
finishBeforeStart: send audio, callfinish(), thenstart(). It checks that the server received the 3,200-byte chunk and was sent Terminate, and that both the partial and the final turn arrived. No wall-clock waits.Drive the Record button in the Mac UI suite, on offline doubles for its capture and live session #410's UI tests (
TranscriptionUITests, the live-recording audit) exercise the reworked double end to end.Written in a Linux sandbox with no Swift toolchain:
scripts/check.sh --portable(jscpd included) passes, as docheck-swift-size.shandcheck-test-clock.sh. CI on macOS verifies the build, tests, swiftlint, swift-format and periphery.scripts/check.shpasses (or CI will, if I'm not on a Mac)I read AGENTS.md and this doesn't reintroduce anything
deliberately removed
Docs updated if behavior changed
🤖 Generated with Claude Code
https://claude.ai/code/session_01DS5B1Vp9Andd7LBEDhGKeC