Skip to content

fix(mobile): reattach restored runtime-owned terminals before activation - #19247

Closed
brennanb2025 wants to merge 4 commits into
mainfrom
brennanb2025/pr11868-folder-tab-snapshots
Closed

brennanb2025 wants to merge 4 commits into
mainfrom
brennanb2025/pr11868-folder-tab-snapshots

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​201 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​201
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​14 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13

Supersedes #11868.

What the user sees

Before. On Orca Mobile, a terminal tab restored after a runtime restart or SSH reconnect renders with its scrollback and reports ready — but typing goes nowhere. The runtime discovered the surviving PTY through inventory and never attached to it, so the tab looks healthy while its writes land nowhere.

After. Activating such a tab reattaches it first, so input reaches the process it appears to be connected to.

Root cause

Inventory presence was treated as ownership. orca-runtime-refresh-pty-worktree-records-with-controller-inventory.ts:217-218 records an inventory-listed session as connected: true without ever setting runtimeSessionOwned. The projection therefore issues a handle and stamps status: 'ready' (runtime-mobile-session-projection.ts:87,214-224,271-273), and the activation gate skips materialization because the tab already claims to be ready.

Attachment is an operation distinct from process existence: seeing a process in restored state is not the same as having attached to it.

The fix

Nine lines at orca-runtime-perform-mobile-session-pty-records-refresh.ts:145-150. A restored serve/SSH-owned binding with no live runtime-owned binding now also triggers materialization, folded into the existing condition so the parked-pane and host-focus guards still apply to both arms.

Evidence

Red-then-green, with the ablation re-run independently:

  • reattaches the restored session on activation instead of trusting inventory — red on unmodified main (zero spawn, zero attach), green after.
  • reattaches once, not on every activation — red on main, green after.
  • records an inventory-restored PTY as connected without owning it — passes on main; this is the mechanism, not a regression test.
  • leaves an inventory-restored local tab alone — negative control, green in both states.

Reverting just the predicate fails exactly the two regression tests and leaves the mechanism test and negative control passing.

src/main/runtime suite: 7,269 passed, 15 skipped, 1 failure (structured-agent-session-adoption-replay.test.ts) confirmed pre-existing on unmodified main. Lint, format, max-lines, ts-nocheck ratchet, reliability and changed-code gates all clean.

Scope notes

  • The fix covers serve and SSH bindings. The strictly-proven live case is an SSH/relay restored PTY reached by activation; serve is covered on the same invariant, since leaving a restored serve PTY un-owned also distorts later teardown and preservation decisions. The one local self-healing path (registerRemote → ensureProviderAttach) is local-only by construction and never covers SSH ids.
  • feat(ssh): verify host keys, and restore panes correctly across a reconnect #14844's relay sweep does not cover this: reattachKnownPtys runs on relay session connect, not on the activation path for a PTY discovered this runtime generation via listProcesses.
  • Typecheck is not evidence for this file — it carries @ts-nocheck (as do 175 files in src/main/runtime), so the test suite is the only real safety here.

What was deliberately dropped from #11868

Four of its five sub-defects landed independently over the past month: folder-scope host resolution and hydration targets (#11832, extended by #17486), same-path folder PTY identity (#12474), reattach-across-reconnect for the relay-connect path (#14844), and folder-deletion pruning (now the worktreeInstanceId fence plus #17779). Its tombstone/overflow-bucket persistence, pane-spawn reservations, stable-pane-id additions, materialization-freshness key and host-aware reservation path flavor are superseded or unexercised, and its new PersistedState fields are not worth the cost.

A separate latent issue was found and deliberately not fixed here: getKnownWorktreeIds() (runtime-workspace-session-controller.ts:116-134) cannot admit a folder: key and enumerates only local + repo hosts, while its sibling getHydrationTargets() (:159-165) also reads getWorkspaceSessionHostIds(). It has no current user impact — the hydration path masks it — and no red test can be written for it today, so it is filed rather than patched.

A restarted runtime records a surviving serve/SSH PTY from provider inventory
as connected, so the mobile projection reports the tab as ready — but nothing
attached it this generation and typed input goes nowhere. Gate activation on a
runtime-owned live binding, not on inventory presence.
@coderabbitai

coderabbitai Bot commented Sep 7, 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: Team

Run ID: 85e2ec0f-84d1-4139-bfa5-d355a506cf67

📥 Commits

Reviewing files that changed from the base of the PR and between 52eef98 and 10ca644.

📒 Files selected for processing (2)
  • src/main/runtime/mobile-restored-terminal-reattach.test.ts
  • src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts

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


📝 Walkthrough

Walkthrough

activateMobileSessionTab now reattaches restored serve or SSH PTYs when no renderer-owned parent exists. Tests verify restored PTY state, reattachment identifiers, one-time reattachment, renderer-owned SSH focus, and local PTY non-reattachment.

Merge Risk: ⚪ Minimal · up to 10ca6

Restored mobile terminal tabs now reconnect when the runtime no longer owns their binding, while renderer-owned and local terminals retain their existing behavior. The covered reattachment and exclusion cases leave no identified merge-blocking risk.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description clearly explains the user impact, root cause, fix, scope, regression tests, and validation results. However, it omits required template sections, including Visual Proof or an explicit … Add the missing template sections. Provide a Visual Proof attachment or write N/A with a reason, identify the issue with Fixes #... or explain the relationship to #11868, document manual testing and affected platforms, and complete the …
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 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 and concisely describes the primary change: reattaching restored runtime-owned terminals before activation.
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 clearly explains the user impact, root cause, fix, scope, regression tests, and validation results. However, it omits required template sections, including Visual Proof or an explicit N/A statement, the Linked Issue format, platform-specific manual testing details, and the checklist sections.

Resolution

Add the missing template sections. Provide a Visual Proof attachment or write N/A with a reason, identify the issue with Fixes #... or explain the relationship to #11868, document manual testing and affected platforms, and complete the Review, Notes, Agent skill upstream boundary, and Checklist sections.

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

@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

  • Activation-time reattach predicate — activateMobileSessionTab now also materializes a serve/SSH-owned terminal tab that already reports ready but has no live runtime-owned binding, so a restored-but-unattached PTY is reattached before input is routed to it. The parked-pane and host-focus guards still apply to both arms.
  • Characterization + regression tests — a new suite models a restarted runtime whose SSH pane survived, pinning the mechanism (inventory presence ≠ ownership), the reattach-on-activation behavior, idempotency, and a negative control for local tabs.

The predicate is sound: hasServeOrSshOwnedBinding (id shape ⇒ runtime-owned) is the same invariant isRuntimeOwnedHeadlessMobileTab and hasLiveOrPersistedServeOrSshOwnedPtyBinding already rely on, and hasLiveRuntimeSessionOwnedPtyBinding (connected && runtimeSessionOwned) is false exactly in the restored-unattached state, since runtimeSessionOwned is set true at create/surface and false only on close/exit/teardown. The reattach reuses the existing createRuntimeOwnedMobileSessionTerminal path with identity.sessionId, which SshPtyProvider treats as a relay reattach and which is idempotent (providers skip startup commands when attaching to live sessions), so no double-launch is possible.

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

@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

Since the prior Pullfrog review, this PR narrowed the reattach predicate and added a matching negative control:

  • Renderer-graph membership gates reattach — needsRestoredRuntimeReattach now also requires !this.tabs.has(tab.parentTabId), so a renderer-published SSH tab is focused instead of reattached, which would steal a live session from the desktop. The discriminator mirrors isRuntimeOwnedHeadlessMobileTab.
  • Negative control for renderer-published tabs — focuses a renderer-published SSH tab instead of reattaching it publishes the tab into the window graph and asserts spawn is not called and focusTerminal is. This is a genuine red-then-green: without the new clause the predicate would be true and the tab would be re-spawned.

The predicate is sound: this.tabs is the renderer window graph keyed by tab id (rebuilt on syncWindowGraph), and tab.parentTabId is the same id isRuntimeOwnedHeadlessMobileTab, orca-runtime-close-mobile-session-tab, and orca-runtime-stop-explicitly-closed-tab-ptys already compare against renderer-graph membership. An ssh: id is minted on the runtime-owned create flow but the flag defaults false on the inventory-restore path, so neither id shape nor runtimeSessionOwned separates "never attached" from "desktop owns it" — only renderer-graph membership does.

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Independent verification at 10ca64457efdda11ebfda31570199848ace9b704: NOT READY — manual mobile/SSH validation remains blocked. Local HEAD, git ls-remote, and GitHub API head agree.

  • Functional correctness: no demonstrated code regression found in this focused review. The committed regression suite passes 5/5, including a desktop-published SSH tab with a nonempty renderer graph: activation reuses desktop focus and does not call the materialization spawn controller.
  • Discriminating ablations: removing only the renderer-graph guard fails exactly that desktop SSH test (4 pass / 1 fail), entering materialization and throwing terminal_handle_stale before its final assertions. Removing the ready-status reattach extension instead fails exactly “reattaches the restored session on activation instead of trusting inventory” and “reattaches once, not on every activation” (3 pass / 2 fail; zero spawn calls). Both experiments started from committed code and were restored from a copy; production contents match the original byte-for-byte.
  • Architectural fit: this is activation-time recovery for a PTY marked connected by inventory without an attachment. It preserves the existing attachment path and sticky runtimeSessionOwned lifetime; it does not remove the broader distinction between inventory presence and attachment readiness. No teardown-ownership change was made.
  • Concrete precedent: renderer-graph membership is an existing discriminator, but the referenced isRuntimeOwnedHeadlessMobileTab is a teardown predicate that returns true for SSH bindings before its graph check. Only graph membership is reused; the ownership semantics are intentionally different, so this is not full architectural equivalence.
  • Validation: final focused runtime/provider run passed 11 tests across 3 files (mobile-restored-terminal-reattach.test.ts, ssh-pty-provider-reattach-incarnation.test.ts, ssh-pty-reattach-absence-discrimination.test.ts). The orca-runtime.test.ts run filtered to deliberately parked pane activation passed 12 tests, with 1,248 intentionally filtered out. All used --config config/vitest.config.ts and ORCA_BACKGROUND_LAUNCH=1. Sequential node, web, and CLI npx tsc --noEmit -p ... checks all exited 0; the changed production module still has @ts-nocheck.
  • Performance: no polling, timers, or new inventory enumeration is introduced. The added checks use the existing tab layout and PTY lookup; the repeat-activation test bounds successful reattachment to one controller call across two activations. Live latency and concurrent activations were not measured.
  • Manual gap: emulator preflight found no running device. No approved disposable paired mobile + SSH environment is available under the credential restrictions, so no native terminal activation, typing/output delivery, or rendered screenshot proof was observed. Serve, real SSH reconnect, folder-workspace behavior, platform parity, and mixed-version mobile transport remain unverified by this run. This is not a CLEAN/merge-ready endorsement.

The PR body needs an evidence refresh: “nine lines” predates the renderer guard, its test list omits the fifth desktop-owned SSH control, and its previous broad-suite counts/live-case statement are not current independent manual evidence. The new claim should name both separate ablations and retain the manual gap until the actual mobile flow is exercised.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing: its issue #27649 is closed.

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