Repository navigation
fix(terminal): hand the shared grid only to a device still showing the terminal - #1085
Merged
Merged
Conversation
Release grid ownership immediately when keepSize hides a terminal, and allow an unchanged local grid to reclaim it. Track keep_size on the existing attach claim so a release during creation cannot revive a hidden grid. Only currently visible terminal clients qualify for handoff; leave size unchanged when none remain. Add real-client three-viewer and pending-attach contract regressions. Verify desktop/phone browser handoff in 147 ms, typecheck, 100 touched unit tests, 3575 unit tests and fast checks. Unrelated cwd/file-path contract failures reproduce on the main server. Refs #472 Plan: .omo/plans/issue-sweep-2026-10-14.md
|
Warning Review limit reachedYou'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 10 minutes. View limit details
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. Comment |
devswha
added a commit
that referenced
this pull request
Oct 14, 2026
…ed (#1095) 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" - On #1085's head `25b09433` and on its squash `7776c4fd` (origin/main at the time): FAIL, 63 pass / 1 fail, because a release-size frame was sent on blur. - On this branch: PASS, 64/64. **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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #472
Follow-up to #1068. Fixes the remaining gap in #1068's grid handoff: when a client released the shared grid, the server could hand the pty to another client whose terminal was hidden (a pane hidden in its split, or a tab put away). That client had stopped showing the terminal but had sent nothing, so its grid was still a handoff candidate.
What changed
src/lib/ws.ts:keepSize()(hidden pane, tab out of use) now releases the grid the same way the Chat lens does. It sendsrelease-sizeonce when this connection drove the grid, and never replays it on reconnect. Showing the terminal again at the same dimensions still sends the resize that takes the grid back.server/index.ts: each client's attach claim records whether it keeps the size (keep_sizeattach orrelease-size; cleared by a resize or drive).release-sizehands the pty only to a client still showing the terminal. If none is left, the size stays. A release that arrives while the attach is still being created is remembered, so the completed attach cannot bring the released grid back.server/api.contract.test.ts: three clients with the realHerdrSockethiding its pane, then a release that lands during attach creation. One extended case insrc/lib/ws.test.ts. Changelog fragment added.Before / after
Contract run (
bun test ./server/api.contract.test.ts -t release-size, isolated herdr session):server/index.ts+src/lib/ws.ts): desktop at 120x40, hidden client at 100x30, phone at 53x33. The hidden client hides its pane and the phone releases: the pty goes to the hidden client's 100x30. With a release during attach creation, the released 100x30 grid comes back when the phone releases. 3 pass / 2 fail.src/lib/ws.test.ts: before, hiding sent norelease-size(62 pass / 1 fail); after, 63 pass.release-size. When the phone returns to Chat, the visible desktop gets 37x143 back in 147 ms.Checks:
bun run typecheckexit 0; touched unit tests (ws, server/src/scripts conventions, changelog fold) 100 pass.