Repository navigation
Keep runtime mirror sized with desktop terminal resizes - #7192
Conversation
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]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis change modifies how headless terminal resizing is synchronized in the runtime. 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)
Related issues: None specified. Related PRs: None specified. Suggested labels: runtime, testing Suggested reviewers: None specified. 🥕 A hop, a skip, a resized pane, 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
Co-authored-by: Orca <[email protected]>
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:resizehandler 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
writeChainused for PTY output bytes.onExternalPtyResize, so local desktop IPC and remote desktop viewport resizes both update the mirror after the provider accepts the resize.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 resizefailed with snapshot80x24instead of120x30.orders headless mirror resizes behind queued PTY writesfailed becauseESC[90GOLDparsed at120columns instead of the queued80-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 unrelatedpty-subprocess.test.tsWSL 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 typecheckPerf 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 🐋