Skip to content

fix(mobile): keep dictation recording through a reconnect and keep what was already said - #35338

Merged
AmoabaKelvin merged 7 commits into
mainfrom
mobile-dictation-reconnect
Oct 28, 2026
Merged

AmoabaKelvin merged 7 commits into
mainfrom
mobile-dictation-reconnect

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​383 $\color{#cf222e}{\Huge{\mathbf{−}}}$​58 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​325
Prod 29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​946 $\color{#cf222e}{\Huge{\mathbf{−}}}$​782 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​164

ELI5

If your phone's connection blinked while you were dictating to Orca Mobile, the recording stopped and everything you'd said was gone. Now the phone keeps recording through the reconnect and you get the whole transcript. If the connection never comes back, you keep whatever was already transcribed.

What Changed

Before: any reconnect mid-dictation ended it. That covers a Wi-Fi/cellular switch, a Relay hiccup or a direct→Relay fallback. The mic stopped, the speech was lost and sometimes a raw code like dictation_owner_mismatch showed up.

After: the recording carries on through the reconnect and stop gives the full transcript. If the phone can't get back within 30s, dictation ends with an error but the words transcribed so far land in the input.

Root cause: the host tied a phone's dictation session to the socket rather than to the phone. A socket close cancelled the session, and requests from the reconnected socket were refused as dictation_owner_mismatch. The phone also gave up on its own: enabled followed connState === 'connected', so the first drop abandoned the recording, and any chunk error ended it.

Host (runtime-mobile-dictation-controller.ts):

  • The session is owned by the phone's device clientId. Socket and client disconnect hooks no longer cancel it.
  • One idle timer ends it: if the owning phone sends nothing for 30s (MOBILE_DICTATION_RECONNECT_GRACE_MS, shared in speech-params.ts), the speech model is released. This covers a killed app, a lost cancel, or a phone that never comes back.
  • A new start from the same phone retires its own active session, so an app relaunch inside the grace can dictate straight away.
  • Chunk replies carry the text so far (text) when it changed, and at least once a second so a reply lost at the drop is replaced. This is additive: old phones ignore the reply body.

Phone:

  • Only starting needs a connection. A recording in progress survives the drop, and the terminal mic stays pressable so you can still stop or cancel it.
  • A chunk lost on the dying socket (delivery-unknown) no longer ends dictation. Requests that never left get sent again on the new connection. That means a cutover during a direct↔Relay move, or a Relay client suspended while recovery dials a replacement (matched by message, so it also works on the OTA page through the bridge).
  • Chunk and start sends wait for a reconnect at most the same 30s. The queued-audio cap rises from 5s to 30s to cover it. The OTA shell ring stays at the host's 5s chunk cap.
  • If dictation fails anyway, the last text-so-far goes into the input before the error shows.
  • Dictation cancels never wait for a reconnect (failWhenDisconnected); the host's idle timer drops a session the phone can't reach.
  • Relay transport: retiring a Relay session that had already failed now releases requests still waiting on it, instead of leaving them to time out 30s later and arrive after newer audio.

Why

The fix sits at the host's session lifetime, where the wrong fact lived ("this dictation belongs to that socket"). Phone-side retries alone can't work, because the host has already thrown the session away. The phone changes only stop treating a reconnect as the end of input, and resend requests that provably never reached the host.

What can still be lost: speech sent on the dying connection before the phone notices the drop. Those chunks may or may not have reached the host, so they aren't replayed (that would duplicate words). That's about 1s on a hard drop, and more on a silent drop until the liveness probe fires. Replaying them safely needs sequence numbers the host can dedupe, gated on a new capability: #35213.

Mixed versions:

  • Old phone + new host: it works, and the extra text in chunk replies is ignored. The old phone still abandons on a drop and sends cancel, which now matches by clientId and goes through.
  • New phone + old host: the old host still cancels on socket close. The phone keeps recording, then fails on the first chunk after the reconnect (dictation_stream_not_started) or after 30s, the same loss as today but reported later. I didn't add a capability gate for that, since the outcome is no worse than today.

Linked Issue

Fixes #35211

Follow-up: #35213 (replay speech sent on the dying connection)

Visual Proof

N/A: there's no new UI, and the change is about what happens across a network drop. Staging a timed Wi-Fi/Relay drop mid-dictation on a simulator doesn't reproduce it reliably. The behaviour is covered by hook, transport and host tests that each fail on the old code (listed below), plus the mobile RPC recording goldens.

Testing

  • Host: runtime-mobile-dictation-controller.test.ts. It shows that the session survives a phone that keeps reaching it from any connection and returns the full transcript, and that it releases the model after 30s of silence. Plus speech.test.ts and orcad-speech-services.test.ts.

  • Phone hook: mobile-dictation-reconnect.test.tsx. It covers chunks lost at the drop not ending the recording, cutover-unsent chunk and finish requests being resent, a suspended-client refusal being held until reconnect (including the bridge-rebuilt error), and the transcribed text being kept when the connection never returns.

  • Session: mobile-dictation-agent-chat-start.test.tsx. A start and a finish that span a drop both complete.

  • Terminal mic: mobile-dictation-disabled-controls.test.tsx. The mic can still stop a recording while offline.

  • Transport:

    • mobile-relay-rpc-session.test.ts: retiring a failed session releases waiting requests unsent.
    • stable-logical-rpc-client.test.ts: requests interrupted by suspension are reported as suspended, and written ones stay ambiguous.
  • Every new test was checked to fail with its fix reverted.

  • Mobile RPC recording goldens re-recorded for the chunk reply handling and the new timeoutMs on start and chunk; all 1695 pass.

  • Changed-file code-quality and react-doctor gates pass. CI covers the full suite and typecheck.

  • No device or simulator run.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Four review rounds with Codex and Claude. Every accepted P0/P1 was fixed with a test:

  • Relay waiters left behind on a failed session
  • unbounded connect waits
  • a finish resend during a connection move
  • relay suspension, including across the OTA page bridge
  • a start stuck waiting on a drop
  • the terminal mic disabled offline

Not taken:

To try (needs blessing: changes host/phone behaviour):

  • Pair a phone and start dictating in a chat or terminal. Mid-sentence, toggle Wi-Fi off and on (or switch to cellular), keep talking, then tap stop: the recording keeps going and the transcript includes speech before and after the drop.
  • Start dictating, then cut the phone's network for over 30s: dictation ends with an error, and the words transcribed before the drop land in the input.
  • Dev build from worktree /Users/kelvinamoaba/orca/workspaces/orca/dictation-reconnect (both desktop and mobile change).

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: session ownership is the authenticated device id, which already gated every dictation call. Dropping the socket check doesn't let another device in.
  • Cross-platform: the host change is platform-neutral. Phone changes cover native (iOS/Android) and the OTA page.
  • Remote: headless orca serve hosts use the same controller.
  • Mobile: this is a mobile fix.
  • Backwards compatibility: see Why.
  • Performance:
    • The host refreshes one timer per chunk and only rebuilds the text when a transcript event arrived.
    • Chunks refused during one outage share a single reconnect wait.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect mobile dictation and the reconnect paths it uses.

The lost-reply finding remains partly unfixed and should be addressed before merging.

Summary

Keeps mobile dictation alive across reconnects and saves received transcript text when recording fails.

  • A phone keeps its dictation session when its network connection changes.
  • The phone keeps recording through reconnects and preserves the transcript if dictation ends.
  • Mobile RPC requests can wait for a replacement Relay connection.

Diagram

sequenceDiagram
  participant Phone
  participant Host
  Phone->>Host: Start dictation
  Phone->>Host: Audio chunks
  Host-->>Phone: Transcript so far
  Note over Phone,Host: Connection drops
  Phone->>Phone: Keep recording within queue limit
  Note over Host: Keep session for 30 seconds
  alt Connection returns
    Phone->>Host: Resume chunks using same phone identity
    Phone->>Host: Finish
    Host-->>Phone: Full transcript
  else Connection does not return
    Host->>Host: Retire idle session
    Phone->>Phone: Keep received text and show error
  end
Loading

Reviews (2) · Last reviewed commit: "fix(mobile): resend dictation text each ..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

Mobile dictation now uses a shared 30-second reconnect grace period. The runtime tracks dictation sessions by mobile client and reports transcript updates with audio feeds. The mobile client retries selected chunk and finish requests across connection changes, retains transcript text, and preserves active recording for unknown-delivery failures. Dictation controls use separate availability and start-permission conditions. Speech RPC fixtures and reconnect tests were updated.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Moderate · up to 4249d

Closing the dictation input can discard text already transcribed, including while completion is pending. Preserve that text before merging; reconnect alone does not trigger this closure path.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preserving mobile dictation across reconnects and retaining transcribed text.
Linked Issues check Passed The changes meet the coding requirements in [#35211]. RuntimeMobileDictationController owns sessions by clientId, removes socket-based cancellation, refreshes a 30-second grace timer, and returns …
Out of Scope Changes check Passed The changes stay within [#35211]. Transport waiters, suspended-client errors, timeout updates, relay-session cleanup, RPC golden updates, and test-fixture changes support reconnect-safe dictation or v…
Description check Passed The pull request follows the required structure and provides clear ELI5, change, rationale, issue, visual proof, testing, review, scope, notes, and checklist details. The linked issue is present, and …
Full details: Linked Issues check

Explanation

The changes meet the coding requirements in [#35211]. RuntimeMobileDictationController owns sessions by clientId, removes socket-based cancellation, refreshes a 30-second grace timer, and returns transcript text. Mobile dictation keeps recording across reconnects, retries requests that did not reach the host, keeps the terminal microphone available, and delivers stored transcript text on failure. The changed tests cover host grace-period behavior, reconnect retry behavior, finish across reconnect, offline stop controls, and transcript retention. The additive text response supports mixed phone and host versions.

Full details: Out of Scope Changes check

Explanation

The changes stay within [#35211]. Transport waiters, suspended-client errors, timeout updates, relay-session cleanup, RPC golden updates, and test-fixture changes support reconnect-safe dictation or validate its changed RPC behavior. Delivery-unknown audio replay remains explicitly deferred to follow-up [#35213]. No unrelated production change is demonstrated.

Full details: Description check

Explanation

The pull request follows the required structure and provides clear ELI5, change, rationale, issue, visual proof, testing, review, scope, notes, and checklist details. The linked issue is present, and the lack of manual testing and local full-suite verification is explicitly documented. The AI Disclosure section is blank, which is acceptable if the author is an internal contributor.

Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 16 functions across 27 files. (7 skipped: 7 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The host tied a phone's dictation to its socket, so any reconnect cancelled
it, and the phone ended the recording as soon as the connection dropped.
The host now owns the session by device and waits a grace period for the
phone to come back. The phone keeps recording through the reconnect and
keeps the text transcribed so far if the connection does not return.

Fixes #35211
…e and send the text so far only when it changes
@AmoabaKelvin
AmoabaKelvin force-pushed the mobile-dictation-reconnect branch from fea5cb5 to 4249db6 Compare October 28, 2026 21:04

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 82b00dbc-b410-435f-a1d3-d71fec00fd11
Commits

Reviewing files that changed from the base of the PR and between fea5cb5 and 4249db6.

Files selected for processing: 12
  • mobile/rpc-foundation/goldens/matrix-speech.dictation-session-speech.dictation.finish-1.json
  • mobile/rpc-foundation/goldens/matrix-speech.dictation-session-speech.dictation.start-1.json
  • mobile/rpc-foundation/goldens/matrix-speech.dictation-start-speech.dictation.cancel-1.json
  • mobile/rpc-foundation/goldens/matrix-speech.dictation-start-speech.dictation.start-1.json
  • mobile/rpc-foundation/goldens/speech-desktop-start-recording-failed.json
  • mobile/rpc-foundation/goldens/speech-desktop-start-superseded.json
  • mobile/rpc-foundation/goldens/speech-dictation-session-cancelled.json
  • mobile/src/hooks/mobile-dictation-desktop-start.test.ts
  • mobile/src/hooks/mobile-dictation-desktop-start.ts
  • mobile/src/hooks/use-mobile-dictation.ts
  • src/main/runtime/runtime-mobile-dictation-controller.test.ts
  • src/main/runtime/runtime-mobile-dictation-controller.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mobile dictation stops and loses what you said when the connection reconnects

1 participant