Skip to content

fix(terminal): hidden tabs reconnect to sessions that survived a restart - #31254

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/hidden-tab-liveness-fix
Oct 21, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/hidden-tab-liveness-fix

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​22 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4

ELI5

When Orca restarts, terminal tabs you aren't looking at should reconnect to agents that are still running, so Orca keeps seeing their bells, title changes and output. Since #29459 they don't: a background tab with a running agent stays disconnected until you click it. This makes the "is this session still running?" check tell the truth after a restart, which is what #29459 already relies on.

What Changed

Before: after a restart, a hidden tab whose agent was still running stayed disconnected until you opened it, and output that arrived meanwhile wasn't seen. Main's daily full E2E run (settled-worker-tab-survives-restart, "liveness before reveal") has failed on this since 10-18.

After: a hidden tab with a running agent reconnects right away. A hidden tab whose session has ended still waits until you open it and resumes there, exactly as #29459 designed.

Mechanism: #29459 holds a hidden tab only when pty:hasPty says its session is gone ("only the host's exited may hold it"). But pty:hasPty answered from the provider's list of sessions attached in this run of Orca. Right after a restart that list is empty, so every session that survived the restart read as gone. Now, when that list says no, the handler asks the host through the provider's existing liveness probe (probePtyLiveness, the same one the runtime controller already uses). The fast "attached here" yes, the remote-id and swap-window guards, and the error-to-unknown handling are unchanged. A provider without a probe (the in-process provider, which is its own sole owner) keeps its answer.

Why

This restores #29459's own design with the smallest change at the point that was wrong: the answer, not its callers. Answers can only move from "gone" to "running" or "unknown", never the other way, so nothing that acts on "gone" can act more often. Every renderer caller of pty:hasPty means "does this session still exist on its host", so they all get a truthful answer. An attached-set miss consults the existing host probe. A current direct host normally answers one size lookup; older hosts and multi-generation ownership resolution can use inventory. Each daemon request has its existing 2-second timeout; this is not an end-to-end bound across startup, recovery and compatibility fallback.

A larger version that also made hidden reconnects attach-only end to end was explored in #30926; it is not needed to restore the intended behaviour.

Intended scope and inherited choices

  • Intended, inherited check-then-reconnect timing: the session can end between the liveness check and reconnect. This restores fix(terminal): resume a relaunched workspace's sleeping agents only when shown #29459's existing flow and does not make those operations atomic.
  • Intended, inherited reconnect on unknown: an unavailable or failed liveness probe returns unknown, and the existing renderer flow still attempts reconnect. This PR preserves that choice.
  • Intended, existing lazy workspace mount limit: hidden tabs reconnect after their workspace is mounted. Workspaces that have not mounted still wait for their existing mount path; this PR does not mount every workspace at startup.

Linked Issue

N/A (maintainer). Daily E2E failure, for example https://github.com/stablyai/orca/actions/runs/39307965554.

Visual Proof

Partial real QA on M4Air, final head f007ce61fed2fc3d26f2f148ae1d43df2bcb78a4, real Claude 2.1.304: current main 6e973fa6d4b5640744453f416c6265b96fe7fefd reproduced the surviving hidden session staying unbound until reveal. The branch bound the same original PTY before reveal and received new output, title events and bells while hidden. The baseline app/renderer came from main but reused the branch CLI emission, so this remains a partial comparison.

Main after restart, before reveal Branch after restart, before reveal
Main hidden pane held Branch hidden session bound and bell received

Review complete under Brennan's explicitly approved QA exception (2026-10-21). The requested one-launch main control reproduced the same startup failure: branch f007ce61 timed out at 02:58:28.977 UTC and main 6e973fa6 at 05:00:13.868 UTC on 2026-10-21, both waiting 60 seconds for workspace-restoration readiness (workspaceSessionReady). All 4,115 existing build artifacts matched the saved main build, so no rebuild was needed. The only controller changes were its Chrome DevTools Protocol and runtime port numbers, taken from fresh QA admission 1017; isolation, shutdown and the readiness wait were unchanged. This establishes that the timeout also occurs on main in this setup; it does not diagnose the timeout or prove the remaining feature flows.

Real QA proved hidden live-session reconnect versus main, including output, title events and bells before reveal, as shown above. The passing settled-worker-tab-survives-restart run 39511560917 supplies the accepted automated evidence for the remaining recovery path: both live and exited cases passed (2/2). The exited case preserves the tab through hold/reveal and allows at most one resume with the saved session ID; it does not require a launch or prove a real reply. The full workflow on final head also passed the changed restart tests.

Not exercised in real QA: the ended-session no-hidden-launch / exactly-one-resume flow with real replies, a visible restored agent replying, and a new terminal rendering a command's output. Both the branch and requested main control timed out after the same 60-second workspace-restoration readiness wait before those flows. These gaps remain disclosed; the automated evidence is accepted under the explicit ruling. The one main launch was shut down through the unchanged helper. The final audit found no surviving recorded process identities and all assigned ports clear. The QA worktree was restored clean to f007ce61; its ignored build artifacts remain the verified main build. The worker and evidence terminal are released, and admission 1017 is done. No product code, commits or pushes were added.

Testing

Review path: full — terminal restart/recovery and IPC semantics require the full review and real-agent QA.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • pty-startup-barrier-and-listing.test.ts: a session the attached list doesn't know but the host reports live now reads true; attached and gone sessions unchanged. With the old handler this case returns false.

  • pty-startup-swap-window-presence.test.ts and pty-session-liveness-and-ownership.test.ts still pass (22 tests across the three files).

  • settled-worker-tab-survives-restart.spec.ts: "liveness before reveal" now asserts the hidden pane is actually bound to its session, since hasPty now reads host liveness and would pass even if the tab never reconnected.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots attached for hidden live-session reconnect; remaining real-QA gaps listed above
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • CI covers full checks: workflow 39514157609 passed on the final head, including changed restart E2E specs.

pty:hasPty answered from the provider's attached-this-run set, so right
after a restart every surviving session read as exited and #29459's
hidden-agent hold kept live hidden tabs disconnected until shown. On an
attached-set miss, ask the host through the provider's existing liveness
probe; providers without one (the in-process provider, its own sole
owner) keep their answer.
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The pty:hasPty handler now checks the provider’s local session map before probing liveness for other PTYs. The IPC test covers restored PTYs and confirms that the probe is not called for a locally known live PTY. The restart test now checks the hidden pane’s data-pty-id binding before reveal for live daemon sessions.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 030c8

The restart test should verify completed reattachment before merge; the implementation itself has no verified production defect.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: reconnecting hidden terminal tabs to sessions that survive a restart.
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.
Description check Passed The pull request description follows the required structure and provides clear ELI5, change, rationale, testing, visual proof, scope, and checklist details. It identifies the linked issue context as a…
Full details: Description check

Explanation

The pull request description follows the required structure and provides clear ELI5, change, rationale, testing, visual proof, scope, and checklist details. It identifies the linked issue context as a maintainer exception, documents manual QA limitations, and reports automated validation results.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

🧹 Nitpick comments: 1
tests/e2e/settled-worker-tab-survives-restart.spec.ts: 1

347-350: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a DOM assertion for the revealed terminal pane.

Keep the pre-reveal PTY binding check. After reveal, assert the reattached pane with a DOM locator. ensureTerminalVisible checks only store state, and visibleTab.toBeVisible() verifies the tab, not the rendered pane. This DOM assertion is required by the E2E test boundary and is not duplicative.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9b3473b3-08b7-41fb-af22-5238b433f677
📥 Commits

Reviewing files that changed from the base of the PR and between f812c67 and 7d2c719.

📒 Files selected for processing: 3
  • src/main/ipc/pty-startup-barrier-and-listing.test.ts
  • src/main/ipc/pty/ipc/inspect.ts
  • tests/e2e/settled-worker-tab-survives-restart.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

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

🧹 Nitpick comments: 1
tests/e2e/settled-worker-tab-survives-restart.spec.ts: 1

343-355: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert reattachment completion, not only the PTY binding.

data-pty-id is written before replay and payload application. A non-throwing false result can leave that binding intact because the caller only clears the pending serializer on that path. The later assertions check pane presence and host PTY liveness, not replay completion. Add an assertion or synchronization for completed reattachment before reveal.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d9964b7b-43e9-4df9-bb0c-ee4bb3d30bf4
📥 Commits

Reviewing files that changed from the base of the PR and between 7d2c719 and 030c83f.

📒 Files selected for processing: 1
  • src/main/ipc/pty-startup-barrier-and-listing.test.ts

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

@brennanb2025

brennanb2025 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor Author

After restarting Orca, a hidden terminal tab could stay disconnected from an agent that was still running. The liveness check mistook this run's empty attachment list for proof that the host session had ended, so output-driven updates did not reach the tab until it was opened.

This change asks the existing host liveness probe when attachment membership misses. Eligible hidden tabs reconnect to surviving sessions before reveal. A confirmed ended session still waits until reveal; visible restores and new terminals retain their existing paths.

The full review completed one correctness and architecture round, plus dedicated performance and readiness checks. No production correction was needed. The loop removed a test-fixture type assertion that blocked CI; all 22 targeted PTY tests passed. Existing compatibility fallbacks and all three renderer liveness callers were traced. A current host normally answers a single-session size request; older hosts and multi-generation ownership can use inventory. Individual RPC timeouts do not guarantee an end-to-end two-second bound.

Intended inherited limits: the liveness check and reconnect are separate, and unknown liveness reconnects. Only mounted eligible panes participate; other workspaces keep their existing lazy mounting. STA-11356 and STA-11405 remain outside this fix. Separate main-side uses of provider attachment membership are unchanged; their full user-facing impact was not reproduced in this review.

Review complete on f007ce61fed2fc3d26f2f148ae1d43df2bcb78a4, under Brennan's explicitly approved QA exception (2026-10-21). Full workflow 39514157609 passed on this head. No open P0/P1 finding remains.

Real QA on the M4Air used Claude 2.1.304 and a hidden app through the Chrome DevTools Protocol. Main (6e973fa6d4b5640744453f416c6265b96fe7fefd) reproduced the surviving host session staying disconnected until reveal. The branch reconnected the same original terminal session before reveal and received new output, title events and bells while hidden; reveal rendered retained output. The baseline app and renderer came from main but reused the branch's command-line build, so this remains a partial comparison. Screenshots are below.

The requested one-launch main control reproduced the same startup failure: branch f007ce61 timed out at 02:58:28.977 UTC and main 6e973fa6 at 05:00:13.868 UTC on 2026-10-21, both waiting 60 seconds for workspace-restoration readiness (workspaceSessionReady). All 4,115 existing build artifacts matched the saved main build, so no rebuild was needed. The only controller changes were its Chrome DevTools Protocol and runtime port numbers, taken from fresh QA admission 1017; isolation, shutdown and the readiness wait were unchanged. This establishes that the timeout also occurs on main in this setup; it does not diagnose the timeout or prove the remaining feature flows.

The automated settled-worker-tab-survives-restart run passed both cases (2/2): hidden live-session reconnect before reveal, and the exited-session hold/reveal recovery path. The latter checks that the tab survives and allows at most one resume launch with the saved session ID; it does not require a launch or prove a real agent reply. The final-head full workflow also passed the changed restart tests. Under the explicit ruling, this automated evidence is accepted for the recovery flows the real QA setup could not reach.

Not exercised in real QA: the ended-session no-hidden-launch / exactly-one-resume flow with real replies, a visible restored agent replying, and a new terminal rendering command output. The branch and the requested main comparison both stalled at the same 60-second workspace-restoration readiness wait before those flows could run. No real-QA success is claimed for them. This exception accepts the passing end-to-end coverage with these remaining limits disclosed.

The one main launch was shut down through the unchanged helper. The final audit found no surviving recorded process identities and all assigned ports clear. The QA worktree was restored clean to f007ce61; its ignored build artifacts remain the verified main build. The worker and evidence terminal are released, and admission 1017 is done. No product code, commits or pushes were added.

For Brennan's review

Partial live-session comparison, before opening the hidden agent tab:

Main: hidden session held Branch: original session bound and bell received
Main after restart, before reveal Branch after restart, before reveal

After reveal:

Main Branch
Main revealed Branch revealed

Main real reply

No ended-session or final-control screenshot is claimed.

  • The host-probe fallback is the entire production change.
  • The existing reconnect-on-unknown and check/reconnect timing choices remain intentional.

@brennanb2025
brennanb2025 merged commit b2370f1 into main Oct 21, 2026
39 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/hidden-tab-liveness-fix branch October 21, 2026 05:14
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