Repository navigation
fix(server): cancel an attach whose client leaves before the pty is ready - #3
Merged
Merged
Conversation
…eady The attach handler added the client to the attachment only after awaiting the terminal lookup. A detach or close that arrived during that await found nothing to remove, so the client was added afterwards anyway. The pty then outlived its last live client: a closed socket stayed in the set forever, and a detached client kept receiving the pane's bytes until it disconnected. The detach case is what switching panes quickly in the sidebar does (detach old, attach new). The pane is now recorded in `attached` before the await, so detach and close clear it, and the attach checks it on resume. A cancelled attach closes the attachment only when no other client still wants the pane. A joiner of the same creation may not have resumed yet, and closing eagerly would hand it a dead record. Tests: two contract tests (disconnect, detach) check that no `herdr terminal attach` process survives the last live client. With the fix reverted both fail 3/3; with the intent check removed both fail 3/3 because the remaining client never receives data. The observer-first test moves to its own pane so it no longer relies on the previous test having released the shared one. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
releaseUnclaimed treats a pane in any client's `attached` set as a live claim. When a pty exits while its herdr pane lives on, closeAttachment deleted the record but left the pane in each member's set. Those members sit on the "terminal ended" screen, and their stale entries then vetoed closing a later attach on that pane that was cancelled mid-creation, so that pty kept running with no clients. closeAttachment now removes the pane from its members' sets. A probe (kill the attach under a watching client, then attach and detach the pane in one tick) leaves 0 attach processes with this change and 2 without it. No contract test pins it: nothing observable marks the moment a cancelled creation with no other joiner has finished. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Nov 1, 2026
devswha
added a commit
that referenced
this pull request
Nov 22, 2026
…st screen, always-QR and About update check (#4435) ## 0.5.10 relay/app integration (one combined review) Owner's method for 0.5.10: every lane put its slice on `release/relay-0510` (per-slice commits, subject prefixed with the slice name). This PR runs the one combined pass: check fast + full CI once, one dori review, one omo gate (anthropic/claude-opus-5-5 high) over the whole diff, t13r on the security slices, one fix round. A bad slice can be dropped by reverting its commits. Base: `860d1b5b6` (main with 0.5.9). ### Slices | slice | commits | what | t13r | |---|---|---|---| | approve-card | fe336dd..112bfd1, b527564 | A PC with no account member lets its first phone in by a tap in the PC's own window (digits shown, "allow only if your phone shows this number"); any other window gets 403. Phone waiting screen: "맥에서 [허용]을 눌러 주세요". QR key confirm: [이 PC에서 확인] opens the existing confirm page (POST /api/account/confirm-page, own window only); no route approves a key. | YES | | uvb-S1, S1b | d32628d, e8a755b, d028865 | Unified sidebar adds the account PCs by itself; nothing to press (no Check again, digits, Change PC); header dot. | - | | uvb-S2 | b9bee3d | Relay drive devices may add account PCs; a vouched PC join is a WATCH row. | YES | | uvb-S3, S3b | e84272c, fe760e2 | Shell opens any online PC by itself, moves off one that goes away; account-only PCs only when confirmed, past new_until, not introduction-only. | YES | | uvb-S4 | ddedeb1 | Vouched PC join approved by a plain tap, bound to the joining server proven in-session and matched against the approver's own /v1/pcs. | YES | | phone-first-build | e62c516..80e5620 | Phone native first screen; Android Tailscale check (manifest `<queries>` com.tailscale.ipn). Owner OK given. | - | | desktop-update-about | 31d609b..d1dd8a8 | Settings > About [업데이트 확인] runs the app's own update check. Replaces #4427. | - | | add-connection-qr | 5ce18df..f7312c0 | Add a connection shows a phone QR on every tab, drops Phones and devices; PC page link `#sign-in=` signs in, then joins that PC. Replaces #4431. Owner UI OK given. | YES | | control-page-fold | e87df8e..a3a28f0, fixes 44fb77d..30d20c6 | Removes the app.ovis.sh control page; 기기 끊기 / PC 빼기 (dead PC, any age) / 계정 삭제 under Settings > 기기와 PC > [계정 관리]. 모든 기기 로그아웃 was later pulled back INTO 0.5.10 by the owner (owner-fix round below). Manage account also reachable from the signed-in start screen (owner-approved). | YES (PCR-1: ovis-sh/account#58, not a regression) | ### Replaced PRs #4428 (closed), #4427 (closed), #4431 (closed). ### Review trail - Combined gate @f7312c09e BLOCK -> fix round -> delta gate @781e03309 BLOCK (HIGH-2) -> fixes -> delta gate @a4c9bb23b CLEAR -> MEDIUM fix 5438550..fd2e5fb CLEAR. - control-page-fold gate @fd2e5fbdf BLOCK (hosted leave feedback) -> fixes 44fb77d..30d20c6 (gate running). - dori @f7312c09e BLOCK (native #picked) -> fixed 477f3d0/a4c9bb23b; dori @a3a28f017 CLEAR; dori at the final tip running. - Fix commits are prefixed by slice ('uvb-fix:', 'approve-card:', 'add-connection-qr:', 'control-page-fold:'). ### Merge conditions - check fast + CI green, dori CLEAR, gate CLEAR, t13r YES on approve-card, uvb-S2/S3/S4, add-connection-qr, control-page-fold. - Owner OK on add-connection-qr UI and phone-first-build: both given. - Owner tests the Mac + phone preview of the final tip and says OK (lead's condition). ## Owner-fix round (fix/owner-0510, landed as 89c9e26..cccb50f) The owner tested the 89c9e26 previews and reported findings #1-#10; the lead added items (a) sign out every device, (c) reconnect speed, (d) PCR-1 app side + #4440 relay/account items, (e) ovis CLI cleanup (lane ovis-cli-design), and the PC proof on re-list (#65 condition). All landed on side branch fix/owner-0510, then fast-forwarded here. | Item | Commits | |---|---| | #1 signed-in 0-PC: 3 tabs + ⋮ menu | 09a09dc | | #2 confirm an unconfirmed PC (+ two-step line, gaps) | 0325bf6, ea87f1e, 3cc9d07 | | #3 setup row = checklist | 164012c | | #4 Tailscale serve/open (+ owner-login condition) | e614cf1, ab20c89 | | #5 phone approve/deny of a join | 701e023, 9cf9b1a, 1dd2c61 | | #6 Direct = address line + code, no QR | 2caeb4e, e02aedc | | #7 signed-out account PC one line | 7928083 | | #8 join notice to the right windows, kept until seen | 6662003, f718efe, dbd2f68, cccb50f | | #9 reconnect UI (grey after 1 s, card after 10 s) | 4a6247e | | #10 Inbox entry beside Settings | 0ec0dbe | | SSH from hosted Direct -> app's own SSH screen | 1c51cb1, 3f9be0b | | (a) sign out every device (account#64 live) | 9b63d95, c8fa0a4, 7b2574f | | (c) reconnect wins | 84b8ce6, 69b5c1e | | (d) PCR-1 app retry + #4440 items + Delete account wording | e26082f, 11c8926..9f60656, e6168df | | PC proof on re-list after ovis logout (account#65 live) | e66b12b | | (e) ovis CLI (login/logout/approve/pair --relay) | 11c13e1, dcae136, f363d42 | | fake parity with account#62/#63, red-test fixes, B1b | 9a47489, 25ad3d9, bcf5059, 181884b, 2072a04, 15cea4f, 1674ca5, ea66c62 | Review trail for the round: security-triage YES per item (Tailscale routes with the owner-login condition; confirm UI conditions; sign-out wording; join notice; SSH handoff; Decline; logout/leave with PC proof; MEDIUM pc-proof scoping ledgered as ovis-sh/account#66, MUST-CLOSE before Step 2 opens beyond the owner). Opus gate (one pass over the round): CLEAR at 181884b, delta CLEAR at cccb50f (join-notice MEDIUM fixed). check fast in the CI image: green at 03fcd4e06 (unit 22471/0). --------- Co-authored-by: sisyphus-dev-ai <[email protected]> Co-authored-by: Claude Fable 5.2 <[email protected]>
devswha
added a commit
that referenced
this pull request
Nov 23, 2026
…that stay, codes kept From the adversarial review of #4492: - #1 #2 #7 #10 One open attempt for the whole connect screen, tracked from the tap (before the Tailscale question, whose wait is bounded and takes only an explicit off as off): a newer tap, Cancel or leaving drops an earlier one's late answer, no second open runs while one does, both panes show the one status, open is called only where the app has it, Cancel shows only where it can stop it, and the plain wait and the removed screen show a scanned PC's open too. - #3 #4 My PCs and Add a PC stay mounted under one parent across 1024 px, so the tab, what is typed, the focus, the search and an open survive a resize; a pairing dialog stays the top of the history when the window narrows under it. - #5 Each desktop pane scrolls on its own; checked at 1024x400 with the wheel. - #6 A code is looked up in its own field, kept through a failure to correct. - #8 Tailscale's IPv6 range counts as a Tailscale address. - #9 Android's no-answer is explained; an unknown reason never shows the app's words. - #11 #12 A PC the app keeps open while choosing shows My PCs with its Back, and only its own scope on a self-hosted relay's origin is marked. - #13 One alert for a failed sign-in on a wide screen. #14 The Cancel test presses it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
devswha
added a commit
that referenced
this pull request
Nov 23, 2026
…ed code line and explained open failures (#4492) Part 2 of 3 of the one Connect a PC screen (part 1: #4487). Hosted page only (`src/`); nothing in `app/` changes. ## What changes for a person - **Desktop width (1024 px and wider):** My PCs and Add a PC stand side by side: the list on the left, the Ovis relay, Tailscale and SSH tabs open in a panel on the right (no Add PC button), each pane scrolling on its own when it is taller than the window. Signed out with nothing saved, Connect a PC is one centred card. Narrower screens keep part 1's phone layout. Both stay mounted across the 1024 px line, so a rotation or a resize keeps the chosen tab, what is typed, the focus, the search and an open under way; a pairing dialog open when the window narrows again stays the top of the history. - **Search on a long My PCs:** past eight PCs, a "Search PC names" field (phone and desktop), and on a desktop the All · On · Off chips. Matching is on the name, in any case; the PC in use is found like any other; no match says so in one line. - **The code, folded:** Pair with a code is one small line under what to do on the PC; it opens its field in place, where the code is looked up: the field is read-only while it looks and keeps what was typed through a failure to correct, and the PC it finds goes on to the comparison (the pairing dialog, signed in). The connect screen owns that lookup: folding the field, Add PC's Back, another tab, the comparison's Cancel or a provider sign-in each end it, and what it answers later opens nothing. In the phone app it sits beside Scan a QR code (the PC offers both), and both are held while a provider sign-in is under way. The wording stays the product's own ("Pair with a code" / "Pair"). - **In the phone app** (what its own connect page did and the hosted page lacked): - Opening a Tailscale, SSH or other address says "Opening <host>…", one at a time for the whole connect screen, which owns it: it follows the person to Add PC and back on a phone and stands in both panes on a desktop; a tab or a pane giving way does not end it; a QR read after its scanner's tab is gone starts none; an open the app has not answered in 25 s ends with the no-answer explanation and takes taps again. A second tap while the app is asked whether Tailscale is on replaces the first, one already opening holds the next, and leaving the screen ends it. The Tailscale tab asks the app whether Tailscale is on only while it is on screen. Cancel shows only where the app has `cancelOpen` (iOS opens at once); `open` is called only where the app has it. The plain wait and the removed-PC screen show a scanned PC's open the same way. - A failed open says why from the app's own reason (not Ovis, refused, no answer within 20 seconds on a home or a public address, name not found, no way to the PC), with Tailscale's hint for a tailnet address (its IPv6 range too), in all four languages; an unknown reason gets a localized line that prints none of the app's own words. The Settings path it names is the current one (Settings → Devices and PCs → Add a connection). - A saved Tailscale PC tapped while the app says Tailscale is off (an explicit off, asked for 1.5 s at most) shows the Tailscale tab's own card, Open Tailscale, instead of waiting for the open to fail. - An SSH PC whose address on the phone another app took says so above the list. - While the app keeps a PC open as the person chooses another (`getState` `choosing` + `current`), My PCs marks that PC In use now, relay, Tailscale and SSH alike, and its Back goes back to it (`backToCurrent`). - Every native method this adds (`cancelOpen`, `backToCurrent`, `tailscale`, `openTailscale`) is used only behind `hasNativeMethod`. Today's apps never open the hosted page while choosing, so the Back to the current PC is not reached until the app side does. Items #3 and #7 of #4487's adversarial review were moved here: the code line beside Scan in the app (#3) and Open Tailscale for a saved Tailscale PC (#7). The side-by-side layout follows the mockup the owner approved, the way desktop mail and chat apps keep their list beside what it opens; no pixels copied. ## App side The app's own change (#4490, open) adds `home`, `fallback` and `back` ("current" | "home" | "") to `HerdrShell.getState`, and the methods `goHome` and `openDemo`. This PR reads only `choosing` and `current` and calls `backToCurrent`, which stay valid; it adds no use of the new fields. ## Known limits (carried from #4487) - Reloading `/#add` loses the In use now mark and its Back target. - One PC saved under several routes shows as several rows (grouping needs a verified PC id per saved route). ## Evidence Before/after captures (light, Korean; desktop 1280 signed out with the code opened, 12 PCs with search and the Off chip, `/#add`; 768; phone search and no match; the browser's and the app's code line; opening; the explained failure; Tailscale off; the SSH-port notice; choosing) were shown to the owner's lead. They come from a fixture with made-up PCs, no real account. ## Validation - `bun run check fast` on the head (5cf7236): workflow syntax, generated types and themes, typecheck, build, unit tests (23,641 pass, 0 fail). - Browser regressions that walk these screens, in the CI runner image on the head (`bun run build:shell` and the app build first, each through `bun run check run`): `relay-shell-browser-qa.ts` (updated for the side-by-side layout at 1440, the code looked up in its field, and a 1024x400 window with 16 PCs, where My PCs' own pane must scroll and the mouse wheel reaches Pair and the last PC), `add-pc-more-relay-regression.ts`, `relay-second-device-join-regression.ts`, `relay-offline-reasons-regression.ts` and `relay-join-browser-qa.ts`: all pass. - `HERDR_TEST_SHARDS=4 bun run check integration` on this PC (on 17556f2; later commits change `src/` and browser scripts only): 2,287 pass, 6 fail, in the two server files that fail the same way on a clean `origin/main` on this PC (`server/machine-profile.contract.test.ts`, `server/reattach.contract.test.ts`; neither imports `src/`; both pass in the CI runner image). - The adversarial review's 14 findings (round 1) and round 2's open and new findings, and what became of each, are in two comments on this PR. Round 2's ownership changes each have a unit test in `RelayShell.test.tsx`, and `RelayShell.history.test.tsx` drives a real Back through `sheetHistory` on a tablet turned under the pairing dialog. - Skipped: the whole browser lane (`check browser`), native Windows and macOS, and device QA on Android or iOS. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
devswha
added a commit
that referenced
this pull request
Nov 27, 2026
…ter a stop (#4856) ## What A Chat send to a Claude Code pane is no longer refused as an input draft when Claude's input box holds only the chat's own last message, which Claude put back folded as `[Pasted text #N +M lines]` after the turn was stopped (#3563). The box's words are no proof the placeholder is the chat's (anyone's paste of as many lines reads the same), so the fix ties it to Claude's own records, as the triage asked ("the send must remember what it pasted"): - `claude-store.ts` `claudeRestoredPaste`: for the pane's one Claude process (its store and its session from the PID record, as `claudeForegroundSession` reads them), the session's **last** prompt in `<config>/history.jsonl` must be exactly one text paste whose content is the chat's last message (`lastChatSubmitted`; inline `content`, or `paste-cache/<contentHash>.txt` for a long one), and its placeholder must be `#(N-1)` with the same line count as the box's `#N`. And the session's transcript must hold **no reply after its last human prompt** (Claude dropped the stopped turn before answering): a turn that went on leaves the same history line, and a paste a person makes after its answer takes the same next number. Tabs compare as the four spaces Claude keeps a paste with. The history file is read from its tail (256 KB) with the same ownership / no-symlink checks as the other Claude records; a hash that is not hex is never used as a path. - `core/composer.ts` `freeClaudeBox`: the existing "restored copy" branch (two Esc, then send) now also takes such a box; the box is read again after Claude's records and must still be the one they were checked for before the Esc presses go. Everything else still refuses exactly as before: a working agent, a queued/automatic send, words beside the placeholder, an image, a truncated paste, an unsubmitted paste, another session's prompt, a later prompt or paste, a record that cannot be read. ## Why this evidence (measured on Claude Code 2.1.330, isolated `HOME`/`CLAUDE_CONFIG_DIR`, a local API stub, no herdr) | Step | Box | `history.jsonl` | |---|---|---| | paste 13 lines | `[Pasted text #1 +12 lines]` | - | | Enter, then Esc while the request is pending | `[Pasted text #2 +12 lines]` (put back under the **next** number) | `{"display":"[Pasted text #1 +12 lines]","pastedContents":{"1":{"id":1,"type":"text","content":<exact text>}},"sessionId":...}` | | Ctrl+U, paste other 13 lines | `[Pasted text #3 +12 lines]` | - | | Esc Esc (clears), paste again | `[Pasted text #4 +12 lines]` | the cleared input is added as its own line | | paste 401 lines, Enter, Esc | `[Pasted text #6 +400 lines]` | `pastedContents` holds `contentHash`, the text is in `paste-cache/<hash>.txt` | Numbers only grow within a process, so a paste the user makes after the restore can never carry the restored number, and a box cleared with Esc Esc adds a later history line, which also refuses. Not covered (still refused, as today): a paste whose Enter never landed (nothing is in Claude's history then), and `claude attach` clients. No contract change, no UI change (the existing refusal and its text stay for every other case), nothing of the user's Claude settings is written: the records are only read. Refs #3563 ## Validation - New `server/submit.contract.test.ts` case (real herdr test session, a `claude` process whose own environment names a temp store with its PID record): **fails on main** (`input_draft` refusal on the second send) and passes here; it also checks that a history line for another message, an answered turn, and a box replaced while the records are read all keep refusing with nothing typed. - New `server/claude-store.test.ts` `claudeRestoredPaste (#3563)` cases (a child process whose environment names a temp store): the restored paste, wrapped placeholder, paste-cache, tabs, an answered turn, a missing transcript, and nine more refusal shapes. - `bun test ./server/claude-store.test.ts ./server/submit.contract.test.ts ./server/prompt.test.ts ./server/core/pending.test.ts ./server/conventions.test.ts` pass; `bun run typecheck` pass. - `bun run check fast` ran on another PC (this one is over 85% CPU). The files it failed (`tui/testing/entry-pty`, `server/usage-login-outcome`, `server/usage-account-list`) fail the same way on main there; `src/App.deviceNotices` and `server/account/device-journal` pass alone. `server/pending-input.contract.test.ts` has 15 s timeouts there and on this PC under load **on main too** (a different handful each run; control run on an unchanged server tree: 7 fail). - Skipped: browser regressions (no UI change).
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.
Problem
The
attachhandler added the client to the attachment and toclient.data.attachedonly afterawait ensureAttachment(...). A frame from the same socket that arrived during that await found nothing to clean up. Bun doesn't serialize an asyncmessagehandler per socket.closewalked an emptyattachedset, so the closed socket was added toattachment.clientsafterwards. It was never removed, and the pty outlived every live client.PaneTerminalsendsdetach(old)and thenattach(new)on every pane switch, so this is the more common trigger. The detach was a no-op, and the client was added to the old pane anyway. It kept receiving that pane's bytes, and the pty stayed alive, until the socket closed.Fix
client.data.attachedbefore the await.detachandcloseboth clear it, and the attach checks it when it resumes. If the attach fails, the entry is removed again.releaseUnclaimed. It closes the attachment only if it's still the current one, has no clients, and no other client has the pane inattached.Follow-up commit: stale claims after a pty exits
With the intent scan in place, an entry left behind in
attachedcounts as a live claim. When a pty exits while its herdr pane survives (e.g. herdr restarts),closeAttachmentdeleted the record but left the pane in each member'sattached. Those members are on the "terminal ended" screen. Their stale entries then blockedreleaseUnclaimedfrom closing a later cancelled attach on that pane, so the pty kept running with zero clients. It did recover on the member's next pane switch or disconnect.closeAttachmentnow removes the pane from its members'attached.No contract test pins this: when a cancelled creation has no other joiner, a client can't observe when it has finished. An ad-hoc probe checked it instead. It kills the attach under a watching client, then attaches and detaches the pane in one tick, and waits 3s. With the change 0 attach processes remain; without it, 2 remain.
Tests
WebSocket client leaving mid-attachhas one test for each trigger, and each runs on its own workspace. The oracle is the leaked resource itself: once the last live client is gone, noherdr terminal attach <terminal_id>process may remain (pgrep -f, bounded wait). Each test first asserts that the process count is above 0, so the pgrep pattern can't pass vacuously.describewith its own pane. It no longer relies on the previous roles test having released the sharedqaPaneId. The test body is unchanged.server/index.tsfix revertedattach … still running 5000ms after its last client left)releaseUnclaimedremovedstayer pty-data not received), so the eager-close trap is pinnedbun test server/api.contract.test.ts×4bun testbun run typecheck/bun run buildw9999:p9999×2 racing, then again)pane_not_foundframes, no hangherdr-web-ui-test*workspacesThe two new tests take about 1.5–2s each, because
herdr terminal attachtakes about 1.2s to exit after the sidecar kills it (measured separately).pushes pane-status …sometimes runs about 4.2s instead of 1.7s. That happens onmaintoo: its status retry loop occasionally takes an extra round. This PR doesn't change it.README: test count 63 → 65, and the coverage sentence now lists this case.
🤖 Generated with Claude Code