Skip to content

Keep remote terminal input working after a failed viewport restore - #34716

Merged
nwparker merged 3 commits into
mainfrom
nwparker/remote-terminal-input
Oct 28, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/remote-terminal-input

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​215 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​215
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8

ELI5

A remote terminal could keep ignoring keystrokes after reconnecting, even after its size recovered. A failed passive viewport update now preserves the stream's existing input permission.

What Changed

Keep passive resize results separate from explicit viewport claims in both multiplex and legacy binary subscriptions. Preserve promise ordering, rejected explicit claims, older clients' implicit claims, and phone input locks.

Why

A reconnecting viewer can restore orphaned ownership while its layout application fails. The stream previously latched that geometry failure into a permanent false input claim, then acknowledged and discarded later keys. Successful passive resizes could not repair it.

Linked Issue

Remote-terminal report supplied for this work: intermittent inability to type.

Visual Proof

Before: the control input renders; input after a failed passive resize disappears.

(screenshot removed: contained real product data)

After: the same keyboard input renders after the resize failure.

(screenshot removed: contained real product data)

Phone ownership still blocks desktop input and shows the existing overlay.

(screenshot removed: contained real product data)

Testing

  • Six final RPC cases exercise the real remote desktop floor, orphan ownership restoration, refused/thrown layout, subsequent typing, explicit claim rejection, and legacy recovery; all pass. An earlier failure-injection variant failed four delivery cases on baseline. The independent real-floor baseline/target replay also reproduced dropped input before the fix and delivery after it.

  • Independent review passed 69 tests across seven suites, including mobile locks, claim ordering, input acknowledgements, and reconnect ownership.

  • Strengthened all four explicit-client failure cases to hold the passive resize pending and prove later input cannot overtake it. Six focused cases pass; removing the ordering await makes exactly those four new assertions fail, while the two legacy controls still pass.

  • Separate hidden Electron before/after runs used a real paired E2EE multiplex connection and actual keyboard input. A one-shot resize failure was injected at the compiled runtime boundary. Failed explicit claims still blocked; a new successful claim recovered; simulated phone ownership blocked typing.

  • Required local ORCA_BACKGROUND_LAUNCH=1 pnpm check:changed --maxWorkers=2: 20/21 checks passed; the unit check had 458 passing suites and 5,999 passing tests. Three cross-version suites timed out during release-source preparation, and one readiness assertion failed under the broad run; the readiness suite passed all four cases in isolation. All four initially failing suites passed in targeted reruns: readiness 4/4 and cross-version 51/51 (ORCA_DISABLE_SHARED_RELEASE_CACHE=1, one worker). The final test-only incremental gate passed all 20 checks. Initial failure logs are retained.

  • Final-head CI: all 43 reported checks settled successfully, including the automatically retried Debian WSL job and the retarget review.

Review

The natural failure path is same-client orphan ownership restoration, rather than an ordinary already-owned passive resize. Layout work and input ordering are unchanged. No new scans, timers, polling, subprocesses, resource owners, or wire fields. Folder workspace identity is untouched. Old-client implicit claims retain their previous behavior.

Agent skill upstream boundary

  • No upstream skill-installer source was copied.

Notes

Targets main after #34721 was merged. The original parent commit includes that already-merged one-line test-import repair.

Runtime proof used macOS loopback paired transport. Legacy binary delivery was exercised in automated tests. Physical SSH, native Linux/Windows, and an actual phone were not run for this case; phone ownership was simulated through the real server driver state.

Checklist

  • Focused fix with independent review and before/after evidence.
  • Cross-platform, mixed-version, mobile, cleanup, and performance behavior reviewed.
  • Required local affected checks, scoped reruns, final incremental gate, and final-head CI complete.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

Passive resize handlers now catch viewport-update failures. When desktop viewport claims are supported, they preserve the prior claim regardless of the resize result. Tests cover standard and multiplexed subscriptions, input around refused or throwing layout updates, explicit claim recovery, and implicit-claim retry for older clients.

Priority: Normal

Merge Risk: Minimal · up to 96959

Passive resize failures preserve input permission while phone ownership still blocks desktop input. An additional transition test is recommended, but no merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary fix: preserving remote terminal input after a failed viewport restore.
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.
Description check Passed The pull request description is detailed and covers the ELI5 summary, changes, rationale, testing, visual proof, review notes, compatibility considerations, and checklist. The Linked Issue section doe…
Full details: Description check

Explanation

The pull request description is detailed and covers the ELI5 summary, changes, rationale, testing, visual proof, review notes, compatibility considerations, and checklist. The Linked Issue section does not contain an actual issue link, and the AI Disclosure section is omitted, but the description is otherwise complete and directly aligned with the pull request objectives.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 4 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Nitpick comments: 1
src/main/runtime/rpc/terminal-passive-resize-input.test.ts: 1

140-178: Trivial · Functional Correctness · Quick win

Hold the passive resize promise before sending input.

mockRejectedValueOnce and mockResolvedValueOnce settle immediately. The test only checks the final processWrites array, so it can pass if input bypasses the passive resize tail. The multiplex test covers a pending explicit claim, but the passive resize path and the legacy handler need this ordering assertion too.

Suggested fix
-      if (failure === 'thrown') {
-        stream.applyLayout.mockRejectedValueOnce(new Error('temporary geometry failure'))
-      } else {
-        stream.applyLayout.mockResolvedValueOnce({ ok: false })
-      }
+      let resolveLayout = (_result: { ok: boolean }): void => {}
+      let rejectLayout = (_error: Error): void => {}
+      stream.applyLayout.mockImplementationOnce(
+        () =>
+          new Promise<{ ok: boolean }>((resolve, reject) => {
+            resolveLayout = resolve
+            rejectLayout = reject
+          })
+      )
       stream.resize()
       stream.type('during')
+      await vi.waitFor(() => expect(stream.applyLayout).toHaveBeenCalledTimes(1))
+      expect(stream.processWrites).toEqual(['before'])
+      if (failure === 'thrown') {
+        rejectLayout(new Error('temporary geometry failure'))
+      } else {
+        resolveLayout({ ok: false })
+      }
       stream.resize()

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2fa0c798-cf36-4ea1-ab10-09ccc14bc796
Commits

Reviewing files that changed from the base of the PR and between b413170 and 53aa2b3.

Files selected for processing: 3
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-slot-frames.ts
  • src/main/runtime/rpc/methods/terminal/terminal-subscribe-binary-control-frames.ts
  • src/main/runtime/rpc/terminal-passive-resize-input.test.ts

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

@nwparker nwparker mentioned this pull request Oct 28, 2026
10 tasks done
@nwparker
nwparker changed the base branch from main to nwparker/remote-validation-test-import October 28, 2026 04:26
@nwparker
nwparker force-pushed the nwparker/remote-terminal-input branch from 53aa2b3 to 8f46560 Compare October 28, 2026 04:28
@nwparker
nwparker changed the base branch from nwparker/remote-validation-test-import to main October 28, 2026 05:26

@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: 1
src/main/runtime/rpc/terminal-passive-resize-input.test.ts: 1

140-184: Trivial · Functional Correctness · Quick win

Add coverage for ownership changes during a pending failed resize.

The binary and multiplex paths can both start desktop input while the driver is idle, wait on the pending resize claim tail, and then observe mobile ownership after the resize fails. Add a case for both multiplex values. The current tests keep the driver idle and do not detect a missing post-tail ownership check.

Suggested fix
 import type { RuntimeTerminalWait } from '../../../shared/runtime-types'
+import type { DriverState } from '../orca-runtime-core'
 ...
   const applyLayout = vi.fn(async () => ({ ok: true }))
+  let driver: DriverState = { kind: 'idle' }
+  const getDriver = vi.fn(() => driver)
 ...
-    getDriver: vi.fn().mockReturnValue({ kind: 'idle' }),
+    getDriver,
 ...
   return {
     processWrites,
+    setDriver: (next: DriverState) => {
+      driver = next
+    },
     updateViewport: vi.mocked(runtime.updateRemoteDesktopViewer),
 ...
   }
 }
@@
   it.each(['refused', 'thrown'])('preserves typing after a %s passive resize', async (failure) => {
@@
   })
+
+  it('blocks input when the phone takes ownership during a failed passive resize', async () => {
+    const stream = await startStream(multiplex, true, true)
+    const layout = Promise.withResolvers<{ ok: boolean }>()
+    try {
+      stream.type('before')
+      await vi.waitFor(() => expect(stream.processWrites).toEqual(['before']))
+
+      stream.applyLayout.mockReturnValueOnce(layout.promise)
+      stream.resize()
+      await vi.waitFor(() => expect(stream.applyLayout).toHaveBeenCalledTimes(1))
+
+      stream.type('during')
+      await new Promise<void>((resolve) => setImmediate(resolve))
+      stream.setDriver({ kind: 'mobile', clientId: 'phone-1' })
+      layout.resolve({ ok: false })
+      await new Promise<void>((resolve) => setImmediate(resolve))
+
+      expect(stream.processWrites).toEqual(['before'])
+    } finally {
+      layout.resolve({ ok: false })
+      await stream.close()
+    }
+  })

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c865bfc4-4c6f-4679-821a-f3f0a2cbf47a
Commits

Reviewing files that changed from the base of the PR and between 53aa2b3 and 9695952.

Files selected for processing: 2
  • src/main/claude/claude-rewind-transcript.test.ts
  • src/main/runtime/rpc/terminal-passive-resize-input.test.ts

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

Move the desktopClaimTail passive-resize rule into chainPassiveDesktopResize
so the multiplex and binary-subscribe transports use one implementation, drop
the unreachable outer catch, and pass startStream test options as an object.
@nwparker
nwparker force-pushed the nwparker/remote-terminal-input branch from 9695952 to 41c0fe0 Compare October 28, 2026 07:07
@nwparker
nwparker merged commit 1983946 into main Oct 28, 2026
29 checks passed
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