Skip to content

fix(ssh): two overlapping bridged-terminal attaches hand back the viewer they replace - #30856

Merged
nwparker merged 3 commits into
mainfrom
nwparker/legacy-bridge-concurrent-attach-viewer
Oct 19, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/legacy-bridge-concurrent-attach-viewer

Conversation

@nwparker

@nwparker nwparker commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19

ELI5

When a terminal is still running under an older Orca on an SSH host, the desktop watches it through a "bridge" and tells the desktop's bridge "one more viewer is watching" each time it attaches. If two attaches for the same terminal pane happened at once, the pane kept only the second "I'm watching" ticket and forgot the first. The desktop then believed someone was still watching after the pane left, and kept sending it the terminal's output.

What Changed

Before: two overlapping attaches for one bridged pane (a connect and an attach, or a connect and a reconnect after the relay came back) each got a viewer from main. The pane overwrote the first viewer with the second, so closing or detaching the pane handed back only one. The leaked viewer kept main counting the terminal as watched, so main kept forwarding that terminal's output to the window after the pane had detached, until the terminal exited or the bridge closed.

After: each attach the pane issues gets a sequence number, and every viewer goes through one small adoptViewer step. The pane keeps the viewer from the newest attach it issued, whichever reply arrives last, and hands every other viewer back to main. Leaving the pane releases the one it holds, so nothing is left behind. An older connect that answers last still returns its screen, because an attach() that won delivers none of its own.

Mechanism: src/renderer/src/components/terminal-pane/legacy-relay-bridge-transport.ts, the two places that stored result.acquisitionId (first connect and reattach) now go through adoptViewer.

Why

Smallest change that closes the leak at the one place viewers are recorded. Ordering by issue rather than by reply means a late reply from an older attach can never release the newer viewer. The alternative was to serialize attaches (a single in-flight attach shared by connect, attach and reattach). That is a larger change to fenced legacy relay code that is retiring on 2027-01-15 (COMPAT(legacy-relay-bridge)), and the existing epoch check already handles attaches that finish after the pane left. Main's detach is per viewer (acquisition id), so releasing the older one cannot affect the kept one.

Linked Issue

Follow-up from the SSH/managed-server deficiency scan; no tracked issue.

Visual Proof

N/A: no visible change. The fix is in how many host-side viewers a pane holds.

Testing

  • New unit test hands back every viewer when two attaches for the pane overlap: a connect and an attach race, both answered "attached" (viewers 1 and 2); after detach, both must be handed back. On main it fails (only viewer 2 is detached); with the fix it passes.

  • New unit test keeps the newest attach’s viewer when an older attach answers last: replies arrive in reverse order. It fails without the sequence numbers.

  • pnpm test src/renderer/src/components/terminal-pane/ (single worker), pnpm tc, pnpm run check:code-quality:changed, and the static-analysis job steps from pr.yml run locally.

  • Verified only in unit tests: reproducing two overlapping attaches against a real older relay needs a timing race this lane cannot stage reliably.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Codex review (gpt-6.1-sol, high): round 1 no findings. Round 2 (after adding the sequence numbers): one finding, fixed. Suppressing an older connect's replay could leave the screen blank when attach() won, so that suppression was dropped. Round 3: no findings. Independent Opus review: mergeable, and its P3 (keep the newest attach's viewer) is addressed 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

SSH: only the legacy relay bridge path changes; managed-server and local transports are untouched. No wire change: it uses the existing detach call. Cross-platform: renderer-only logic.

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 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The transport now orders overlapping initial attaches and reattaches by issue sequence. It releases stale viewer acquisitions and releases a previously held acquisition when it adopts a newer viewer. An initial attach returns replay only if its response remains current. Tests cover overlapping calls, reverse response order, and detachment of acquired viewers.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to 3bd05

Overlapping attaches can leave the terminal blank until further output arrives. Deliver the winning replay before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

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 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description covers the change, rationale, testing, visual proof, scope, review, and checklist. However, the required Linked Issue section states that no tracked issue exists and provides no issue … Add a link to the issue addressed by this PR. If the author is a stablyai maintainer, confirm that the maintainer exception applies and document the relevant pre-existing issue or rationale instead of leaving the required reference absent.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main fix for overlapping bridged-terminal attaches.
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.
Full details: Description check

Explanation

The description covers the change, rationale, testing, visual proof, scope, review, and checklist. However, the required Linked Issue section states that no tracked issue exists and provides no issue reference.

Resolution

Add a link to the issue addressed by this PR. If the author is a stablyai maintainer, confirm that the maintainer exception applies and document the relevant pre-existing issue or rationale instead of leaving the required reference absent.

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

@nwparker
nwparker force-pushed the nwparker/legacy-bridge-concurrent-attach-viewer branch from b75f2ba to 3bd0519 Compare October 19, 2026 21:15

@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: d55cf71a-7d8d-4ec5-9021-5d1c5f9f2e97
📥 Commits

Reviewing files that changed from the base of the PR and between b75f2ba9300248301be11ed72cb0d1fa5bfdfc1a and 3bd0519.

📒 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; 0 remain after this review.

@nwparker
nwparker merged commit fbd0a29 into main Oct 19, 2026
47 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