Repository navigation
fix(ssh): an old relay terminal's tab shows output again after a reconnect - #27951
Conversation
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to Closing an old relay terminal tab while a reconnect attempt is still pending can start a fresh attach for a tab that no longer exists. The remote pane then stays attached with nothing to detach it. Clear the pending reattach on disconnect before merging. Pre-merge checks |
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
643b6da1-cd73-4786-8476-009c6cacf392
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/legacy-relay-bridge-transport.test.tssrc/renderer/src/components/terminal-pane/legacy-relay-bridge-transport.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| if (reattachQueued) { | ||
| reattachQueued = false | ||
| if (!attached) { | ||
| void reattach() |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Cancel queued attachment when the transport disconnects.
If a pane change queues an attach and the caller then invokes disconnect(), release() removes the subscriptions but leaves mode === 'bridge' and the queue intact. When the pending request returns unverifiable, this block starts another attach for the disconnected transport. Invalidate pending requests and clear the queue on release. Based on learnings, an async operation can outlive a disconnect and must check whether it still owns the state before rescheduling work.
Source: Learnings
The last stage of the catch-up. Measured from the post-stage-5 main: 425 commits, 23 conflicting files, merge base `6cbbe456c0` — the previous stage's target, so the lineage is clean. Four analysts planned the clusters in parallel, one implementer applied all four, and an independent critic reviewed the staged index. ## What upstream did Upstream deleted the SSH relay client path, the SSH PTY provider and most of `src/main/providers/` — about 153 files and 17.8k lines — plus the `ipc/pty.ts` and `providers/types.ts` barrels. Commits `ff27338299e`, `a4a96fee704`, `0df25b7ac9b`, `c5224f70d8c`, `b368ebc7a6c`, `aeffeb4cfb5`, `3c49cdf09ce`. **It changed no owner-routing logic.** So nearly every conflict had the same shape: the fork's per-window routing with an SSH-projection line inside it, against upstream's main-window line with that line removed. The resolution is the fork's logic minus the SSH lines — `combine`, never `take-ours`, which would re-reference deleted modules and fail typecheck. ## The two decisions this merge turned on **The legacy relay bridge must reach every window, and gate its input.** Upstream's new `legacy-relay-bridge-ipc.ts` keeps 1.4.224's running terminals alive after an upgrade (stablyai#27787, stablyai#27951). It merges cleanly, and its `send` reaches `getMainWindow()` only. Three analysts found this independently: a relay-era SSH pane whose tab lives in a fork project window attaches, replays, and then never receives output or exit again. It now broadcasts to every app window, which is safe because each window's transport filters by `ptyId`, and relay-era ids (`ssh:<target>@@<relay id>`) are often unknown to `getPtyWorktreeId` so an owner lookup would fall back to main anyway. Its `write`, `resize` and `detach` also accepted input from any sender, where every sibling PTY input path in this fork is gated by `isTrustedUIRenderer` (`write.ts:18,29,41`, `resize-visibility.ts:111,166`, `delivery-flow.ts:167`, `serialize-buffer.ts:43`). The gate is applied. The legitimate path was traced end to end before doing so: the only renderer sender is `legacyRelayBridgeApi`, its only caller is `pty-input-recovery.ts:294`, and that path runs in the main, workspace and satellite windows, all registered as trusted UI renderers. The dashboard pop-out loads the same preload and is *not* trusted, but nothing under `components/dashboard-popout/` imports the bridge transport. **The user-named access ratchet stays, and the fork now owns it.** Upstream `26ee9bbfabe` (stablyai#27308, "remove source text checks") deletes the whole ratchet from `local-file-access.test.ts` — all three lists, the three helpers and the `node:fs`/`node:path` imports — and replaces it with nothing. Keeping it means the fork maintains all three lists, not just its own two entries, and a future upstream commit that adds a user-file builder or a tab opener will fail this test. That is the point: stage 5's SFTP defect arrived exactly as "upstream added a new way to open a user-named tab", so a failure here is the alarm working. The block carries a comment saying the fork owns these lists and that the response to a failure is to check each new entry against the SFTP guard, never to delete the fork's entries. The import removal merged cleanly, so the two imports are restored; without them six identifiers were undefined. ## Defects found that no conflict marker could show This stage's real work was outside the 23 conflicts: 11 hand edits, three of which no plan predicted. - **The scoped reconnect path.** Upstream `bd54fc7fa32` deleted `reconnectPersistedTerminals(signal, { workspaceKeys })` as dead code — true upstream, where direct SSH was its only caller. The fork has three production callers and one test that need it for project windows, and the deletion lands cleanly in every region the fork did not touch: the scoping filter, the early return, the deferred-SSH preservation, the `remaining*` computation and the `workspaceSessionReady` gating. Resolving only the conflict hunks would have made every scoped call a silent global reconnect, so the file was replaced whole. - `pty/delivery/payload.ts` — the fork-only `if (!ownerState)` block still used the removed `projectionAdmissionIds` and returned the old object from a function now typed `boolean`. - `pty/delivery/window-flow-state.ts` — a fork-only `max-lines` extraction stranding upstream's SSH-projection removal; it was not on any extraction list. 297 → 287 lines. - `ssh-filesystem-provider-sftp.ts` — a whole-side take still breaks, because the import line upstream deleted sits *outside* the conflict hunks and merges cleanly, leaving four types and a helper undefined. Six fork files call them. - Two fork tests still named the deleted `ipc/pty` barrel: the fork's primary multi-window routing suite would have failed to load, and a `vi.mock` of the barrel would have silently stopped intercepting, running real PTY registration inside a test. - Found by the cold typecheck: two upstream tests called `isHiddenRendererPty` with one argument. The fork keys hidden marks per window, so it takes two. - Found by the sweep: `daemon-host-path-budget.test.ts` hard-coded upstream's `Orca` host root. - Found by the critic, in a file no gate executes: the fork-only `orcinus-cd.yml` still ran `config/scripts/relay-watcher-fault-harness.mjs`, which upstream deleted in `2b4b60a87ea` while removing the same step from its own release workflows. The next `v*` tag would have failed both build legs before publishing. Removed, mirroring upstream. Coverage upstream deleted and the fork still needs was restored: `sftp-directory-entries.test.ts` ports the five cases that cover SFTP handle cleanup on cancellation, for code the fork keeps. ## Review An independent critic returned REJECT for the `orcinus-cd.yml` defect above and nothing else: the 27 decisions are applied as specified, both coordinator decisions hold when re-derived, and every gate re-measures as reported. It found the defect with a set difference of every repo-path string in every tracked text file, merged tree minus both parents — it was the only merge-only dangling path in the repository. No compiler, linter or test executes a workflow file. The critic also partitioned the sweep's "same" bucket by *which* baseline fails: `both=2451 mainOnly=35 upOnly=131 neither=5`. Those 35 are the fork's own pre-existing reds, none merge-caused, and three of them mean a fork feature has no live test — project windows (`create-project-window.test.ts`), the custom date-range usage dashboard (`UsageOverviewFilters.test.tsx`) and notifier owner routing. A follow-up owns them; this merge does not. `verify-orcinus-identity` is blind to the identity residue this merge adds: the new macOS terminal-host helper's `CFBundleName` 'Orca', its Orca icon, and the "Orca allows…" usage-description strings. All inert on an unsigned build. ## macOS terminal-host helper Upstream `3f8d296b8d7` adds a signed `Orca Terminal Host.app`, about 124 MiB per mac slice, started from a copy through launchd. Read statically; no Mac host was available. The fork's unsigned build *can* produce it ad hoc, and can never load it: the runtime requires the copy to satisfy the running app's designated requirement, which for an ad-hoc app is its own cdhash. Every failure path falls back to the pre-merge fork launch. No gate or packaging step the fork runs assumes a signing identity — `orcinus-ci.yml` is ubuntu-only, `orcinus-cd.yml` has no macOS leg, and upstream's mac workflows are guarded on their repository. The cost is that every daemon launch on a fork mac build copies the helper, fails the check and deletes it. Skipping `packageMacTerminalHost` on unsigned builds is recorded as a follow-up. ## Gates Cold typecheck (after deleting `config/*.tsbuildinfo`): 0 errors, measured independently twice; its first run is what caught the two `isHiddenRendererPty` arity breaks. Runtime-electron ratchet: `nothing reachable imports electron`. oxlint: 0 warnings, 0 errors across 32,422 files; oxfmt clean. verify-orcinus-identity: OK, `upstreamRefs=0`. Unsigned smoke: OK, `forceCodeSigning=false`. Fork contract tests: 32/32. Windows CLI launcher: the Rust build runs here and passes. Localization catalog: OK. max-lines ratchet: OK, 4 grandfathered, no new bypasses. Regression sweep, scoped as the whole universe rather than by directory — the error that cost stage 4 a rejection and left a 46% hole in stage 5: `discoverUnitFiles()` is 12,051 files on this tree, every one reported, 0 missing. The three-tree recheck of all 493 failing files gives `same=2615 diff=2 mergeOnly=5`. One of those five was a real merge defect, the `Orca` host root, and is fixed. The other four are attributed with evidence: three flakes that also fail on the upstream baseline in the same file, and one CRLF artefact of this long-lived working copy whose index blobs are LF in all three trees. Merge-only failures attributable to this merge: **0**. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
ELI5
After upgrading from 1.4.224, the legacy relay bridge (#27787) keeps old terminals working in their old tabs. If you disconnected the SSH host and connected again while such a tab was open, the tab came back looking fine, but it never showed new output again. What you typed still reached the old shell, but nothing came back. Now the tab hooks itself back up after the reconnect.
What Changed
Before: a disconnect hangs up the bridge in the main process (
stopLegacyRelayBridge). That publishes an empty pane list and reports no exit, because the terminal didn't exit. The tab's bridge transport still thought it was attached. On reconnect, a new bridge listed the pane asliveagain, but the transport only reattaches panes it thinks are detached, so it never did. The new bridge forwards output only to panes that attached to it, so all output was dropped. Input still reached the shell, and the tab still reported input as delivered.After: when its pane leaves the bridge's list, the transport counts itself detached and asks the bridge again. While the host is away that answer is
unverifiable: the tab stays bound and input is reported as not delivered. When the host is back and the pane islive, the transport attaches with the relay's screen and output flows again. An answer ofexitedstill ends the pane, as before.Why
unverifiable, shows "still running on the host… reconnecting", retries on backoff, and retires only when the relay reports the exit or every relay for the host answered without it. No placeholder change was needed there. Losing contact through a deliberate disconnect was the one path where the tab lost its terminal, and this fixes it.Linked Issue
Follow-up to #27787.
Visual Proof
N/A: there's no new UI. The bridged tab shows output again after a reconnect, which the Docker e2e checks.
Testing
liveagain. Written first, it failed on main because the second attach never happened. It now passes. It also checks that input during the gap reports not delivered, and that the pane never exits.ssh-orcad-legacy-relay-bridge.spec.tsnow disconnects and reconnects the host while the old tab is open, then types and expects the old shell's echo.pnpm tc,pnpm lint,pnpm run check:code-quality:changed, oxlint, and the focused vitest. No Docker or Electron was run locally; the e2e runs in CI.Review
P0/P1 review: my own pass plus a codex reviewer (GPT-6.1 Sol), in parallel.
liveupdate arriving meanwhile was dropped, so the pane stayed detached. A trigger that arrives mid-flight now queues one more ask, which runs only if the pane is still detached. There is never more than one ask in flight plus one queued.onExit(-1)from the follow-up ask. That was already the behaviour before this PR and is out of scope here.Agent skill upstream boundary
Notes
COMPAT(legacy-relay-bridge)transport file.exitedanswer ends it.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)