Skip to content

Fix Orca Mobile agent tabs opening as a plain shell instead of launching the agent - #7837

Merged
brennanb2025 merged 2 commits into
mainfrom
fix-mobile-tab-spawn
Jul 8, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
fix-mobile-tab-spawn

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Spawning a Claude (or any agent) tab from Orca Mobile could produce a tab that shows the agent icon but runs a plain shell — the agent never started. This PR makes the mobile activate path launch the tab's agent when it materializes a pending agent tab, so a tab labeled Claude actually runs Claude.

What changes: activateMobileSessionTab materializes pending terminal tabs headlessly (phone taps send session.tabs.activate with notifyClients: false). That call site passed identity/cwd/launchAgent to createHeadlessMobileSessionTerminal but dropped the startup command, unlike every other agent-tab path. It now resolves the agent launch plan exactly like the mobile create path (resolveMobileSessionTerminalCommand: platform/remote-aware quoting, agent-enablement check, workspace trust marking) and threads command/env/startupCommandDelivery/launchConfig into the materialize. If the agent is disabled or the plan can't be built, it falls back to the previous plain-shell behavior instead of failing the activation.

What does not change: the create-side flows (renderer, headless, timeout-materialize, #7664 rescue) already delivered the command and are untouched. Live sessions cannot double-launch: every provider (local daemon createOrAttach, degraded local provider, SSH relay attach) skips startup commands when attaching to an existing live session, and a live session means the tab is ready, which skips the materialize branch entirely.

Root cause / reproduction

Reproduced end-to-end on the reporter's machine and deterministically on a dev instance:

  1. A Claude tab created from the phone while the desktop renderer is stalled (locked screen/App Nap/occlusion) times out server-side and survives as a pending tab: launchAgent: "claude", status: "pending-handle", no PTY, title reverted to "Terminal N".
  2. Tapping it on the phone materialized it without the command → fresh serve-* daemon session running a bare zsh under the Claude icon.

Evidence from the affected machine: both broken sessions' terminal-history logs contain zero command bytes (prompt only), spawned 12s apart matching two taps after the create's 10s+1s timeout cadence; the tabs persist in orca-data.json with launchAgent: "claude" and serve-* bindings. Deterministic repro rig: seed a Claude tab → exit it → SIGSTOP the renderer → session.tabs.activate with notifyClients: false → before the fix the daemon spawn received command: null and produced a plain shell; after the fix the same steps relaunch Claude (validated live, plus on the Android emulator through the real mobile UI).

Validation

  • New regression tests in src/main/runtime/orca-runtime.test.ts: pending agent tab activation spawns with the resolved claude command; pending tab without launchAgent still spawns a plain shell (no command); disabled agent falls back to plain shell without failing activation. Full orca-runtime.test.ts suite passes (580 tests).
  • Live dev-rig validation of the exact reporter flow (stalled renderer → tap pending Claude tab): Claude launches, tab title becomes "✳ Claude Code".
  • Android emulator (Orca Mobile) end-to-end: PASS on both scenarios (Pixel 7 API 36 emulator paired to a dev desktop build of this branch). Scenario A: "+" → Claude produced a tab with Claude Code running. Scenario B (the bug): a seeded pending tab (status: "pending-handle", launchAgent: "claude", no terminal handle, title "Terminal 10" with the Claude icon — the reporter's exact broken state) was tapped in the mobile tab bar and materialized with Claude running; server-side the tab flipped to "✳ Claude Code" / "ready" with a fresh terminal handle. Screenshot evidence captured for pairing, both scenarios, and the pre-tap pending state (kept locally under /tmp/mobile-claude-fix-evidence/; not committed per repo evidence policy).
  • pnpm tc clean; oxlint/oxfmt clean.

Risks / notes

  • Deliberate behavior change: tapping a dead agent tab on mobile now relaunches the agent fresh (previously: plain shell under the agent icon). Desktop shows a dead pane with scrollback instead; mobile has no dead-pane rendering, so relaunching the labeled agent is the closest faithful behavior. Scrollback from the dead session is still cold-restored before the relaunch.
  • Not a resume: hibernated/sleeping agent sessions materialized through this path get a fresh agent launch, not --resume; resume-on-activate remains a separate feature.
  • SSH: command resolution and delivery reuse the create path's machinery (relay commandDelivery, attach paths never deliver); validated by code inspection and existing create-path coverage, not a live SSH rig.

Made with Orca 🐋

…d on activation

When a mobile Claude tab was created while the desktop renderer was
stalled, the tab could survive as a pending agent tab (launchAgent set,
no PTY). Tapping it on the phone materialized it through
activateMobileSessionTab, which passed identity/cwd/launchAgent to
createHeadlessMobileSessionTerminal but no startup command - yielding a
plain shell under the Claude icon. Resolve the agent launch plan like
the create path does and thread it into the materialize; fall back to
the plain shell when the agent is disabled or unresolvable.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9792b9f4-d43e-4218-b0c8-301973e1e444

📥 Commits

Reviewing files that changed from the base of the PR and between 7a14c72 and e4170a4.

📒 Files selected for processing (1)
  • src/main/runtime/orca-runtime.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/orca-runtime.test.ts

📝 Walkthrough

Walkthrough

The runtime now resolves agent-specific startup details when activating a pending mobile session tab with a launchAgent, and passes the resolved command, environment, startup command delivery, and launch configuration into terminal creation. If that resolution fails or the agent is disabled, activation falls back to a plain shell. Tests add a helper runtime setup and cover activation with an enabled agent, no agent, and a disabled agent.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: mobile agent tabs now launch the agent instead of a plain shell.
Description check ✅ Passed The description covers summary, root cause, validation, and notes, though the screenshots, AI review, and security sections are not explicit.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
src/main/runtime/orca-runtime.ts (1)

4004-4037: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Stale launchAgent tag persists when the agent resolution fails (disabled/unresolvable agent).

launchAgent: tab.launchAgent (line 4035) is passed unconditionally, but when tab.launchAgent is set and resolution throws (disabled agent, unresolvable workspace, etc.), agentStartup stays {} — the PTY is materialized as a plain shell yet still tagged launchAgent: tab.launchAgent. This isn't just a cosmetic mismatch: pty.launchAgent = launchOpts.launchAgent ?? null gets set from this value, and loadPtyForegroundAgentFromController short-circuits with if (pty.launchAgent) { return false }, so the runtime will never probe the real foreground process for this PTY again — agent-status detection is permanently wrong for that terminal, not just its icon.

Use agentStartup.launchAgent instead of tab.launchAgent — resolveMobileSessionTerminalCommand's success path already echoes launchAgent: opts.agent (i.e. tab.launchAgent), and its failure path leaves it undefined, so this correctly clears the tag exactly when the plain-shell fallback kicks in, and is a no-op for the already-passing tests.

🐛 Proposed fix
             cwd: tab.startupCwd,
             command: agentStartup.command,
             env: agentStartup.env,
             startupCommandDelivery: agentStartup.startupCommandDelivery,
             launchConfig: agentStartup.launchConfig,
-            launchAgent: tab.launchAgent,
+            launchAgent: agentStartup.launchAgent,
             targetGroupId
🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.test.ts (1)

16636-16680: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider reusing makePendingAgentTabActivationRuntime instead of duplicating its setup.

This test re-implements the full runtime/session/pty-controller setup already in the new helper just to omit launchAgent on the persisted tab. Extending the helper with an optional launchAgent parameter (defaulting to 'claude') would let this test reuse it and reduce duplication.

♻️ Sketch
-  function makePendingAgentTabActivationRuntime(opts: { disabledTuiAgents?: string[] } = {}): {
+  function makePendingAgentTabActivationRuntime(
+    opts: { disabledTuiAgents?: string[]; launchAgent?: string | null } = {}
+  ): {
     runtime: OrcaRuntimeService
     spawn: ReturnType<typeof vi.fn>
   } {
     const spawn = vi.fn().mockResolvedValue({ id: 'serve-materialized-pty' })
     const { runtimeStore } = makeRuntimeStoreWithWorkspaceSession(
       makeWorkspaceSessionWithHeadlessTerminal({
         tabsByWorktree: {
           [TEST_WORKTREE_ID]: [
             {
               id: 'host-tab',
               ptyId: 'serve-dead-pty',
               worktreeId: TEST_WORKTREE_ID,
               title: 'Terminal 1',
               customTitle: null,
               color: null,
               sortOrder: 0,
               createdAt: 1,
-              launchAgent: 'claude'
+              ...(opts.launchAgent !== null ? { launchAgent: opts.launchAgent ?? 'claude' } : {})
             }
           ]
         },

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dfd8937b-a130-4ad9-8fe1-e28341bd123f

📥 Commits

Reviewing files that changed from the base of the PR and between 0784a7e and 7a14c72.

📒 Files selected for processing (2)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts

Comment thread src/main/runtime/orca-runtime.test.ts Resolved
@brennanb2025
brennanb2025 merged commit bd4f2e0 into main Jul 8, 2026
1 check passed
brennanb2025 added a commit that referenced this pull request Aug 3, 2026
…ver a bare renderer PTY (#12197)

A mobile New Tab -> Codex create resolves the launch command and hands it
to the renderer, but when the renderer's startup queue is lost (the #7587
stall class) the pane spawns a plain shell and the create still settles
ready via PTY adoption - silently binding the phone to a bare terminal
forever, since the ready status also disables the #7837 activation-time
materialize recovery.

Record the resolved launch command on the pending create and, at every
renderer-backed settle point, deliver it to the adopted PTY when no spawn
command was recorded for it. Spawn commands are noted per PTY by both
spawn IPC handlers, so a missing record on the locally registered live
PTY proves the launch never ran; delivery types the command exactly like
the create would have, and the note prevents double delivery.

Fixes STA-3214
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ver a bare renderer PTY (stablyai#12197)

A mobile New Tab -> Codex create resolves the launch command and hands it
to the renderer, but when the renderer's startup queue is lost (the stablyai#7587
stall class) the pane spawns a plain shell and the create still settles
ready via PTY adoption - silently binding the phone to a bare terminal
forever, since the ready status also disables the stablyai#7837 activation-time
materialize recovery.

Record the resolved launch command on the pending create and, at every
renderer-backed settle point, deliver it to the adopted PTY when no spawn
command was recorded for it. Spawn commands are noted per PTY by both
spawn IPC handlers, so a missing record on the locally registered live
PTY proves the launch never ran; delivery types the command exactly like
the create would have, and the note prevents double delivery.

Fixes STA-3214
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