Skip to content

fix(terminal): recover remote pane geometry and replacement mouse state - #19925

Closed
mmarabel wants to merge 6 commits into
stablyai:mainfrom
mmarabel:fix/remote-terminal-recovery-18464
Closed

mmarabel wants to merge 6 commits into
stablyai:mainfrom
mmarabel:fix/remote-terminal-recovery-18464

Conversation

@mmarabel

@mmarabel mmarabel commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Remote terminals should reconnect without shrinking to a nearly blank grid or sending mouse escape codes into a replacement shell. This fixes those two failures while preserving the terminal modes of an agent that is still running.

What Changed

  • Keep remote/mobile ownership holds when their dimensions are unknown, but do not resize xterm to 0×0. Measurable panes fit locally without claiming or resizing the host; genuine positive small grids remain authoritative.
  • Deliver optional process-incarnation identity on initial attachment and recovery using existing RPCs. Retire predecessor modes, replay work and positively attributed client status only after a known incarnation change.
  • Preserve ownership maps for same-handle identity updates and retain same-incarnation/unknown-identity behavior.
  • Add causal unit regressions and an isolated paired-host/client Electron test covering warm reconnect, shell replacement, actual mouse reports and host-side echo.

Why

The release reproduction captured an owner-fit override calling terminal.resize(0, 0), which xterm clamped to 2×1. A separate replacement path retained the predecessor's mouse modes because the pane did not consistently receive incarnation changes.

Linked Issue

Refs #18464

Stack 1/2. This PR addresses terminal recovery, not the entire identity issue. A dependent PR will address host-published automatic titles and completed agent metadata. The issue should remain open until that work is complete.

Visual Proof

Synthetic, disposable Linux fixtures; screenshots captured through CDP without showing or focusing native windows. Before: exact v1.4.199. After: this commit rebased onto current upstream main, whose package still reports 1.4.197; both use Electron 43.6.0. No release-version changes are included.

Case Before After
Warm reconnect: 2×1 → 75×60, surviving agent retained Blank after reconnect Recovered terminal after reconnect
Replacement shell: mouse-coordinate echo → no reports Mouse coordinates echoed by Bash Replacement shell without coordinate echo

The old Pi title visible in the replacement screenshot is a known host-publication defect reserved for stack 2, not a claim of complete identity cleanup.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

Fresh checks on the rebased commit:

  • 1,001 targeted tests across 101 files passed, including connect reattachment with a rotated handle.
  • 10 terminal wire-skew tests passed, including older peers without mode metadata.
  • Web and node TypeScript checks, changed-file formatting/lint and the changed-code quality check passed.
  • Electron E2E build passed; isolated paired-terminal scenario passed (42.7s), including a run without a caller-exported background-launch variable.
  • Same retained xterm and surviving-agent mouse mode verified across warm reconnect; replacement fits the measured pane, emits no mouse reports and does not retain a working Pi row.

Rendered validation used Linux/Xvfb, ORCA_BACKGROUND_LAUNCH=1, sanitized environment and disposable HOME/profiles. Test entry point: tests/playwright.remote-replacement.config.ts. No default global E2E setup, live service or real agent session was used. No native macOS/Windows or real SSH rendered validation; mixed-version coverage is protocol-level. Full repository lint/test/build suites are not claimed.

AI Disclosure

AI-assisted implementation and separate review using OpenAI coding assistants.

Review

Independent review covered process-identity races, same-handle ownership preservation, unknown/older-peer metadata, successor state, remote/mobile resize authority, cross-platform behavior and performance/security risks. A same-handle ownership-map regression found during review was reproduced, fixed and re-reviewed. No new host execution, provider-specific behavior, shortcuts, filesystem operations or protocol opcode is introduced. RPC enrichment occurs at attachment/recovery boundaries, not per output chunk. Visual recovery evidence was inspected.

Agent skill upstream boundary

  • Not applicable; no skill-installer material changed.

Notes

The full original identity diagnostic remains available for the dependent patch. PR 1's test deliberately checks terminal recovery and absence of stale working state; it does not claim that host-published Pi titles/completed metadata are cleared. No skipped or expected-failure tests conceal that distinction.

Checklist

  • Scoped to terminal recovery; most additions are regression coverage
  • Changes and rationale explained, including ELI5
  • Before/after screenshots attached
  • Self-reviewed and independently reviewed for correctness, security and performance
  • Cross-platform, SSH/remote, mobile ownership and backwards compatibility considered
  • Full pnpm lint, pnpm typecheck, pnpm test, and pnpm build run; targeted checks listed above

@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 30d3987a-859e-4754-a8c2-ec4169995611

📥 Commits

Reviewing files that changed from the base of the PR and between 2409f0a and dec7d7b.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-attachment-metadata-order.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The changes propagate PTY incarnation identity through remote transport recovery and rebind events. They retire superseded PTY state, cancel stale reads and replay work, and apply incarnation-aware replay guards. They add redraw requests for qualifying reattach viewport updates and validate fit overrides with finite positive dimensions. Unit, integration, and end-to-end tests cover replacement state, replay ordering, geometry, agent tracking, redraw behavior, and terminal modes.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to dec7d

Obsolete attachment responses are now rejected before changing the active terminal identity. No actionable merge-blocking issue remains in the supplied evidence; merge after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to dec7d

The changes strengthen separation between successive terminal processes and constrain redraw requests to eligible terminals with unchanged geometry. No concrete security regression was established in the reviewed paths, but host-side signaling and mixed-version behavior were not validated end to end.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The new redraw path targets one resolved PTY per request and sends a fixed SIGWINCH signal. Aggregate exposure depends on which terminal handles a caller can access through the existing RPC boundary; the inspected ranges do not establish tenant-wide or environment-wide authorization scope.

Trust Boundaries and Controls

  • observed — Request-controlled redraw and client type pass through existing viewport handling. Redraw requires an applied desktop update with unchanged dimensions; after the asynchronous update, the runtime resolves the live handle again and rejects missing PTYs, mobile drivers, or dimension mismatches. The desktop field is request data, not independent authentication evidence.

Resilience and Maintainability Implications

  • observed — Replacement invalidates pending replay work and resets predecessor input modes before replacement replay. Redraw is optional, and unavailable controllers or provider signaling failures produce false rather than requiring a terminal resize to force refresh.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.83% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 48 functions across 35 files. 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 identifies the two primary changes: remote pane geometry recovery and replacement mouse-state handling.
Description check ✅ Passed The description covers the required sections, explains the user impact and implementation, links the issue, provides visual proof, documents testing and limitations, includes AI disclosure, and record…
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.
  • Fix all pre-merge checks with AI

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: 2

🧹 Nitpick comments (1)
tests/playwright.remote-replacement.config.ts (1)

7-7: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider a larger timeout for this spec.

The spec chains long polls inside one test: 60s for worktree visibility, 45s for warm text, 45s for the warm incarnation, 45s for the warm probe, 45s for the replacement pty id, and 60s for the replacement incarnation. It also launches two Electron apps and restarts the serve process twice. The sum of the poll budgets alone exceeds the 180s test timeout. A slow CI machine then reports a Playwright timeout that reads like a product failure instead of a slow environment.

Raise the timeout to cover the declared poll budgets, or reduce the individual poll timeouts in the spec.

♻️ Proposed change
-  timeout: 180_000,
+  timeout: 420_000,

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 33cc0670-ea10-4eca-8e38-736aacd3dc9a

📥 Commits

Reviewing files that changed from the base of the PR and between 4f5a827 and 5b3d9ac.

📒 Files selected for processing (19)
  • src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.test.ts
  • src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.ts
  • src/renderer/src/components/terminal-pane/pty-connection-daemon-snapshot-replay.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-remote-snapshot-source-grid.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-replay-payload-handling.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.ts
  • src/renderer/src/components/terminal-pane/pty-connection/remote-pty-incarnation-replacement.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/remote-pty-incarnation-replacement.ts
  • src/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-incarnation-recovery.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/lib/pane-manager/pane-fit-unknown-owner-size.test.ts
  • src/renderer/src/lib/pane-manager/pane-fit.ts
  • src/renderer/src/runtime/web-session-terminal-handle-events.test.ts
  • src/renderer/src/runtime/web-session-terminal-handle-events.ts
  • tests/e2e/helpers/remote-terminal-geometry-probe.ts
  • tests/e2e/paired-remote-terminal-replacement-state.spec.ts
  • tests/playwright.remote-replacement.config.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

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

✅ No new issues found.

Reviewed changes

  • Geometry recovery — pane-fit.ts stops resizing a held remote/mobile owner to a clamped 0×0/2×1 grid; a new hasKnownFitOverrideDimensions() guard treats only finite positive override dims as authoritative and otherwise fits locally while retaining the hold.
  • Incarnation delivery — remote-runtime-pty-transport.ts publishes the host's incarnation id via onPtyRebind before the first snapshot on reattach, and resolves it from update.incarnationId or a terminal.resolvePane fallback in the recovery paths; remote-pty-incarnation-replacement.ts (new) retires predecessor evidence only on a proved, handle-differentiated incarnation change.
  • Replacement mouse/state fencing — replay-data-drain.ts fences the drain on remotePtyIncarnationId and switches a replacement replay to POST_REPLAY_LIVE_AGENT_SNAPSHOT_RESET unless the owner is a known shell; pane-foreground-agent-tracker.ts gains resetForPtyReplacement() and pty-input-forward.ts fences isCurrent() on the incarnation.
  • Regression coverage — unit grids for mouse-mode reconciliation, same-handle/both-known/unknown-identity retirement, unknown-owner fit behavior, plus an isolated paired-host/client Electron diagnostic (paired-remote-terminal-replacement-state.spec.ts) verifying warm reconnect geometry, surviving-agent mouse retention, and a replacement shell with no mouse reports.

The incarnation plumbing stays within existing RPCs — incarnationId is already host-published on RuntimeTerminalResolvePane and RuntimeMobileSessionTerminalTab, consumed optionally with ?? null degradation, and no new opcode or stream frame is introduced, so mixed-version peers are safe. Retirement is deliberately conservative (old && new && old !== new only), matching the repo's live/unverifiable verdict philosophy. The one scoping note — the retained "π" title after a replacement, and completed-agent metadata — is explicitly deferred to the dependent stack, so #18464 rightly remains open.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

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

✅ No new issues found.

Reviewed changes

  • Predecessor identity retained on reconnect — attachHostSessionMirror now accepts the persisted sessionId and forwards it as the replacedPtyId in onPtyRebind, so a connect({ sessionId }) web-mirror reattach retires the old (persisted) pane identity instead of a degenerate ptyId === replacePtyId no-op.
  • Regression coverage — remote-runtime-pty-incarnation-recovery.test.ts adds it.each(['terminal-1', 'terminal-2']) asserting the exact rebind triple (nextHandle, persistedSessionId, incarnationId) for both same-handle and rotated-handle reattachment.
  • Diagnostic config hardening — the isolated Playwright config pins ORCA_BACKGROUND_LAUNCH=1 and raises the per-test timeout from 180s to 420s to cover the spec's declared poll budgets.

The change correctly narrows the second argument of onPtyRebind: in the connect web-mirror path existingPtyId is absent, so the predecessor resolves to the persisted sessionId; the attach path (existingPtyId ?? remotePtyId) is unchanged. The consumer in pane-pty-visibility-bind.ts feeds that value into both retireRemotePtyIncarnation and bindActivePanePty({ replacePtyId }), and parseRemoteRuntimePtyId degrades gracefully to no retirement when the id isn't a remote handle. Verified locally: the 22-case recovery test file passes.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@LesleyMurfin

Copy link
Copy Markdown
Contributor

@mmarabel Heads up: this has merge conflicts against main following recent runtime transport refactors (#20096, #20359). Could you rebase when you have a moment?

Also, a note from a fresh repro reported in #18464 (restarting orca serve with surviving PTYs):

  • The pane-fit.ts fix stops the 2×1 geometry collapse on reattach.
  • However, in reattach-grid-push.ts, SIGWINCH is explicitly skipped for remote PTYs (if (!isRemoteRuntimePtyId(reattachPtyId))).
  • Calling session.transport.resize(cols, rows) with the same dimensions is a no-op in the host kernel (TIOCSWINSZ), so no SIGWINCH is delivered to idle foreground TUIs (like Claude Code). That is why the reporter had to manually run kill -WINCH on the host to force a repaint.

If remote PTYs can trigger a synthetic WINCH/redraw kick on reattach when dimensions are unchanged, that would fully solve the idle remote case.

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

Run ID: cb18eee8-6706-4454-b36a-ae1085dba191

📥 Commits

Reviewing files that changed from the base of the PR and between 542573a and 23a9b8f.

📒 Files selected for processing (24)
  • src/main/ipc/pty/runtime/controller.ts
  • src/main/ipc/pty/runtime/pty-redraw.test.ts
  • src/main/ipc/pty/runtime/pty-redraw.ts
  • src/main/runtime/orca-runtime-serialize-main-terminal-buffer.ts
  • src/main/runtime/rpc/methods/terminal/terminal-viewport-methods.ts
  • src/main/runtime/rpc/terminal-reattach-redraw.test.ts
  • src/main/runtime/runtime-pty-controller-contract.ts
  • src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker-contract.ts
  • src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.test.ts
  • src/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.ts
  • src/renderer/src/components/terminal-pane/pty-connection-daemon-snapshot-replay.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-remote-snapshot-source-grid.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-replay-payload-handling.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-grid-push.ts
  • src/renderer/src/components/terminal-pane/pty-connection/remote-pty-incarnation-replacement.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport-reattach-redraw.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/lib/pane-manager/pane-fit-unknown-owner-size.test.ts
  • src/shared/rpc-contract/terminal-viewport-schemas-params.ts
  • tests/e2e/paired-remote-terminal-replacement-state.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@mmarabel

mmarabel commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the conflicts against current main in 23a9b8f. I merged rather than force-pushing a rebase so the existing review history stays intact.

Your redraw suggestion was right: a same-size resize does not generate SIGWINCH. Remote reattach now carries an optional redraw flag on the existing terminal.updateViewport RPC. When the host grid is unchanged, the host requests SIGWINCH through the owning PTY provider, which targets the POSIX foreground process group. The path rechecks the live handle, applied grid, and mobile ownership after the viewport update. Older hosts ignore the flag; no new stream opcode is needed.

The hidden paired-host/client Electron regression now checks that the surviving idle process repaints after restarting orca serve, before any probe input. It passed, along with 5,756 tests across 594 files, 10 wire-skew tests, node/web/CLI types, and the PR-scoped quality gate. The original geometry and replacement-shell mouse-state controls still pass. This remains a partial fix for #18464, not a claim that every identity issue is solved.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Terminal pane geometry recovery and remote PTY replacement handling.

The PR appears safe to merge based on the changes since the previous review.

Summary

The PR improves remote terminal geometry recovery and replacement-shell mode handling. Since the previous review, it adds attachment-freshness checks and a regression test for obsolete metadata responses. The previously reported small-pane redraw finding is manually resolved.

Reviews (3) · Last reviewed commit: "fix(terminal): reject obsolete mirror at..."

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

✅ No new issues found.

Reviewed changes

Reviewed the commits since the prior pullfrog review (542573a): a merge of upstream main plus a repaint-on-reattach kick for remote panes.

  • Redraw idle remote panes on reattach — a remote pane whose applied grid is unchanged at reattach now sends terminal.updateViewport with a new optional redraw field; the host re-resolves the leaf, re-confirms the grid still matches, and best-effort signals SIGWINCH to the execution host's foreground group (requestTerminalRedraw → requestPtyRedrawFromRuntimeController).
  • Client redraw bypasses the stream opcode — remote-runtime-pty-transport.resize(..., { redraw }) clears the queued viewport batcher and issues a single RPC instead of a Resize frame, used only for remote runtime pty ids and bounded to the legacy viewport schema.
  • Agent-tracker contract extracted — PaneForegroundAgentTracker / …Deps moved into pane-foreground-agent-tracker-contract.ts; resetForPtyReplacement() is wired into the returned object. Mechanical.
  • Regression coverage — host terminal-reattach-redraw.test.ts (mobile ownership, geometry re-check, stream-gone, replaced handle, degraded controller), provider pty-redraw.test.ts, client remote-runtime-pty-transport-reattach-redraw.test.ts, and e2e assertions that an idle fixture repaints via SIGWINCH after a process-only serve restart and that a held unknown owner still fits locally without claiming the PTY.

The optional redraw field is wire-safe (older hosts strip it and keep prior behavior; the client swallows a refusal), the host re-checks the applied grid after the await, and the new unit tests fail if the feature is removed. Verified locally: pty-redraw.test.ts, terminal-reattach-redraw.test.ts, remote-runtime-pty-transport-reattach-redraw.test.ts, pane-foreground-agent-tracker.test.ts, and remote-pty-incarnation-replacement.test.ts all pass.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

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

⚠️ Outside diff range comments (1)

🟠 Major · Reject obsolete results before adopting execution metadata. · remote-runtime-pty-transport.ts:631

src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts:631
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Reject obsolete results before adopting execution metadata.

If attachment A is waiting for activation or polling while attachment B completes, a late result for A can overwrite B’s authoritative incarnation at either adoption site. The isCurrent() check in waitForHostSessionHandleWithRecovery then rejects A’s handle, but it cannot undo the metadata change. A later publication can treat B’s unchanged PTY as a replacement. Check isCurrent() before both calls to adoptExecutionMetadata.

Also applies to: 685-685


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: bfe88230-1e7d-4e4d-97f4-511a6c51f11e

📥 Commits

Reviewing files that changed from the base of the PR and between 23a9b8f and 2409f0a.

📒 Files selected for processing (6)
  • src/main/runtime/rpc/terminal-reattach-redraw.test.ts
  • src/main/runtime/terminal-viewport.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-published-metadata-order.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport-reattach-redraw.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/shared/terminal-viewport.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

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

✅ No new issues found.

Reviewed changes

This run re-reviewed the single commit pushed since the prior pullfrog review (23a9b8f3a6 → 2409f0aeb3), which resolves two external-bot findings.

  • Clamped redraw requests to the host grid — the client no longer skips the redraw RPC for panes outside the legacy 20–240 × 8–120 bounds; it clamps to the host's range and always issues the terminal.updateViewport call, so sub-minimum and oversized remote panes also repaint after a warm reattach.
  • Moved the clamp to a shared module — clampTerminalViewport now lives in src/shared/terminal-viewport.ts, re-exported from src/main/runtime/terminal-viewport.ts, so the client redraw path and the host resize paths cannot drift.
  • Fenced accepted-snapshot ordering — a new publishedHandleUpdateSequence invalidates an in-flight resolvePane lookup when a newer accepted publication lands, so an older handle can no longer rebind over a newer one.
  • Regression coverage — host kick at both clamped boundaries, client 10×4 → 20×8 / 500×300 → 240×120 clamping, and a publication-order race that fails without the sequence fence.

Traced both fixes end to end: the clamped viewport stays within the legacy schema bounds and matches the host's own clamp, so the previousSize === requested redraw condition holds for genuinely unchanged grids, and requestTerminalRedraw still re-resolves and re-checks the applied grid after the await. The sequence fence was independently examined across the detach/resubscribe/retire/auto-recovery interleavings — it only drops continuations the newer publication already supersedes. No open pullfrog threads remained to retire.

Pullfrog

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@mmarabel

mmarabel commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the outside-diff finding about obsolete attachment metadata in dec7d7b926.

Both the activation response and the polled inventory response now check the attachment's existing isCurrent() guard before adopting execution metadata. A late reply from an older attachment can no longer overwrite the newer terminal's host, platform or session identity, or make its unchanged PTY look like a replacement.

remote-runtime-pty-attachment-metadata-order.test.ts covers both paths: attachment A waits, B completes, then A replies late. The tests check that B's host/platform survive and a subsequent publication does not trigger a false replacement. Both failed before the fix; removing either guard independently fails only its corresponding case.

Validation: 5,706 terminal/wire tests passed (2 skipped); node, web and CLI typechecks, lint and the PR-scoped quality gate passed. I also audited the full review bodies, including outside-diff and nitpick sections; the earlier timeout suggestion is already covered by the 420-second test configuration.

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

✅ No new issues found.

Reviewed changes

This run re-reviewed the single commit pushed since the prior pullfrog review (2409f0aeb3 → dec7d7b926), which closes the last external-bot finding on attachment metadata ordering.

  • Reject obsolete mirror attachment metadata — waitForHostSessionHandle (remote-runtime-pty-transport.ts) now returns early when isCurrent() is false before adopting a ready terminal, at both the immediate-activation site and the polled inventory site. Because isCurrent closes over attachGeneration/lifecycleEpoch, which every attach()/detach()/disconnect() bumps, a stale attachment's late activation or inventory result can no longer overwrite a newer attachment's incarnation, execution host, or platform.
  • Regression coverage — remote-runtime-pty-attachment-metadata-order.test.ts runs two overlapping attaches from each entry point (activation and inventory) and asserts the newer attachment's metadata survives the older one's late response. It drives the exact race the prior external review described and fails without the new guards.

The guards sit before the only two adoptExecutionMetadata sites reachable from a stale mirror attach; the remaining adoption sites are fenced by their own generation/sequence checks, so the fix is correctly scoped rather than applied blanket-wide. The pre-existing redraw and publication-ordering work from the prior commit still reads clean.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@mmarabel

mmarabel commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Both failures this PR fixed are handled on main now. A restarted host publishing a 0x0 grid hold no longer shrinks the pane: the fit-override handler in remote-runtime-terminal-response-controller.ts drops non-desktop-fit holds with zero columns or rows (#26483). And a replacement shell no longer keeps the old process's mouse modes, title or agent identity (replaced-process-input-modes.ts, #35889). Rebasing this onto the transport refactors would mostly redo that work, so I'm closing it. If the blank pane or stray mouse codes come back on a current build, I'll open a new issue with a capture.

@mmarabel mmarabel closed this Nov 8, 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.

2 participants