Skip to content

fix(agent-launch): move only the requesting client's view to a launched tab - #22914

Merged
brennanb2025 merged 4 commits into
mainfrom
brennanb2025/agent-launch-caller-navigation
Sep 27, 2026
Merged

brennanb2025 merged 4 commits into
mainfrom
brennanb2025/agent-launch-caller-navigation

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​295 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​295
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​103 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​98

ELI5

When you start an agent from your phone, your phone should open on the new tab the next time you look at that workspace, and nobody else's view should move. Before, a new chat from the phone was made the active tab in the list the computer shares with every device, and a new terminal wasn't remembered as the tab the phone wanted, so the phone came back to whatever it showed before. Now the phone that asked gets the new tab as its own choice, and the shared list isn't touched.

What Changed

Before: agent.launch into an existing workspace, from a paired client (a phone, or a desktop client connected to a remote Orca server):

  • a structured chat was published with activate: true, making it the active tab in the host's shared tab list (what every client without its own selection follows);
  • a terminal agent was published unfocused, and nothing recorded it as the caller's selection, so the caller's view didn't follow it (the older session.tabs.createTerminal path did record it).

After: for those launches the host publishes the chat without activating it for everyone, then records the new tab as the calling client's own selection through the same caller-navigation step session.tabs.createTerminal runs after its own create (exposed as selectCreatedMobileSessionTabForClient). The terminal is found by the pane the launch created (paneKey), the chat by its session id (never a predicted tab id). It is deliberately not the tab-tap path (activateMobileSessionTab): a tap refreshes the PTY inventory and treats a pane that isn't ready as a wake gesture that respawns its agent, which a launch must never do.

Unchanged:

  • In-process callers (no paired client) keep today's behaviour byte for byte.
  • Launches that create their workspace keep worktree.create's navigation, whose host activation is what runs the new workspace's setup.
  • A replayed operation answers from its record and moves nothing.
  • Selecting the tab is bookkeeping: if it fails, the launch still succeeds and the view is left as it was.

This applies to paired desktop clients of a remote server as well as phones, intentionally: a view change belongs to the connection that asked for it, as it already does for worktree.create and session.tabs.activate.

Why

The host already owns each paired client's tab selection — session.tabs.createTerminal and caller-scoped browser tab creation already record the tab they create as the caller's selection — so a launch records the caller's selection the same way rather than broadcasting an activation. Two alternatives were considered:

  • The client navigates itself from the launch reply. This is how selection works where the client owns it, but in Orca the selection lives on the host either way, so it would add a second write after every launch and a new route for opening a chat by session, without removing host state.
  • Leave it as is. A phone's chat launch keeps moving the shared tab list every client without its own selection follows, and the phone itself doesn't come back to what it launched.

Deviation recorded: selection here is applied by the host at launch, from the requesting connection, rather than by the client after the reply.

Linked Issue

No linked issue.

Visual Proof

Android phone running the mobile client that sends this launch (the commit-failure Fix button, from the follow-up mobile PR), paired to an isolated desktop host built without this change (before) or with it at 7d944aa8aa (after). Both arms started from the same seeded state: one workspace with Terminal 1 active. Fix is tapped from Source Control opened outside the session, then the workspace is opened on the phone.

Before After
Terminal launch, phone
back on Terminal 1

opens on the new Claude terminal (at Claude's folder-trust prompt)
Chat launch, phone
back on Terminal 1

opens on the new chat

Desktop window after the phone's chat launch (after): still on Terminal 1, the new chat present but not selected.

A launch from the desktop window itself still moves the desktop to the new tab (after):

A phone that is already showing the workspace does not switch live; it opens on the new tab the next time the workspace is opened (after):

Right after Fix After reopening the workspace

Testing

  • created-mobile-session-tab-caller-selection.test.ts (a real runtime, two subscribed devices): a launched terminal and a launched chat become the caller's selection while the shared tab list and a second subscribed device stay put; a tab that isn't published is reported, not substituted; selecting a pane that isn't ready never spawns (the tap path does).
  • agent-launch-caller-selection.test.ts (through the real agent.launch / agent.launchReplay handlers):
    • a paired client's terminal launch selects that pane for the caller only (navigation: 'caller', its device id);
    • a paired client's chat launch publishes with activate: false, then selects the chat, found by session id, for the caller;
    • a failure while selecting still returns the launch;
    • no pane reported → nothing selected;
    • an in-process caller still activates the chat and selects nothing per client;
    • the host's own desktop window (a runtime client with no paired device) still activates the chat and selects nothing per client;
    • a workspace-creating launch from a paired client keeps activate: true and selects nothing;
    • a replay of the same operation answers from the record, creates nothing and selects nothing.
  • pnpm tc; src/main/runtime/rpc/methods + src/main/agent-launch — 216 files / 2,184 tests pass; oxlint on changed files; check:code-quality:changed 0 findings.
  • Live QA at 7d944aa8aa (Android emulator driven only through orca emulator; isolated desktop host built with and without this change, identical seeded state per arm, desktop window hidden and checked over CDP):
    • Terminal launch from the phone: before → the phone comes back to Terminal 1; after → the phone opens on the new Claude terminal. The desktop stays on Terminal 1 in both.
    • Chat launch from the phone: before → the phone comes back to Terminal 1; after → the phone opens on the new chat. The desktop window stays on Terminal 1 in both (the desktop window keeps its own selection; what moved on main was the shared tab list other clients follow).
    • Desktop-initiated launch (after): the desktop moves to the new chat as before; the phone is not moved.
    • Phone already on the workspace (after): stays on its current tab until the workspace is reopened, as described above.
  • Ablations (each reverted alone):
Removed behaviour Tests that went red
Chat still activated for everyone publishes the chat without activating it for everyone…
No caller selection after the launch the terminal and chat selection tests, and the replay test's first launch
Selection fanned out to every live client ('all') both real-runtime selection tests (second device moved)
Selection routed through the tab-tap path the "never spawns" test, plus both selection tests
A selection failure fails the launch still reports the launch when selecting its tab fails
Workspace-creating launches not excluded a workspace-creating launch from a paired client keeps the create navigation

Notes

  • Wire compatibility: no wire change. Clients see a different tab selection after a launch; older hosts keep the old behaviour.
  • SSH / remote servers: the caller is identified by its paired device on the host that runs the launch; a desktop client of a remote server gets the same caller-only selection.
  • Scope: agent-launch-surfaces.ts changes are one parameter and one argument; the runtime gains one public method, selectCreatedMobileSessionTabForClient, a thin wrapper over the existing caller-navigation step.

…ed tab

A launch into an existing workspace from a paired client (a phone, or a
desktop client of a remote server) activated a new chat for every client and
the host, and recorded no selection for the caller's terminal. It now
publishes the chat without activating it for everyone and records the new tab
as the caller's own selection, the way that client's own tab tap does
(session.tabs.activate with caller navigation). In-process callers and
workspace-creating launches are unchanged. Selecting the tab is bookkeeping:
a failure there never fails the launch.
…ate does

The launch recorded the caller's selection through the tab-tap path, which
refreshes the PTY inventory (twice for a chat) on the reply path and treats a
non-ready pane as a wake gesture that respawns its agent. Record it through
the same caller-navigation step session.tabs.createTerminal uses after its own
create: no host focus, no refresh, no materialize.
…vates a launched chat

The desktop renderer reaches agent.launch as a runtime client with no paired device, so it must keep the host-wide activation rather than be treated as a paired caller.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready for review (head 7d944aa8aa)

Verdict: the change does what it says. When a phone (or a desktop client of a remote Orca server) launches an agent into an existing workspace, only that client lands on the new tab; the shared tab list and every other view stay where they were. Launches from the desktop window itself, in-process callers and workspace-creating launches behave as before.

Review loops (3, the last one clean):

  • Loop 1 found one real problem and fixed it (d292cc20dd, 4298d6f512). The first version selected the tab through the tab-tap path (activateMobileSessionTab). A tap refreshes the terminal inventory on every launch, and it treats a pane that isn't ready as a request to wake it, which can restart that pane's agent. A launch must never do that. The selection now goes through the same step session.tabs.createTerminal runs after its own create (applyMobileSessionTabNavigation with caller navigation), exposed as selectCreatedMobileSessionTabForClient. A real-runtime test with two subscribed devices covers it.
  • Loop 2 added a missing test (7d944aa8aa): the host's own desktop window, which calls agent.launch as a runtime client with no paired device, still activates a launched chat.
  • Loop 3 re-checked everything and found nothing further. Checked across the loops: no race with tab publication on windowed or headless hosts, no wire change, and replays, reused terminals, SSH and folder workspaces all correct. Ablations turn the new tests red.

Readiness checklist: passed at the start and at the end, with nothing blocking.

Live QA ran on a separate Mac with an Android emulator and an isolated desktop host, built with and without this change from identical seeded state. It passed on the new head. Terminal and chat launches from the phone open on the new tab, and the desktop stays on Terminal 1. A desktop-initiated launch still moves the desktop. Screenshots are in the PR body.

Worth knowing (not blockers for this PR):

  • A phone that is already showing the workspace does not switch to the launched tab live; it opens on it the next time the workspace is opened. That is what this PR claims. Switching live needs the phone to act on the launch reply, which belongs to the mobile follow-up that starts sending this launch.
  • Not caused by this PR: agentSession.create from a phone still activates a new chat for everyone, while agent.launch from the same phone now doesn't. Left as is to keep scope.
  • Minor, left as is: the selection runs after the launch delivers its prompt. For agents whose prompt is typed in after start, that can take up to about 60 seconds, so a tab the user picks on the phone during that wait would be replaced. If the prompt commit on a paired chat launch fails, the chat exists but is selected for nobody. The new runtime method lives in one of the runtime's @ts-nocheck split files, like its neighbours, so its body is covered by tests rather than the type checker.
  • No client on main sends this kind of launch yet, so this PR changes nothing users see until the mobile follow-up lands.

@brennanb2025
brennanb2025 marked this pull request as ready for review September 27, 2026 18:09
@coderabbitai

coderabbitai Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 883100fd-7401-47b8-bfdb-28a4df3f29bd

📥 Commits

Reviewing files that changed from the base of the PR and between 01ed4b9 and 7d944aa.

📒 Files selected for processing (6)
  • src/main/runtime/created-mobile-session-tab-caller-selection.test.ts
  • src/main/runtime/orca-runtime-apply-mobile-session-tab-navigation.ts
  • src/main/runtime/rpc/methods/agent-launch-caller-selection.test.ts
  • src/main/runtime/rpc/methods/agent-launch-caller-selection.ts
  • src/main/runtime/rpc/methods/agent-launch-surfaces.ts
  • src/main/runtime/rpc/methods/agent-launch.ts

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


📝 Walkthrough

Walkthrough

The runtime adds a method to select a created mobile-session tab for a specific client. Agent launches derive a caller navigation ID for eligible existing-target launches and select the resulting tab when available. The changes also add tests for runtime selection, launch behavior, and replay.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 7d944

No confirmed issue currently prevents merging. Structured-chat selection timing remains unverified.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 7d944

The reviewed paired-client path limits the new selection to the requesting device and workspace, and no introduced security vulnerability was established. Some alternate dispatch and failure paths remain insufficiently verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — On the reviewed paired WebSocket path, the new navigation write is limited to the authenticated device ID and the result worktree. Connections sharing one paired-device identity share that device’s selection; a different device’s selection is not the target.

Trust Boundaries and Controls

  • observed — The caller-selection helper takes identity from RPC context, not from an agent-launch request field. The reviewed authenticated WebSocket dispatcher populates that context from its validated device record.
  • observed — The unary dispatcher’s context construction omits pairedDeviceId. Whether a production paired-client agent.launch uses that dispatcher, rather than the reviewed WebSocket dispatcher, remains unestablished.

Resilience and Maintainability Implications

  • inferred — Selection failure does not redirect navigation to a different tab or device. Distinct concurrent launches are not shown to have request-order selection guarantees, although same-operation active calls share a promise.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 6 files. 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 and concisely describes the primary change: caller-only navigation to a launched tab.
Description check ✅ Passed The description is comprehensive and covers the user impact, implementation, rationale, testing, visual proof, compatibility, and known limitations. It includes the required core sections, although it…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

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

ℹ️ No critical issues — one comment-accuracy nit inline.

Reviewed changes

Read the complete diff plus the surrounding runtime/executor/navigation code it touches.

  • Caller-scoped launch selection (new) — agent-launch-caller-selection.ts resolves the requesting paired device id (existing-workspace targets only) and, after the launch, selects the tab the host just published by paneKey (terminal) or sessionId (chat); failures warn, never fail the launch.
  • runAgentLaunch becomes async — computes the caller id, publishes a chat with activate: false for paired callers, then records the caller's selection; replays return from the ledger before selection so nothing re-moves.
  • Surface factory gains activateChat — agentLaunchSurfaceFactory threads a new 4th param into the structured create's activate (defaults true, so in-process callers and the host window are unchanged).
  • Runtime selection helper (new) — selectCreatedMobileSessionTabForClient finds the tab in getMobileSessionTabsForWorktree and reuses the existing applyMobileSessionTabNavigation(..., 'caller', id), deliberately skipping the tap path (no PTY refresh / respawn).
  • Tests — a real-runtime two-device test (caller moves, bystander and shared list do not, no respawn) and RPC-boundary coverage for paired/in-process/host-window/create-worktree/replay/failure arms.

I verified the design against existing conventions: the clientKind === undefined gate mirrors terminal.create's pairedViewer boundary, publishStructuredAgentSessionTab(activate:false) still publishes a selectable tab, the stored selection survives later coalesced broadcasts, and mobile's resolveActiveSessionTab reads the projected isActive — so no wire or client change is needed. Covering the chat arm by sessionId rather than a predicted tab id is the right call.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

...(tabId ? { tabId } : {}),
// The user asked for this chat, so it takes the surface — unlike a dispatched worker.
activate: true
activate: activateChat

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.

The comment one line above — "The user asked for this chat, so it takes the surface" — no longer describes every case: with activateChat false, the chat is published without taking the host surface (it is selected for the paired caller instead). Worth restating as "a chat the user asked for takes the surface for host/in-process callers; a paired caller gets it as its own selection", so the code and comment do not drift.

@brennanb2025
brennanb2025 merged commit bdaf9a3 into main Sep 27, 2026
70 checks passed
nwparker added a commit to yohangwak/orca that referenced this pull request Nov 23, 2026
When a paired phone created a workspace with a chat agent, the host
briefly activated the chat, then the desktop window republished its own
active tab (Setup) and the phone followed it about half a second later.

agentLaunchCallerNavigationId skipped create-worktree targets, so these
launches recorded no per-phone tab selection. It now returns the paired
device for every target, so the creating phone keeps its own selection on
the agent tab, the same as existing-workspace launches (stablyai#22914).

Worktree creation still passes callerPresentsSurface=false, so host-wide
chat activation is unchanged and a windowless host's other clients still
open the new worktree on the chat.

Fixes stablyai#47688

Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
nwparker added a commit that referenced this pull request Nov 23, 2026
…tab (#47687)

When a paired phone created a workspace with a chat agent, the host
briefly activated the chat, then the desktop window republished its own
active tab (Setup) and the phone followed it about half a second later.

agentLaunchCallerNavigationId skipped create-worktree targets, so these
launches recorded no per-phone tab selection. It now returns the paired
device for every target, so the creating phone keeps its own selection on
the agent tab, the same as existing-workspace launches (#22914).

Worktree creation still passes callerPresentsSurface=false, so host-wide
chat activation is unchanged and a windowless host's other clients still
open the new worktree on the chat.

Fixes #47688

Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
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