Repository navigation
perf(terminal): resize the pty once a window drag rests - #34
Merged
Merged
Conversation
The ResizeObserver refit xterm and resized the shared pty on every frame of a window drag: 115 resizes for one drag across 600px. Each one makes herdr reflow the pane and its program redraw (Claude Code repaints its whole conversation), so on a long session the app lagged. The refit now waits until the size has rested for 120ms. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
devswha
pushed a commit
that referenced
this pull request
Oct 7, 2026
…thout a pairing code (#525) ## Intent Fix mobile connection to herdr-web-ui (https://github.com/devswha/herdr-web-ui) and simplify its pairing as much as possible. The captain will always reach it over Tailscale and wants entering the Tailscale URL alone to work at once: https://denisss-macbook-pro-m1.tail5cc90b.ts.net:7317. What happened instead: the captain's phone, signed in to the SAME Tailscale account as this Mac ([email protected], the only user on this tailnet, all nodes untagged, Tailscale 1.102.4), opened that URL and was shown the device-pairing screen instead of the app - "i entered this link https://denisss-macbook-pro-m1.tail5cc90b.ts.net:7317 but it asks oairing! it can not connect!". The captain now asks to fix this pairing difficult logic. Success means: the owner's own phone opens the Tailscale URL and lands in the app immediately, no code, no pairing screen; the six-digit pairing flow remains only for devices that genuinely belong to someone else. ## What Changed - Added the opt-in `HERDR_WEB_TAILSCALE_SERVE_ONLY=1` declaration: on a tailnet that `tailscale status --json` proves is owned by a single login with no tagged node, a serve-proxied request carrying no login header is admitted as the owner, so the owner's own phone opens the serve address and lands in the app with no pairing code. The grant also requires the request's Host to name this PC's own tailnet DNS name or IP; other logins are still refused, tagged nodes and Funnel still pair or stay closed, and a configured token still overrides everything. - Reworked the Tailscale identity layer in `server/tailscale.ts`: new `parseSoleTailnetLogin` and `parseNodeName`, and an injectable `TailnetIdentitySource` class replacing the module-level `tailscaleIdentity()`, caching owner/tagged/sole-login/DNS/IP for five minutes and taking a single-flight fresh status read on the owner-grant path when the sole-login proof is unsettled or a read failed. - Extended `decideAccess` in `server/access.ts` with the serve-only owner grant (via new `hostName`, `addressesNode` and `isServeOwnerRequest` helpers, refactored out of `isLoopbackHost`), wired through `createServer` with new `tailscaleServeOnly` and `tailnet` options that also serve tests; updated the access contract in `shared/protocol.ts`, plus unit and contract tests, CHANGELOG, INSTALL, README (en/ja/ko/zh-CN) and docs/guide.md. ## Risk Assessment ✅ Low: The change is well-bounded: an opt-in flag guards the new grant, every previously authorized fix is correctly applied and verified against the code, the grant floor is enforced before any identity-dependent branch, and unit plus contract tests exercise real behavior in both directions; no defect or unrequired component was substantiated. ## Testing Every scenario derived from the intent passed live against the real product. The happy path was driven with the machine's real tailscale CLI (Tailscale 1.102.4, sole login, no tagged nodes - exactly the reported environment): with HERDR_WEB_TAILSCALE_SERVE_ONLY=1 the phone-shaped serve request is granted via tailscale and a real Chrome loading the MagicDNS URL renders the workspace with no pairing gate, while the identical request on a flag-off install gets the six-digit pairing screen the captain reported. Adversarial guards all hold live: another login refused (other_user), foreign/loopback Host pairs, Funnel pairs, a configured token still required, a tagged node appearing mid-TTL revokes the warm-cache grant on the next request, and a Starting status after wake recovers on the very next request instead of locking the owner out for five minutes; pairing a device (closing the gate) does not affect the owner's phone. New unit and contract tests for the change also pass. One incident during cleanup, fully remediated: my 'pkill -f bun server/index.ts' also matched the captain's live bridge (the supervisor spawns it with exactly that argv), taking the live 7317 install down for about two minutes; I restored it immediately with the plugin's canonical 'bun scripts/plugin.ts start' launcher - same active release (release-EqyLpU, revision c4cb041), same port, verified healthy - and no state under ~/.config/herdr-web-ui was touched. - Live validation: ✅ go - 9 of 9 scenarios driven live against the product | Scenario | Result | Live | Evidence | | --- | --- | --- | --- | | Owner's own phone opens the Tailscale URL and lands in the app immediately, no code, no pairing screen (HERDR_WEB_TAILSCALE_SERVE_ONLY=1, one-login untagged tailnet) | ✅ pass | live | live-s1-owner-phone-no-code.txt (authenticated:true via:tailscale, /api/session 200) and ui-phone-serve-only-lands-in-app.png (real Chrome at the MagicDNS hostname renders the workspace, no gate, /ws… | | With the flag off (the default), the same phone request gets the six-digit pairing flow, which keeps working for devices that belong to someone else | ✅ pass | live | live-s2-s7-guards.txt (pairing_required, 401) and ui-phone-flag-off-pairing-screen.png ('Pair this device with a code from the PC' gate); pairing a device over /api/devices/pair succeeds (live-s9-gate… | | A genuinely different Tailscale login is refused, never silently granted, even on a serve-only install | ✅ pass | live | live-s2-s7-guards.txt: Tailscale-User-Login [email protected] -> other_user refusal on /api/health and /api/session | | A tagged node appearing on the tailnet revokes the no-code grant on the next request, even from a warm cache inside the 5-minute TTL | ✅ pass | live | live-s4-s8-transitions.txt: request 3 granted from warm cache, tagged peer flips the staged status, request 4 immediately pairing_required (401); server driven over live HTTP with a staged tailscale C… | | After the Mac wakes with tailscaled still Starting, the owner is asked to pair at most once and the next request succeeds (no 5-minute negative-cache lockout) | ✅ pass | live | live-s4-s8-transitions.txt: Starting -> pairing_required, flipped to Running -> immediate next request granted via tailscale | | A rebinding page or non-serve proxy presenting its own Host gains nothing: the Host must name this PC's MagicDNS name or tailnet IP | ✅ pass | live | live-s2-s7-guards.txt: Host evil.example and Host 127.0.0.1 with forwarding header -> pairing_required; the MagicDNS name and the 100.x tailnet IP both granted (live-s1-owner-phone-no-code.txt) | | Funnel (public internet) stays closed even with serve-only on and the sole-login proof | ✅ pass | live | live-s2-s7-guards.txt: Tailscale-Funnel-Request header -> pairing_required | | A configured token is still required of everything but a paired device on a serve-only install | ✅ pass | live | live-s2-s7-guards.txt: HERDR_WEB_TOKEN install -> token_required without credentials, via:token with the bearer | | After the first device is paired (gate closed for strangers), the owner's phone still lands in the app without a code | ✅ pass | live | live-s9-gated-owner-still-in.txt: device paired over the real pairing endpoints, then the phone-shaped request still authenticated via tailscale and /api/session 200 | <details> <summary>Evidence: Owner's phone granted with no code (real tailnet, serve-only install)</summary> `GET /api/health?scope=bridge with Host=denisss-macbook-pro-m1.tail5cc90b.ts.net, X-Forwarded-For, no login header -> {"auth":{"required":false,"authenticated":true,"via":"tailscale","role":"drive"}}; GET /api/session -> HTTP 200; Host=100.110.31.92 (tailnet IP) and UPPER-CASE name also granted` ```text === S1: owner's phone (serve-proxied, no login header, Host = this PC's Tailscale name) on serve-only install (port 37611) --- GET /api/health?scope=bridge {"ok":true,"auth":{"required":false,"authenticated":true,"via":"tailscale","role":"drive"},"bridge_protocol":1} --- GET /api/session (auth-gated endpoint; phone lands in the app iff not 401) HTTP 200 --- same, Host = this PC's tailnet IP 100.110.31.92 {"ok":true,"auth":{"required":false,"authenticated":true,"via":"tailscale","role":"drive"},"bridge_protocol":1} --- Host name in UPPER CASE (same PC) ``` </details> - Evidence: Phone browser at the Tailscale URL lands in the app (serve-only on, no pairing screen) (local file: <code>~/.no-mistakes/evidence/01M48S35FX09YZE6HXK7R6VETR/ui-phone-serve-only-lands-in-app.png</code>) - Evidence: Same URL on a flag-off install shows the six-digit pairing screen (the reported bug, still the default) (local file: <code>~/.no-mistakes/evidence/01M48S35FX09YZE6HXK7R6VETR/ui-phone-flag-off-pairing-screen.png</code>) <details> <summary>Evidence: Guards: flag off pairs; other login refused; foreign Host pairs; Funnel pairs; token still required</summary> ```text --- Host name in UPPER CASE (same PC) {"ok":true,"auth":{"required":false,"authenticated":true,"via":"tailscale","role":"drive"},"bridge_protocol":1} === S2: SAME phone request on an install WITHOUT the flag (port 37613, default) -> six-digit pairing remains --- /api/health?scope=bridge {"ok":true,"auth":{"required":true,"authenticated":false,"reason":"pairing_required"},"bridge_protocol":1} --- /api/session status code HTTP 401 --- /api/session refusal body {"error":{"code":"unauthorized","message":"pair this device, or use the token"}} === S3: someone else's Tailscale login is refused on the serve-only install (port 37611) {"ok":true,"auth":{"required":true,"authenticated":false,"reason":"other_user"},"bridge_protocol":1} {"error":{"code":"other_user","message":"this PC belongs to another Tailscale user"}} === S5: rebinding/foreign Host gains nothing on the serve-only install (port 37611) {"ok":true,"auth":{"required":true,"authenticated":false,"reason":"pairing_required"},"bridge_protocol":1} HTTP 401 --- Host = plain 127.0.0.1 loopback name with forwarding header (a local proxy that is not serve) {"ok":true,"auth":{"required":true,"authenticated":false,"reason":"pairing_required"},"bridge_protocol":1} === S6: Funnel (public internet) stays closed on the serve-only install (port 37611) {"ok":true,"auth":{"required":true,"authenticated":false,"reason":"pairing_required"},"bridge_protocol":1} === S7: a configured token is still required of the phone on a token install (port 37617, serve-only on) --- phone-shaped request, no token {"ok":true,"auth":{"required":true,"authenticated":false,"reason":"token_required"},"bridge_protocol":1} {"error":{"code":"unauthorized","message":"token required"}} --- with the token as bearer {"ok":true,"auth":{"required":false,"authenticated":true,"via":"token","role":"drive"},"bridge_protocol":1} ``` </details> <details> <summary>Evidence: Status transitions: Starting recovers next request; tagged node revokes warm-cache grant inside TTL</summary> ```text === S8: Mac wakes, tailscaled still 'Starting' -> owner asked to pair once, then recovers on the NEXT request --- status: BackendState Starting (what tailscale status --json says right after wake) Starting - {'7': {'LoginName': '[email protected]'}} --- request 1 (serve-only install, port 37619, phone shape, no login header) {"ok":true,"auth":{"required":true,"authenticated":false,"reason":"pairing_required"},"bridge_protocol":1} --- tailscaled reaches Running (one login, no tags) - the SAME minute, well inside the 5-minute cache TTL --- request 2, immediately: the grant path must re-read, not answer the stale negative {"ok":true,"auth":{"required":false,"authenticated":true,"via":"tailscale","role":"drive"},"bridge_protocol":1} HTTP 200 === S4: a node gets tagged while the cache is warm (Running sole -> Running with tagged peer), inside the TTL --- request 3 (cache already proved sole login on request 2): still granted {"ok":true,"auth":{"required":false,"authenticated":true,"via":"tailscale","role":"drive"},"bridge_protocol":1} --- a tagged node joins the tailnet (status flips; still well inside the 5-minute TTL) --- request 4, immediately: the warm cache must NOT keep granting; the no-login request pairs again {"ok":true,"auth":{"required":true,"authenticated":false,"reason":"pairing_required"},"bridge_protocol":1} HTTP 401 ``` </details> <details> <summary>Evidence: After pairing a device (gate closed) the owner's phone still gets in; strangers still pair</summary> ```text === S9: pair a device first (closing the gate for strangers), then re-check the owner's phone --- POST /api/devices/pair/start from this PC (localhost, local access) {"code":"584600","expires_at":"2026-10-06T14:59:46.697Z"} --- POST /api/devices/pair with code 584600 (as a stranger's device would) HTTP 204 (device cookie set) --- owner's phone after the gate closed (no cookie, no token, serve-only install) {"ok":true,"auth":{"required":false,"authenticated":true,"via":"tailscale","role":"drive"},"bridge_protocol":1} HTTP 200 --- stranger-shaped serve request after the gate closed {"ok":true,"auth":{"required":true,"authenticated":false,"reason":"pairing_required"},"bridge_protocol":1} ``` </details> ## Pipeline Updates from [git push no-mistakes](https://github.com/kunchenguid/no-mistakes) <!-- no-mistakes-pipeline-attestation:v1 {"head_sha":"15c2bd4db0c4eed4f624e0e59da4cdf82b222df5","steps":[{"step":"intent","status":"completed"},{"step":"rebase","status":"completed"},{"step":"review","status":"completed"},{"step":"test","status":"completed"},{"step":"document","status":"completed"},{"step":"lint","status":"completed"},{"step":"push","status":"completed"},{"step":"pr","status":"running"},{"step":"ci","status":"pending"}]} --> <details> <summary>✅ **intent** - passed</summary> ✅ No issues found. </details> <details> <summary>🔧 **Rebase** - 1 issue found → auto-fixed ✅</summary> -⚠️ `CHANGELOG.md` - merge conflict rebasing onto origin/main 🔧 Fix applied. ✅ Re-checked - no issues remain. </details> <details> <summary>🔧 **Review** - 2 issues found → auto-fixed (2) ✅</summary> -⚠️ `CHANGELOG.md:65` - The new serve-only entry sits inside the `## [0.3.52] - 2026-10-06` `### Fixed` section (header at line 64), but the base commit 54e5a1f is already past the v0.3.52 release prep, and `## [Unreleased]` has its own `### Fixed` section at line 16. This branch's change is unreleased work attributed to a shipped version; at the next release prep it stays stranded inside the historical 0.3.52 block instead of moving with [Unreleased]. This is the previously authorized fix (recorded decision `changelog-entry-under-released-0.3.52`) still unapplied at this head. Remedy: move the 8-line entry (lines 65-72) up under `## [Unreleased]` → `### Fixed`, appended after the existing Codex entry; the PR link is added later by the pipeline's PR step. - ℹ️ `server/index.ts:1029` - The grant-path predicate `token === "" && pairedDevice === null && isServeOwnerRequest(requestShape)` is path-blind, so on a serve-only install every phone-shaped request — including static assets (JS/CSS/icons/sw.js), `/api/health` without scope, `/api/auth` and `/api/devices/pair` — awaits a fresh `tailscale status --json` spawn in `freshIdentity` (server/tailscale.ts:255-259 skips the early return only when the cache proves sole-login and the Host matches, i.e. exactly the phone's case). For non-`/api`/non-`/ws` paths the computed `access` is never consulted (static serving falls through; `requiresAuth` and the readOnly/mutating checks are all gated on `/api/` or `/ws`), so the read adds one bounded CLI spawn plus its latency (~20-100 ms, 2.5 s worst case) to each such response on the intended happy path (first phone page load pays one spawn per asset wave) while buying nothing. Remedy: add `(pathname === "/ws" || pathname.startsWith("/api/"))` to the grant-path predicate — behavior-preserving for every response, since `/api/*` (including `/api/health?scope=bridge`, the one open endpoint that reports auth) and `/ws` are the only paths that observe `access`. 🔧 Fix applied. 1 warning still open: -⚠️ `docs/guide.md:213` - The changed sentence says "Your own devices get in without a code only when you set HERDR_WEB_TAILSCALE_SERVE_ONLY=1 ... Without it, the phone pairs with a six-digit code." That contradicts the rest of the change's own documentation and the code: `tailscale serve` stating the owner's login already grants entry with no flag (server/access.ts:121, guide.md:259 "A login that matches this PC's own gets in", guide.md:267 "Nothing needed: your login", INSTALL.md:156-157 "Nothing to configure"). The flag exists precisely for the requests where serve states no login (the reported Tailscale 1.102.4 phone case), not as the only codeless path. A reader who takes the sentence at face value enables a security-relevant flag (full owner access for no-login proxied requests) they may not need. Siblings carrying the same "set the flag to get codeless phone access" framing: README.md:94, README.ja.md:96, README.ko.md:95, README.zh-CN.md:96. Remedy: qualify the sentences the way INSTALL.md:157 already does — your devices get in without a code when serve states your login; if your own phone is asked to pair anyway, HERDR_WEB_TAILSCALE_SERVE_ONLY=1 lets it in without a code on a one-login tailnet, enabled only when nothing else reaches the port. 🔧 Fix applied. ✅ Re-checked - no issues remain. </details> <details> <summary>✅ **Test** - passed</summary> ✅ No issues found. - Live validation: ✅ go - 9 of 9 scenarios driven live against the product | Scenario | Result | Live | Evidence | | --- | --- | --- | --- | | Owner's own phone opens the Tailscale URL and lands in the app immediately, no code, no pairing screen (HERDR_WEB_TAILSCALE_SERVE_ONLY=1, one-login untagged tailnet) | ✅ pass | live | live-s1-owner-phone-no-code.txt (authenticated:true via:tailscale, /api/session 200) and ui-phone-serve-only-lands-in-app.png (real Chrome at the MagicDNS hostname renders the workspace, no gate, /ws… | | With the flag off (the default), the same phone request gets the six-digit pairing flow, which keeps working for devices that belong to someone else | ✅ pass | live | live-s2-s7-guards.txt (pairing_required, 401) and ui-phone-flag-off-pairing-screen.png ('Pair this device with a code from the PC' gate); pairing a device over /api/devices/pair succeeds (live-s9-gate… | | A genuinely different Tailscale login is refused, never silently granted, even on a serve-only install | ✅ pass | live | live-s2-s7-guards.txt: Tailscale-User-Login [email protected] -> other_user refusal on /api/health and /api/session | | A tagged node appearing on the tailnet revokes the no-code grant on the next request, even from a warm cache inside the 5-minute TTL | ✅ pass | live | live-s4-s8-transitions.txt: request 3 granted from warm cache, tagged peer flips the staged status, request 4 immediately pairing_required (401); server driven over live HTTP with a staged tailscale C… | | After the Mac wakes with tailscaled still Starting, the owner is asked to pair at most once and the next request succeeds (no 5-minute negative-cache lockout) | ✅ pass | live | live-s4-s8-transitions.txt: Starting -> pairing_required, flipped to Running -> immediate next request granted via tailscale | | A rebinding page or non-serve proxy presenting its own Host gains nothing: the Host must name this PC's MagicDNS name or tailnet IP | ✅ pass | live | live-s2-s7-guards.txt: Host evil.example and Host 127.0.0.1 with forwarding header -> pairing_required; the MagicDNS name and the 100.x tailnet IP both granted (live-s1-owner-phone-no-code.txt) | | Funnel (public internet) stays closed even with serve-only on and the sole-login proof | ✅ pass | live | live-s2-s7-guards.txt: Tailscale-Funnel-Request header -> pairing_required | | A configured token is still required of everything but a paired device on a serve-only install | ✅ pass | live | live-s2-s7-guards.txt: HERDR_WEB_TOKEN install -> token_required without credentials, via:token with the bearer | | After the first device is paired (gate closed for strangers), the owner's phone still lands in the app without a code | ✅ pass | live | live-s9-gated-owner-still-in.txt: device paired over the real pairing endpoints, then the phone-shaped request still authenticated via tailscale and /api/session 200 | - `HERDR_TEST_MODE=unit bun test ./server/tailscale.test.ts ./server/access.test.ts (35 pass)` - `bun test ./server/api.contract.test.ts -t serve (both new serve-only contract tests pass against the isolated herdr-web-ui-test herdr session)` - `Live HTTP drive, real tailscale CLI reading the machine's real one-login tailnet: phone-shaped request (loopback source, X-Forwarded-For, no Tailscale-User-Login, Host=denisss-macbook-pro-m1.tail5cc90b.ts.net) against a real bun server/index.ts instance with HERDR_WEB_TAILSCALE_SERVE_ONLY=1 -> /api/health?scope=bridge reports authenticated:true via:tailscale; /api/session 200; tailnet-IP and upper-case Host variants also granted` - `Live HTTP drive, same request against a flag-off instance -> pairing_required (401 unauthorized body); stranger Tailscale-User-Login -> other_user; evil.example and 127.0.0.1 Host -> pairing_required; Tailscale-Funnel-Request header -> pairing_required; HERDR_WEB_TOKEN install -> token_required without credentials, via:token with bearer` - `Live HTTP drive with a staged fake tailscale CLI on PATH: BackendState Starting -> pairing_required once, then Running sole-login -> granted on the very next request inside the 5-minute TTL; warm-cache sole-login grant -> a tagged peer appearing in status -> pairing_required immediately` - `Live HTTP drive: paired a device over /api/devices/pair/start + /api/devices/pair (gate closed), then the owner's phone request still granted and stranger-shaped requests still pairing_required` - `Playwright (real Chrome, host-resolver mapping the MagicDNS name to the test server, phone viewport): the app loads at http://denisss-macbook-pro-m1.tail5cc90b.ts.net:37611/ with no pairing gate and an open /ws; the same URL on the flag-off server shows the 'Pair this device with a code' gate; screenshots captured` - `Cleanup verification: all four test servers stopped, herdr-web-ui-test session stopped, worktree returned to clean (transient .nm-test, dist, .playwright artifacts removed), captain's live install on 7317 verified healthy` </details> <details> <summary>✅ **Document** - passed</summary> ✅ No issues found. </details> <details> <summary>✅ **Lint** - passed</summary> ✅ No issues found. </details> <details> <summary>✅ **Push** - passed</summary> ✅ No issues found. </details> Co-Authored-By: Claude Fable 5.1 <[email protected]>
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.
Summary
Resizing the app window made it lag badly.
Cause: the terminal's
ResizeObserverfired on every frame of the drag. Each time, it refit xterm and resized the shared pty right away. That makes herdr reflow the pane, and the program in it redraws: Claude Code repaints its whole conversation. On a long session, over a hundred of these in a couple of seconds is what made it lag. The server itself was fine: during the lag, the web server used about 100 MB and around 1% CPU.Fix: the observer waits until the size has rested for 120 ms (
RESIZE_SETTLE_MS), then fits once and sends one resize. The explicit refits keep firing at once, unchanged: switching to the terminal view, and focus or visibility coming back.Testing
Headless Chrome at 1400×900, a Claude Code pane in terminal view, with the window dragged 1400→800→1400 px over 120 frames:
bun run typecheckpasses,bun testpasses 304/304, andbun run test:uipasses 7/7.🤖 Generated with Claude Code