Add scoped SSH preview port forwarding
Summary
- add an Effect-based environment port router with scoped route ownership
- acquire ref-counted, loopback-only SSH port forwards through the desktop bridge
- route preview automation, discovered ports, and manual navigation consistently
- keep T3 Connect forwarding explicitly unsupported for now
Verification
vp checkvp run typecheck- 48 focused SSH, IPC, client-runtime, and preview tests
- React Doctor changed-file scan (no actionable diagnostics)
- the orchestration-timeout test file from the all-repo parallel run passes 39/39 standalone
[!NOTE] Medium Risk Cross-cutting changes to SSH tunnel lifecycle and preview navigation; lease or scope bugs could leak forwards or break remote previews, though auth and relay paths are largely unchanged.
Overview Adds scoped SSH preview port forwarding so localhost/dev-server URLs on SSH environments resolve through ref-counted loopback tunnels instead of only rewriting hosts for direct private-network access.
The stack wires desktop IPC (
acquireSshPortForward/releaseSshPortForward) throughSshEnvironmentManager(shared forwards per remote port, TCP readiness, cleanup on disconnect), exposesforwardPortonSshEnvironmentGateway(desktop bridge with acquire/release; mobile blocked), and introducesEnvironmentPortRouterin client-runtime for direct vs private-network vsssh-forwardresolution (relay/T3 Connect ports still rejected).Web preview replaces synchronous
browserTargetResolverURL mapping with async route acquisition (commit/releaseper tab, SSH scopes held until tab close). Preview automation, manual navigation, discovered ports, and session close all use this lifecycle. Contracts addssh-forwardtoPreviewUrlResolution;NetService.hasListenerOnHostsupports forward readiness probes.Reviewed by Cursor Bugbot for commit e5f5c40fdc3f82a828a75f5852664ffa85ae9b35. Bugbot is set up for automated code reviews on this repo. Configure here.
[!NOTE]
Add scoped SSH preview port forwarding with reference-counted lease management
- Adds
acquirePortForwardandreleasePortForwardtoSshEnvironmentManager, tracking concurrent leases per target/remotePort and tearing down the SSH tunnel only when the last lease is released.- Introduces
EnvironmentPortRouterinpackages/client-runtime/src/preview/router.tsthat resolves preview navigation targets todirect,direct-private-network, orssh-forwardresolutions, acquiring scoped SSH port forwards for SSH connections.- Replaces synchronous URL resolution in browser navigation with an acquire/commit/release model (
acquireBrowserNavigationTarget,releaseBrowserNavigationRoute,withBrowserNavigationRoute) so SSH-forward leases remain alive per tab until the tab is closed.- Extends the desktop IPC bridge with
acquireSshPortForwardandreleaseSshPortForwardchannels, wired throughDesktopSshEnvironmentand exposed onwindow.desktopBridge.- Adds
hasListenerOnHosttoNetServiceand uses it to poll for TCP readiness when establishing port-forward tunnels, with a timeout bounded bySSH_READY_TIMEOUT_MS.- Risk: SSH port forwards now hold OS resources (a TCP tunnel process) per active tab; tabs that are never explicitly closed or whose routes are never released will leak the forward until the environment is disconnected.
๐ Macroscope summarized e5f5c40. 21 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted
๐๏ธ Filtered Issues
No issues evaluated.
[!IMPORTANT]
Review skipped
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.โ๏ธ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
be16e21a-13d5-4686-8d19-160fab814eebYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- [ ] ๐ Trigger review
โจ Finishing Touches
๐งช Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Commit unit tests in branch
t3code/add-ssh-preview-port-forwarding
Comment @coderabbitai help to get the list of available commands.
Approvability
Verdict: Needs human review
5 blocking correctness issues found. New feature adding SSH preview port forwarding with complex lifecycle management. Multiple unresolved review comments identify potential resource leaks, race conditions, and concurrency bugs that require human attention before merging.
You can customize Macroscope's approvability policy. Learn more.
Any update on this? I'd find this very helpful
Ready for review: #7639 is a companion PR targeted directly at this PR feature branch.
Merging #7639 will add the fixes to #4039 and rerun this PR checks. No cherry-pick or local branch setup is needed.
It addresses all seven distinct actionable findings on this PR:
- wait for the actual OpenSSH forward-ready signal
- serialize forward reuse and final lease release
- cancel pending forwards during manager shutdown
- close forwards when setup is interrupted
- prevent stale tab navigation from replacing newer routes
- preserve routes until in-flight navigation finishes
- release routes after disconnect, authoritative tab removal, and environment removal
The companion review found and fixed six follow-ups: removed tabs retire routes until in-flight work finishes, shutdown interrupts pending SSH setup before waiting on the forwarding lock, ready forwards close if interrupted before registration, environment cleanup closes route scopes in the caller Effect runtime, preview-close consumers use the canonical route module directly, and cancelled route acquisition does not open a useless local browser tab.
Manual two-machine testing between Nova and Showtime also found two entry-point defects. Terminal links now use the environment router before opening the preview, and preview forwards resolve remote localhost so normal IPv4 or IPv6 dev-server binding works without a special host flag. A direct SSH forwarding smoke test returned HTTP 200.
Validation passed: focused web and SSH tests, web and SSH package typechecks, targeted formatting and lint, and git diff --check.
All automated checks on #7639 are terminal with no failures, and all companion review threads are resolved. Macroscope left an informational note that human review is appropriate because this changes SSH forwarding lifecycle behavior.
Two-machine validation details, sanitized environment specs, and screenshot proof: https://github.com/pingdotgg/t3code/pull/7639#issuecomment-5362320919