Skip to content

feat(dashboard-popout): size the terminal dialog's PTY to the dialog grid - #9997

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/popout-dialog-grid-claim
Jul 23, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/popout-dialog-grid-claim

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

What

The experimental agent-dashboard popout's terminal dialog previously rendered the pane's serialized frame at its original cols/rows and CSS-scaled it down to fit — shrunken, blurry, and sized by the main window rather than the dialog. The dialog now claims the PTY grid for its own box: the PTY reflows to the dialog's dimensions and renders crisp and full-size, exactly like a normal terminal.

How

  • Reuses the existing remote-desktop viewer registry (updateRemoteDesktopViewer / unregisterRemoteDesktopViewer) with a synthetic dashboard-popout:<contentsId> viewer key — the dialog is just another remote viewer of the shared PTY:
    • main-window pane parks under the established remote-desktop-fit hold (no lock banner, input still shared), and reclaims its geometry when the claim is released (dialog close, unsubscribe, or popout window destruction);
    • a phone-driven PTY keeps the floor — the claim politely loses and the dialog falls back to the previous scale-to-fit rendering.
  • New popout-gated terminalPreview:fit IPC; claims tracked per webContents so they can never leak past the window's lifetime.
  • TerminalPreviewOutputStream.requestResync() + a subscribeToTerminalResize hook: any grid change under a live preview stream (fit landing, host reclaim, phone takeover) pushes a resync so the dialog repaints from a snapshot at the new grid. This also fixes a pre-existing bug where the open dialog garbled if the pane resized under it.
  • Renderer preview-grid-claim.ts: measures the cell size from .xterm-screen layout dims (transform-immune), computes the grid the box holds (clamped to the runtime's 20–240 × 8–120 viewport range), debounced 200 ms, and keyed by target dims — an unchanged target is never re-requested, so a host/phone taking the grid back cannot start a resize tug-of-war.
  • preview-clipboard-shortcuts.ts extracted verbatim from AgentTerminalPreview (max-lines cap).

Evidence (live Electron QA, real zsh PTY)

stty size in the shared PTY proves the grid at each step.

1. Before — main pane owns the grid (58×135):

1-main-before.png

2. Popout board with the agent card:

2-board.png

3. Dialog open — PTY reflowed to the dialog grid (33×107), terminal fills the dialog at scale 1 (screen 902×528 in a 906×536 box, no CSS transform):

3-dialog.png

4. Main pane during the hold — same content at the held grid, no garbling, no lock banner:

4-main-during.png

5. Dialog closed — main pane reclaims its geometry (58×135):

5-main-after.png

Tests

  • terminal-preview.test.ts: fit claims + reported effective size, claim release on unsubscribe/sender destruction (one-shot), resize→resync push, non-popout sender rejection.
  • AgentTerminalPreview.test.tsx: claims the grid matching the dialog box, never re-requests an unchanged target after a reconnect.
  • 44 targeted vitest tests green; typecheck node/web/cli green; oxlint green.

Notes

  • SSH/WSL PTYs go through the same enqueueLayout → provider resize path the mobile/remote-desktop flows already use.
  • Known inherited caveat: xterm mouse selection misaligns under a CSS scale() — after this PR that only applies in the rare fallback mode (phone owns the grid).

Reliability and performance contract

  • Invariant — terminal-geometry.visible-convergence: while a preview is live, the applied PTY grid, main-process headless snapshot, and preview xterm converge after every viewer/host/mobile ownership change; unsubscribe and popout destruction release the preview's resize floor.
  • Failure source: the popout previously rendered the main pane's grid through a blurry CSS shrink, and a live preview could become garbled when the underlying PTY resized.
  • Oracle: the attached live stty size sequence proves dialog claim and host reclaim. Deterministic tests prove effective-size reporting, resize-to-resync ordering, one-shot cleanup, stale/in-flight claim rejection, unchanged-target deduplication, and ACK-before-resync behavior.
  • Gate: config/reliability-gates.jsonc → terminal-geometry.visible-convergence; its 8-file command passes (1,363 tests). Focused preview/remote-desktop/mobile ownership coverage also passes (110 passed, 2 skipped).
  • Provider/platform coverage: live evidence is local macOS. Local, daemon, SSH, and remote-runtime geometry use the shared enqueueLayout contract covered by the gate; mobile precedence/fallback is covered deterministically. Live Linux, Windows/ConPTY, SSH, and WSL popout runs remain gaps.
  • Performance budget: no polling, session inventory scan, subprocess, or unbounded retry was added. A continuous 1 s resize burst previously issued 5 fit/resize/resnapshot cycles; the final scheduler issues exactly 1 after settlement. Once a resize resync is pending, changed-grid output schedules 0 discard-only batch timers and resumes from the bounded authoritative snapshot.
  • Diagnostics: resize/resync event assertions and claim call counts identify ownership, convergence, and cleanup failures without recording terminal contents.
  • Residual gaps: the inherited CSS-transform selection offset remains possible only in fallback mode when another owner controls the grid; no live cross-platform/remote popout artifact is attached yet.

…grid

The popout agent-terminal dialog rendered the pane's serialized frame at its
original cols/rows and CSS-scaled it down to fit. The dialog now claims the
PTY grid for its own box through the remote-desktop viewer registry: the PTY
reflows to the dialog's dimensions (crisp, unscaled), the main-window pane
parks at the held grid like any remote viewer hold, and closing the dialog
releases the claim so the pane reclaims its geometry. A phone-driven PTY
keeps the floor; the dialog then falls back to the scale-to-fit rendering.

Any grid change under a live preview stream (fit landing, host reclaim,
phone takeover) now pushes a resync so the dialog repaints from a snapshot
at the new grid — this also fixes garbled dialogs when the pane resized
while a dialog was open.
@coderabbitai

coderabbitai Bot commented Jul 22, 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 Plus

Run ID: 96edc987-f215-40c2-8584-200b00be5ce7

📥 Commits

Reviewing files that changed from the base of the PR and between 7f5c41b and 2aff138.

📒 Files selected for processing (6)
  • src/main/ipc/terminal-preview-output-stream.ts
  • src/main/ipc/terminal-preview.test.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/dashboard-popout/preview-grid-claim.test.ts
  • src/renderer/src/components/dashboard-popout/preview-grid-claim.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/preload/index.ts
  • src/preload/api-types.ts
  • src/main/ipc/terminal-preview-output-stream.ts
  • src/renderer/src/components/dashboard-popout/preview-grid-claim.ts
  • src/main/ipc/terminal-preview.test.ts

📝 Walkthrough

Walkthrough

Terminal previews now resynchronize when PTY dimensions change and expose a fit IPC API for negotiated grid sizing. Main-process handlers track and release per-preview fit claims while updating remote desktop viewer dimensions. Dashboard popouts measure and debounce terminal grid requests, avoid duplicate fits, and clean up observers and claims. Clipboard shortcut handling was extracted into a dedicated Xterm helper. Tests cover resize resync, fit validation and cleanup, grid deduplication, and preview shortcut integration.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.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 matches the main change: sizing the dashboard popout PTY to the dialog grid.
Description check ✅ Passed It covers the user-visible change, visuals, tests, notes, and risk/perf details, though the template headings aren't followed exactly.
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

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

🧹 Nitpick comments (2)
src/main/ipc/terminal-preview.ts (1)

186-219: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Harden terminalPreview:fit input validation and claim bookkeeping.

Two related gaps in this handler:

  1. args.cols/args.rows are only checked with typeof === 'number' and Number.isFinite — no positive/integer/bounds check, unlike the sibling terminalPreview:ack handler which validates args.bytes against <= 0 and a max. A negative, zero, or non-integer value passes straight into runtime.updateRemoteDesktopViewer.
  2. claimed.add(ptyId) runs before updateRemoteDesktopViewer is awaited; if that call throws, the claim is left registered even though the update never landed, so a later release calls unregisterRemoteDesktopViewer for a viewer that may never have been established.

If clampTerminalViewport downstream already clamps values, point 1 is lower risk, but explicit boundary validation here is still cheap and matches the ack handler's existing pattern.

🛡️ Proposed fix
       if (
         !isDashboardPopoutRenderer(event.sender) ||
         !isValidPtyId(args?.ptyId) ||
         typeof args.cols !== 'number' ||
         typeof args.rows !== 'number' ||
         !Number.isFinite(args.cols) ||
-        !Number.isFinite(args.rows)
+        !Number.isFinite(args.rows) ||
+        args.cols < 1 ||
+        args.rows < 1
       ) {
         return null
       }
       const ptyId = args.ptyId
+      const cols = Math.floor(args.cols)
+      const rows = Math.floor(args.rows)
       // Why: guarantees the destroyed hook exists even if this claim outlives
       // the current output stream across a resync reconnect.
       subscriptionsFor(event.sender)
-      let claimed = fitClaimsByContents.get(event.sender.id)
-      if (!claimed) {
-        claimed = new Set()
-        fitClaimsByContents.set(event.sender.id, claimed)
-      }
-      claimed.add(ptyId)
       const viewerKey = previewViewerKey(event.sender.id)
       try {
-        await runtime.updateRemoteDesktopViewer(ptyId, viewerKey, viewerKey, args.cols, args.rows)
+        await runtime.updateRemoteDesktopViewer(ptyId, viewerKey, viewerKey, cols, rows)
       } catch {
         return null
       }
+      let claimed = fitClaimsByContents.get(event.sender.id)
+      if (!claimed) {
+        claimed = new Set()
+        fitClaimsByContents.set(event.sender.id, claimed)
+      }
+      claimed.add(ptyId)
       return runtime.getTerminalSize(ptyId)
src/renderer/src/components/dashboard-popout/preview-grid-claim.ts (1)

63-72: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Failed/unlanded fit requests permanently suppress retries at that exact grid size.

lastRequestedFit is set before the fit() promise settles and is never cleared on failure or a null (not-landed) result. If the same target size recurs later (e.g. a phone releases the grid, or a transient IPC failure), the dedup check skips the request entirely since the key still matches.

♻️ Proposed fix
     lastRequestedFit = fitKey
     // The resize triggers a main-side resync push; the reconnect snapshot
     // carries the new grid. If the claim didn't land (a phone owns the size),
     // the dialog's scaled fallback rendering stays correct as-is.
-    void window.api.terminalPreview.fit(args.ptyId, cols, rows)
+    void window.api.terminalPreview.fit(args.ptyId, cols, rows).then((effective) => {
+      if (!effective && lastRequestedFit === fitKey) {
+        // Allow a retry at this exact target once conditions change.
+        lastRequestedFit = null
+      }
+    })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 124c9a56-d0de-414a-90e3-576450c1f35c

📥 Commits

Reviewing files that changed from the base of the PR and between c6d2803 and cfc9de2.

📒 Files selected for processing (9)
  • src/main/ipc/terminal-preview-output-stream.ts
  • src/main/ipc/terminal-preview.test.ts
  • src/main/ipc/terminal-preview.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.test.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx
  • src/renderer/src/components/dashboard-popout/preview-clipboard-shortcuts.ts
  • src/renderer/src/components/dashboard-popout/preview-grid-claim.ts

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/components/dashboard-popout/preview-grid-claim.ts (1)

61-69: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reset lastRequestedFit when the fit request does not land.

terminalPreview:fit returns null when the requested grid is not applied, but this component commits fitKey before awaiting the result and discards the response. That suppresses future retries for the same target size even after the claim should be retried, so use the returned value to reset the cache key on null as well as on rejection.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4e54ce6c-097f-417a-beec-56fc0c875ee2

📥 Commits

Reviewing files that changed from the base of the PR and between cfc9de2 and 7f5c41b.

📒 Files selected for processing (5)
  • src/main/ipc/terminal-preview.test.ts
  • src/main/ipc/terminal-preview.ts
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx
  • src/renderer/src/components/dashboard-popout/preview-grid-claim.test.ts
  • src/renderer/src/components/dashboard-popout/preview-grid-claim.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx
  • src/main/ipc/terminal-preview.ts

@brennanb2025
brennanb2025 merged commit 1d8ce38 into main Jul 23, 2026
4 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…grid (stablyai#9997)

* feat(dashboard-popout): size the terminal dialog's PTY to the dialog grid

The popout agent-terminal dialog rendered the pane's serialized frame at its
original cols/rows and CSS-scaled it down to fit. The dialog now claims the
PTY grid for its own box through the remote-desktop viewer registry: the PTY
reflows to the dialog's dimensions (crisp, unscaled), the main-window pane
parks at the held grid like any remote viewer hold, and closing the dialog
releases the claim so the pane reclaims its geometry. A phone-driven PTY
keeps the floor; the dialog then falls back to the scale-to-fit rendering.

Any grid change under a live preview stream (fit landing, host reclaim,
phone takeover) now pushes a resync so the dialog repaints from a snapshot
at the new grid — this also fixes garbled dialogs when the pane resized
while a dialog was open.

* fix(dashboard-popout): harden terminal grid claims

* perf(dashboard-popout): bound terminal preview resize work
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