Skip to content

fix(terminal): hidden tabs reconnect to their still-running session after a restart - #30926

Closed
brennanb2025 wants to merge 11 commits into
mainfrom
brennanb2025/hidden-tab-attach-only
Closed

brennanb2025 wants to merge 11 commits into
mainfrom
brennanb2025/hidden-tab-attach-only

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 31 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1113 $\color{#cf222e}{\Huge{\mathbf{−}}}$​254 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​859
Prod 57 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1005 $\color{#cf222e}{\Huge{\mathbf{−}}}$​501 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​504

ELI5

When Orca restarts, terminal tabs you aren't looking at should quietly reconnect to agents that are still running, so Orca keeps seeing their output (bells, titles, agent status). Since #29459 they don't: a hidden tab asks "is my session still running?", the answer comes from a list that only knows terminals reconnected since the restart, so a running session looks finished and the tab waits until you open it. This PR makes the hidden tab reconnect only to a session that's still running, and never start a new one, and makes that question ask the terminal background service directly.

What Changed

Before: after a restart, a hidden tab with a running agent stayed disconnected until you opened it. Output that arrived meanwhile wasn't seen. The daily full E2E run (settled-worker-tab-survives-restart) has failed on this since 10-18.

After:

Mechanism:

  • Reconnect only, never create. A hidden tab's restore attempt now carries an "attach only" flag from the renderer through to the terminal provider. Every path that used to fall through to starting a fresh session refuses instead: no saved owner, an owner released after "not found", and a missing session id. The providers already supported attach-only; this connects the renderer's restore to it. When the answer is "not found", the tab arms the existing hold-until-shown, whose wake is the normal full restore.
  • The liveness question tells the truth. pty:hasPty keeps its fast "yes, attached here" answer. When that list says no, it now asks the terminal background service (the existing probePtyLiveness). Only the in-process local provider may still answer "no" without asking, as before. Overlapping questions about the same terminal share one request. This also fixes typing into a terminal that isn't reconnected yet, which asked the same question and read "no" as "the session ended".
  • The hidden tab's separate "is it still running?" check before reconnecting is removed: trying to attach answers that question, without a window in which the answer goes stale.

Why

Only checking liveness first, then reconnecting with the ability to create, would leave two ways for a hidden agent to restart in the background: the session ends between the check and the reconnect, or the terminal service doesn't answer during a restart. The common pattern keeps "is it alive" and "may I create one" separate, and adopts an existing session through an operation that cannot create. This follows that. Fixing only the reconnect would leave the liveness question wrong for its other callers, so both are in this PR.

Differences from the common pattern:

  • Intended: hidden live sessions reconnect immediately rather than on first view, because Orca reads bells, titles and agent status from their output.
  • Intended: older terminal services without native attach-only use the existing emulation, which may briefly start and immediately retire a shell before reporting "not found". It never launches the agent.

Linked Issue

N/A (maintainer). Daily E2E failure, for example https://github.com/stablyai/orca/actions/runs/39307965554 (settled-worker-tab-survives-restart, "liveness before reveal").

Visual Proof

Pending real QA on a QA machine: restart with a hidden tab running an agent, then with a hidden tab whose agent has ended.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Named vitest files pass (stable-owner no-create cases; pty:hasPty true/false/unknown/failure and shared overlapping probes; the hidden sleeping-resume renderer spec). The E2E "liveness before reveal" check now asserts the pane is actually bound to its session instead of asking hasPty.

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 or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…ession

After a restart, a hidden tab whose agent was still running in the terminal
daemon stayed detached until shown: the hidden sleeping-agent deferral asked
pty:hasPty, which answers from the set of sessions this app run attached, so
every surviving session read as exited and was held until reveal.

A hidden sleeping-agent restore is now an attach-only connect end to end
(renderer transport, preload, main spawn options, early adoption and the
stable-owner path). A live session attaches eagerly; absence or any other
failure keeps the saved binding and arms the existing reveal hold, whose wake
runs the ordinary restore. Nothing after an attach-only attempt can create a
PTY or resume the agent while the pane is hidden.

pty:hasPty keeps its fast attached answer and its guards, and resolves a miss
from the host's liveness probe (only the in-process provider may answer false
without one), sharing overlapping probes per provider and id.
@brennanb2025
brennanb2025 marked this pull request as ready for review October 19, 2026 23:22
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: d7a925f4-4597-4312-8f80-8e3bea4c39d3
📥 Commits

Reviewing files that changed from the base of the PR and between 55cee0a and f2c36af.

📒 Files selected for processing: 19
  • src/main/acp/acp-tool-timeline.ts
  • src/main/codex/codex-structured-journal-translation-turn-lifecycle.test.ts
  • src/main/ipc/pty/ipc/spawn-execute.ts
  • src/main/ipc/pty/ipc/spawn-preflight.ts
  • src/main/ipc/pty/ipc/spawn-types.ts
  • src/main/ipc/pty/pane/adopt-stable.ts
  • src/main/ipc/pty/pane/attach-only-spawn-options.ts
  • src/main/ipc/pty/pane/stable-owner.ts
  • src/main/jsonl-rpc/timeline-final-tail.test.ts
  • src/main/jsonl-rpc/timeline-lane.ts
  • src/main/native-chat/agent-session-journal/journal-completed-content.test.ts
  • src/main/native-chat/agent-session-wire/agent-session-item-wire-form.test.ts
  • src/main/native-chat/agent-session-wire/agent-session-item-wire-form.ts
  • src/main/pi/rpc-messages.ts
  • src/main/pi/rpc-session.ts
  • src/renderer/src/components/native-chat/NativeChatToolOutput.test.tsx
  • src/renderer/src/components/native-chat/NativeChatToolOutput.tsx
  • src/renderer/src/components/terminal-pane/pty-connection-test-store-state.ts
  • src/renderer/src/i18n/locales/en.json
🚧 Files skipped from review as they are similar to previous changes: 1
  • src/renderer/src/i18n/locales/en.json

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

📝 Walkthrough

The change adds attach-only PTY requests that adopt existing sessions without creating new ones. Renderer restore and reattach paths now use structured outcomes with generation tracking. Sleeping-session selection and cleanup use pane identity and provider-session claims. The terminal UI adds retry handling for unverifiable reattachments. Tests cover attach failures, liveness probes, restore outcomes, sleeping-record cleanup, and hidden-session recovery.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to f2c36

A hidden terminal tab that remounts while its session spawn is still pending can stay disconnected and not bind to its session. Fix this binding path before merge, or explicitly accept the risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.35% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 71 functions across 66 files. (1 skipped:… 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 primary change: hidden terminal tabs reconnect to still-running sessions after a restart.
Description check Passed The description is detailed and covers the required ELI5, changes, rationale, issue context, testing, scope, and checklist. Visual proof and full local validation remain pending, but these omissions d…
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 is detailed and covers the required ELI5, changes, rationale, issue context, testing, scope, and checklist. Visual proof and full local validation remain pending, but these omissions do not make the description incomplete or off-topic.

Full details: Docstring Coverage

Explanation

Docstring coverage is 25.35% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 71 functions across 66 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fb7fa890-b482-44e6-84ce-512509d1d2cb
📥 Commits

Reviewing files that changed from the base of the PR and between e7d6ee6 and 442e9c6.

📒 Files selected for processing: 73
  • src/main/ipc/pty-spawn-codex-home-unavailable.test.ts
  • src/main/ipc/pty-startup-barrier-and-listing.test.ts
  • src/main/ipc/pty/ipc/inspect.ts
  • src/main/ipc/pty/ipc/spawn-commit.ts
  • src/main/ipc/pty/ipc/spawn-env-codex.ts
  • src/main/ipc/pty/ipc/spawn-env.ts
  • src/main/ipc/pty/ipc/spawn-execute.ts
  • src/main/ipc/pty/ipc/spawn-options.ts
  • src/main/ipc/pty/ipc/spawn-preflight.ts
  • src/main/ipc/pty/ipc/spawn-run.ts
  • src/main/ipc/pty/ipc/spawn-types.ts
  • src/main/ipc/pty/pane/adopt-stable.ts
  • src/main/ipc/pty/pane/stable-owner.ts
  • src/main/ipc/pty/pane/stable-pane-absence-respawn.test.ts
  • src/main/ipc/pty/provider/liveness.ts
  • src/main/ipc/pty/runtime/operations.ts
  • src/main/ipc/pty/spawn-options-assembly.ts
  • src/preload/api/pty-api.ts
  • src/preload/api/pty-bridge-session-control.ts
  • src/renderer/src/components/terminal-pane/TerminalErrorToast.tsx
  • src/renderer/src/components/terminal-pane/TerminalPaneSurface.tsx
  • src/renderer/src/components/terminal-pane/ipc-pty-opencode-model.test.ts
  • src/renderer/src/components/terminal-pane/ipc-pty-spawn-request.ts
  • src/renderer/src/components/terminal-pane/pty-connection-agent-session-resume.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection-cold-restore-agent-resume.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection-cold-restore-resume-command.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection-command-finished-cleanup.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection-deferred-reattach-live-output.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection-hibernation-wake.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection-hidden-sleeping-resume.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection-pending-spawn.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection-reattach-binding.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-remote-runtime-attach.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection-sleeping-resume-banner.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection-test-pane-fixtures.ts
  • src/renderer/src/components/terminal-pane/pty-connection-test-store-fixtures.ts
  • src/renderer/src/components/terminal-pane/pty-connection-test-store-state.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.ts
  • src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-cold-restore-and-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-choice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-newer-daemon-hold.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-startup-snapshot.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-types.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hibernated-agent-wake-completion.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-agent-resume-deferral.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-agent-resume-deferral.ts
  • src/renderer/src/components/terminal-pane/pty-connection/in-place-resume-hold-wiring.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-binding.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-connect-limits.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-session.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler-park-reveal-verdict.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-success-settle.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.ts
  • src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts
  • src/renderer/src/components/terminal-pane/pty-connection/unbound-pane-spawn-recovery.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/components/terminal-pane/terminal-error-accumulation.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-projection.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-title-state.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/sleeping-pane-record-selection.ts
  • src/renderer/src/runtime/sleeping-records-to-layout-owner.test.ts
  • src/renderer/src/store/slices/agent-status-recovery-actions.ts
  • src/renderer/src/store/slices/agent-status-runtime.ts
  • src/renderer/src/store/slices/agent-status-slice-contract.ts
  • tests/e2e/helpers/completed-worker-retirement-fixture.ts
  • tests/e2e/settled-worker-tab-survives-restart.spec.ts
💤 Files with no reviewable changes: 2
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-session.ts
  • src/main/ipc/pty/ipc/spawn-env-codex.ts

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Superseded by #31254, which restores the intended behaviour with a minimal fix to the session liveness check. This larger version also made hidden reconnects attach-only end to end; it is not needed to fix the regression.

@brennanb2025
brennanb2025 deleted the brennanb2025/hidden-tab-attach-only branch October 21, 2026 05:13
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