Skip to content

fix(layout-owner): keys typed into a new terminal before it binds reach its shell (C5-L312) - #52260

Merged
Jinwoo-H merged 31 commits into
layout-owner-v2from
layout-owner-ssh-input-c5-l312
Nov 29, 2026
Merged

Jinwoo-H merged 31 commits into
layout-owner-v2from
layout-owner-ssh-input-c5-l312

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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.

Files Added Deleted Net
Test 20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​915 $\color{#cf222e}{\Huge{\mathbf{−}}}$​151 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​764
Prod 20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​446 $\color{#cf222e}{\Huge{\mathbf{−}}}$​61 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​385

Before / after

Before (switch on) After
Type right away into a new terminal in an SSH/server workspace keys lost (prompt only) command runs
Type right away into a new local terminal keys lost command runs
"Open in Terminal" from Files in an SSH workspace new tab appears, but the old tab stays in front the new terminal is shown
Show a server pane another client slept, then type (switch on or off) never wakes wakes; the command runs
Sleep a server workspace from the sidebar, open it again, type at once switch off: first keys lost (ho WOKE…: command not found); switch on: all keys lost or no wake the command runs
Sleep a local workspace, open it again, type at once (switch on) first keys lost in 2–3 of 5 runs (o LOCAL…: command not found) the command runs
A server pane whose terminal sleeps (switch on) could wait as starting indefinitely shows sleeping right away; any pane still waiting for its handle stops after 5 s

Mechanism

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:

  1. 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 as starting. 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.

  2. Local panes main starts (pane-transport-options.ts). holdsInputUntilConnect counted 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).

  3. 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, yet restored=null … FRESH SPAWN.

  4. 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.

  5. 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 pane starting with no end. The server now marks a pane sleeping when 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; starting is added only when the server published none.

  6. 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 intent automatic, 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 intent user and 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 a worktreeTerminalSleepState event 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 intent user; the same rule decides there.

  7. 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.ts strips the ptyId until session.tabs gives a handle) still holds keys for the terminal its wake binds. The pane's own sleeping status 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.

  8. 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, or unstarted: 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) mainStartsPane is 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, as connect() 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 / settleBindExpectation in 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:

  • Showing a slept server pane, or typing into it, now wakes its terminal. Before, a pane that stayed mounted while its terminal slept (for example, slept from another desktop or phone) never woke.
  • Keys typed while that wake runs now reach the woken terminal once, in order, when the host says it slept the old one (its existing worktreeTerminalSleepState event; no new field). Before, some or all of them were dropped.
  • Kept as before: an agent resume (startup work) still drops keys typed during it, with the existing notice. A terminal that replaces the pane's one without the user's wake still gets none of the held keys (fix(daemon): respawn on PTY write dropped to a dead daemon socket (STA-2373) #10065). An exited terminal still ends its pane.
  • A pane is no longer remounted when a host snapshot follows the wake (the remount counter is kept).
  • The server marks a pane sleeping when 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.

  • Deterministic repros, new lane specs that type on the first animation frame the new pane has no terminal:
    • 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 own terminal.read.
    • local-new-terminal-first-keys: switch-on without fix 0/3; switch-off 3/3; with fix 4/4.
  • Unit test server-layout-frame-ids.test.ts (a bound server pane with no handle is starting, then binds): fails with the fix reverted, passes with it.
  • SSH Docker lane on CI (Linux), switch on, all C5-L312 forgiveness removed: run 46232456111, all three shards green (56 passed, 3 skipped, no retries). Locally on macOS: 26/26.
  • ssh-orcad-terminal-root-owner now waits for the managed Open in Terminal tab to come to the front before typing; the old helper raced the activation.
  • The SSH helpers print a pane's connect verdicts, start status and first-mounted state when its text never shows.
  • Neighbouring specs, switch on: 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.
  • Slept server panes, paired-desktop-server-slept-pane-status (headless paired server + desktop client):
    • Sleep over the server's local socket, then require sleeping within 3 s: with the mark, 3/3; with the mark reverted, fails (starting at 3 s).
    • Wake: sleep from the desktop sidebar or from another client, show the pane, type echo WOKE''_PANE, expect WOKE_PANE in the pane. Each case launches its server and client with the switch on and then off. Before the fix every cell failed (never woke, or ho 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.
    • Added to the e2e-paired list; the wake cases cover both switch settings in that job.
  • Slept local panes, local-slept-terminal-wake-keys (sidebar Sleep, open again, type echo LOCAL''_WOKE at once): switch on without (8) failed 2/5 and 3/5 (the diagnostics show the 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.
  • After merging layout-owner-v2 (with fix(layout-owner): window tabs that launch an agent or carry a draft start through main #51934): 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:
    • A pane names terminal-1, the host hands it terminal-2, and keys are typed before the bind. Without a host sleep record (a restart by another client) the keys are dropped, and keys typed after the bind reach terminal-2 (the existing attach bug). With a record, they are delivered once, before later keys.
    • Switch-on wake with no named terminal: keys typed during it are delivered.
    • After a wake that a published handle completes, the next stream loss activates with intent automatic, not user.
    • Seven keys during recovery ask for one retry.
  • server-layout-frame-ids.test.ts: a wait that ran out before any redraw still reports its deadline (fails without the fix).
  • Paired neighbours with both settings: 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:ci clean. 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

  • Switch-on only: a terminal created in an SSH/server workspace without a target group (Files → Open in Terminal) now comes to the front, matching switch-off. This is a bug fix.
  • Both settings: a slept server pane wakes when you show it or type into it, and answers what you typed. This is a bug fix.

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.
…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
@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 3/5 · The PR still needs fixes for lost input after a slow handle arrives and gestures that cannot restart stopped recovery.RetriggerView in GreptileConfidence Score: 3/5

[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.

Findings

  1. P1 Late handles lose typed keys ▶
  2. P1 Later gestures cannot retry ▶

Summary

This PR keeps early terminal input until a pane binds, wakes slept server terminals, and preserves panes across host updates.

  • New terminal panes keep early typing until their shell connects.
  • Sleeping terminal panes wake on use and keep keys for their resumed shell.
  • New terminals without a placement target come to the front in frame-drawn workspaces.

Reviews (15) · Last reviewed commit: "test(terminal): wake-input test reads th..." · Reviewed by Greptile

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

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.

…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.
…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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Late handles lose typed keys

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.

…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
…he slept-pane sleep retries a liveness read still under way
…ries once per gesture, and an attach settles its pre-bind typing so later keys are never swallowed
Comment on lines +2071 to +2073
if (userWakeRequested) {
return
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Later gestures cannot retry

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.

@Jinwoo-H
Jinwoo-H merged commit 8e141dc into layout-owner-v2 Nov 29, 2026
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant