Skip to content

fix(client): re-assert host mouse modes after a terminal reconnect - #2285

Open
dengoswei wants to merge 1 commit into
herdrdev:masterfrom
dengoswei:fix/host-mouse-modes-after-reconnect
Open

fix(client): re-assert host mouse modes after a terminal reconnect#2285
dengoswei wants to merge 1 commit into
herdrdev:masterfrom
dengoswei:fix/host-mouse-modes-after-reconnect

Conversation

@dengoswei

Copy link
Copy Markdown

Current behavior

A host terminal can be re-created underneath a live client. Web VS Code restores a
reconnected terminal from a serialized snapshot that brings back the mouse tracking
mode without the SGR encoding Herdr asked for. Every mouse report then arrives in an
encoding the client cannot parse and leaks into the focused pane as text, so moving
the mouse types garbage. Recovering requires detaching and reattaching.

Reproduction

  1. Attach to a Herdr session in the VS Code web terminal.
  2. Reload the browser tab.
  3. Move the mouse over the pane — escape-sequence garbage is typed into it.

Fix

Re-assert the host mouse mode set on regained focus and on resize, both of which fire
when a client reconnects. set_mouse_capture already clears host mouse reporting
first, so this also drops the stale tracking mode.

Checks

cargo fmt --check, cargo clippy --all-targets --locked -- -D warnings, and the
x86_64-pc-windows-msvc clippy pass are clean on this branch.

cargo test --locked leaves 6 failures on my machine. All 6 fail identically on an
unmodified checkout of the same base commit: five update::tests cases that talk to a
running Herdr server (I have one running) and
workspace::tests::generated_workspace_ids_are_short_base32_handles, which passes in
isolation. Nothing in raw_input or client fails.

A host terminal can be re-created underneath a live client. Web VS Code
restores a reconnected terminal from a serialized snapshot that brings back
the mouse tracking mode without the SGR encoding herdr asked for, so every
mouse report then arrives in an encoding the client cannot parse and leaks
into the focused pane as text. Recovering required detaching and reattaching.

Re-assert the host mouse mode set on regained focus and on resize, both of
which fire when a client reconnects. set_mouse_capture already clears host
mouse reporting first, so this also drops the stale tracking mode.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3d727423-770c-4639-bae7-aff0053515ea

📥 Commits

Reviewing files that changed from the base of the PR and between 4473e39 and 0366a1d.

📒 Files selected for processing (2)
  • src/client/mod.rs
  • src/raw_input.rs

📝 Walkthrough

Walkthrough

The client detects outer-focus-gained input and reapplies configured host mouse capture on Unix, Windows, and terminal resize flows. Tests cover focus gain, focus loss, and regular key input.

Changes

Host mouse capture refresh

Layer / File(s) Summary
Detect host mode refresh events
src/raw_input.rs
events_require_host_mode_refresh detects OuterFocusGained events independently of repaint settings. Tests cover focus gain, focus loss, and regular key input.
Refresh host capture in client flows
src/client/mod.rs
The client reapplies host mouse-capture settings during Unix and Windows input handling and after terminal resize events. Errors are logged without stopping the client loop.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the fix for host mouse modes after a terminal reconnect.
Description check ✅ Passed The description explains the reconnect issue, reproduction steps, fix, and validation results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@kangal-bot kangal-bot added the ai-review Trigger automated AI reviews for pull requests admitted by the PR gate label Aug 4, 2026
@greptile-apps

greptile-apps Bot commented Aug 4, 2026

Copy link
Copy Markdown

Greptile Summary

The PR reasserts host mouse modes after focus-gained and resize events so terminal surfaces restored with stale tracking encodings recover automatically.

  • Adds a focus-event predicate for host-mode refreshes.
  • Refreshes mouse capture from Unix and Windows focus events and from resize events.
  • Adds focused unit coverage for the new raw-input predicate.
  • The resize path currently conflicts with direct-terminal attach’s independently enabled mouse mode.

Confidence Score: 4/5

The direct-attach resize regression should be fixed before merging because resizing can disable mouse handling for users whose normal mouse-capture setting is off.

Direct-terminal attach always enables host mouse capture, but the new resize handler reapplies a separately initialized configuration value and can therefore turn that required mode off.

Files Needing Attention: src/client/mod.rs

Important Files Changed

Filename Overview
src/client/mod.rs Adds mouse-mode reassertion to focus and resize handling, but the resize refresh can disable the mouse mode that direct-terminal attach installed independently of configuration.
src/raw_input.rs Adds a narrow predicate and tests mapping OuterFocusGained to a required host-mode refresh.

Sequence Diagram

sequenceDiagram
  participant Host as Host terminal
  participant Client as Herdr client
  participant Server as Herdr server
  Host->>Client: Focus gained or resize
  Client->>Host: Clear restored mouse modes
  Client->>Host: Reapply tracked capture state
  Client->>Server: Forward input or resize
  Server-->>Client: MouseCapture updates
Loading

Reviews (1): Last reviewed commit: "fix(client): re-assert host mouse modes ..." | Re-trigger Greptile

Comment thread src/client/mod.rs
// A reconnect re-syncs the terminal size before the user touches
// anything, so this usually restores the mode set before the
// first stray mouse report can leak into a pane.
refresh_host_mouse_capture(state.mouse_capture_active);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Resize disables direct-attach mouse mode

When a Unix direct-terminal attach has ui.mouse_capture disabled, setup still enables host mouse capture, but this resize refresh reapplies the configuration-derived false state, causing mouse interaction and attach-mode scrolling to stop after the first resize.

Knowledge Base Used: Client attach and raw input pipeline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Trigger automated AI reviews for pull requests admitted by the PR gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants