Repository navigation
fix(mobile): deliver the agent launch command when a create settles over a bare renderer PTY - #12197
Conversation
…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 SummaryThis 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.
Confidence Score: 4/5Safe 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 Files Needing Attention: The new deliverPendingStartupCommandToBareRendererPty method in orca-runtime.ts is the only area worth a second look, specifically the unchecked
|
| 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
Reviews (1): Last reviewed commit: "fix(mobile): deliver the agent launch co..." | Re-trigger Greptile
| 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) | ||
| } |
There was a problem hiding this comment.
\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.
📝 WalkthroughWalkthroughMobile 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)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.test.ts (1)
31260-31265: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest 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-bareand assert thatwriteremains 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
📒 Files selected for processing (2)
src/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.ts
| // 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) | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
🎯 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:
waitForStartupDraftReadywaits for render quiescence after a bracketed paste.waitForStartupFollowupReadypolls 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
|
QA evidence (isolated instances only):
|
…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


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):noteTerminalSpawnCommand.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— fulloxlintclean; pre-commit ran oxlint + react-doctor + oxfmt on staged filespnpm typecheckpnpm test— targeted: fullsrc/main/runtime/orca-runtime.test.ts(1006 passed | 1 skipped) viavitest --config config/vitest.config.tspnpm build— not run;electron-vitemain/preload/renderer bundles built and booted in the live QA rigNew 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 PTYdoes not re-deliver the agent launch command when the adopted renderer PTY spawned with oneLive 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:
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
finallyas before; disconnected creates still throw before the delivery points), and the race betweenregisterPtyandnoteTerminalSpawnCommand(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
buildAgentStartupPlanoutput the create already ships to the renderer, so host-shell quoting (macOS/Linux/Windows, WSL, SSH) is unchanged.\rsubmits 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
buildAgentStartupPlanfrom host-side settings, or thecommanda paired client already supplies today (which the renderer would have executed at spawn) — paired clients can already write to these terminals viaterminal.send, so no privilege change. No secrets logged or persisted; the spawn-command record reuses the existingterminalSpawnCommandsByPtyIdmap. IPC surface unchanged (no new channels or schema changes).Notes