Skip to content

fix(ssh): an old relay terminal's tab shows output again after a reconnect - #27951

Merged
OrcaWin merged 2 commits into
mainfrom
OrcaWin/bridge-followup-reattach-after-stop
Oct 12, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
OrcaWin/bridge-followup-reattach-after-stop

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​74 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​74
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​12

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 as live again, 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 is live, the transport attaches with the relay's screen and output flows again. An answer of exited still ends the pane, as before.

Why

  • This was flagged twice by the automated review on fix(ssh): keep 1.4.224's running terminals working after the upgrade (legacy relay bridge) #27787 and was left open. It's a silent failure: the tab looks alive but is deaf.
  • It belongs to the "unreachable relay" follow-up from the bridge's author (open item 2). I checked that item on current main. A relay the bridge can't reach already keeps its tab: the pane stays 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.
  • It's a one-line change in the transport. The other option, keeping the main-process bridge alive across a disconnect, would change teardown, which the README promises hangs up every bridge connection.

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

  • Automated tests added/updated
  • New transport unit test: an attached pane, then the bridge is stopped (empty pane list, no exit), then the pane is published live again. 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.
  • The Docker e2e ssh-orcad-legacy-relay-bridge.spec.ts now disconnects and reconnects the host while the old tab is open, then types and expects the old shell's echo.
  • Locally: 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.

  • Codex P1, fixed: a second disconnect could leave a reattach in flight against a bridge that had already been replaced. A live update 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.
  • Codex re-review of the fix: no P0/P1.
  • My pass: no other P0/P1. Known and unchanged: when a bridged terminal exits, the pane can get a second 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • No wire or IPC change. This is renderer-only and stays inside the bridge's COMPAT(legacy-relay-bridge) transport file.
  • SSH boundary: a missing pane is never read as exited. Only the bridge's own exited answer ends it.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

When a pane is absent from the bridged-pane list, the transport clears its attached state and requests reattachment. If an attach is already in flight, the transport queues another attempt and starts it after the current request completes if the transport remains unattached. Tests cover input rejection while disconnected, recovery with replay, and shell input and output after reconnection.


Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 50743

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 | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the primary SSH legacy relay reconnect fix.
Description check Passed The description is complete and focused. It explains the user-facing issue, implementation, rationale, linked issue, visual-proof status, testing, review findings, compatibility considerations, and ch…

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 643b6da1-cd73-4786-8476-009c6cacf392
📥 Commits

Reviewing files that changed from the base of the PR and between cf760cb and 5074377.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/legacy-relay-bridge-transport.test.ts
  • src/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.

Comment on lines +81 to +84
if (reattachQueued) {
reattachQueued = false
if (!attached) {
void reattach()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 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

@OrcaWin
OrcaWin merged commit 33ddc1a into main Oct 12, 2026
45 checks passed
sj900211 added a commit to sj900211/orcinus that referenced this pull request Oct 14, 2026
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]>
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