Skip to content

fix(mobile): deliver the agent launch command when a create settles over a bare renderer PTY - #12197

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/sta-3214-mobile-codex-tab
Aug 3, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/sta-3214-mobile-codex-tab

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

Fixes STA-3214 (Linear) / #12109: on Orca Mobile, "New Tab → Codex" could open a terminal tab in which the Codex session never started — the tab stayed a bare shell named "Terminal N", accepted input, and never showed the Codex banner.

Root cause: the mobile create resolves the agent launch command and delegates tab creation to the renderer. When the renderer's startup queue is lost (the #7587 renderer-stall class the codebase already documents), the pane spawns a plain shell, and the create still settles ready by adopting that live PTY (ensurePtyBackedMobileSurfaceForRendererTab). That success is silent and permanent: because the surface is ready, the #7837 activation-time materialize recovery is bypassed too, so the phone stays bound to a bare shell forever.

Fix (runtime-side, src/main/runtime/orca-runtime.ts):

  • Record the resolved agent launch command on the pending mobile create.
  • At every renderer-backed settle point (ready wait, ready fallback, catch-path rescue), check whether the backing PTY ever received a spawn command — both spawn IPC handlers already record per-PTY launch commands via noteTerminalSpawnCommand.
  • If the locally registered live PTY has no recorded spawn command, the launch provably never ran: type the launch command into the shell (Enter as its own write) and record it so repeated settles cannot double-deliver.

The healthy path is untouched: a pane that spawned with its startup command has a recorded spawn command and is skipped; runtime-owned/materialize spawns already carry the command; remote-runtime PTYs are excluded because they are not locally registered.

Screenshots

No visual change (main-process fix). QA evidence: with the renderer's startup queue deliberately dropped (simulating the #7587 stall), before the fix the mobile create settled into a permanently bare "Terminal 12"; after the fix the same sequence boots Codex (banner + tab renamed) on a real paired iOS-simulator client.

Testing

  • pnpm lint — full oxlint clean; pre-commit ran oxlint + react-doctor + oxfmt on staged files
  • pnpm typecheck
  • pnpm test — targeted: full src/main/runtime/orca-runtime.test.ts (1006 passed | 1 skipped) via vitest --config config/vitest.config.ts
  • pnpm build — not run; electron-vite main/preload/renderer bundles built and booted in the live QA rig
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

New regression tests (verified to fail without the fix — the delivery write is never made — and pass with it):

  • delivers the agent launch command when a create settles over a bare renderer PTY
  • does not re-deliver the agent launch command when the adopted renderer PTY spawned with one

Live QA on an isolated dev desktop (own HOME + ORCA_USER_DATA_PATH) paired to the real mobile app in an iOS simulator, plus a wire-protocol paired client:

  • Baseline: New Tab → Codex booted Codex in all environmental variants tried (worktree open/closed on desktop, window visible/hidden/minimized, sequential and concurrent creates, chat-by-default settings, 10+ existing tabs) — the mainline delivery path is unchanged.
  • Repro + fix: with the renderer startup queue dropped once, pre-fix the create settled ready over a bare shell (exact ticket symptom); post-fix the identical sequence delivers the Codex launch and the tab boots (verified on the paired phone UI).

AI Review Report

Reviewed the settle-path change for: double-delivery (guarded by the per-PTY spawn-command record, which is also written after delivery), delivery into the wrong PTY (lookup is scoped to the pending create's worktree + renderer tab id and requires a locally registered, connected PTY with a valid pane key), interaction with the client-disconnect path (pending record is deleted in the same finally as before; disconnected creates still throw before the delivery points), and the race between registerPty and noteTerminalSpawnCommand (both run in one synchronous block in the spawn IPC handlers; delivery runs from promise continuations, which cannot preempt that block).

Cross-platform: main-process-only change; the delivered command comes from the same buildAgentStartupPlan output the create already ships to the renderer, so host-shell quoting (macOS/Linux/Windows, WSL, SSH) is unchanged. \r submits across supported shells and is written separately so a long command cannot swallow it. SSH spawns record their spawn commands through the same IPC handlers, so SSH panes are discriminated identically; remote-runtime PTYs are excluded (not locally registered). No shortcuts, labels, or path handling touched.

Security Audit

No new input surfaces. The delivered text is the create's own resolved startup command: either built by buildAgentStartupPlan from host-side settings, or the command a paired client already supplies today (which the renderer would have executed at spawn) — paired clients can already write to these terminals via terminal.send, so no privilege change. No secrets logged or persisted; the spawn-command record reuses the existing terminalSpawnCommandsByPtyId map. IPC surface unchanged (no new channels or schema changes).

Notes

  • The renderer-side trigger (losing the queued startup) was reproduced synthetically; the mainline renderer path delivers correctly in every environment variant tested. The runtime-side guarantee added here closes the entire class regardless of which renderer anomaly drops the startup, matching the recovery philosophy of Fix Orca Mobile agent tabs opening as a plain shell instead of launching the agent #7837 (which fixed the same symptom for the activation/materialize path only).
  • Delivery types into the shell even if the shell is still initializing; the kernel input queue holds it until the prompt is ready — same behavior as a user typing immediately after opening a terminal.

…ver a bare renderer PTY

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
@greptile-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a mobile-specific bug (STA-3214) where "New Tab → Codex" could silently settle over a bare shell PTY — leaving the phone bound to a plain terminal forever — when the renderer's startup queue is lost during the #7587 stall class. The fix is runtime-side only: record the resolved agent launch command on the pending mobile create, then at each of the three renderer-backed settle points check whether the backing PTY ever received a spawn command; if not, type the command (and Enter as a separate write) into the shell and mark it delivered.

  • startupCommand is added to the pendingMobileTerminalCreatesByKey record, and deliverPendingStartupCommandToBareRendererPty is called at all three settle branches (ready wait, ready fallback, and catch-path rescue), guarded by terminalSpawnCommandsByPtyId to prevent double-delivery.
  • Two regression tests are added: one that reproduces the bare-PTY scenario by registering a PTY without a spawn-command record and verifies the command + \ are written; one that registers a PTY with a prior spawn-command record and verifies no write occurs.

Confidence Score: 4/5

Safe to merge; the change is main-process-only, the healthy path is fully untouched, and the recovery logic is well-guarded against double-delivery.

The three settle-path insertions are minimal and scoped to an already-isolated code path. The double-delivery guard (terminalSpawnCommandsByPtyId) is robust, and the new method is entirely synchronous and easy to reason about. The only gap is that the
write result is not checked before noteTerminalSpawnCommand is called, leaving a theoretical window where a command is typed but not submitted and retries are blocked — though the PTY exit handler cleans up the record if the PTY dies, limiting the blast radius.

Files Needing Attention: The new deliverPendingStartupCommandToBareRendererPty method in orca-runtime.ts is the only area worth a second look, specifically the unchecked
write at lines 25652–25656.

Important Files Changed

Filename Overview
src/main/runtime/orca-runtime.ts Adds startupCommand to the pending mobile create record and introduces deliverPendingStartupCommandToBareRendererPty, called at all three settle points; logic is sound with one minor concern around unchecked \r write result.
src/main/runtime/orca-runtime.test.ts Adds two focused regression tests: one verifying the command is typed into a bare PTY and one verifying no re-delivery when the PTY already carried a spawn command; both correctly mirror the spawn-IPC handler's register+note sequence.

Sequence Diagram

sequenceDiagram
    participant Mobile as Mobile Client
    participant Runtime as OrcaRuntimeService
    participant Renderer as Renderer (BrowserWindow)
    participant PTY as PTY Controller

    Mobile->>Runtime: createMobileSessionTerminal(agent: 'codex')
    Runtime->>Runtime: resolveMobileSessionTerminalCommand() → startupCommand
    Runtime->>Runtime: "pendingMobileTerminalCreatesByKey.set(key, { startupCommand })"
    Runtime->>Renderer: terminal:tabCreateRequest
    Note over Renderer: Startup queue stalled (#7587)<br/>PTY spawns as bare shell
    Renderer->>Runtime: registerPty('pty-bare') [no noteTerminalSpawnCommand]
    Renderer->>Runtime: "terminal:tabCreateReply { tabId }"
    Runtime->>Runtime: ensurePtyBackedMobileSurfaceForRendererTab()
    Runtime->>Runtime: waitForMobileTerminalSurface() → surface (ready)
    Runtime->>Runtime: "isReadyMobileTerminalSurface() = true"
    Runtime->>Runtime: deliverPendingStartupCommandToBareRendererPty()
    Note over Runtime: terminalSpawnCommandsByPtyId.has(ptyId) = false
    Runtime->>PTY: write(ptyId, 'codex ...')
    Runtime->>PTY: write(ptyId, '\r')
    Runtime->>Runtime: noteTerminalSpawnCommand(ptyId, command)
    Runtime-->>Mobile: "surface { status: 'ready' }"
    Note over PTY: Codex launches in the shell
Loading

Reviews (1): Last reviewed commit: "fix(mobile): deliver the agent launch co..." | Re-trigger Greptile

Comment on lines +25652 to +25656
if (this.ptyController?.write(pty.ptyId, command)) {
// Why: Enter rides its own write so a long command cannot swallow it.
this.ptyController.write(pty.ptyId, '\r')
this.noteTerminalSpawnCommand(pty.ptyId, command)
}

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 \r write result unchecked before recording the spawn command

noteTerminalSpawnCommand is called unconditionally after the \r write, even though the \r write's result is not checked. If the PTY dies in the narrow window between the command write and the \r write (for example, the process exits immediately after receiving input), the command text would be buffered in the TTY but Enter would never be delivered, and the spawn-command record would be set, blocking any future delivery attempt. The PTY exit handler does delete the entry in its cleanup, so state would eventually be consistent, but the surface would be returned as ready while the terminal has an un-submitted command in its input line.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Mobile terminal creation now records the resolved startup command. When a surface becomes ready or is rescued, the runtime sends the command and a carriage return to an eligible bare renderer PTY. The runtime records the command after a successful write and skips PTYs that already recorded the command. Tests cover both bare and already-initialized PTYs.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main mobile runtime fix for delivering the agent launch command to a bare renderer PTY.
Description check ✅ Passed The description covers all required sections, explains the change, documents testing and review, and clearly notes that the full build was not run.
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

🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.test.ts (1)

31260-31265: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test idempotency after fallback delivery.

This test verifies the first fallback write. It does not verify that fallback delivery records the command. Trigger a second settle or rescue for pty-bare and assert that write remains at two calls. This detects a regression that launches Codex twice after the first fallback succeeds.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 02fe68d5-c2fe-4214-b942-841ef638ca13

📥 Commits

Reviewing files that changed from the base of the PR and between 4481b9b and 1978488.

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

Comment on lines +25635 to +25658
// Why: a create can settle over a renderer PTY that spawned without its
// startup command (the create's renderer stalled, #7587), silently binding
// the client to a plain shell under an agent tab forever — once the surface
// is ready, the activation-time materialize recovery (#7837) never runs
// (STA-3214). Spawn commands are recorded per PTY at spawn time, so a
// missing record on the locally registered live PTY proves the launch never
// ran; type it into the shell like the create would have.
private deliverPendingStartupCommandToBareRendererPty(worktreeId: string, tabId: string): void {
const pending = this.pendingMobileTerminalCreatesByKey.get(`${worktreeId}::${tabId}`)
const command = pending?.startupCommand
if (!command) {
return
}
const pty = this.findLiveRegisteredPtyForRendererTab(worktreeId, tabId)
if (!pty || this.terminalSpawnCommandsByPtyId.has(pty.ptyId)) {
return
}
if (this.ptyController?.write(pty.ptyId, command)) {
// Why: Enter rides its own write so a long command cannot swallow it.
this.ptyController.write(pty.ptyId, '\r')
this.noteTerminalSpawnCommand(pty.ptyId, command)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Add a readiness/quiescence check before typing the startup command.

deliverPendingStartupCommandToBareRendererPty writes command and then \r as soon as the mobile surface reports "ready." "Ready" only means the tab has a connected PTY and a terminal handle. It does not mean the underlying shell finished its startup or profile scripts and is ready to accept input.

Two sibling recovery helpers in this same file wait before typing text into a PTY:

  • waitForStartupDraftReady waits for render quiescence after a bracketed paste.
  • waitForStartupFollowupReady polls until the foreground process matches the expected agent process.

This new method has no equivalent wait. On a slow-starting shell (SSH-backed workspace with network latency, login banners, or heavy profile scripts), the command can land before the prompt is ready and get partially swallowed or corrupted. That reproduces the original bug (an agent tab with no working session) in a different form, silently.

Add a wait for quiescence or a foreground-process check, similar to waitForStartupFollowupReady, before writing the command.

As per coding guidelines, "All changes must support SSH use cases and must not assume local-only execution." SSH-backed shells are the case most likely to expose this timing gap.

🐛 Proposed fix sketch
-  private deliverPendingStartupCommandToBareRendererPty(worktreeId: string, tabId: string): void {
-    const pending = this.pendingMobileTerminalCreatesByKey.get(`${worktreeId}::${tabId}`)
-    const command = pending?.startupCommand
-    if (!command) {
-      return
-    }
-    const pty = this.findLiveRegisteredPtyForRendererTab(worktreeId, tabId)
-    if (!pty || this.terminalSpawnCommandsByPtyId.has(pty.ptyId)) {
-      return
-    }
-    if (this.ptyController?.write(pty.ptyId, command)) {
-      // Why: Enter rides its own write so a long command cannot swallow it.
-      this.ptyController.write(pty.ptyId, '\r')
-      this.noteTerminalSpawnCommand(pty.ptyId, command)
-    }
-  }
+  private deliverPendingStartupCommandToBareRendererPty(worktreeId: string, tabId: string): void {
+    const pending = this.pendingMobileTerminalCreatesByKey.get(`${worktreeId}::${tabId}`)
+    const command = pending?.startupCommand
+    if (!command) {
+      return
+    }
+    const pty = this.findLiveRegisteredPtyForRendererTab(worktreeId, tabId)
+    if (!pty || this.terminalSpawnCommandsByPtyId.has(pty.ptyId)) {
+      return
+    }
+    void this.waitForShellReadyBeforeDeliveringStartupCommand(pty.ptyId).then((ready) => {
+      if (!ready || this.terminalSpawnCommandsByPtyId.has(pty.ptyId)) {
+        return
+      }
+      if (this.ptyController?.write(pty.ptyId, command)) {
+        this.ptyController.write(pty.ptyId, '\r')
+        this.noteTerminalSpawnCommand(pty.ptyId, command)
+      }
+    })
+  }

Source: Coding guidelines

@brennanb2025

Copy link
Copy Markdown
Contributor Author

QA evidence (isolated instances only):

  • Desktop-side Electron validation deliberately dropped the first renderer startup queue delivery; the settle path re-delivered the startup command and the terminal printed STA-3214_RECOVERED_STARTUP_COMMAND.
  • iOS mobile validation used the real New Tab → Codex flow with the same one-shot dropped renderer delivery; Codex opened as a chat tab instead of a bare shell.

Desktop Electron recovery

Mobile Codex tab recovery

@brennanb2025
brennanb2025 merged commit b4d9ae4 into main Aug 3, 2026
44 checks passed
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