Skip to content

fix(mobile): reread the host dictation mode when the session connects - #30513

Closed
innocarpe wants to merge 1 commit into
stablyai:mainfrom
innocarpe:ios-dictation-preference-refresh-20261019
Closed

innocarpe wants to merge 1 commit into
stablyai:mainfrom
innocarpe:ios-dictation-preference-refresh-20261019

Conversation

@innocarpe

Copy link
Copy Markdown
Contributor

ELI5

The phone remembers whether you hold or tap the mic to dictate, but it only asked the desktop once, sometimes before it was even connected. Now it asks again when the connection comes up or the app comes back.

What Changed

refreshDictationMode in use-mobile-session-native-chat-dictation.ts:

  • runs on [client, connState] and only once the connection is connected (a read before that is rejected by the relay);
  • runs again when the app returns to active while the screen is focused;
  • numbers each request and ignores replies from a previous focus or connection, so an older reply cannot overwrite a newer mode;
  • unsubscribes and invalidates pending requests when focus is lost.

Before: a cold start or reconnect could leave the mic in toggle mode while the host was set to hold (or the reverse). After: the mic follows the host's current setting after connecting, reconnecting or returning to the app.

Why

The client is a long-lived logical object that survives reconnects, so keying the read on it alone misses every reconnect. Keying on connection state follows the same pattern as other host-backed settings in the session screen (use-live-worktree-name.ts, tab reconciliation).

Linked Issue

Fixes #30511

Visual Proof

N/A — no new UI; the existing mic binds hold (press-in/out) or toggle (tap) according to the mode it reads. The regression tests below assert that binding after connect and reconnect.

Testing

  • New mobile-dictation-mode-refresh.test.tsx (4) mounts the real screen-state hook, the dictation hook and MobileTerminalInputActions with a client that rejects reads while disconnected and keeps its identity across reconnects: first connect, reconnect, a late reply from a dropped connection, and app-foreground/focus-loss cleanup. Without the change all 4 fail; with it they pass, together with the existing mobile-dictation-refused-start-routing.test.tsx.

  • Mobile tsc --noEmit, the tests typecheck ratchet, and oxfmt/oxlint on the changed files passed.

  • Not run: the full mobile suite, a release build, or a physical device check.

  • I manually tested these changes locally

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

AI Disclosure

Prepared with Claude Code (Claude Opus).

Review

Self-review: mobile-only; uses the existing speech.models.list read, so no host or protocol change and the same behavior over local, SSH and relay connections. Adds at most one small read per connect or app foreground. No security impact. If #30316 (hide the mic when dictation is disabled) lands first, its setDictationEnabled line in the same function should sit under the same request guard; the conflict would be textual and small.

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.

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)

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The session dictation hook now reads the host’s dictation mode only while connected. It refreshes the mode when the connection state changes and when the focused app returns to the foreground. It ignores replies from older reads, preserves the last reported mode when a read fails, and removes the foreground listener during cleanup. Tests cover initial connection, reconnection, stale replies, foreground refresh, and microphone binding.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to add26

The microphone may briefly use the previous connection’s dictation mode. This is a bounded risk, but invalidating pending reads when the connection changes would resolve it.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description is complete and aligned with the template. It explains the user impact, implementation, rationale, linked issue, testing, limitations, AI disclosure, review considerations, and checkli…
Title check Passed The title clearly and concisely describes the main change: rereading the host dictation mode when the mobile session connects.
Linked Issues check Passed Issue #30511 requires dictation-mode reads when the connection becomes connected and when the app becomes active while the session is focused. The hook now keys refresh behavior on client and `connS…
Out of Scope Changes check Passed The changes are limited to the mobile dictation refresh hook and focused automated tests for the behavior in issue #30511. The test wiring validates the existing microphone binding without adding unre…
Full details: Description check

Explanation

The description is complete and aligned with the template. It explains the user impact, implementation, rationale, linked issue, testing, limitations, AI disclosure, review considerations, and checklist status.

Full details: Linked Issues check

Explanation

Issue #30511 requires dictation-mode reads when the connection becomes connected and when the app becomes active while the session is focused. The hook now keys refresh behavior on client and connState, skips reads unless connState === 'connected', registers an AppState listener within useFocusEffect, and invalidates pending reads during focus cleanup. The request counter prevents stale replies from updating the mode. The new test file covers cold connect, reconnect, stale replies, foreground refresh, and focus-loss cleanup.

Full details: Out of Scope Changes check

Explanation

The changes are limited to the mobile dictation refresh hook and focused automated tests for the behavior in issue #30511. The test wiring validates the existing microphone binding without adding unrelated product behavior or public API changes.

  • Fix all pre-merge checks with AI
  • 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.

@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
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 56a7b203-c3a9-4a0a-9537-62f24be0fa1d
📥 Commits

Reviewing files that changed from the base of the PR and between df0c445 and add26ee.

📒 Files selected for processing: 2
  • mobile/src/session/mobile-dictation-mode-refresh.test.tsx
  • mobile/src/session/use-mobile-session-native-chat-dictation.ts

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

try {
const setup = await fetchDictationSetup(client)
setDictationMode(setup.dictationMode)
if (read === dictationModeReadRef.current) {

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Invalidate old reads when the connection changes.

If the connection changes before the focus effect cleanup runs, a reply from the old connection can still pass the generation check. Invalidate the read generation during the connection-change commit so the old reply cannot update the microphone mode.

Source: Learnings

nwparker added a commit that referenced this pull request Oct 21, 2026
Honor enabled voice settings across terminal/chat controls and capture. Refresh hold/toggle state on connection, focus and foreground while fencing stale replies.

Adversarial review: 63 existing tests plus six disable/late-finish/unmount/settings ownership probes pass; final required CI and aggregate gate pass. Existing native screenshots and microphone lifecycle exercise are attached to the PR.

Fixes #30307. Fixes #30511.
Adapted from community #30316 and #30513 by @innocarpe.

Co-authored-by: Wooseong Kim <[email protected]>
@nwparker

Copy link
Copy Markdown
Contributor

Closing as superseded by merged #31349 (12e0b37293c24273aa8f0a15b258f4cb5c5f0af0), which carries this reconnect/foreground mode refresh together with #30316's enabled setting under the same stale-response guard. Wooseong Kim is credited as co-author in the actual merged commit.

Native hold/toggle, reconnect and foreground behavior were exercised and screenshots attached to #31349. Independent adversarial review passed 63 existing tests plus six disable/late-finish/unmount/settings-race probes; CI and aggregate gate passed. Thank you @innocarpe.

@nwparker nwparker closed this Oct 21, 2026
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.

fix(mobile): reread the host dictation mode when the session connects

2 participants