Skip to content

Keep runtime mirror sized with desktop terminal resizes - #7192

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/mirror-resize-fanout
Jul 3, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/mirror-resize-fanout

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Symptom

Hidden-output restore snapshots come from the main-process runtime mirror. On desktop, accepted PTY resizes updated the PTY and renderer geometry state, but the runtime mirror stayed at its birth dimensions. That explains the v1.4.119 garble report: normal-buffer TUI status repaints could soft-wrap inside the stale-width mirror, so cursor-up repaints stacked instead of overwriting and later restores painted the corrupted ladder back into the renderer.

Mechanism

Desktop has three terminal parsers involved in restore correctness: the PTY, the renderer terminal, and the runtime mirror. The local pty:resize handler resized the provider PTY and cached accepted size, then only reported geometry to the runtime. Remote desktop viewport resize already touched the mirror, but did so immediately instead of preserving output ordering.

Fix

  • Queue runtime mirror resizes on the same per-PTY writeChain used for PTY output bytes.
  • Fan accepted desktop resizes through onExternalPtyResize, so local desktop IPC and remote desktop viewport resizes both update the mirror after the provider accepts the resize.
  • Preserve existing suppression/mobile-fit override gates and rejected-provider behavior.

Ordering Rationale (F3)

Resize reflow is parser state. If it jumps queued output bytes, the mirror can parse bytes at the wrong width and bake a bad snapshot even when the final dimensions are right. This PR serializes mirror resize reflow with output writes, matching the daemon-side discipline where emulator and PTY resize order are coupled.

Tests

Red-proven before the fix:

  • resizes the headless mirror after an accepted desktop PTY resize failed with snapshot 80x24 instead of 120x30.
  • orders headless mirror resizes behind queued PTY writes failed because ESC[90GOLD parsed at 120 columns instead of the queued 80-column position.

Green validation:

  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orca-runtime.test.ts -t "headless mirror"
  • pnpm exec vitest run --config config/vitest.config.ts src/main/ipc/pty.test.ts -t "desktop resizes"
  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orca-runtime.test.ts src/main/ipc/pty.test.ts (745 passed)
  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime src/main/daemon src/main/ipc 2>&1 | tail -n 80 (3503 passed; one known unrelated pty-subprocess.test.ts WSL env assertion failed, matching the brief's known-failure note)
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts (295 passed)
  • pnpm run typecheck
  • Commit hook: oxlint, oxlint react doctor, oxfmt

Perf Note

No polling, timers, renderer hot-path work, or per-output-chunk cost was added. The only new cost is one runtime mirror reflow per accepted resize for an existing headless mirror. Resize storms serialize naturally through the existing per-PTY chain; this keeps correctness without debounce windows that could reintroduce stale mirror dimensions.

Reliability Proof

Reliability invariant: terminal-session.snapshot-freshness / terminal-geometry.visible-convergence — hidden-output restore snapshots must be parsed at the PTY geometry that accepted subsequent bytes, and resize reflow must not jump queued output.

Material impact: this blocks the stale-runtime-mirror class that turns in-place TUI repaints into permanent restore corruption.

Product change type: mixed runtime hardening plus regression coverage.

Performance risk inventory: touches resize, hidden-output snapshot freshness, runtime mirror parser ordering, local desktop IPC, and remote desktop viewport resize. It does not touch renderer rendering, typing, focus, startup, provider listing, or polling loops.

No-regression evidence: the targeted red/green tests prove both geometry fan-out and write-chain ordering; touched files and the broader runtime/daemon/ipc sweep were run; typecheck and hook lint/format passed.

Provider/platform coverage: local desktop PTY resize is covered through IPC tests; remote desktop resize is covered through updateDesktopViewport; daemon/SSH/WSL/Windows provider differences are preserved by only acting after provider resize acceptance and by retaining rejected-resize behavior. Mobile/relay layout paths keep using the same mirror resize primitive, now ordered. Live Windows/SSH device runs are not included.

Residual gaps: F2/F4/F5/F6/F7 remain follow-ups by design. This PR does not add new manifest promotion; gate status is partial through deterministic unit/integration coverage.

Rollback or demotion rule: if resize storms show measurable mirror reflow pressure, if provider resize drops are observed to update snapshots incorrectly, or if hidden-output restore shows fresh stale-dimension ladders, demote the gate and revert this fan-out while preserving the red tests as the diagnostic oracle.

Out Of Scope

F2, F4, F5, F6, and F7 are intentionally left for follow-up PRs.

Made with Orca 🐋

Desktop has three terminal parsers in play: the PTY, the renderer terminal, and the main-process runtime mirror used for hidden-output restore snapshots. The desktop resize path updated the PTY and renderer geometry bookkeeping but left the runtime mirror at its spawn dimensions, so normal-buffer TUI redraws could wrap and stack in the mirror before being restored into the renderer.

Fan accepted desktop resizes into the runtime mirror and serialize mirror resize reflow on the same per-PTY writeChain as output bytes. This keeps resize ordering aligned with PTY data and avoids resizing the mirror for rejected provider resizes.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 3, 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: f330666a-e02a-4eae-8628-4f5f74ac15c5

📥 Commits

Reviewing files that changed from the base of the PR and between 4caea00 and d4407f5.

📒 Files selected for processing (3)
  • src/main/ipc/pty.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts

📝 Walkthrough

Walkthrough

This change modifies how headless terminal resizing is synchronized in the runtime. resizeHeadlessTerminal now applies emulator resize serialized behind the PTY's write chain and swallows resize errors, rather than resizing directly. The direct resize call previously invoked from an earlier resize path was removed, and onExternalPtyResize now triggers headless resize mirroring before refreshing renderer geometry. Corresponding tests were added in pty.test.ts to verify resize fan-out to the runtime on accepted/rejected provider resizes, and in orca-runtime.test.ts to verify headless mirror resizing and its ordering relative to queued PTY writes.

Sequence Diagram(s)

sequenceDiagram
  participant Provider
  participant OrcaRuntime
  participant HeadlessEmulator

  Provider->>OrcaRuntime: resize succeeds
  OrcaRuntime->>OrcaRuntime: onExternalPtyResize(ptyId, cols, rows)
  OrcaRuntime->>OrcaRuntime: resizeHeadlessTerminal(ptyId, cols, rows)
  OrcaRuntime->>OrcaRuntime: writeChain queued writes complete
  OrcaRuntime->>HeadlessEmulator: resize(cols, rows)
  OrcaRuntime->>OrcaRuntime: refreshRendererGeometry(ptyId, cols, rows)
Loading

Related issues: None specified.

Related PRs: None specified.

Suggested labels: runtime, testing

Suggested reviewers: None specified.

🥕 A hop, a skip, a resized pane,
The headless mirror joins the chain,
Writes go first, then size falls in line,
Tests confirm each timing sign,
A rabbit's nod to orderly panes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it does not follow the repository's required PR template sections and checklist structure. Rewrite the PR description to match the template with Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: keeping the runtime mirror sized with desktop terminal resizes.
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.
✨ 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.

@brennanb2025
brennanb2025 merged commit d65c938 into main Jul 3, 2026
2 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/mirror-resize-fanout branch July 3, 2026 05:42
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.

1 participant