Skip to content

Prevent mobile worktree selection from focusing desktop - #6461

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/894
Jun 27, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/894

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add a notifyClients option to worktree.activate so paired clients can hydrate session surfaces without broadcasting a desktop worktree switch.
  • Send notifyClients: false from mobile worktree/session activation and paired-web activation paths.
  • Keep desktop/local activation behavior unchanged.

Linear

STA-894: https://linear.app/stably/issue/STA-894/prevent-mobile-worktree-selection-from-switching-desktop-workspace

Verification

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/runtime/web-runtime-session.test.ts src/renderer/src/lib/worktree-activation-created-agent.test.ts src/main/runtime/rpc/methods/worktree.test.ts
  • pnpm exec vitest run src/session/mobile-session-startup-source.test.ts src/worktree/mobile-worktree-activation-source.test.ts from mobile/
  • pnpm exec oxlint src/main/runtime/rpc/methods/worktree-schemas.ts src/main/runtime/rpc/methods/worktree.ts src/main/runtime/orca-runtime.ts src/renderer/src/runtime/web-runtime-session.ts src/renderer/src/lib/worktree-activation.ts src/main/runtime/rpc/methods/worktree.test.ts src/renderer/src/runtime/web-runtime-session.test.ts src/renderer/src/lib/worktree-activation-created-agent.test.ts 'mobile/app/h/[hostId]/index.tsx' 'mobile/app/h/[hostId]/session/[worktreeId].tsx' mobile/src/session/mobile-session-startup-source.test.ts mobile/src/worktree/mobile-worktree-activation-source.test.ts
  • pnpm exec tsgo --noEmit -p config/tsconfig.node.json
  • pnpm exec tsgo --noEmit -p config/tsconfig.tc.web.json
  • pnpm exec tsc --noEmit from mobile/
  • git diff --check

Physical phone check

  • Built/launched the current mobile dev bundle on the connected iPhone and verified it loaded through Metro.
  • Could not complete the live STA-894 host pairing: the phone storage still showed only the existing saved host endpoint, and the patched STA-894 host never registered a paired device/grant. No pairing tokens or secrets were logged.

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This change adds an optional client-notification flag to worktree.activate and threads it through the runtime, renderer web session activation, and mobile session activation paths. The runtime now branches on the flag to either notify clients or hydrate mobile session state, and the related tests were updated to cover the new request payloads.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: preventing mobile worktree selection from focusing desktop clients.
Description check ✅ Passed The description accurately summarizes the notifyClients change, affected activation paths, and unchanged desktop behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

🧹 Nitpick comments (1)
mobile/src/worktree/mobile-worktree-activation-source.test.ts (1)

4-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document why this test inspects source text.

Reading the TSX file and asserting on string slices is a non-obvious constraint for a test. Add a short Why: comment so future refactors do not replace it with a behavior-only test and lose this payload-shape guard.

Suggested change
-const source = readFileSync(new URL('../../app/h/[hostId]/index.tsx', import.meta.url), 'utf8')
+// Why: this locks the mobile activation call shape so regressions do not
+// reintroduce paired-client notifications during session opens.
+const source = readFileSync(new URL('../../app/h/[hostId]/index.tsx', import.meta.url), 'utf8')

As per coding guidelines, when TS/TSX code is driven by a non-obvious constraint, add a short comment explaining why.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8138bd27-1940-414f-aa61-22bd995bf840

📥 Commits

Reviewing files that changed from the base of the PR and between b899aef and 6bc2d0c.

📒 Files selected for processing (12)
  • mobile/app/h/[hostId]/index.tsx
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/session/mobile-session-startup-source.test.ts
  • mobile/src/worktree/mobile-worktree-activation-source.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/worktree-schemas.ts
  • src/main/runtime/rpc/methods/worktree.test.ts
  • src/main/runtime/rpc/methods/worktree.ts
  • src/renderer/src/lib/worktree-activation-created-agent.test.ts
  • src/renderer/src/lib/worktree-activation.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Updated this PR with a second fix from physical-device repro.

What changed:

  • session.tabs.activate now accepts notifyClients: false.
  • Mobile session routes pass notifyClients: false for phone-local tab activation.
  • The runtime updates/emits the mobile session snapshot directly in that mode instead of calling desktop focus notifiers (focusTerminal / focusEditorTab).

Why: the first fix kept worktree.activate quiet, but physical iPhone repro showed the follow-up mobile session.tabs.activate still made the desktop switch worktrees.

Verification:

  • Focused runtime/RPC tests passed.
  • Mobile source guard tests passed.
  • oxlint passed on touched desktop and mobile files.
  • tsgo --noEmit -p config/tsconfig.node.json and mobile tsc --noEmit passed before the final comment-only rerun.
  • Physical iPhone verification on plugged-in iPhone 3FF34709-B5C4-5607-A492-A756D109CB6F:
    • Paired dev host: host-1782525883165 at ws://100.123.212.97:6769.
    • Desktop baseline before phone route: active worktree was /Users/thebr/orca/workspaces/orca/894, activeModal: none.
    • Launched phone deep link to primary first and confirmed phone storage wrote /Users/thebr/orca/workspaces/orca/894.
    • Launched phone deep link to smoke worktree and confirmed phone storage wrote /Users/thebr/orca/workspaces/894/sta-894-phone-smoke.
    • Desktop after phone smoke route stayed on /Users/thebr/orca/workspaces/orca/894, activeModal: none.

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
mobile/app/h/[hostId]/session/[worktreeId].tsx (1)

2773-2808: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Avoid bypassing notifyClients: false with terminal.focus.

Line 2802 still sends terminal.focus before the silenced session.tabs.activate; the adjacent comment says this makes desktop follow the mobile active terminal. That can still move paired desktop focus when switching terminal tabs, defeating the phone-local activation path.

Proposed fix
-  // Why: unsubscribe the old terminal so the server restores its desktop dims
-  // (clearing the phone-fit banner), then subscribe the new terminal with the
-  // measured viewport so the server phone-fits it. Also call terminal.focus
-  // so the desktop renderer follows the mobile user's active terminal.
+  // Why: unsubscribe the old terminal so the server restores its desktop dims
+  // (clearing the phone-fit banner), then subscribe the new terminal with the
+  // measured viewport so the server phone-fits it.
   const switchTab = useCallback(
@@
       subscribeToTerminal(handle)
       if (client) {
-        void client.sendRequest('terminal.focus', { terminal: handle }).catch(() => {})
         if (matchingTab) {
           void client
             .sendRequest('session.tabs.activate', {
🧹 Nitpick comments (1)
src/main/runtime/rpc/methods/session-tabs.ts (1)

31-32: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document why mobile activation can suppress client notifications.

This notifyClients !== false branch is a non-obvious mobile-only exception. Please add a short comment that false is used to hydrate phone-local session state without stealing focus on paired desktop clients.

Suggested diff
   handler: async (params, { runtime }) =>
+    // Mobile-only activation hydrates phone state without switching focus on paired desktops.
     runtime.activateMobileSessionTab(params.worktree, params.tabId, params.leafId, {
       notifyClients: params.notifyClients !== false
     })

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8e9302c0-6a67-4a12-9f60-c7d3d23e41e4

📥 Commits

Reviewing files that changed from the base of the PR and between 6bc2d0c and 840ab04.

📒 Files selected for processing (7)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/session/mobile-session-startup-source.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/session-tabs-schemas.ts
  • src/main/runtime/rpc/methods/session-tabs.test.ts
  • src/main/runtime/rpc/methods/session-tabs.ts

@brennanb2025
brennanb2025 merged commit 5fd9f0c into main Jun 27, 2026
2 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/894 branch June 27, 2026 02:34
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 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.

1 participant