Skip to content

fix(mobile): start + menu, quick command and diff-note agents through agent.launch - #22954

Merged
brennanb2025 merged 15 commits into
mainfrom
brennanb2025/mobile-new-tab-agent-launch
Sep 30, 2026
Merged

brennanb2025 merged 15 commits into
mainfrom
brennanb2025/mobile-new-tab-agent-launch

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1339 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1326
Prod 39 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2122 $\color{#cf222e}{\Huge{\mathbf{−}}}$​491 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1631

Based on main

#23732 (goldens without the per-golden commit pin) has merged, so this PR now targets main directly and is no longer stacked. Nothing about the phone's behaviour changed in this move.

Against main, the PR changes 50 files: 36 of code, tests and the scenario file, plus 14 goldens. pnpm --dir mobile rpc:diff origin/main reports 10 changed, 4 added, 0 removed (794 goldens). The 4 added are the new launch scenarios (+ as a terminal, + as a chat, notes delivered, notes not delivered). The 10 changed are existing create-terminal goldens whose recorded state now shows one pending selection instead of two refs; their requests are unchanged.

ELI5

Starting an agent from the phone's "+" menu, a quick command, or review notes' "New agent session" now asks the computer to start it, and the computer decides chat or terminal the same way it does everywhere else: from the "open agent tabs in chat" setting. Before, the phone decided on its own — Claude and Codex from "+" always became a chat when the computer could make one, and review notes were typed into the new terminal right after it opened, racing the agent's startup.

The phone also names the new tab before it asks, so it switches to the tab the moment it appears, instead of waiting until the computer has finished typing the prompt into the agent.

What Changed

Builds on #22762's shared launch client, now on main.

Before

  • "+" menu: Claude/Codex asked agentSession.createSupport and then agentSession.create (a chat whenever supported, ignoring the chat-by-default setting); every other agent got session.tabs.createTerminal.
  • Agent quick commands: session.tabs.createTerminal with the agent and its prompt.
  • Diff notes → New agent session: session.tabs.createTerminal with the agent, then an immediate terminal.send of the notes while the agent was still starting. This is the session tab's "Send review notes to AI" → New agent session: it opened a Claude terminal, flashed mobile_input_floor_unavailable and never delivered the notes (same on main; fix(mobile): start AI-button agents through agent.launch, never a bare shell #22762 does not touch it).
  • After creating a chat the phone guessed its tab id as agent-session:<sessionId> to select it.

After

  • All three call agent.launchReplay into the existing workspace (prompt submit for quick commands and notes; launch sources quick_command and diff_notes_send). The host picks chat or terminal and delivers the prompt.
  • User-visible change: with the chat default off — including when the experimental structured chat is on — Claude and Codex from "+" now open a terminal; with it on, a chat, as before.
  • Notes are marked sent only when the host reports them delivered; if the agent started without them the phone says so and keeps them unsent.
  • That in-session "Send review notes to AI" → New agent session path now delivers: in emulator QA (below) it opened a Claude chat whose first message was the note, and the note was marked sent.
  • The phone names the new tab before it asks. Each launch reserves a fresh pane (a tab UUID and a leaf UUID) and, for Claude or Codex, a chat session id, and sends them on agent.launchReplay as its paneKey and sessionId. They are minted once per launch and resent unchanged on every retry of the same operation, because the host's replay fingerprint includes them; a new tap is a new operation with new ids. This is how the desktop's own background launches work: the caller mints the tab, leaf and operation id before calling the host and reuses them on retry.
  • The phone lands on the tab as soon as it is listed, not when the host replies. The pending choice is armed with that reservation before the request goes out. A terminal is recognised by its pane's tab and leaf ids, a chat by its session id (the tab list shows a chat under its session, never under the reserved tab id). For an agent that takes its prompt after it starts, the reply waits up to a minute for delivery, but the tab is listed right after the agent spawns, so you see it (including any folder-trust prompt) at once.
  • The phone's pending tab choice is one value instead of two refs: a tab, a terminal by its handle, or the tab a launch is creating. The guessed agent-session: id is gone.
  • When the launched tab arrives, the phone tells the computer it is now on that tab, exactly as a tap does. The launch itself carries no navigation, so without this the computer kept the phone on the previous tab and leaving the session and coming back reopened it (the old "+" terminal path asked the computer to select the new tab).
  • The reply now only reports what happened: whether the prompt or notes were delivered, and any warning. It also adds the handle or session id the host actually built, which is how a computer that ignores the reservation still lands (see compatibility below), and only then starts the 5-tab-list fallback wait. The phone reads the tab list as soon as the reply arrives, instead of 500 ms later. On computers older than v1.4.206, a chat started from "+" no longer blanks the open terminal while it waits for the chat's tab; the open tab stays live until the chat appears.
  • The "+" button unlocks when the tab lands, not when the reply arrives. The lock is held by that launch's own id, so the first launch's late reply cannot unlock a second launch started after it.
  • Because "+" unlocks before a prompted reply, review notes being sent to a new agent session are held from the tap until that launch's reply: "Send review notes to AI" no longer counts or offers them, so they cannot start a second agent. Notes the computer did not deliver become sendable again once the reply arrives; notes added meanwhile can still be sent. The review screen's Send Unsent Notes → New Agent Session already held its notes until the reply.
  • If you tap another tab while a launch is in flight, that tap replaces the pending choice, so you stay where you tapped, and the late reply leaves it alone. This replaces the earlier check of which tab you launched from.
  • If the computer refuses the reservation as already taken (a live pane or an existing chat with that id, which fresh UUIDs should never hit), the phone says "Couldn't start the agent. Try again." After a retried send it says it couldn't confirm the start instead, since the pane or chat holding the id may be this launch's own.
  • If the reply is lost after the launched tab has already landed, the phone no longer says it couldn't confirm the agent started (you are looking at it). It says "The agent started, but couldn't confirm the prompt was sent." (or "...the notes were sent."), keeps notes unsent, and says nothing for a launch without a prompt. With no tab listed it still says it couldn't confirm the start.
  • Shell-command quick commands and insert-only drafts are unchanged (plain terminals).
  • The "+" menu's host launch moved into new-tab-agent-host-launch.ts; the mobile UUID fallback (no crypto.randomUUID) now yields a v4 UUID, because a pane key's leaf must be one.
  • Hosts older than v1.4.206 (no agent.launch.v2 + agent.launch.replay-required.v1) keep today's paths, marked COMPAT for removal once no supported host predates them. If the host refuses the very first send as unsupported, this launch falls back to today's path; an outcome that may have started is never retried as a second agent.

Why

These were the last session-screen launch points choosing their own surface, so the same tap produced a chat or a terminal depending on which button you used. Routing them through the host's one launch method removes that.

The phone only learned which tab was the launch from the reply, and the reply comes after prompt delivery, so navigation, the "+" lock and the delivery receipt all waited on the slowest step. Naming the tab up front separates "which tab is it" from "was the prompt delivered" without any host change, using the paneKey and sessionId fields the launch method already accepts. Alternatives considered: landing on any new tab that appears (two concurrent launches confuse it), launching bare and then sending the prompt to the terminal (loses the host's prompt delivery and adds a second operation), and having the host reply early and report delivery separately (a host and wire change; listed below as an optional follow-up).

Safety of phone-minted ids: every host, desktop and phone holder of a pane key, chat tab id or session id was checked. A fresh UUID matches no existing entry, and a key that is already live or a session that already exists is refused rather than adopted, so a new launch never duplicates or renames an existing session. With the workspace open on the desktop, the desktop adopts the reserved tab and leaf ids unless the tab id already exists, which a fresh UUID never does.

Optional follow-up: the host could reply as soon as the surface exists and report prompt delivery separately; the phone would then free the "+" lock and show the delivery result independently of each other. Not needed for this fix.

Recorded deviations:

  • A terminal opened from "+" now lands at the end of the tab row instead of after the active tab: the launch method carries no placement. Chats already landed where the host put them.
  • "+" sends no launch source (there is no phone value in the telemetry schema yet).

Linked Issue

Part of STA-8255 (every agent launch entry point should honour the chat default). Related: #18098.

Visual Proof

Android emulator driven only through orca emulator, paired with an isolated dev host built from main (89cf55dfc8, its own profile and home). BEFORE = phone JS from the base branch (982958b4e0); AFTER = this branch (df62184dcd; the final commit d2b68830cd only adds the review-notes hold, checked separately below). These runs used the branch before its rebases onto #22762's later heads; later rebases changed only the base branch's own files, and the final run is below. Prompts were harmless; the "Goose" agent was a local stand-in that waits 20 s before it reads input, to make a slow-starting agent visible.

BEFORE: "+" → Claude with the chat default off still opens a chat BEFORE: review notes → New agent session: raw error toast, notes not sent
Chat opened despite chat default off mobile_input_floor_unavailable toast
AFTER: chat default off → "+" → Claude lands on a new terminal AFTER: chat default on → "+" → Claude lands on a new chat AFTER: a workspace also open on the desktop, chat default on → lands on the chat
Claude terminal selected Claude chat selected Chat selected with the desktop open on the workspace
AFTER: notes → slow agent: lands on it within 0.5 s, "+" usable again, before the host replies AFTER: the user taps another tab while that launch is still replying: they stay there AFTER: notes → Claude: the note is the first message (marked sent) AFTER: untrusted folder: Claude's trust prompt is on screen at once
Landed on the slow agent before the reply User stays on the tab they picked Note delivered as first message Trust prompt visible
  • Host records confirmed each launch: the terminal tab the host created carries the pane key the phone chose (also with the workspace open in the desktop window), and the chat carries the session id the phone chose. Leaving the session and reopening it kept the phone on the launched tab. Plain "+" → Terminal and a shell quick command still open plain terminals; an agent quick command's "say hello" is the chat's first message.
  • The stand-in agent never looked ready to the host, so its notes came back not delivered after the host's 60 s wait; the phone said "The agent started, but the notes weren't sent." and kept the notes. Real agents that take the prompt on the command line (Claude, Codex, Gemini, OpenCode) don't wait at all.

At the final head (d2b68830cd), review notes sent to the slow stand-in agent are held until that launch replies, so they can't start a second agent:

While the first agent is still receiving the notes: Send is greyed, a tap does nothing, the host saw exactly one launch After the host replies "not delivered": the notes are still there and Send works again
Send greyed while notes are in flight Send enabled after the reply

Sending those same notes to Claude then worked: "Notes sent", the note was Claude's first message, and the notes were cleared.

Final run (before the rebase onto main) on 78b37d01d1: "+" → Claude with the chat default off and on, notes → the slow stand-in (lands in 0.33 s, Send greyed, one launch), the same notes → Claude (first message, marked sent), an untrusted folder, a workspace open in the desktop window (the host's tab id is the tab half of the pane key the phone sent), and "+" → Terminal all passed. The review screen's Send Unsent Notes → New Agent Session, on #22951's one-sheet-at-a-time drawer, shows one sheet at a time and ends with "Review notes sent", 0 unsent:

Review screen: only the Send Notes sheet is open "Review notes sent", 0 unsent notes
One send sheet Review notes sent
  • Re-run on the head rebased onto main (phone JS 74191a3d22, the same tree as the head): "+" → Claude with the chat default off and on, notes → the slow stand-in (Send greyed, one launch, notes kept), notes → Claude (first message, marked sent), the review screen's one-sheet send, a workspace open in the desktop window, and "+" → Terminal all passed. The untrusted-folder case first showed Claude's terminal in the phone's chat view with the trust prompt hidden; that was the shared test phone's own "Open sessions in Chat UI" setting being on. With it off, the same build showed the trust prompt at once, and the per-tab "Switch to chat view" stays available from a long-press.
  • With 31 to 39 tabs open in one workspace, a newly opened terminal sometimes stays blank and then shows "Terminal failed to load — no ready signal from the terminal view" until Reload. An A/B at the same tab count reproduced it on the base branch too (2 of 3 plain terminals on each side, with the same error); at 3 to 4 tabs it renders normally. It is not caused by this PR, which only makes it reachable from "+" → Claude with the chat default off, because that now opens a terminal.
Earlier shots (iPhone simulator, before the phone chose the launch's ids)

iPhone simulator driven only through orca emulator, paired with an isolated dev host built from #22913 (its own profile; every host read and write went through a client pinned to that profile). Phone build: this branch plus #22951. Prompts were harmless ("say hello"); folder-trust prompts were never answered.

"+" → Claude, chat default on: lands on the new chat "+" → Claude, chat default off, beside an open shell: lands on the new terminal tab Agent quick command: "say hello" is the chat's first message
New Claude chat selected New Claude terminal tab selected Quick command prompt delivered
Session tab "Send review notes to AI" → New agent session: the notes are the first message …and the notes are marked sent Review screen Send Unsent Notes → New Agent Session: "Review notes sent", 0 unsent
Notes delivered as first message No review notes left Review notes sent toast
Claude disabled on the host while the menu is open, empty session: the host's refusal is shown, nothing is created
Disabled agent refusal
  • The same refusal in a session with open tabs showed nothing: a failed create was shown only on the empty-session screen. The failure is now also shown as a toast (commit fb4bb40352; its test fails without the fix). The caller's own copy is kept when it gave one, such as "Couldn't run ". Re-checked on Android against a host from fix(agent-launch): refuse a disabled agent on the chat route too #23043, with Claude turned off while the "+" menu was open:

    Chat default on, beside an open shell Chat default off, beside an open shell
    Refusal toast, chat default on Refusal toast, chat default off
  • With the chat default on, tapping a disabled Claude used to start a chat, because the host's chat route didn't check whether the agent is enabled (on main too). fix(agent-launch): refuse a disabled agent on the chat route too #23043 fixes that on the host; the shots above are against it.

  • Host tab lists confirmed the surfaces: chat default on → an agent-session tab; off → a terminal tab.

Testing

  • use-mobile-session-terminal-create-agent-launch.test.ts: "+" launches through agent.launchReplay with no prompt or source and waits for the terminal by its reserved pane or the reply's handle, and the chat by session id (no tab id set); older host and first-send refusal fall back to today's path; an unknown outcome starts nothing else; quick commands send their prompt with quick_command; notes use diff_notes_send, are marked sent only when delivered, and stay unsent with a notice when not; shell-command quick commands stay plain terminals.
  • use-mobile-session-terminal-create-agent-launch.test.ts: a host refusal from the "+" menu shows the host's reason as a toast when the session already has tabs (fails without the fix).
  • pending-session-selection.test.ts: chat by session id whatever its tab id; terminal by handle; waits across tab lists that lack it, then gives up; the tab-id and handle halves drop independently.
  • use-mobile-session-tab-application-launch.test.ts: when a launched terminal or chat lands in a tab list, the phone sends one session.tabs.activate for it (caller navigation, like a tap) and switches to it; a host "follow" navigation still wins and sends nothing. Route parity re-pinned for that activation (callback body, +1 identity payload, +4 strings); The 4 launch goldens were re-recorded for the immediate tab-list read (each loses its 500 ms timer effect; requests and state unchanged); the older-host Codex chat test now asserts the open terminal stays live and the tab list is read at once.
  • use-mobile-session-terminal-create-agent-launch.test.ts: a tab picked while a prompted launch is still waiting for its reply keeps the phone there (fails without the fix).
  • mobile-session-diff-notes-new-agent-send.test.ts (the real notes, create and sheet hooks together): after the tab lands and "+" unlocks, sending the same notes again while the first reply is outstanding offers nothing, a stale tap on the old sheet starts nothing, and exactly one agent.launchReplay goes out; delivered notes leave the list; notes reported not delivered can be sent again. Route parity re-pinned for it (+3 hooks, +1 callback, callback bodies, the diff view's leaf JSX); no golden moved.
  • Existing create-actions and last-tab-close tests updated for the single pending value; the old Codex test now asserts no guessed tab id.
  • Route parity re-pinned; restoring only the edited route files turned it green first, so they are the sole cause.
  • RPC goldens: 4 added (+ as a terminal, + as a chat, notes delivered, notes not delivered); 10 existing create-terminal bodies moved only because the recorded state now shows one pending value instead of two refs (their requests are unchanged); the rest header-only. Re-recorded after the refusal-toast fix: header-only (baseline pin), no body changed.
  • Rebased onto fix(mobile): start AI-button agents through agent.launch, never a bare shell #22762's merge with main (its code commits replayed; goldens re-recorded once on the rebased tree): the same 4 added and the same 10 create-terminal bodies moved (one pending value instead of two refs), everything else header-only; re-validated in normal mode. Session route parity re-pinned with the same count moves as before (−1 hook, +14 strings); bridged-parity tallies unchanged.
  • Reservation (this revision): the first send and a replay carry identical paneKey/sessionId, and every tap reserves new ids (use-mobile-session-terminal-create-agent-launch.test.ts); against the real host launch handler, a lost reply is replayed with the same ids, the host answers from its ledger and creates the terminal once, with the reserved tab and leaf ids (agent-launch-mobile-replay.test.ts); a Claude chat reservation passes the real host dispatcher's params check, an older host's schema drops both fields rather than refusing (agent-launch-params.test.ts), and the phone then lands by the reply's handle; both taken-reservation refusals show readable copy, and after a replay read as unconfirmed; the tab lands and the "+" lock frees before a paste-after-start agent replies; a second launch's lock survives the first one's reply; an empty session whose only tab the host selected before replying still lands and records the pick; no countdown before the reply, 5 tab lists after it; the no-randomUUID fallback mints a pane the host adopts. A reply lost after the tab landed reports only the prompt or notes as unconfirmed, keeps notes unsent, and is silent for a bare launch.
  • Route parity re-pinned for this revision: callback body (the landing frees the lock), nested functions (handleCreateTerminal), strings 548 → 540 (nine moved with the host launch into its own module, one 'launched' added for the landing). A later fix re-pinned nested functions once more, for handleCreateTerminal passing the tab list to the launch; no golden moved.
  • RPC goldens re-recorded from a repinned baseline: the 4 launch goldens now show the reservation in the request and the pending choice armed before the send; the other create-terminal goldens move only their adapter hash; the rest header-only.
  • Rebased onto main after fix(mobile): start AI-button agents through agent.launch, never a bare shell #22762 merged (its commits dropped; base retargeted to main). One conflict by hand: main's fix(mobile): size a terminal's first subscribe from the document's reported cell box #23080 added subscribeIntendedActiveTerminal, which now reads the one pending selection (pendingSelectionHandle(...) ?? activeHandle, the same meaning as the old ref), and main's rewrite of the webview test file replaced this branch's one-line edit there. This branch's net change outside goldens and route parity is byte-identical to before. Route parity re-pinned on main (this branch's moves: hooks 281 -> 283, callbacks 80 -> 81, strings 529 -> 538). Goldens re-recorded from a repinned baseline: against main, 4 added, the same 10 create-terminal bodies moved, 780 header-only; each of the 14 changed goldens matches its pre-rebase recording except for the baseline. Mobile tsc and the tests-typecheck ratchet, this PR's 12 mobile test files plus the recording, pin-guard, params-boundary, subscription and review-send suites, the root agent-launch-params test and check:code-quality:changed all pass.
  • Mobile tsc, tests-typecheck ratchet, targeted mobile suites (session pending/create/tab-application/route-parity/last-tab-close/webview/startup, launch replay and architecture, all of rpc-recording and bridged-parity), oxlint, check:code-quality:changed 0 findings. Earlier revisions: full mobile suite 881 files / 9,593 tests.
  • Rebased onto test(mobile): record RPC goldens without a pinned commit, and check recorded requests against the desktop's params rules #23732 (at e01b85424ab, which includes main at a57863ba167). The code and test commits replayed unchanged, and every product file is byte-identical to before the rebase. The scenario edits were re-applied without the old baseline and version fields, the baseline-only commits were dropped, and the goldens were re-recorded once with rpc:record --prune (10 changed, 4 added, 0 removed, as above). main deleted the session route-parity test and mobile-session-last-tab-close.test.ts in test: remove junk tests that assert source text instead of behavior #23815 (tests that read source text), so this branch's edits to those two files are gone with them. Mobile tsc and the tests-typecheck ratchet pass. This PR's mobile tests plus all of rpc-recording (including the new recorded-request params check), bridged-parity/divergence-classes and the params type-only boundary pass (34 files, 1,886 tests). The root agent-launch-params test, oxlint and check:code-quality:changed against the new base (0 findings, 35 files) also pass.
  • Rebased onto main after test(mobile): record RPC goldens without a pinned commit, and check recorded requests against the desktop's params rules #23732 merged (squash e594cb06af3; now on main at 75040eba5a0). Only this PR's 15 commits were replayed, with no conflicts; every commit's content is unchanged. rpc:record --prune on the rebased tree rewrote no golden, and rpc:diff origin/main lists only the 14 moves above. Mobile tsc and the tests-typecheck ratchet pass. This PR's mobile tests plus the recording, recorded-request params, derived-golden and launch-architecture suites pass (15 files, 1,720 tests), as do the root agent-launch-params test, oxlint and check:code-quality:changed against main (0 findings, 35 files).
  • Ablations (each reverted alone):
Removed behaviour Test that went red
Chat looked up by tab id instead of session id finds a launched chat by its session id
No bounded wait for the tab keeps waiting across snapshots that lack the tab, then gives up
Unknown outcome falls back to today's path never starts a second agent when the outcome is unknown
Notes marked sent regardless of delivery keeps review notes unsent when the agent started without them (onPromptSent called)
Landed launch not recorded on the computer records a launched terminal / chat as this device's pick (2 red)
Tab list read 500 ms after the reply asks the host to start the agent and waits for its terminal by handle
Older-host chat path blanks the open terminal early uses the structured agent-session path for a bare Codex launch
Late launch reply takes focus regardless of a tab picked meanwhile leaves the user on a tab they picked while the prompt was being delivered
Fresh ids minted on each send resends the same ids on a replay; reaches the host with the pane it reserved, once
Reply's own handle ignored lands by the reply's ids when an older host ignored the reservation
Taken-reservation refusal shown raw / as a clean failure after a replay says plainly that nothing started (2 red); never calls a taken reservation a clean failure after a replay
Pending choice armed after the reply lands on the tab and frees the + lock before a paste-after-start agent replies
Lock not freed on landing / any create frees the lock frees the + lock when the tab lands; keeps a second launch's + lock
Terminal not matched by its reserved pane lands in an empty session whose only tab the host selected before replying
Countdown runs before the reply waits without a countdown until the reply
Old 32-hex UUID fallback mints a pane the host adopts even where the runtime has no crypto.randomUUID
Notes still being sent offered again / stale sheet tap not ignored / sheet not routed through the hold starts one agent while the first send of the same notes is still waiting on its reply (each alone red)

Notes

  • Wire compatibility: no new fields. paneKey and sessionId are existing optional fields of agent.launchReplay; a host that predates them drops them (the params schema is not strict) and the phone lands by the reply's handle or session id; a host that knows paneKey but not sessionId lands a chat by the reply's session id. Hosts older than v1.4.206 keep today's paths.
  • SSH and folder workspaces: the host resolves the workspace and its execution host, and the reserved pane takes the same path for local, SSH (forwarded to the relay) and folder workspaces; nothing phone-side is local-only.
  • Cross-platform: phone-only change.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready for review at d2b68830cd. CI green (one unrelated bun-pty-process flake passed on rerun).

What the review loops changed (8 loops plus a separate architecture review):

  • The phone now names the launch's pane and chat session before it asks (paneKey/sessionId on agent.launchReplay, minted once per operation and resent unchanged on every replay), lands on the new tab as soon as it is listed, and frees "+" at that point. Before, it learned the tab only from the reply, which for agents that take their prompt after starting arrives only after the prompt is delivered (up to 60 s), so the phone sat on the old tab with "+" greyed out and a trust prompt unseen.
  • The host now records the launched tab as this phone's pick (session.tabs.activate), so leaving and reopening the session keeps you on it.
  • A tab the user picks while a launch is still replying wins over the late reply.
  • If a launch's reply is lost after its tab is already on screen, the phone says the prompt or notes may not have been sent, rather than that the agent may not have started.
  • Review notes are held from the tap until their launch settles, so the same notes can't start a second agent in the gap between landing and the reply.
  • Older hosts that don't know one or both fields drop them and the phone lands from the reply; hosts before agent.launch.v2 keep today's paths.

Phone QA (Android emulator, driven only through orca emulator, isolated dev host from main): before/after for "+" with the chat default off and on, a workspace also open on the desktop, a slow-starting agent, tapping away mid-launch, notes to Claude, an untrusted folder's trust prompt, plain terminals and quick commands, and the notes hold at the final head. All passed; screenshots are in the PR body.

Not caused by this PR (for follow-up):

  • After a launch the phone can't confirm, tapping again mints a new operation id and can start a second agent (the launch client from fix(mobile): start AI-button agents through agent.launch, never a bare shell #22762; most likely on the notes path, since the notes stay unsent).
  • Agent quick commands can't target agents that take their prompt after starting; the host rejects them with a generic "Invalid input".
  • Optional host follow-up: reply as soon as the agent's surface exists and report prompt delivery separately.

Minor UX, left as is: while a slow agent is still receiving review notes, the diff view's Send is greyed with no hint why.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/mobile-new-tab-agent-launch branch 3 times, most recently from 78b37d0 to 37d07b4 Compare September 28, 2026 06:25
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Status update: ready for review at 37d07b4eb9, rebased onto #22762's head d5a82cc58e. CI is green; one unrelated HTML-preview test flaked and passed on rerun.

  • Rebase: no code conflicts. This branch's net change outside the goldens and route parity is byte-identical to before. Its diff-notes path never used the review screen's send sheet, so fix(mobile): show one review sheet at a time so the review screen never freezes #22951's closeSheet('send') drawer needed no change here.
  • Pins and recordings: route parity was re-pinned on the combined tree. The goldens were re-recorded from a repinned baseline, and the only changes are the same 4 added and the same 10 moved bodies, each matching its pre-rebase recording apart from the baseline line.
  • Gate: mobile tsc and the tests-typecheck ratchet pass. So do this PR's tests plus the recording, pin-guard and review-send suites (19 files) and check:code-quality:changed.
  • Final phone QA: run on Android on shipped code identical to the head. Every scenario passed, including the review screen's one-sheet send flow. Screenshots are in the PR body.
  • Not caused by this PR: with 31–39 tabs open in one workspace, a new terminal can show "Terminal failed to load" until Reload. An A/B at the same tab count reproduced it on the base branch in 2 of 3 attempts, the same as with this PR.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/mobile-new-tab-agent-launch branch from 37d07b4 to 74191a3 Compare September 28, 2026 22:52
@brennanb2025
brennanb2025 changed the base branch from brennanb2025/mobile-launch-points-agent-launch to main September 28, 2026 22:52
@brennanb2025
brennanb2025 force-pushed the brennanb2025/mobile-new-tab-agent-launch branch from 74191a3 to 7081583 Compare September 28, 2026 22:57
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Status update: rebased onto main after #22762 merged. Head 70815835da, base retargeted to main.

  • Rebase: one hand-resolved conflict. main's new subscribeIntendedActiveTerminal now reads the single pending selection, and main had removed the webview test file. Outside the goldens and route parity, this branch's net change is byte-identical to before.
  • Pins and recordings: route parity was re-pinned on main, and the goldens were re-recorded from a repinned baseline: 4 added and the same 10 moved bodies, each matching its pre-rebase recording apart from the baseline.
  • Gate: passes with every typecheck run through tc-gate.
  • CI: everything passes except "Verify localization catalogs". That check also fails on a clean origin/main (2af897d7ea) with the same missing key, auto.components.sidebar.worktree.card.compact.agents.a128d7006b in en-runtime-required.json, so it is main's red, not this PR's. It clears once main regenerates that catalog.
  • Phone QA on this head: every scenario passed. One run first looked like a failure on the untrusted folder, but the cause was the test phone's own "Open sessions in Chat UI" setting; with it off, the trust prompt shows at once. Details are in the PR body.
  • Minor, not caused by this PR: the review screen's Send Notes sheet keys rows by label, so untitled terminals with the same name raise a React duplicate-key warning in dev builds.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/mobile-new-tab-agent-launch branch from 7081583 to 6a84346 Compare September 29, 2026 23:18
@brennanb2025
brennanb2025 changed the base branch from main to brennanb2025/mobile-rpc-goldens-overhaul September 29, 2026 23:18
@brennanb2025
brennanb2025 marked this pull request as ready for review September 30, 2026 00:03
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Refactors terminal creation and agent launch flow in mobile session.

The PR does not appear safe to merge until bypassed queued-send retries retain their identity across an app restart.

Findings

  1. P2 Prompt receipt hides host warning ▶

Summary

The PR routes mobile agent starts through host-owned launch and tab selection. Changes since the previous review also add mobile structured-message queuing, consolidate host chat journals, and adjust subscription cleanup and Codex startup.

  • A bypassed queued-send retry can lose its replay identity across an app restart, allowing duplicate delivery.

Reviews (2) · Last reviewed commit: "test(mobile): record the + menu and diff..."

Comment on lines +109 to +117
if (launched.promptDelivered === false) {
triggerError()
showToast(options?.initialPrompt ? NOTES_NOT_SENT_MESSAGE : AGENT_PROMPT_NOT_SENT_MESSAGE, 2400)
} else if (launched.promptDelivered && options?.initialPrompt) {
triggerSuccess()
showToast(options.successToast ?? 'Notes sent')
options.onPromptSent?.()
} else if (warning?.trim()) {
showToast(warning.trim(), 2400)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Prompt receipt hides host warning For a prompted launch, the delivery notice takes precedence over warning. If the terminal is running but the host could not make its tab discoverable, the phone hides the host’s explanation and instructions for revealing it. Show the warning independently of the prompt-delivery notice.

Knowledge Base Used: Agent integrations and hooks

@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 — two narrow, non-blocking observations on where the new notes hold does and doesn't reach.

Reviewed changes

  • One launch path for agents — the "+" menu, agent quick commands, and diff-notes "New agent session" now call agent.launchReplay (new-tab-agent-host-launch.ts), letting the host pick chat vs terminal from the chat-default setting; the phone no longer predicts an agent-session:<id> tab id.
  • Pre-named tabs — each launch mints a paneKey/sessionId reservation and arms a PendingSessionSelection before the request, so the phone lands on the tab when it is listed (and frees the "+" lock) rather than when the host replies after prompt delivery.
  • Delivery receipts — notes are marked sent only when the host reports delivery; a lost reply after the tab landed downgrades to "started but couldn't confirm the prompt/notes" instead of "may not have started".
  • Single pending selection — pendingActiveSessionTabIdRef + pendingActiveTerminalHandleRef collapse into one PendingSessionSelection; creatingTerminalRef becomes an id-string lock (terminal-create-lock.ts) released only by its own launch.
  • Notes hold — sendingDiffCommentIds holds notes from the tap until the launch reply so the same notes can't start a second agent on the session screen.
  • Wire compat — paneKey/sessionId are existing optional fields; hosts older than v1.4.206 fall back to today's paths, and agent-launch-params.test.ts pins that an older schema drops them rather than refusing.

ℹ️ The notes hold is per-screen, so the review screen can still start a second agent

The hold added in use-mobile-session-diff-comments.ts lives in a hook-local useRef, while the review screen's "Send Unsent Notes → New Agent Session" launches through createTerminalAndSend (use-mobile-diff-review-send-actions.ts:123), whose only guard is its own agentLaunchInFlightRef. If the user opens the review screen while a session-screen launch is still delivering the same notes, the notes are still unsent on the host record, so the review screen offers them again and a second agent can start — the outcome this PR set out to prevent. This is narrow (it requires navigating mid-launch, within the 60s/90s prompt wait) and the PR text only claims the guarantee for the session screen and for the review screen's own launch, so it may be intended scope; worth confirming whether the two holds should be shared.

Technical details
# Cross-screen notes hold gap

## Affected sites
- `mobile/src/session/use-mobile-session-diff-comments.ts:35` — `sendingDiffCommentIdsRef` is a hook-local ref; unmounted when the session screen routes away.
- `mobile/src/session/use-mobile-diff-review-send-actions.ts:123` — `createTerminalAndSend` consults only `agentLaunchInFlightRef`, never the session hold.
- `mobile/src/components/MobileDiffReviewDrawers.tsx:121` — the review screen's "New Agent Session" action.

## Required outcome
- The same host-persisted notes cannot be sent to two agents from two entry points while either is in flight. Either share the sending-id set across the session and review surfaces (e.g. a store/module-level registry keyed by comment id), or have the review screen read the same hold.

## Open questions for the human
- Is cross-screen sharing in scope, or is the cross-surface composition deliberately out of scope for this PR?

ℹ️ On hosts without agent.launch.v2, the hold lifts before terminal.send settles

When the host is older than v1.4.206, launchNewTabAgentThroughHost returns false and the notes path falls back to legacy sessionTabCreateTerminal, whose terminal.send for initialPrompt is fire-and-forget (use-mobile-session-terminal-create-actions.ts:207). handleCreateTerminal therefore resolves before onPromptSent fires, so sendDiffNotesToNewAgent's finally clears the hold during the terminal.send round-trip, and a second Send tap in that window re-offers the still-unsent notes. This is a one-RTT window on older hosts only, and the modern path (awaiting the host reply) is correct, but it is the same stated guarantee.

Technical details
# Legacy-host hold release

## Affected sites
- `mobile/src/session/use-mobile-session-terminal-create-actions.ts:206-239` — `terminal.send` for `options.initialPrompt` is `void`ed, not awaited; `onPromptSent` runs in its `.then`, after `handleCreateTerminal` returns.
- `mobile/src/session/use-mobile-session-diff-comments.ts:180-188` — `finally` clears the sending ids when `launch()` resolves.

## Required outcome
- On the legacy path the hold should outlive the `terminal.send` round-trip (await it, or clear the hold from `onPromptSent`/the send's settle rather than from the create's return).

## Open questions for the human
- Whether this legacy-only window is worth covering before the COMPAT branch is removed.

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

… agent.launch

The session screen's + menu, agent quick commands and diff notes' New agent
session now ask the host to start the agent with agent.launchReplay, so the
host picks chat or terminal from the desktop's default and delivers any
prompt. Hosts without the launch capabilities keep today's paths.

The phone's pending tab choice is one value (a tab, a terminal by handle, or a
launched surface) instead of two refs, and a launched chat is found by its
session id in the next snapshot rather than a predicted tab id. A launched
surface waits a bounded number of snapshots for its tab.
…s; drop test casts

The corpus grows from 790 to 794 goldens; all four new ones replay identically.
The inline create error renders only in an empty session, so a host refusal
(for example a disabled agent) from the + menu in a session with tabs showed
nothing. Always toast the failure: the caller's own copy when it gave one,
otherwise the host's reason.
…he host

A launch carries no navigation, so the phone selected the new tab only
locally while the host kept this device on the tab it had before. Leaving
the session and coming back, or a reconnect that reset the screen, reopened
that old tab. The "+" terminal path this replaced asked the host to select
the tab for the caller.

When a launched surface's tab lands in a snapshot, activate it for the
caller exactly as a tap does. The resolver now names the landed tab in
place of the unused `missed` flag. Route parity re-pinned for the new
activation body, identity payload and strings.
…a blank pane

The host publishes a launched tab before it replies, so the tab list the
phone already holds usually has it by the time the reply arrives. The
launch paths still waited for a refetch 500 ms later, leaving the phone on
the old tab for that long after every launch. Read the tab list at once.

On hosts without agent.launch, the chat path also unsubscribed the open
terminal and cleared its handle before the chat's tab landed, while the old
terminal tab stayed selected: a blank pane until the next tab list. Leave the
open tab live until the chat lands, as the launch path does; applying that
tab list tears the old terminal down.

Route parity re-pinned for the two bodies.
…till replying

A quick command or review-notes launch now waits for the host to deliver the prompt, which can take up to a minute. The launched tab shows up in the tab row well before that, so a user who tapped another tab meanwhile was pulled back onto the launched one when the reply arrived, and that pick was recorded on the host.

The launch now remembers which tab the phone was on when it started and only takes focus if the phone is still there when the reply lands. Any move made in between, by a tap or by the computer navigating this phone, wins. Session route parity re-pinned for the handleCreateTerminal body only.
…t when it is listed

A "+" menu, quick-command or review-notes launch now reserves its tab before it asks the host: a fresh pane key (tab and leaf UUIDs) and, for an agent the host may start as a chat, a session id. Both are minted once per launch and sent unchanged on every replay, since the host's replay fingerprint covers them.

The phone arms its pending selection with that reservation before sending, so it lands on the terminal (matched by pane halves) or chat (matched by session id) as soon as the tab is listed. For an agent whose prompt is pasted after start, that is long before the reply, which waits for delivery. Landing also frees the "+" lock; the lock holds the create's id, so an older launch's reply cannot free a newer one's. The reply now only adds its own handle or session id (an older host ignores the reservation), starts the fallback countdown, and reports prompt delivery.

A tab the user picks mid-launch replaces the pending selection, so the launch-start tab check is gone. A reservation the host refuses as already taken reads "Couldn't start the agent. Try again." on the first send, and as unconfirmed after a replay. The mobile UUID fallback now yields a v4 UUID, because a pane key's leaf must be one. The host launch path moved to new-tab-agent-host-launch.ts; session route parity re-pinned for that move and the landing's lock release.
The four launch scenarios now expect the pane key and session id the phone sends (the scripted ids come first, so the operation id moves from ...001 to ...004).
…s looking at it

When a launch's reply was lost after its tab had already landed, the phone said "Couldn't confirm the agent started", although the listed tab proves it did. Now a listed tab narrows the doubt to the prompt or notes ("The agent started, but couldn't confirm the notes were sent."), the notes stay unsent, and a bare launch says nothing. Only the nested-function parity pin moves, for handleCreateTerminal passing the tab list to the launch.
…arams schema

The anti-slop audit rejects Reflect.get; parsing with AgentLaunchReplay also
asserts the host accepts the params the phone sent.
…mporting its schema

Mobile code may import the params contract only as types. The phone's tests
now read the sent reservation by narrowing, a chat reservation is checked
through the real host dispatcher, and the older-host drop is pinned host-side.
The "+" lock is now freed when the launched tab lands, but review notes are
only cleared when the launch's reply confirms delivery, which for a prompted
launch can take up to a minute. In that window "Send review notes to AI" still
offered the same notes, and choosing a new agent session started a second
agent with them.

The notes a new agent session is being started with are now held from the tap
until that launch settles: the Send button no longer counts them, the sheet no
longer offers them, and a stale tap on the old sheet starts nothing. Notes the
host did not deliver become sendable again once the reply arrives.
4 added (+ as a terminal, + as a chat, notes delivered, notes not delivered). 10 existing create-terminal goldens move only because the recorded state now shows one pending selection instead of two refs; their requests are unchanged.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/mobile-new-tab-agent-launch branch from 6a84346 to 6cbfb78 Compare September 30, 2026 06:42
@brennanb2025
brennanb2025 changed the base branch from brennanb2025/mobile-rpc-goldens-overhaul to main September 30, 2026 06:42
@coderabbitai

coderabbitai Bot commented Sep 30, 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: dc43b463-8aa5-480d-b9f9-312e0c84f23a

📥 Commits

Reviewing files that changed from the base of the PR and between 75040eb and 6cbfb78.

📒 Files selected for processing (50)
  • mobile/rpc-foundation/goldens/matrix-session.create-terminal-session.tabs.createterminal-1.json
  • mobile/rpc-foundation/goldens/matrix-session.create-terminal-terminal.send-1.json
  • mobile/rpc-foundation/goldens/session-create-terminal-agent-launched-as-chat.json
  • mobile/rpc-foundation/goldens/session-create-terminal-agent-launched.json
  • mobile/rpc-foundation/goldens/session-create-terminal-diff-notes-launched.json
  • mobile/rpc-foundation/goldens/session-create-terminal-diff-notes-not-delivered.json
  • mobile/rpc-foundation/goldens/session-create-terminal-ignores-a-second-create-in-flight.json
  • mobile/rpc-foundation/goldens/session-create-terminal-launches-an-agent-quick-command.json
  • mobile/rpc-foundation/goldens/session-create-terminal-refused.json
  • mobile/rpc-foundation/goldens/session-create-terminal-replaces-active.json
  • mobile/rpc-foundation/goldens/session-create-terminal-runs-a-quick-command.json
  • mobile/rpc-foundation/goldens/session-create-terminal-with-prompt.json
  • mobile/rpc-foundation/goldens/session-create-terminal-without-active-tab.json
  • mobile/rpc-foundation/goldens/session-create-terminal-without-handle.json
  • mobile/rpc-foundation/pilot-scenarios.json
  • mobile/src/session/MobileSessionActiveContent.tsx
  • mobile/src/session/MobileSessionFileReader.tsx
  • mobile/src/session/mobile-diff-comments.ts
  • mobile/src/session/mobile-existing-agent-launch.test.ts
  • mobile/src/session/mobile-existing-agent-launch.ts
  • mobile/src/session/mobile-session-diff-notes-new-agent-send.test.ts
  • mobile/src/session/mobile-session-route-types.ts
  • mobile/src/session/new-tab-agent-host-launch.ts
  • mobile/src/session/pending-session-selection.test.ts
  • mobile/src/session/pending-session-selection.ts
  • mobile/src/session/structured-session-operation-id.ts
  • mobile/src/session/terminal-create-lock.ts
  • mobile/src/session/use-mobile-session-close-actions.ts
  • mobile/src/session/use-mobile-session-diff-comments.ts
  • mobile/src/session/use-mobile-session-panel-route-actions.tsx
  • mobile/src/session/use-mobile-session-screen-state.ts
  • mobile/src/session/use-mobile-session-startup.ts
  • mobile/src/session/use-mobile-session-tab-application-launch.test.ts
  • mobile/src/session/use-mobile-session-tab-application.ts
  • mobile/src/session/use-mobile-session-tab-switching.ts
  • mobile/src/session/use-mobile-session-terminal-create-actions.test.ts
  • mobile/src/session/use-mobile-session-terminal-create-actions.ts
  • mobile/src/session/use-mobile-session-terminal-create-agent-launch.test.ts
  • mobile/src/session/use-mobile-session-terminal-runtime.ts
  • mobile/src/session/use-mobile-session-terminal-subscription.test.tsx
  • mobile/src/session/use-mobile-session-terminal-webview.ts
  • mobile/src/tasks/agent-launch-mobile-replay.test.ts
  • mobile/src/tasks/agent-launch-request.ts
  • mobile/src/test-support/bridged-parity/divergence-classes.test.ts
  • mobile/src/test-support/bridged-parity/divergence-classes.ts
  • mobile/src/test-support/rpc-recording/adapters/session-screen-tab-mount-adapters.ts
  • mobile/src/test-support/rpc-recording/adapters/session-startup-mount-adapters.ts
  • mobile/src/test-support/rpc-recording/adapters/session-terminal-create-mount-adapters.ts
  • mobile/src/test-support/rpc-recording/rpc-recording-through-bridge.test.ts
  • src/shared/rpc-contract/agent-launch-params.test.ts

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


📝 Walkthrough

Walkthrough

The mobile session flow now uses a unified pending-selection model for tabs, terminals, and launched agent surfaces. Eligible launches can send reserved pane and session identifiers through the workspace host. Diff-note delivery tracks comments while a launch is in progress. Tests, RPC recordings, and pilot scenarios cover launch results, selection updates, and note-delivery outcomes.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 6cbfb

The mobile launch changes have no identified merge-blocking issue. Failed launches already clean up correctly; merge after normal checks pass.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 6cbfb

Agent launches now follow the computer’s launch policy, with duplicate-launch prevention and explicit handling of uncertain delivery. No security regression was established in the inspected paths, but workspace authorization and deployed-version behavior were not fully verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The sensitive outcomes are agent execution and prompt or review-note delivery in a selected host workspace. The base already permitted agent creation and terminal input from these mobile actions. The inspected change does not establish broader execution privilege, but the maximum per-device workspace scope and downstream agent tool or credential exposure remain incompletely traced.

Trust Boundaries and Controls

  • observed — The inspected mobile transport validates the device token against the local registry, binds relay authentication to the same device identity, and forwards plaintext only from an authenticated socket. Replay admission separately requires a paired-device identity for non-local callers. The complete handoff into dispatch and any workspace-specific authorization policy were not established.

Resilience and Maintainability Implications

  • observed — Host-routed note sends exclude comment IDs already in flight and clear notes only after confirmed prompt delivery. Refusal or uncertainty retains the notes and reports their status. Replay prevents duplicate execution within one operation; a later deliberate user retry is a new operation and is not an at-most-once guarantee across separate actions.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.49% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 78 functions across 35 files. (15 skipped… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly summarizes the main change: routing mobile start-menu, quick-command, and diff-note agent launches through agent.launch.
Description check ✅ Passed The description is detailed and covers the user impact, implementation, rationale, linked issue, visual proof, testing, compatibility, and known limitations. It omits explicit AI Disclosure, Review, A…
Full details: Docstring Coverage

Explanation

Docstring coverage is 29.49% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 78 functions across 35 files. (15 skipped: 15 unsupported.)

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

@brennanb2025
brennanb2025 merged commit ca7c14d into main Sep 30, 2026
35 checks passed
brennanb2025 added a commit that referenced this pull request Sep 30, 2026
…ream-transport-release

Corpus is 793 goldens: main's 794 (four #22954 launch goldens) minus this
branch's deleted notification-unsubscribe matrix. Bridged tally 401 identical,
342 / 3 / 6 / 33 / 8, confirmed by replay; re-record with --prune moved nothing.
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