Skip to content

fix(terminal): keep the grid on a desktop that is visible but unfocused - #1095

Merged
devswha merged 2 commits into
mainfrom
fix/keep-grid-on-unfocused-desktop
Oct 14, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/keep-grid-on-unfocused-desktop

Conversation

@devswha

@devswha devswha commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Refs #472

Follow-up to #1085 (merged), which hands the shared grid back only to a device still showing the terminal.

The regression

In #1085, PaneTerminal's leave() sent release-size whenever the page was out of use, and "in use" means visibilityState === "visible" && document.hasFocus(). A desktop window that is still on screen but merely unfocused (a second monitor, alt-tab to another app, using the phone beside the PC) therefore gave its grid away on every blur. When the phone then went back to Chat, no candidate was left, so the visible desktop stayed at phone width.

The fix

  • leave() now releases the grid only when the document is actually hidden: socket.keepSize(pane, document.visibilityState === "hidden").
  • HerdrSocket.keepSize(paneId, releaseGrid = true): with releaseGrid = false it changes only the reconnect policy (keep_size on the next attach) and sends no release-size.
  • Blur's reconnect policy is unchanged. A pane hidden in a split (shown = false) and a document that becomes hidden still release as before.
  • Cleanup: drops a duplicate mode !== "interact" check in the server's release-size handler (no await in between, so it was dead), and widens the two 1 s waitFor deadlines in the release-size contract tests to the 5 s their neighbors use.
  • The changelog entry has its own fragment, changelog.d/keep-grid-unfocused-desktop.md.

Evidence

Failing-first unit test: src/lib/ws.test.ts > "keeps a visible unfocused grid while changing only its reconnect policy"

Contracts: the 5 release-size cases in server/api.contract.test.ts pass on an isolated herdr session.

Browser QA: Playwright with a real herdr pty. Desktop 1280x800 in the terminal lens, phone 390x844 touch on the same pane.

  1. The phone opens Live terminal; the pty goes to 33x53.
  2. The desktop stays visibilityState: "visible", hasFocus() returns false, and a window blur is dispatched.
  3. The phone taps Chat transcript.
release-size frames from the desktop after blur pty after phone Chat
before (origin/main) 1 stays at phone 33x53 (not restored within 3 s)
after (this branch) 0 desktop 37x143 after 167 ms

The repo's browser regressions also pass on this branch: checkChatKeepsTerminalSize (including the new blur block), checkPaneSwitchKeepsTerminalSize, checkBackgroundTabKeepsTerminalSize (#1068 cases, including "a desktop window shown without the focus leaves the shared grid at the phone's 33 53"), checkFocusedWindowReclaimsTerminalSize and checkSplitView. Typecheck passes.

@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 17 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ef804156-7124-484d-b209-c565cc490579
📥 Commits

Reviewing files that changed from the base of the PR and between 505f915 and e2dc4e1.

📒 Files selected for processing: 7
  • changelog.d/keep-grid-unfocused-desktop.md
  • scripts/chat-size-regression.ts
  • server/api.contract.test.ts
  • server/index.ts
  • src/components/PaneTerminal.tsx
  • src/lib/ws.test.ts
  • src/lib/ws.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 69b627eb-7c27-4392-9527-3da45cb44788
📥 Commits

Reviewing files that changed from the base of the PR and between 705e9ae and 505f915.

📒 Files selected for processing: 7
  • changelog.d/keep-grid-unfocused-desktop.md
  • scripts/chat-size-regression.ts
  • server/api.contract.test.ts
  • server/index.ts
  • src/components/PaneTerminal.tsx
  • src/lib/ws.test.ts
  • src/lib/ws.ts

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

📝 Summary

Summary by CodeRabbit

  • New Features
    • A visible desktop terminal now keeps its current size when its window loses focus. Returning to Chat on your phone restores the desktop terminal’s full grid automatically, without requiring another click or refocus.
    • Switching back to the terminal view on your phone continues to restore the phone’s terminal grid.

The client now preserves a desktop terminal’s grid when its visible window loses focus. When the phone switches to Chat, regression checks verify desktop grid restoration. The checks also verify that returning the phone to its terminal lens restores the phone grid.

Changes: Desktop grid retention

Layer / File(s) Summary
Client keep-size policy
src/lib/ws.ts, src/components/PaneTerminal.tsx, src/lib/ws.test.ts
keepSize accepts a releaseGrid argument that defaults to true. PaneTerminal.leave passes whether the document is hidden. Tests cover preserving the grid without releasing it and reconnect behavior.
Grid restoration checks
server/index.ts, server/api.contract.test.ts, scripts/chat-size-regression.ts, changelog.d/keep-grid-unfocused-desktop.md
The release-size attachment check removes a redundant mode condition. Contract tests allow five seconds for geometry responses. The browser regression check verifies desktop and phone grid restoration. The changelog records the desktop behavior.

Priority: ⬇️ Low

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

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: wouldu-pres

Merge Risk: ⚪ Minimal · up to 505f9

This restores the desktop terminal grid when the phone returns to Chat, and no concrete 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 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. (1 skipped: 1… 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 main change: preserving the grid for a desktop terminal that remains visible but loses focus.
Description check Passed The description explains the regression, fix, retained behavior, cleanup, changelog, unit tests, contract tests, browser QA, and typecheck results. It does not use the exact "## Change" and "## Valida…
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • 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.

Keep blur as a reconnect-policy change without releasing the visible terminal's server-side grid. Hidden documents and panes still release, and a later Chat transition retains its one-shot release.

Add unit and built-app browser regressions for visible blur followed by phone Chat. The old head sends one release and leaves the pty at 33x53; the fix sends none and restores 37x143, with the real shell confirming it in 844 ms.

Verify 101 focused unit tests, five release-size contracts, the browser regression, explicit script typecheck, and fast checks with 3576 unit passes.

Refs #472
Plan: .omo/plans/issue-sweep-2026-10-14.md
… deadlines, give the follow-up its own changelog fragment
@devswha
devswha force-pushed the fix/keep-grid-on-unfocused-desktop branch from 505f915 to e2dc4e1 Compare October 14, 2026 18:15
@devswha
devswha merged commit 935d35d into main Oct 14, 2026
17 checks passed
@devswha
devswha deleted the fix/keep-grid-on-unfocused-desktop branch October 14, 2026 18:26
devswha added a commit that referenced this pull request Oct 14, 2026
## Problem

GitHub-hosted fork CI repeatedly failed `checkChatKeepsTerminalSize`
with `no size-5 answer from the pane` (runs 38618468326 and
38624998171). The pane snapshot showed the `size-5` command and the next
shell prompt, but not the command's output. Main's self-hosted runs and
local runs passed.

## Root cause

The send RPCs were not lost or queued: the exact command reached the
shell and the prompt returned. Probes also cannot overlap because each
`size()` call is awaited until its unique marker resolves or throws. The
failure was the observation channel: `pane.read(source: "recent")` reads
a screen/history snapshot, and this helper already documents that a
concurrent resize can reflow the screen and lose a completed output
line.

#1095 added a real-PTY restoration probe during the resize but used the
screen-backed mode. On slower hosted runners, reflow could erase the
marker even though the shell executed it.

## Change

Use the helper's existing file-backed mode for
`checkChatKeepsTerminalSize`. Each probe remains sequential and still
runs `stty size` in the real pane shell, but reads its answer from the
fixture directory instead of a reflowing screen snapshot. The two
one-second restoration assertions are unchanged; no timeout or fixed
sleep was added. Test-only change, so no changelog fragment.

## Validation

- `bun run check run --build bun scripts/chat-size-regression.ts` — exit
0 (focused real browser/PTY regression)
- `taskset -c 0 bun run check run --build bun
scripts/ui-contexts-regression.ts` — exit 0; report verified, source
unchanged (build 10.2 s, run 304.7 s)
- `taskset -c 0-7 bun run check run --build bun
scripts/ui-contexts-regression.ts` — exit 0; report verified, source
unchanged (build 4.1 s, run 179.0 s)
- `bun run typecheck` — exit 0 on final main base
- `HERDR_TEST_MODE=unit bun test ./scripts/conventions.test.ts
./scripts/ci-browser.test.ts` — exit 0 on final main base

Two intermediate full-suite attempts exited 1 before reaching chat-size
in the pre-existing `checkTabMenu` locator timeout also present in the
supplied hosted-CI artifact; no unrelated code was changed.
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