Skip to content

fix(terminal): avoid stale PTY resize after tab reveal#7961

Open
gatsby74 wants to merge 1 commit into
stablyai:mainfrom
gatsby74:gatsby74/issue-7951-bug-terminal-ui
Open

fix(terminal): avoid stale PTY resize after tab reveal#7961
gatsby74 wants to merge 1 commit into
stablyai:mainfrom
gatsby74:gatsby74/issue-7951-bug-terminal-ui

Conversation

@gatsby74

@gatsby74 gatsby74 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Proposes a potential fix for the terminal UI breakage reported in #7951. When a hidden terminal becomes visible, the PTY size reassertion captures xterm dimensions and asynchronously reads the size applied to the PTY. A reveal-time fit can change xterm while that read is in flight; the old callback can then resize the PTY back to the pre-reveal grid, matching the report that affected sessions remain at 80x24 or an extremely narrow size until a manual window resize repairs them.

This change re-measures xterm after the applied-size read. If the visible grid changed, it suppresses the stale resize and queues a fresh reconciliation pass against the latest dimensions. A regression test covers a reveal-time change from 80x24 to 145x78 and verifies that the stale 80x24 target is never forwarded.

Screenshots

No visual change.

Testing

  • pnpm lint (not run end-to-end; targeted oxlint passed)
  • pnpm typecheck (not run end-to-end; pnpm run typecheck:web passed)
  • pnpm test (not run end-to-end; focused test file passed 10/10)
  • pnpm build (not run)
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Targeted validation:

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-size-reassertion.test.ts
  • pnpm exec oxlint src/renderer/src/components/terminal-pane/pty-size-reassertion.ts src/renderer/src/components/terminal-pane/pty-size-reassertion.test.ts
  • pnpm exec oxfmt --check src/renderer/src/components/terminal-pane/pty-size-reassertion.ts src/renderer/src/components/terminal-pane/pty-size-reassertion.test.ts
  • pnpm run typecheck:web
  • pnpm run check:max-lines-ratchet
  • git diff --check

Released Orca 1.4.130 was also exercised with a live stty size probe, hidden-terminal window resizing, 60 rapid same-worktree tab switches, 40 rapid cross-worktree switches, and a coordinated 60-cycle CLI switch loop while manually alternating the native window width.

AI Review Report

Reviewed the visibility-resume PTY reconciliation flow, including target capture, asynchronous applied-size readback, request coalescing, disposal/rebinding guards, and resize forwarding. The main risk checked was that a second layout change could cause either a stale resize or overlapping reconciliation loops. The implementation keeps at most one read in flight, reuses the existing pending-pass mechanism, and forwards only after the captured and latest xterm grids match. The regression test verifies that the stale target is not sent and that the latest target is forwarded once.

Cross-platform review covered macOS, Linux, and Windows. This change uses existing renderer-side terminal dimensions and promise scheduling only; it adds no shortcuts, labels, file paths, shell behavior, or Electron platform APIs. Local and app-managed SSH PTYs retain the existing applied-size path and resize suppression rules. remote: runtime PTYs remain excluded by the existing reassertion gate because their viewport transport does not use pty:getSize; that path is unchanged. Mobile-owned/suppressed PTYs, PTY rebinding, and disposal checks are also unchanged.

Agent and integration compatibility is provider-neutral because the fix operates below individual CLI agents and git providers. Performance risk is limited to one synchronous dimension read after each applied-size response and one coalesced follow-up pass only when the grid changed during the read. No additional code changes were needed after review.

Security Audit

No new input handling, command execution, filesystem/path access, authentication, secrets, dependencies, IPC channels, or network behavior were introduced. The code reads existing in-memory xterm dimensions and uses the existing authenticated PTY size read/resize paths. The new guard reduces the chance of sending an obsolete resize and does not broaden which PTYs are eligible for resizing. No follow-up security work was identified.

Notes

  • Refs [Bug] Terminal UI breakage on switching #7951 as a potential solution; the reported corruption was not reproduced locally.
  • Reproduction attempts used released Orca 1.4.130 on macOS 26.5.1 (25F80). The PTY followed observed widths including 179, 38, 103, and 116 columns without remaining stale.
  • Because [Bug] Terminal UI breakage on switching #7951 reports local and remote-server sessions, confirmation from the affected setup is still needed, especially for the separate remote: runtime viewport path.
  • X/Twitter handle: not provided.

@gatsby74 gatsby74 marked this pull request as ready for review July 9, 2026 18:50
@coderabbitai

coderabbitai Bot commented Jul 9, 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: Pro

Run ID: c4137a9c-d565-4f14-9144-9818ab1e46de

📥 Commits

Reviewing files that changed from the base of the PR and between ff661a7 and 82f9e87.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/pty-size-reassertion.test.ts
  • src/renderer/src/components/terminal-pane/pty-size-reassertion.ts

📝 Walkthrough

Walkthrough

The forwardIfDrifted function in pty-size-reassertion.ts now re-reads the terminal's current dimensions before deciding whether to forward the originally observed target size back to the PTY. If the re-measured dimensions differ from the original target, forwarding is skipped and a pending flag is set for a later re-run, instead of forwarding potentially stale dimensions. Corresponding test coverage was updated to reflect the additional dimension re-measurement call, and a new test was added verifying that only the latest dimensions are forwarded when xterm dimensions change while an applied-size read is still in flight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately captures the main change: preventing stale PTY resizes after tab reveal.
Description check ✅ Passed The description follows the template and includes summary, screenshots, testing, AI review, security audit, and notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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.

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