Repository navigation
fix(terminal): give the shared grid back when a phone returns to Chat - #1068
Merged
Merged
Conversation
A phone that opened the Live terminal sized the shared pty to its own grid and kept it there after going back to Chat, so a desktop on the same pane stayed at phone width until its own resize, focus or click. The chat lens now sends a new client frame, release-size, when this tab drove the grid. The server hands the pty to the latest grid of another interact client still showing the terminal, and only while the releasing client is still the last driver: a resize another client sent in between is never overwritten, and no client in Chat ever claims the size. An older server ignores the frame. Tests: the api.contract release-size cases (regression, fails on main: the desktop grid returns within 1 s and the shell's stty size shows it; controls: a later competing resize wins with at most one server resize, and a release from a client that never drove changes nothing and answers no error) and a ws.test.ts case for when the client sends the frame (regression, fails on main). Fixes #472.
|
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 5 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 |
Fix the blocking PR #1068 finding: keepSize marks reconnect policy, not whether the current connection still owes a grid release. Track that release separately and cover hide-then-Chat with a one-shot, no-replay regression.
devswha
added a commit
that referenced
this pull request
Oct 14, 2026
…e terminal (#1085) 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 sends `release-size` once 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_size` attach or `release-size`; cleared by a resize or drive). `release-size` hands 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. - Tests: two contract cases in `server/api.contract.test.ts`: three clients with the real `HerdrSocket` hiding its pane, then a release that lands during attach creation. One extended case in `src/lib/ws.test.ts`. Changelog fragment added. ## Before / after Contract run (`bun test ./server/api.contract.test.ts -t release-size`, isolated herdr session): - Before (main's `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. - After: the pty goes to the **remaining terminal's 120x40** within 1 s, with one resize. With no terminal viewer left, the size stays. 5 pass / 0 fail. - `src/lib/ws.test.ts`: before, hiding sent no `release-size` (62 pass / 1 fail); after, 63 pass. - Browser QA (three real pages): a hidden page sends exactly one `release-size`. When the phone returns to Chat, the visible desktop gets 37x143 back in 147 ms. Checks: `bun run typecheck` exit 0; touched unit tests (ws, server/src/scripts conventions, changelog fold) 100 pass.
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.
Fixes #472
Root cause
When a phone opened the Live terminal on a pane that a desktop was also showing, its attach and resize sized the shared pty to the phone's grid (
server/index.ts:2864attach,server/index.ts:3031resize). Going back to Chat only marked the grid locally as covered (src/components/PaneTerminal.tsx:1910,keepSize). Nothing told the server, and the server didn't track whose grid the pty had, so the pty stayed at the phone's 53 columns. The desktop drew a phone-width terminal with a dead area on the right until its own resize, focus or click.Change
shared/protocol.ts: new client framerelease-size { pane_id }. It is never answered, and an older server ignores it.src/lib/ws.ts/PaneTerminal.tsx: when the chat lens covers a terminal that this tab sized (interact mode only), it sendsrelease-sizeonce. A reconnect doesn't replay it; the reconnect attaches withkeep_size.server/index.ts: each attachment remembers each interact client's own grid while that client shows the terminal, plus which client drove the pty last. Onrelease-sizefrom the current driver, the pty takes the latest grid of another interact client still showing the terminal. If nothing qualifies, or another client resized in between, the size stays. A client covered by the chat lens never claims the size.site/demo/transport.ts: accepts the frame without a reply. Changelog fragment added.REMOTE_BUNDLE_VERSIONis not bumped: bundle sync happens at release time.Evidence
api.contract.test.tscase. Desktop at 120x40, then the phone attaches at 53x33 and sendsrelease-size: the desktop getspane-geometry120x40 within 1 s, andstty sizein the pane reads40 120. On origin/main it fails with "the grid given back not received within 1000ms".ws.test.tscase. The client sendsrelease-sizeonce, only for a grid it drove, never replays it, and never sends it as an observer.release-size, the pty is back at the desktop's 37x143 within 46-157 ms, and the desktop draws a full 143-cell row. Screenshots at 1280x800 and 390x844 in light and dark: the phone's Chat screens are pixel-identical before and after, there is no horizontal scroll at 390, no console or CSP errors, and no new strings.Checks
bun run typecheck: okHERDR_TEST_MODE=unit bun test ./src/lib/ws.test.ts ./scripts/conventions.test.ts ./src/conventions.test.ts ./server/conventions.test.ts ./scripts/changelog-fold.test.ts: 99 passbun run test:unit: 3516 pass, 0 fail, 8 skipserver/api.contract.test.ts -t release-size: 3 pass. Whole file: 120 pass, 2 fail, and both failures are unrelated to this change. "repository diff of a pane's folder" fails on origin/main the same way. "workspace and discovery endpoints" fails only under a nested TMPDIR on this machine, on origin/main too (2 of 3 runs), and passes 3/3 on both refs with a plain TMPDIR.