Skip to content

fix(mobile): surface host create warnings and terminal-create errors - #20125

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-worktree-default-agent
Sep 11, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-worktree-default-agent

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​109 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​105
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​35 $\color{#cf222e}{\Huge{\mathbf{−}}}$​22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13

What happened

Creating a workspace from the phone with Claude as the default agent landed on
No tabs in this session with a bare red Failed to create terminal and nothing
to act on.

The underlying cause that day was pty pressure on the host. At the time of the
failure kern.tty.ptmx_max read 511 with 506 ttys in use, 484 of them held by
login (Orca's macOS TCC-wrapped spawn strategy). Note the cap is dynamic, not a
constant: it later read 999, and the highest device node is now /dev/ttys513 --
the kernel grew the table past 511, which is consistent with it having been pressed
against that ceiling when the spawn failed. The host's startup Claude terminal
failed to spawn, and so did the phone's follow-up create. Both failures were
reported by the host with a real reason -- the phone just never showed either of
them.

Two independent drops

  1. createWorktreeWithNameRetry returned only {worktreeId, name}, discarding
    worktree.create's warning, and hostNewWorktreeSessionRoute built the
    session route with only name + created=1.

    The session screen has always had the banner for this (MobileSessionContentRow

    • createWarningState) -- only the tasks create path
      (use-mobile-tasks-workspace-create-actions.tsx) ever fed it, so the New
      Workspace path could never report a startup terminal that failed to spawn.
  2. handleCreateTerminal collapsed every failure to the literal
    'Failed to create terminal', throwing away response.error.message.

After

Both propagate, so the daemon's existing pty-allocation hint reaches the phone:

Your system cannot allocate any more pty devices.

Orca requires a pty device to launch a new terminal. This error is usually due to
having too many terminal windows or terminal sessions open, either in Orca or
another program.

The hint is already composed by addNodePtyRecoveryHint; it was dying in the main
process. The same change surfaces every other host reason on this path -- a disabled
agent, an unresolved worktree owner, after_tab_not_found.

Behaviour is otherwise unchanged: a blank warning is still omitted from the route,
and a host that gives no reason still reads Failed to create terminal. Quick-command
toasts keep their labelled text; the reason goes to the inline error the empty state
renders.

Testing

  • 44/44 in the three touched mobile suites; tsc --noEmit, oxlint and oxfmt --check
    clean; check:code-quality:changed reports 0 new findings (incl. React Doctor) across
    all 10 changed files.
  • Ablated. With the tests in place I reverted the three source files to their
    pre-fix state and re-ran: exactly the three new behavioural tests go red, one per
    fix, and the two negative tests (blank warning omitted, generic fallback preserved)
    stay green. Restored and re-verified at the rebased head.

Not fixed here (deliberately out of scope)

Two follow-ups this investigation turned up, both wider than "show the error":

  • Mobile's launch sites disagree. prefersStructuredNativeChatByDefault() has
    exactly two consumers -- the desktop renderer (agent-launch-routing.ts) and
    orchestration worker-start. The worktree.create startup path never consults it, so
    with structured native chat on, a desktop create gets an agent-session tab while a
    mobile create gets a PTY (launchAgent: claude, viewMode: "chat"). That is why the
    mobile create burned a pty it did not need and died first, while Create Tab -> Claude
    (which does route structured) succeeded.
  • A workspace can be returned as a success with zero tabs. In
    runtime-local-worktree-terminal-startup.ts, the fallback terminal is gated on
    !args.createdWithAgent, so when an agent workspace's startup terminal fails there is
    no fallback at all. Shared by desktop, CLI and mobile.

A workspace created from the phone could land on "No tabs in this session"
with a bare red "Failed to create terminal" and no way to tell why. Two
independent drops hid the host's own explanation:

- createWorktreeWithNameRetry returned only {worktreeId, name}, discarding
  worktree.create's `warning`, and hostNewWorktreeSessionRoute built the
  session route with only `name` + `created=1`. The session screen has always
  had the banner (MobileSessionContentRow + createWarningState) -- only the
  tasks create path ever fed it, so the New Workspace path could never report
  a startup terminal that failed to spawn.
- handleCreateTerminal collapsed every failure to the literal
  'Failed to create terminal', throwing away response.error.message.

Both now propagate, so the daemon's pty-allocation hint ("Your system cannot
allocate any more pty devices.") reaches the phone instead of dying in the
main process. Behaviour is otherwise unchanged: a blank warning is still
omitted from the route, and a host that gives no reason still reads
'Failed to create terminal'.

@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 new issues found.

Reviewed changes

  • Create-warning propagation — createWorktreeWithNameRetry now returns the host's non-fatal warning (WorktreeCreateResult success variant gains a trimmed, blank-omitted warning?: string), threaded through onCreated into hostNewWorktreeSessionRoute's warning query param, which the session screen already consumes via createWarningState.
  • Terminal-create error surfacing — handleCreateTerminal replaces the collapsed 'Failed to create terminal' with a reportCreateFailure helper that sets the inline error to the host's real reason (falling back to the quick-command label / generic text) while keeping the toast on its labelled errorToast.
  • Tests — three new behavioral tests with exact toEqual/toBe string assertions (route carries warning, warning omitted when blank, host reason surfaced, generic fallback preserved), plus a trimmed-warning unit test.

Both changes are minimal, well-scoped, and match the existing tasks-create path (use-mobile-tasks-workspace-create-actions.tsx already sets queryParams.set('warning', ...)). The host's warning field is confirmed present in RuntimeWorktreeCreateResult.warning? (src/shared/runtime-worktree-contracts.ts:118). Type changes to onCreated are backward-compatible (optional third arg). No behavioral regressions identified.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

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: 7ba277c8-abe5-4d2e-aec2-b57b57f833b8

📥 Commits

Reviewing files that changed from the base of the PR and between 95cb099 and aee1f1c.

📒 Files selected for processing (1)
  • mobile/src/session/mobile-session-route-parity.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The worktree creation result now preserves non-blank host warnings. Callback types and handlers forward the warning to the session route, which URL-encodes it when present. Terminal creation now displays the host-provided failure reason and falls back to the configured or generic error message when the reason is empty. Tests cover warning propagation, whitespace handling, terminal error messages, and updated route parity hashes.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to aee1f

Host warnings and terminal failure reasons are surfaced without changing the documented fallback behavior. The reported validation passes, so the PR is mergeable.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description gives a detailed and relevant explanation of the problem, implementation, scope, and testing. However, it omits required template sections, including a linked issue, visual proof or an… Update the description to follow the repository template. Add a real issue reference under Linked Issue, add before/after visual proof or write N/A with a reason, complete the Testing checkboxes, and provide the remaining required sections …
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies both primary changes: surfacing host worktree creation warnings and terminal-creation errors in mobile.
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.
Full details: Description check

Explanation

The description gives a detailed and relevant explanation of the problem, implementation, scope, and testing. However, it omits required template sections, including a linked issue, visual proof or an explicit N/A justification, AI Disclosure, Review, Agent skill upstream boundary, Notes, and the checklist items.

Resolution

Update the description to follow the repository template. Add a real issue reference under Linked Issue, add before/after visual proof or write N/A with a reason, complete the Testing checkboxes, and provide the remaining required sections and checklist information. Preserve the existing technical explanation and test results.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Mobile visual proof — iOS Simulator

Native iOS QA for this PR, driven end to end through orca emulator taps on a booted simulator.

Rig

Device iPhone 17 Pro (50FD514C-…), iOS 26.5
App Orca dev client com.stably.orca.mobile, Expo SDK 55 dev build over Metro (http://10.0.0.4:8087) from this PR's worktree at 95cb0998b5
Host Mock host — the repo's own mobile/scripts/mock-server.ts (E2EE, port 6768), paired through the app's normal orca://pair flow

On the two strings. Reproducing real pty exhaustion would take down the machine's terminal fleet, so the mock replays the real host's verbatim text rather than inventing a message:

  • Warning banner string is the host's own template from src/main/ipc/worktree-remote.ts:464 — `Failed to create the startup terminal for ${worktree.path}: ${message}` (also runtime-remote-managed-worktree-create.ts:139, runtime-folder-worktree-create.ts:164).
  • Terminal-create error string is verbatim PTY_ALLOCATION_HINT from src/main/daemon/node-pty-error-hints.ts:29-35.

The mock was patched locally and uncommitted so worktree.create returns that warning alongside the worktree, and session.tabs.createTerminal fails with that message. Nothing in this PR's diff was touched to produce the proof, and no mock change is committed.

Flow exercised (identical in both runs): Host list → New workspace → name → Create worktree → lands on the new session, which hydrates with zero tabs and auto-creates its first terminal (which fails).


Before — pre-fix (all 7 non-test source files reverted to merge-base 9aa0f7e77d)

before-both.png

Same mock host, same two host strings on the wire — both dropped by the client:

  • No warning banner at all. hostNewWorktreeSessionRoute built the route with only name + created=1, so the host's warning never reached the session screen.
  • Failed to create terminal — the generic literal, with the host's actual reason discarded.

This is exactly the reported symptom: a bare red line on No tabs in this session with no explanation.

After — this PR at 95cb0998b5

after-both.png

  • Amber create-warning banner (AlertTriangle + dismiss X, via MobileSessionContentRow/createWarningState) now carries the host's reason: "Failed to create the startup terminal for /Users/brennanbenson/orca/workspaces/orca/hammerhead: Your system cannot allocate any more pty devices." The banner already existed — only the tasks create path ever fed it; it is now threaded through onCreated → warning query param.
  • The real pty reason replaces Failed to create terminal in the empty-state inline error, via the new reportCreateFailure helper — all three paragraphs of the daemon hint, including the remediation line.

Both states are shown with surrounding context (workspace header, 0 tabs, Create Tab, command dock) so the banner's and the error's placement is legible.

Ablation hygiene: the after-state was re-captured on the restored tree after the before-run, and the 7 reverted files were verified byte-identical to their pre-ablation contents. Screenshots were read from result.screenshot.path, visually inspected, and contain no pairing codes, device tokens, or QR payloads.

Electron: not applicable. Every file in 9aa0f7e77d..95cb0998b5 is under mobile/ (filtering for non-mobile/ paths returns zero), so there is no desktop/renderer surface to validate. No Electron run was performed and no desktop screenshots are claimed.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review complete. I ran the readiness checklist at the start and end, plus an adversarial same-model review loop. No proven in-scope P0/P1/P2 issues remain; no fixes were needed.

Validation:

  • pnpm --dir mobile test src/host-route-action-state.test.ts src/tasks/worktree-create-retry.test.ts src/session/use-mobile-session-terminal-create-actions.test.ts
  • 3 files, 44 tests passed.
  • Focused parity-inclusive review suite: 4 files, 47 tests passed.

The warning propagation and terminal error fallback are wired through the mobile create flow. Residual gaps are runtime emulator/SSH/network validation; Electron is not applicable because this PR is mobile-only. Backward compatibility impact is limited to optional warning data and route query state.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Follow-up: CI had two failures in the existing mobile route parity hash assertions because the source changes intentionally altered the extracted nested-function/runtime-string bodies. Updated only those two expected SHA-256 baselines in commit aee1f1ce71; full mobile suite now passes locally (528 files, 4341 passed, 3 skipped), with lint/format hooks passing. CI is rerunning on the pushed fix.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Correction to the earlier review note: this PR does include visible mobile changes. The create-warning banner and host-provided terminal error are user-facing UI states, so mobile visual QA is applicable. The existing iOS Simulator evidence is recorded in the earlier “Mobile visual proof — iOS Simulator” comment with before/after screenshots, and Electron remains inapplicable because the diff is mobile-only. I also completed the requested local OSS reference review for mobile remote-control/error-delivery patterns; the relevant mechanism here is already aligned with the repository flow: preserve the host result, carry it through navigation state, and render actionable failure text at the affected surface. No production changes were needed from that comparison.

@brennanb2025
brennanb2025 merged commit 9a56797 into main Sep 11, 2026
22 checks passed
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