Skip to content

fix: preserve focused viewer geometry during activation - #3746

Open
akbash-bot wants to merge 2 commits into
herdrdev:masterfrom
akbash-bot:akbash/3744-background-activation-resize
Open

fix: preserve focused viewer geometry during activation#3746
akbash-bot wants to merge 2 commits into
herdrdev:masterfrom
akbash-bot:akbash/3744-background-activation-resize

Conversation

@akbash-bot

@akbash-bot akbash-bot commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Issue

Switching an SSH surface in a background client resizes a shared pane that another client is actively viewing. The focused client can lose the bottom or right edge of its terminal UI.

Problem

Surface activation always claimed the shared tab's size before the following host-focus update arrived. Its presentation-sync reassertion claimed the size again, so an unfocused client could replace the size selected by a focused viewer.

How did we fix it?

Herdr now keeps the focused viewer's tab size while another same-tab client activates and synchronizes its surface. Focused surface reassertions and normal focus, navigation, and input still transfer sizing control.

Verification

The regression test failed before the change with 99×35 instead of 67×17 immediately after activation. It now preserves 67×17 through activation, focus=false, and presentation synchronization. The focused reassertion test still transfers control. Surface-interest tests and CI pass on Ubuntu, macOS, Windows, and the Windows ConPTY package check.

refs #3744

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

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

Run ID: 106ada9f-f1f7-495f-866c-b6d5d5de1276

📥 Commits

Reviewing files that changed from the base of the PR and between 9e01168 and 8c5208c.

📒 Files selected for processing (2)
  • src/server/headless/surface_interest.rs
  • src/server/headless/tests/surface_interest.rs

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


📝 Walkthrough

Walkthrough

The active shell surface path now claims tab geometry only when the activating client did not already own a previously focused tab. New integration tests cover background activation without geometry changes and focused-surface reassertion that restores geometry ownership and runtime size.

Suggested reviewers: ogulcancelik

Merge Risk: ⚪ Minimal · up to 8c520

Background SSH surface activation now preserves the focused viewer’s terminal size, while focused reassertion still restores sizing control. The covered behavior is ready to merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files.
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.
Title check ✅ Passed The title clearly summarizes the main change: preserving focused viewer geometry during activation.
Description check ✅ Passed The description directly explains the background activation resizing issue, the fix, and the verification results.

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.

@kangal-bot

Copy link
Copy Markdown
Collaborator

@coderabbitai review
@greptileai

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

@kangal-bot I will review pull request #3746.

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

@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown

Greptile Summary

This PR attempts to preserve a focused viewer's terminal geometry when another client activates the same shared tab.

  • Detects shared tabs that had a focused viewer before activation.
  • Skips the activating client's initial geometry claim in that case.
  • Adds regression coverage for background activation and focused reassertion.
  • The normal presentation-sync reassertion still bypasses the new protection and restores the background client's geometry.

Confidence Score: 4/5

The PR is not safe to merge because the normal presentation-sync request can immediately undo the geometry preservation.

A normal endpoint activation sends two active-surface requests; after the first marks the surface active, the second takes the unchanged path and allows the background client to reclaim and resize the focused viewer's tab.

Files Needing Attention: src/server/headless/surface_interest.rs, src/server/headless/tests/surface_interest.rs

Important Files Changed

Filename Overview
src/server/headless/surface_interest.rs Adds focused-tab geometry preservation for changed activations, but unchanged activation-phase reassertions bypass it.
src/server/headless/tests/surface_interest.rs Adds useful geometry regression tests, but the background-client test omits the presentation-sync reassertion that follows normal activation.

Sequence Diagram

sequenceDiagram
    participant B as Background client
    participant S as Headless server
    participant F as Focused viewer
    B->>S: "SurfaceSet(active=true)"
    Note over S: changed=true
    S-->>F: Preserve focused geometry
    B->>S: "Presentation-sync SurfaceSet(active=true)"
    Note over S: changed=false
    S->>S: claim_shell_tab_geometry(B)
    S-->>F: Shared tab resized to B's geometry
Loading

Reviews (1): Last reviewed commit: "fix: preserve focused viewer geometry du..." | Re-trigger Greptile

Comment thread src/server/headless/surface_interest.rs Outdated
Comment on lines +72 to +75
let focused_viewer_already_owns_tab = changed
&& self
.shell_tab_id_for_client(client_id)
.is_some_and(|tab_id| focused_tabs_before.contains(&tab_id));

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 Reassertion Undoes Geometry Protection

A normal activation sends another active: true request during presentation synchronization. Because the first request already marked the surface active, this second request has changed == false, calls claim_shell_tab_geometry, and resizes the shared tab to the background client's geometry. This undoes the focused viewer's geometry protection before activation completes. The new regression test checks only the first request, so it does not cover this normal second phase.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

agreed, fixed in c2d200e

hdosys pushed a commit to hdosys/herdr-win that referenced this pull request Sep 9, 2026
Backport herdrdev/herdr@8c5208c and herdrdev/herdr@c2d200e. Retain deferred startup initialization and normal focus/input authority transfers.

Refs herdrdev#3746, herdrdev#3744.
hdosys added a commit to hdosys/herdr-win that referenced this pull request Sep 9, 2026
Append eleven coherent mailboxes without changing stable BASE. Preserve the reviewed foundation except total-count subjects, retain source credit and provenance, and reproduce accepted source 53fd505 at tree 66dcebc. All 24 Windows prefixes compile; the current installer is unchanged.

Refs herdrdev#3661, herdrdev#3701, herdrdev#3721, herdrdev#3651, herdrdev#3592, herdrdev#3589, herdrdev#3770, herdrdev#3779, herdrdev#3742, herdrdev#3735, herdrdev#3781, herdrdev#3778, herdrdev#3787, herdrdev#3766, herdrdev#3755, herdrdev#3754, herdrdev#3807, herdrdev#3764, herdrdev#3760, herdrdev#3746, herdrdev#3744, herdrdev#3819, herdrdev#3759
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