Repository navigation
fix(layout-owner): keys typed into a new terminal before it binds reach its shell (C5-L312) - #52260
Conversation
Restores the ssh-orcad journeys (cut 11-21) into the layout-owner suite, passes the server setting to the Docker host's orcad through sshd, and checks the orcad took it.
…er-ssh-orcad-lane # Conflicts: # .github/workflows/layout-owner-switch-on.yml
The nohup launch backgrounds its whole && chain, so the PID removal added in #51342 ran in the background and could delete the PID file the foreground had just written. The host's server then read as unverifiable and connect failed. Remove the old PID before the chain instead.
… and both-mode drift
…d setup-script prompt
…o layout-owner-ssh-input-c5-l312
…ch its shell (C5-L312) A new server tab is drawn from the server's layout frame before session.tabs gives the desktop its handle. The pane mounted unbound, created its own terminal and dropped the typed keys; it now waits as starting and attaches the server's terminal with the keys held. A local pane main starts now holds pre-bind keys too, since main sends any startup work before the pane attaches. A terminal created without a target group in a frame-drawn workspace is activated, as the mirror's focus intent did. Removes the C5-L312 expected-fail marks.
…er-ssh-input-c5-l312 # Conflicts: # .github/workflows/layout-owner-switch-on.yml # src/main/managed-server/install/orcad-remote-empty-markers.integration.test.ts # tests/layout-owner-e2e/helpers/docker-ssh-host-target.ts # tests/layout-owner-e2e/helpers/orcad-convert-flow.ts # tests/layout-owner-e2e/helpers/orcad-managed-workspace.ts # tests/layout-owner-e2e/helpers/ssh-config-host-picker.ts # tests/layout-owner-e2e/helpers/ssh-remote-only-browser-fixture.ts # tests/layout-owner-e2e/ssh-orcad-browser-drop-owner.spec.ts # tests/layout-owner-e2e/ssh-orcad-browser-routing.spec.ts # tests/layout-owner-e2e/ssh-orcad-browser-service-status.spec.ts # tests/layout-owner-e2e/ssh-orcad-codex-question-skip.spec.ts # tests/layout-owner-e2e/ssh-orcad-desktop-browser-bridge.spec.ts # tests/layout-owner-e2e/ssh-orcad-editor-drafts-migration.spec.ts # tests/layout-owner-e2e/ssh-orcad-explorer-selected-host.spec.ts # tests/layout-owner-e2e/ssh-orcad-idle-exit.spec.ts # tests/layout-owner-e2e/ssh-orcad-pairing-repair.spec.ts # tests/layout-owner-e2e/ssh-orcad-shared-home-machines.spec.ts # tests/layout-owner-e2e/ssh-orcad-shared-login-migration.spec.ts # tests/layout-owner-e2e/ssh-orcad-sleep-disconnected.spec.ts # tests/layout-owner-e2e/ssh-orcad-terminal-browser-link.spec.ts # tests/layout-owner-e2e/ssh-orcad-terminal-journeys.spec.ts # tests/layout-owner-e2e/ssh-orcad-terminal-network-outage.spec.ts # tests/layout-owner-e2e/ssh-orcad-terminal-reconnect-idle-frame.spec.ts # tests/layout-owner-e2e/ssh-orcad-terminal-root-owner.spec.ts # tests/layout-owner-e2e/ssh-orcad-unbindable-tunnel-port.spec.ts # tests/layout-owner-e2e/ssh-orcad-update-anyway.spec.ts # tests/layout-owner-e2e/ssh-orcad-workspace-tools.spec.ts
[Medium impact] The changes affect terminal startup and wake behavior in local and paired server workspaces. The PR still needs fixes for lost input after a slow handle arrives and gestures that cannot restart stopped recovery. FindingsSummaryThis PR keeps early terminal input until a pane binds, wakes slept server terminals, and preserves panes across host updates.
Reviews (15) · Last reviewed commit: "test(terminal): wake-input test reads th..." · Reviewed by Greptile |
|
Post-merge (after catching up with layout-owner-v2, which now includes #52103), switch on, darwin arm64, Docker SSH host with a local linux-arm64-glibc orcad template: 26/26 passed across ssh-orcad codex-question-skip, desktop-browser-bridge, pairing-repair, sleep-disconnected, terminal-browser-link, terminal-network-outage, terminal-reconnect-idle-frame, terminal-root-owner, unbindable-tunnel-port, update-anyway, terminal-journeys and workspace-tools, plus local- and paired-desktop-server-new-terminal-first-keys. All C5-L312 forgiveness is removed. Repo Actions reported no checks on this branch at the time of writing, so this is local evidence only. |
…ngs when its text never shows
…attaches the terminal main bound On a slow host the server pane's binding lands between the pane's mount and its deferred connect. The connect chose from the mount-time bindings and started a fresh terminal, dropping the keys typed into the pane; it now adopts the binding main published first, as the start wait already does.
… to the front before typing
… handle is unknown; review fixes
…d a slept terminal's pane is marked sleeping A bound server pane without a handle waits as starting so typed keys are held, but session.tabs lists a slept or exited terminal without a handle too; the wait is now bounded, after which the pane is drawn unbound as before. The server also marks a pane sleeping when the workspace sleep commits its terminal. CI's switch-on lane now runs both first-keys specs.
| ...(ptyGeneration !== undefined ? { ptyGeneration } : {}) | ||
| } | ||
| } | ||
| return awaitsHandle(hostTabId, pane.leafId) ? { status: 'starting', ...rest } : rest |
There was a problem hiding this comment.
If a live server terminal takes more than five seconds to supply its handle, desktopPane removes starting without supplying a binding. This releases waitsForMainPaneStart, which connects without a restored terminal ID. For a mirrored tab, keepTypeAheadForNewTerminal returns false, so the remote transport calls expect(null) and discards the buffered keys before attaching. Users on slow SSH connections can therefore lose their first command again.
Keep the input hold until the server supplies a handle or confirms that the terminal ended. Elapsed time alone cannot distinguish those cases.
…inside the handle wait
…nd keys typed during the wake reach the woken terminal
…er-ssh-input-c5-l312 # Conflicts: # .github/workflows/layout-owner-switch-on.yml # src/renderer/src/components/terminal-pane/pty-connection/spawn/main-pane-start-request.ts
…r its reattach instead of being dropped
…he slept-pane sleep retries a liveness read still under way
…pt one wakes into, never a replacement
…ries once per gesture, and an attach settles its pre-bind typing so later keys are never swallowed
| if (userWakeRequested) { | ||
| return | ||
| } |
There was a problem hiding this comment.
If someone types into or reveals a disconnected server pane during a long outage, userWakeRequested stays true after the recovery deadline moves the pane to disconnected. Every later key or reveal returns here without calling retryNow(), so those gestures cannot restart the parked retry even after the host is reachable.
Allow a new wake after recovery stops, while still combining keystrokes during an active attempt.
… type guard, not a cast
ELI5
With the new layout path on, the first keys you type into a brand-new terminal could vanish: the prompt showed, but the command never ran. It happened in SSH workspaces and in local ones. The terminal was drawn before it was connected to its shell, and keys typed in that gap had nowhere to go. Now the pane holds them and delivers them once it connects, as the old path did.
A slept terminal had the same problem, and a worse one. With a server terminal put to sleep, showing its pane again often did not wake it at all, and when it did, the keys you typed while it woke were lost. That happened with the switch off too. Now showing the pane, or typing into it, wakes the terminal, and the keys typed during the wake reach it once, in order. That matches local panes.
Before / after
ho WOKE…: command not found); switch on: all keys lost or no wakeo LOCAL…: command not found)startingindefinitelysleepingright away; any pane still waiting for its handle stops after 5 sMechanism
Census row C5-L312. The input route was fine; the pane was simply not bound yet, and four things made keys typed during that gap disappear:
Server workspaces (
server-layout-frame-ids.ts). The server's layout frame can reach the desktop before session.tabs gives it the new terminal's handle. The translator then showed the pane as unbound, so the pane started its own terminal create, and because the pane belongs to a server tab, the transport threw away keys typed before that create. Now a pane the server reports as bound but whose handle hasn't arrived yet is shown asstarting. The pane waits through the existing start gate, adopts the binding when the handle lands, and attaches to the server's terminal by id. The transport's pre-bind hold then delivers the keys to that terminal.Local panes main starts (
pane-transport-options.ts).holdsInputUntilConnectcounted every main-started pane as having startup work, so even a plain shell never held pre-bind keys. Main sends any startup work at spawn, before the pane attaches, so held keys always come after it. Holding now depends only on startup work the window knows about (agent panes still keep their pre-ready draft).A start that ends before the pane's first connect (
main-pane-start-request.ts). On slower hosts (CI Linux), the binding landed after the pane mounted but before its deferred connect. The connect chose from the pane's mount-time bindings, saw none, and started a fresh terminal. A switch-on pane with no saved binding now adopts the binding main already published, as the start wait already did. CI diagnostics showed exactly this: bound on its first mounted frame, yetrestored=null … FRESH SPAWN.Activation in frame-drawn workspaces (
web-runtime-terminal-placement-settlement.ts). A create with no target group (e.g. Files → Open in Terminal) relied on session.tabs' focus intent, which frame-drawn workspaces never read. It now activates the drawn tab, but only if the user is still on that workspace.No wait without a bound (
server-handle-wait.ts,worktree-terminal-stop-targets.ts). Session.tabs also lists a slept or exited terminal without a handle, so (1) alone could keep such a panestartingwith no end. The server now marks a panesleepingwhen its terminal sleeps. The desktop also stops waiting after 5 s and redraws the pane unbound, as it did before (1). A server pane's own status is kept;startingis added only when the server published none.Waking a slept server pane (
remote-runtime-pty-transport.ts,remote-runtime-recovery-input-hold.ts). A pane still mounted when its server terminal slept kept retrying the dead handle. Those retries ask the host with intentautomatic, which by design never wakes a slept terminal, so nothing woke it. Now a reveal or a typed key on such a pane counts as the user's wake: the next activation asks with intentuserand any waiting retry runs at once. The woken terminal is the pane's own continuation, not a replacement, so the keys held for the slept handle move to it instead of being dropped. The proof is the host's own: it already sends every client aworktreeTerminalSleepStateevent naming the terminals a sleep committed (and replays it to clients that connect later). The desktop now keeps those handles (host-slept-terminals.ts, bounded). Held keys move only when the pane's old terminal is in that record when the wake starts, and only when the pane's pre-connect gate allows it (an agent resume still drops them, with the existing notice). A terminal restarted or closed by another client is never in the record, so keys typed against its old screen still drop (fix(daemon): respawn on PTY write dropped to a dead daemon socket (STA-2373) #10065). A host that doesn't send the event gets the same safe default: the wake works, and the keys drop. An exited terminal (the host's retirement proof) still ends the pane. Opening a slept pane already used intentuser; the same rule decides there.Pane remount on a host snapshot (
terminal-build.ts). Opening a slept workspace bumps each tab's remount counter (generation), but the next host snapshot rebuilt the tab without it. The pane's key changed, so the pane remounted and its held keys were lost. The rebuild now keeps the counter, as it already keeps the recovery ledger.A wake is spent once a terminal binds, or when recovery settles, detaches or disconnects. A leftover wake would wake the pane's next sleep right back up. A gesture asks for one retry when the wake starts, not one per key (per-key retries cancelled backoff and flapped the banner). With the switch on, a slept server pane the server names no terminal for (
server-layout-frame-ids.tsstrips the ptyId until session.tabs gives a handle) still holds keys for the terminal its wake binds. The pane's ownsleepingstatus from the server says it is a wake (keepTypeAheadThroughWake).The 5 s handle wait now tracks whether each pane was last drawn waiting. A wait that ran out before anything redrew it (the timer rescheduled just after the deadline) still gets its redraw, instead of staying
starting.Keys typed while main wakes a local pane (
ipc-pty-attach-miss-hold.ts,pty-transport.ts). With fix(layout-owner): window tabs that launch an agent or carry a draft start through main #51934, a switch-on pane attaches to the terminal main holds. When main answers a miss it will follow with a reattach (sleeping, orunstarted: a start still under way), the transport flushed its pre-connect buffer with no terminal. That dropped the held keys and stopped the buffer, so keys typed during the wake were dropped too. The buffer now waits for main's reattach on the same transport. Any other answer (failed,exited,held,unknown) drops the keys as before, because the terminal main brings next is not the one typed into. This was the open check on fix(layout-owner): window tabs that launch an agent or carry a draft start through main #51934's attach-miss retry.(1), (4) and (5)'s handle wait run only for frame-drawn workspaces, (3) is behind the switch, and in (2)
mainStartsPaneis always false with the switch off. (8) only runs on main's attach-only connect, which happens only with the switch on. (6) and (7) are not gated; see Switch-off changes.The C5-L312 forgiveness in the SSH lane (
expectUnlessKnownSwitchOnSymptom(lostTerminalKeys…),forgiveLostKeys, and the first-command tracking) is removed, so those specs must pass.PR #51934 (main starts every terminal) does not fix the local race: the same deterministic spec fails 3/3 on its branch. #52149 doesn't touch this path.
Existing bug fixed here (also on main): typing swallowed after an attach onto a different terminal
On every build,
attach()set up the input hold for the terminal the pane names but never settled it. When the host gave the pane a different terminal (after a server or orcad restart, another client's restart, or a wake on an older host), the hold's release saw the mismatch, re-armed itself for the old terminal, and swallowed all later typing until a reconnect.attach()now settles that expectation the moment the attach binds, asconnect()already did. Keys typed against the old screen still drop (#10065), and keys typed after the bind reach the new terminal. It is self-contained (bindExpectation/settleBindExpectationin the transport), so it can go to main on its own.Switch-off changes
What changes for today's users (switch off), all in paired-server and SSH-server workspaces:
worktreeTerminalSleepStateevent; no new field). Before, some or all of them were dropped.sleepingwhen its terminal sleeps; only switch-on desktops read that status.How it was tested
Switch on (
ORCA_LAYOUT_OWNER=main,ORCA_SERVER_LAYOUT_OWNER=main, exported and logged), darwin arm64, hidden windows. The Docker SSH lane ran against a locally built linux-arm64-glibc orcad template.paired-desktop-server-new-terminal-first-keys: without fix 0/3 (and 0/2 earlier); with fix 8/8. Its oracle reads the server's ownterminal.read.local-new-terminal-first-keys: switch-on without fix 0/3; switch-off 3/3; with fix 4/4.server-layout-frame-ids.test.ts(a bound server pane with no handle isstarting, then binds): fails with the fix reverted, passes with it.ssh-orcad-terminal-root-ownernow waits for the managed Open in Terminal tab to come to the front before typing; the old helper raced the activation.local-cli-terminal-retention,relaunch-first-terminal,relaunch-sleeping-agents-resume-on-view,terminal-cli-split-closed-before-mount,terminal-cold-activation-deferral,terminal-pane-close-layout-consistency,terminal-tab-close-restart-persistence,restored-terminal-first-size,paired-desktop-server-layout-frames,-held-pane-reopen,paired-remote-terminal-serve-restart-binding: 18/18 passed.paired-desktop-server-slept-pane-status(headless paired server + desktop client):sleepingwithin 3 s: with the mark, 3/3; with the mark reverted, fails (startingat 3 s).echo WOKE''_PANE, expectWOKE_PANEin the pane. Each case launches its server and client with the switch on and then off. Before the fix every cell failed (never woke, orho WOKE''_PANE: command not found). With (6) alone, switch-off sidebar still failed 3/3 (the remount), and (7) fixed it. Final: switch on 9/9, switch off 6/6, combined spec 10/10.local-slept-terminal-wake-keys(sidebar Sleep, open again, typeecho LOCAL''_WOKEat once): switch on without (8) failed 2/5 and 3/5 (the diagnostics showthe terminal did not attach, then keys arriving at a transport that is neither buffering nor connected); with (8) 6/6 and 1/1. Switch off: 5/5 and 3/3. Added to the e2e-window list.window-tab-main-start-wake-and-inputs,window-tab-main-start-lifecycle,relaunch-sleeping-agents-resume-on-view, both first-keys specs and both slept-pane specs: 22/22, switch on.remote-runtime-pty-transport-wake-input.test.ts(real transport, mocked host RPC), 5 cases, each failing with only its own fix reverted:automatic, notuser.server-layout-frame-ids.test.ts: a wait that ran out before any redraw still reports its deadline (fails without the fix).paired-desktop-server-held-pane-reopen,paired-remote-terminal-serve-restart-binding,paired-desktop-server-layout-frames,headless-serve-focused-terminal-create, and both first-keys specs: all passed.remote-runtime-pty-transport-input-replay.test.ts: 5/5.pnpm run typecheck:ciclean.typecheck:e2e: only the pre-existing missing generated mobile locale files in this checkout.Performance
None, because nothing new runs on a hot path. A server pane waits on the existing start gate instead of starting a terminal create (one fewer RPC per new tab). Activating a group-less create in a frame-drawn workspace reuses the placement settlement's bounded 250 ms poll (at most 10 s, once per create). Holding pre-bind keys uses the existing pre-connect buffer. The wake check on a typed key is a few field reads while the pane is healthy. While it recovers, it at most runs the already-armed retry early, once. No new polling, listeners or RPCs: the wake reuses the existing activation call with a different intent.
Visible changes