Skip to content

fix(terminal): clear stale mouse and focus modes before snapshot replay - #30195

Open
nwparker wants to merge 3 commits into
mainfrom
nwparker/bug-pane-restore-re-enables-mouse-tracking-1003h
Open

nwparker wants to merge 3 commits into
mainfrom
nwparker/bug-pane-restore-re-enables-mouse-tracking-1003h

Conversation

@nwparker

@nwparker nwparker commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

After a server restart, moving the mouse could type 35;…;…M into a restored shell. The client now clears the previous program’s mouse and focus settings before reading the server’s full terminal snapshot. A still-running TUI gets its settings back from that snapshot.

What Changed

Serialized snapshots describe enabled modes and omit defaults. A mounted client could therefore retain mouse/focus reporting from a dead TUI even when the replacement shell’s snapshot was clean. A persisted agent title then selected an epilogue that preserved those inherited modes.

Reset mouse protocols and focus reporting before authoritative snapshot replay. Preserve the encoding when an older host omits it; explicit encoding bytes in a snapshot still apply. Reuse one reset in the shared replay prologue and the daemon-reattach snapshot path, covering paired reconnects and hidden-pane restores. Preserve existing post-replay policy and partial live-stream replay.

Why

The snapshot’s actual mode bytes become authoritative. Clearing modes after replay would break a surviving TUI; removing mouse enables from checkpoints would not clear modes already active in a mounted client. This approach also works with 1.4.229 servers that omit ownership metadata and changes no wire format.

Linked Issue

Fixes #18424

Credit to @bjornrun for the open proposal in #20087 and @innocarpe for the diagnosis and earlier proposal in #18454. This completes the client-side snapshot handling alongside @Jinwoo-H’s daemon recovery fix in #22735.

Visual Proof

Both captures use an official Linux 1.4.229 server with a macOS client. The after capture uses the initial fix build; final-source validation is listed below. A controlled TUI enabled mouse/focus reporting, was killed, and the server/daemon restarted while the client stayed mounted. Moving the pointer produces shell garbage before the fix and zero reports afterward. The after capture is taken before running reset or reloading.

Before:

Mouse reports typed into restored shell

After:

Restored shell remains clean after pointer movement

Surviving TUI after app reattach (wheel and drag behavior asserted):

Live TUI retains mouse input

Testing

  • Snapshot regression matrix: 48 tests covering normal/alternate buffers, folded/split snapshots, all mouse protocols, SGR/pixel encodings, focus, skipped alternate frames, and partial-gap preservation. Eight tests fail when the snapshot baseline fix is removed; all pass with it.
  • Connection regressions replay real xterm writes with a persisted agent title, testing replacement-shell defaults, live-agent reporting, and older live snapshots that omit encoding metadata.
  • Focused connection/replay suites pass, including the existing remote host-chain tests. Final focused validation: 201 passed across four suites.
  • Official Linux 1.4.229 server + macOS client with the initial fix build: cold-restart E2E passes, with no mouse/focus reports at the replacement shell before any workaround.
  • All seven local paired-host scenarios passed in one invocation with the hardened harness (4.9 minutes): TUI death before/during serve shutdown, cold daemon teardown, normal-screen TUI, no-title control, and integrated-shell control. This run used the initial fixed renderer build.
  • Rebuilt final source: cold-restart proof, existing leak control, and surviving-TUI control all pass (3 tests, 1.3 minutes). Wheel events still advance the live TUI, and dragging produces no xterm text selection.
  • Renderer typecheck, changed-code quality gate, formatting, and E2E build pass.
  • Repository-wide E2E typecheck remains blocked by existing unrelated missing cloud dependencies/type errors; no diagnostics point to the added proof files.

Reproduce locally after an E2E build:

ORCA_BACKGROUND_LAUNCH=1 SKIP_BUILD=1 ORCA_MOUSE_PROOF_LOCAL=1 pnpm exec playwright test --config tests/playwright.config.ts --project electron-headless --workers=1 tests/e2e/pane-restore-mouse-owner-proof.spec.ts
  • I manually tested these changes locally (validation was agent-driven hidden Electron/CDP)
  • Automated tests added/updated

AI Disclosure

Review

Claude Opus 5.5 reviewed this through Orca orchestration in two rounds. Final commit f0127939baf9dbbf72b2feea9b38b11e48f81cb0 is CLEAN: all four initial findings resolved, with no outstanding actionable regression. The review covered full versus partial replay, live TUI mode restoration, older-host encoding compatibility, cleanup, and the proof claims.

The reviewer also noted a pre-existing default-encoding gap when a main-model restore skips a too-wide alternate frame. This PR preserves that existing behavior.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer code or artifacts copied.

Notes

Production change is platform-independent and runs in the renderer; no subprocesses, process probes, polling, or wire changes added. Tested on macOS with local and Ubuntu 24.04 paired hosts, including a non-git folder workspace. Windows was not executed. Linux captures precede the older-host encoding refinement; the final build was rechecked with the local cold-restart and live-TUI controls above. The externally provisioned release proof uses a protocol-controlled TUI and a source-built macOS client, not a packaged macOS client or a real Claude session. Test apps remained hidden. Owned remote fixtures were stopped after validation.

Checklist

  • This PR is small and focused
  • I explained the before/after, mechanism, and alternatives
  • Before/after screenshots attached
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and compatibility impact considered
  • Full lint/typecheck/test/build suite (focused checks above; CI must cover the full gate)

Full snapshots omit disabled input modes. Clear inherited mouse protocols,
encodings and focus reporting before replay, then let a live TUI re-arm
its own modes. Cover daemon reattach, paired reconnect and hidden restore.

Fixes #18424.

Thanks to @bjornrun (#20087), @innocarpe (#18454), and @Jinwoo-H (#22735)
for the earlier diagnosis, proposals, and daemon recovery work.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 7e36dcd9-557e-4115-b25d-eddabc2fa4a1
📥 Commits

Reviewing files that changed from the base of the PR and between fa738f3 and 3b7a566.

📒 Files selected for processing: 8
  • src/renderer/src/components/terminal-pane/pty-connection-daemon-snapshot-replay.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts
  • src/renderer/src/components/terminal-pane/terminal-snapshot-input-modes.test.ts
  • src/shared/terminal-mode-reset-profiles.ts
  • tests/e2e/fixtures/mouse-mode-owner.cjs
  • tests/e2e/helpers/mouse-owner-replay-probes.ts
  • tests/e2e/pane-restore-mouse-owner-linux-proof.spec.ts
  • tests/e2e/pane-restore-mouse-owner-proof.spec.ts

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

📝 Walkthrough

Terminal snapshot restoration now resets mouse and focus reporting before replaying snapshot content. Unit tests cover replay modes and screen state. Opt-in end-to-end tests capture terminal behavior around local and remote restart and reload scenarios.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 3b7a5

The inspected replay paths preserve mouse encoding for a surviving TUI. No issue requiring a fix before merge was established.

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. Analyzed 7 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed For #18424, the shared RESET_SNAPSHOT_MOUSE_AND_FOCUS clears mouse protocols, mouse encodings, and focus reporting before snapshot replay. The daemon reattach path writes this reset before the autho…
Out of Scope Changes check Passed The production changes are limited to terminal snapshot replay and daemon reattach handling for #18424. The added fixtures, probes, regression tests, and opt-in end-to-end scenarios directly validate …
Title check Passed The title is concise, specific, and accurately describes the primary change: clearing stale mouse and focus modes before snapshot replay.
Description check Passed The description follows the repository template and clearly explains the user impact, mechanism, rationale, linked issue, visual proof, testing, compatibility considerations, and known limitations.
Full details: Linked Issues check

Explanation

For #18424, the shared RESET_SNAPSHOT_MOUSE_AND_FOCUS clears mouse protocols, mouse encodings, and focus reporting before snapshot replay. The daemon reattach path writes this reset before the authoritative snapshot. A replacement-shell snapshot therefore does not inherit stale mouse reporting, while a live TUI can re-enable its modes from the snapshot. The added replay and connection tests cover replacement-shell and live-agent cases, protocols, encodings, focus, alternate screens, and replay boundaries.

Full details: Out of Scope Changes check

Explanation

The production changes are limited to terminal snapshot replay and daemon reattach handling for #18424. The added fixtures, probes, regression tests, and opt-in end-to-end scenarios directly validate stale-mode cleanup, live-TUI preservation, and restore behavior. No unrelated production behavior or wire-format change is established.

  • Fix all pre-merge checks with AI
✨ 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.

This branch has not been deployed

No deployments
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.

[Bug]: Pane restore re-enables mouse tracking (?1003h/?1006h) when the TUI that owned it does not come back

1 participant