Repository navigation
fix(ssh): two overlapping bridged-terminal attaches hand back the viewer they replace - #30856
Conversation
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to
|
…replace Co-authored-by: Claude <[email protected]>
…er one answers last Co-authored-by: Claude <[email protected]>
b75f2ba to
3bd0519
Compare
…er attach keeps the viewer Co-authored-by: Claude <[email protected]>
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:
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.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; 0 remain after this review.
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
adoptViewerstep. 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 anattach()that won delivers none of its own.Mechanism:
src/renderer/src/components/terminal-pane/legacy-relay-bridge-transport.ts, the two places that storedresult.acquisitionId(first connect and reattach) now go throughadoptViewer.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 frompr.ymlrun 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
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)