Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(preview): route remote ports through t3 connect #8841

Closedmaria-rckswants to merge 8 commits intomain fromrefs/pull/8841/headopened View on GitHub

maria-rckscommented

Environment-port previews now keep local and private routing unchanged and use a five-minute port-scoped signed gateway when the environment is reached through T3 Connect. The desktop preview proxy preserves localhost browser origins while relaying HTTP, streaming responses, redirects, cookies, and WebSocket and Vite HMR traffic to the remote server's loopback port; the gateway rejects invalid targets, expired or cross-environment tickets, and sessions without operate scope. Verified with focused server, desktop, and web tests, changed-file lint and format checks, and affected typechecks; the real MCP flow remains unverified because the active installed preview host does not contain the worktree route. Built with gpt-5.6-sol via Codex in T3 Code.


Note

Medium Risk Introduces authenticated proxying and ticket issuance with loopback-only targets, but incorrect validation or header forwarding could widen reach or break remote previews.

Overview Adds an authenticated preview gateway so the desktop integrated browser can open HTTP dev servers on a remote environment's loopback while keeping localhost URLs in the webview (assets, cookies, redirects, Vite HMR).

Server: New HTTP/WebSocket gateway routes proxy only validated loopback targets using port-scoped, time-limited signed tickets (preview.issueGatewayTicket, orchestration operate scope). Advertises a previewGateway capability; tickets are environment-bound via per-server signing keys.

Desktop: A per-environment local loopback proxy (PreviewGatewayProxy) plus Electron session setProxy wiring (configureGateway / clearGateway IPC) forwards matching traffic to the remote gateway over the existing environment connection, including WebSocket tunnels.

Web: Environment-port navigation for public relay endpoints now resolves as environment-gateway instead of failing; navigation issues a ticket and configures the proxy before load, refreshes credentials before expiry, and surfaces structured gateway failures in toasts and automation readiness.

Local/private-network preview behavior is unchanged; hosted web and mobile do not install the desktop proxy.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 4f7845bf2695478e85051c7804a45d1bd7775521. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Route remote preview ports through authenticated PreviewGateway proxy

  • Adds a server-side gateway (apps/server/src/preview/Gateway.ts) that proxies HTTP and WebSocket requests to loopback targets using signed, port-scoped, 5-minute tickets issued via the preview.issueGatewayTicket WebSocket RPC
  • Adds a desktop loopback proxy (apps/desktop/src/preview/PreviewGatewayProxy.ts) and wires it through BrowserSession.configureGateway/clearGateway so Electron sessions route selected localhost ports to the remote gateway via fixed_servers
  • Updates browser navigation flows (PreviewView, PreviewAutomationHosts, HostedBrowserWebview) to prepare or clear the gateway before navigation, detect gateway error meta tags in loaded documents, and show failure toasts
  • Extends contracts (packages/contracts) with DesktopPreviewGatewayConfig, PreviewGatewayTicket, PreviewUrlResolution kind 'environment-gateway', and PreviewGatewayFailureReason; non-private environment URLs now resolve as environment-gateway instead of throwing
  • Risk: resolveEnvironmentPortTarget no longer throws for non-private hosts — callers that relied on the throw to block public-relay previews will now get an environment-gateway resolution requiring gateway setup; verify no in-tree callers depend on the old error path
Macroscope summarized 4f7845b.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: ac6a89dc-2188-4822-9de9-d2549a2138c3

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Warning

      Your free Security trial is over. An organization admin can activate Security or dismiss this notice.


      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. UI consistency review found two user-visible regressions in the new gateway preparation paths: a preview surface that can render permanently blank, and address-bar / discovered-server navigation that becomes a silent no-op when gateway preparation fails. Both are in apps/web/src and are introduced by changed lines.

      Posted via Macroscope — UI Consistency
    4. Effect service conventions review: 4 findings, all in the new preview gateway code (apps/server/src/preview/Gateway.ts, apps/web/src/components/preview/previewAutomationErrors.ts). Details inline.

      Posted via Macroscope — Effect Service Conventions
      apps/server/src/preview/Gateway.ts lines 67 to 80OutdatedResolvedby maria-rcks
    5. Two new convention findings in the gateway error modeling (the four findings from the previous run on apps/server/src/preview/Gateway.ts and apps/web/src/components/preview/previewAutomationErrors.ts are still open and not repeated here).

      Posted via Macroscope — Effect Service Conventions
    6. Reviewed the web-side changes (apps/web/src/**) for UI/behavior consistency. The two issues flagged on the previous run are addressed (the gateway-prep failure now unblocks the webview and toasts, and PreviewView reports gateway failures). Two follow-up regressions remain in the new failure paths.

      Posted via Macroscope — UI Consistency
    7. Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e796a19e6cb73e12dab472ba64fc1a6e0ef21277. Configure [here](https://www.cursor.com/dashboard/bugbot).
      apps/desktop/src/preview/PreviewGatewayProxy.ts line 274OutdatedResolvedby maria-rcks
    8. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This 39-file change introduces authenticated HTTP/WebSocket proxying, signed gateway tickets, desktop session routing, and new remote-preview navigation behavior. It also changes authorization logic and advertises the gateway as a default server capability, so the runtime and security scope requires human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    9. One convention finding: the new client-side PreviewGatewayNavigationError declares no cause, so every wrap site discards the real underlying failure.

      Posted via Macroscope — Effect Service Conventions
    10. One finding on the new gateway preparation path in the Electron browser host. Everything else in the in-scope web files (target resolver rewrite, usePreparePreviewGatewayNavigation, automation host wiring, readiness gateway probe, capability read) resolves its environment from explicit thread/prop scope and reads capability, connection, and RPC target from the same environment, so no environment-routing or primitive/styling issues were found.

      Posted via Macroscope — UI Consistency
    11. maria-rcks closed this

Sign in to join this conversation.