Skip to content

Keep new terminal tabs open during startup - #6796

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-terminal-tab-crash
Jun 29, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-terminal-tab-crash

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Prevents newly created local terminal tabs and agent terminal tabs from being mistaken for dead sessions during startup. The dead-session reconciler now runs only after a real hidden-to-visible resume, while fresh mounts start with resume-only liveness probes disarmed until a true resume re-arms one check.

This does not change normal shell or agent process failures after startup. If Codex/Claude needs trust/auth/quota input, the terminal tab should persist and show that prompt rather than closing immediately.

Fixes #6773.

Design Approach

  • Treat previousIsVisible === false && isVisible === true as the only visibility resume edge.
  • Gate both the dead-session reconcile pass and noteVisibilityResume() behind that edge.
  • Start input-triggered liveness rechecks disarmed on a fresh PTY binding, then let noteVisibilityResume() grant exactly one post-resume input probe.
  • Preserve existing SSH and remote: web-runtime skips because local listSessions() is not authoritative for those PTYs.
  • Route spawn-time size reconcile resize forwarding through the existing mobile-fit/PTY-lock suppression.

Design Review Outcome

Design review was clean after tightening the plan around input-triggered liveness: fresh mounts must not arm listSessions() from the first terminal input, and real agent terminal Electron validation is required.

Implementation

  • Added isTerminalPaneVisibilityResume and passed previous visibility into scheduleVisibilityReconcilePass.
  • Updated the lifecycle visibility effect to call resume-only binding hooks only on true hidden-to-visible transitions.
  • Reworked PTY input liveness to use a resume token that starts disarmed, is consumed before provider checks, and is re-armed by the next resume.
  • Added focused tests for initial mount, true resume, fresh input, one-shot post-resume input, second-resume re-arm, SSH skip, and remote-runtime skip.

No deviations from the reviewed design.

Completeness Verification

Read-only completeness verification found the headline behavior implemented with no blockers. It confirmed startup-time dead-session reconciliation no longer applies to fresh terminal/agent launches, while real hidden-session cleanup remains available on resume.

Headline Behavior Status

Implemented. The shared local terminal startup path used by New Terminal and tab-menu agent launches no longer runs authoritative dead-session checks during PTY birth.

Broad App Consistency

Source-of-truth behavior compared: desktop active-workspace tab bar New tab menu.

Compared neighboring surfaces:

  • New tab -> New Terminal
  • New tab -> Codex agent terminal launch
  • keyboard/new-terminal path through the same lifecycle
  • split/floating terminal neighboring PTY startup behavior
  • status/resource backing state
  • SSH and web-runtime liveness ownership

This PR fixes the local desktop terminal/agent tab persistence mismatch without changing visible labels, menu order, shortcuts, remote ownership, or mobile terminal behavior.

Risks, Ambiguities, And Non-Goals

  • Agent command success is not guaranteed by this change. Auth, trust, missing CLI, or quota prompts can still appear inside the persistent terminal.
  • Natural PTY exits after startup still use existing exit handling.
  • Remote/web-runtime and SSH reconciliation are intentionally unchanged.
  • The first input into a genuinely dead newborn PTY will not run the resume-only liveness probe; normal startup/exit handling owns that case because daemon listSessions() can lag during PTY birth.

Perf Audit

Perf audit found no performance bug. The diff reduces initial-mount daemon listing work, avoids fresh-input listSessions() polling, preserves one-shot post-resume checks, and keeps mobile-fit resize suppression in the spawn reconcile path. Existing deterministic call-count tests were considered sufficient.

Code Review

Code-review loop ran one round with two parallel reviewers. Both returned clean, with no actionable findings and no fixes required.

Brennan Test Changes Result

Verdict: land.

Electron validation used a separate dev app launched from this worktree with CDP, a temporary user-data path, and a disposable local git repo/workspace. App identity confirmed devRepoRoot: /Users/thebr/orca/workspaces/orca/seabiscuit.

Manual validation screenshots:

  • New terminal tab persisted: /var/folders/nk/tt6kt56s3hn9rv32dj7kymv00000gn/T/orca-terminal-validation.TQ4LPl/new-terminal-terminal-2.png
  • Real Codex agent terminal persisted at trust prompt: /var/folders/nk/tt6kt56s3hn9rv32dj7kymv00000gn/T/orca-terminal-validation.TQ4LPl/codex-agent-terminal-3.png

Observed:

  • New tab -> New Terminal: after 6s, Terminal 2 remained selected with shell prompt and a backing PTY listed by window.api.pty.listSessions().
  • New tab -> Codex: after 12s, Terminal 3 remained selected, launchAgent: "codex", with Codex trust prompt visible and a backing PTY listed by window.api.pty.listSessions().

Checks

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.ts src/renderer/src/components/terminal-pane/terminal-dead-session-reconcile.test.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-size-reconcile.test.ts
  • pnpm exec tsgo --noEmit -p config/tsconfig.tc.web.json
  • pnpm run lint passed with one existing warning in useGitStatusPolling.ts outside this diff
  • git diff --check

Post-PR Stabilization

CodeRabbit stabilization completed: one actionable comment was addressed in commit 82f3239, and the refreshed CodeRabbit review reported no actionable comments. PR checks are passing: verify and wayland terminal input.

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The changes refactor how terminal pane visibility resumes are detected and acted upon. A new exported helper isTerminalPaneVisibilityResume encapsulates the hidden→visible transition check. scheduleVisibilityReconcilePass gains a previousIsVisible parameter and only schedules dead-session reconciliation on a true resume. In connectPanePty, the liveness recheck flag is renamed from livenessRecheckFiredSinceResume to livenessRecheckArmedForResume, armed in noteVisibilityResume and consumed immediately in recheckLivenessAfterInput. PTY resize in reconcilePtySizeAfterSpawn is now conditioned on shouldSuppressDesktopPtyResize(). Tests are updated and extended throughout.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main fix: keeping new terminal tabs open during startup.
Linked Issues check ✅ Passed The changes address #6773 by preventing fresh terminal and agent tabs from being treated as dead sessions at startup.
Out of Scope Changes check ✅ Passed No clear out-of-scope code changes are present; the resize and remote/SSH adjustments support the stated terminal startup fix.
Description check ✅ Passed The description is mostly complete and covers the change, design, testing, and validation, with only minor template section omissions.
✨ Finishing Touches
📝 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.

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4383a587-e379-49e8-927f-e58e772e4d50

📥 Commits

Reviewing files that changed from the base of the PR and between ab1aac2 and 4252f50.

📒 Files selected for processing (4)
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts

@brennanb2025
brennanb2025 merged commit 53e2582 into main Jun 29, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

[Bug] Cannot create new tab/agent

1 participant