Repository navigation
fix(session-tabs): keep recent worktree streams warm and stop resubscribing live ones - #29241
Conversation
…ing live ones Switching worktrees on one SSH host tore down and reinstalled the per-worktree session.tabs.subscribe stream on every switch (a subscribe round trip, an orphan recovery pass and a snapshot re-apply). A hostContactEpoch bump also reinstalled both session-tabs streams even when they never ended. - Keep the three most recently selected worktree streams warm, keyed by connection identity; a new runtime session, re-pair or hidden window drops them. Only the selected worktree may seed or respawn a terminal. - On a hostContactEpoch bump, restart only streams that ended or are waiting on the retry backoff; live streams are untouched.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 17 minutes. View limit details
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to
|
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:
443ef322-6279-4e02-a946-f6e7dd070bf8
📒 Files selected for processing: 7
src/renderer/src/runtime/web-session-tabs-sync-worktree-switch.test.tsxsrc/renderer/src/runtime/web-session-tabs-sync/active-session-subscription.tssrc/renderer/src/runtime/web-session-tabs-sync/global-session-subscription.tssrc/renderer/src/runtime/web-session-tabs-sync/use-web-session-tabs-sync.tssrc/renderer/src/runtime/web-session-tabs-sync/warm-worktree-subscriptions.tssrc/renderer/src/runtime/window-visibility-subscription-entry.tssrc/renderer/src/runtime/window-visibility-subscription-parking.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
| } | ||
| try { | ||
| if (isCurrent() && bootstrap) { | ||
| if (isCurrent() && isSelected() && bootstrap) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Reconsider terminal creation when a warm worktree becomes selected.
If an empty snapshot arrives after the user leaves a worktree, isSelected() suppresses its initial terminal bootstrap. When the user returns, the live stream is reused without another snapshot or bootstrap check. The worktree can remain without its initial terminal indefinitely. The same gap applies to a suppressed wake respawn. Retain the eligible follow-up and reconsider it on selection, without resubscribing.
…the selected worktree
…ocus-read count stays in the hook
…d changes identity
ELI5
When you click between workspaces on the same SSH machine, Orca used to hang up and redial the machine's "what tabs are open here" feed every time, then reload the answer it already had. Now it keeps the feeds for the last few workspaces you visited open, so switching back just works. It also stops hanging up feeds that were still working whenever a background health check briefly lost and then regained the machine.
What Changed
Before: Every worktree switch on a paired host or SSH host (orcad) closed the per-worktree
session.tabs.subscribestream and opened a new one. Each switch cost one subscribe round trip, an orphan-recovery pass, and a full snapshot re-apply before the panes settled. Separately, everyhostContactEpochbump ("the host answered again") reinstalled both session-tabs streams, the per-worktree one and the all-worktrees one, even when neither had ended. So a flapping status probe forced a resubscribe each time it flapped.After:
warm-worktree-subscriptions.tskeeps the three most recently selected worktree streams open, keyed by host and worktree. Switching A→B→A opens two streams, not three, and A's original stream is never closed. A warm stream is dropped when the host comes back as a new runtime session (connection generation or runtime id moved) or is re-paired, when the window is hidden (so reveal does not resume extra streams), when workspace session readiness drops, and when it is evicted from the three-stream pool.window-visibility-subscription-parking.tsgainsrestartEnded(). It restarts, immediately and without waiting for the retry backoff, only the streams that already ended or failed to subscribe. On ahostContactEpochbump, both effects now call it instead of reinstalling. Live streams are untouched.Why
The per-worktree stream exists alongside
session.tabs.subscribeAllfor three reasons: it resumes immediately on window reveal, it is the closure that decides the initial-terminal bootstrap and wake respawn for the selected worktree, and it runs orphan recovery before apply. Keeping it per-worktree and warm keeps all three. Replacing it with local filtering of the global stream would have moved those decisions into the global path, and the global stream resumes staggered behind other hosts.The epoch edge exists because streams that ended during an outage need reviving (#20359). Since #27098, an ended stream already sits on a retry backoff, so a regained host only needs to skip that wait. A stream that never ended has nothing to recover: transport drops are owned by the shared-control reconnect replay. That is why the epoch now restarts ended streams only. The wire is unchanged: same methods, same params, no new opcodes. Mixed-version peers are unaffected.
I checked whether an unchanged snapshot re-apply itself retires or recreates panes. It does not: the store slices stay reference-equal, and a test pins that. The cost on each switch was the round trip and the recovery pass, not a store rewrite.
Not changed here. These per-switch calls come from other mechanisms:
worktree.activate+session.tabs.list(with forced re-accept) fromweb-runtime-worktree-activation.tsgit.statusandfiles.watchre-subscribesfiles.readDir,repo.hooksCheck,repo.setupScriptImports,git.checkIgnored,github.prForBranch,terminal.inspectProcessLinked Issue
N/A (maintainer; SSH worktree-switch latency investigation)
Visual Proof
N/A. No visual change: the tabs and panes render identically. The change is fewer round trips per worktree switch, which the tests count.
Testing
New
src/renderer/src/runtime/web-session-tabs-sync-worktree-switch.test.tsx:tabsByWorktree,terminalLayoutsByTabId,ptyIdsByTabId,unifiedTabsByWorktreeandgroupsByWorktreereference-equal.The existing
web-session-tabs-sync-reconnect-resubscribetest still passes: streams that ended during an outage are revived when the host answers again.pnpm test src/renderer/src/runtime src/renderer/src/app-shell(280 files) passes, as dopnpm tcandpnpm run check:code-quality:changed.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)