Skip to content

[Bug]: Remote port forward hidden/fails over T3 Connect: x-t3-tunnel-port-refused on probe 502 never reaches the desktop app #39750

Closed

Description

@piero-dev25

What happened

On the desktop app on my MacBook, connected to my Mac Studio through T3 Connect, the Servers list in thread details never shows the "Forward to this machine, for any app here" button. Trying to forward a port fails with:

This environment can't be reached right now. Try again once it reconnects.

The environment works fine otherwise: chat runs, and the in-app browser preview of the same ports loads over the same tunnel route.

Diagnosis

This adds the T3 Connect evidence requested in #39546, whose last comment asked for (1) the status and headers of the probe's /api/preview/tunnel request on the environment and (2) whether a relay sits in front of the server. The no-repro there did not test the T3 Connect route.

From the 0.1.11 source:

  • The forward button renders only when the port-forward locality is remote (renderer: f = locality === "remote", from the desktop:port-forward-locality atom, which uses desktopBridge.preview.sharesLoopback).
  • LoopbackTunnel.probeLoopback (desktop main) opens a probe listener on a random local port and dials the environment's /api/preview/tunnel?port=<probe port>. It returns false (remote) only if dialDestination's unexpected-response handler sees the x-t3-tunnel-port-refused header. Anything else becomes LoopbackTunnelUnavailableError, so locality is unknown. That hides the button and makes forwardPort fail with the message above, because forward calls sharesLoopback first.

On the environment (the Mac Studio), the server answered both probes correctly: 502 with x-t3-tunnel-port-refused: 1 (PreviewTunnelConnectError maps to status: 502, headers: PORT_REFUSED_HEADERS). The desktop app still reported unavailable. So the header, or the 502 itself, does not reach the client over the T3 Connect relay, which is a Cloudflare tunnel (*.t3coderelay.com).

Successful upgrades through the same route work: in-app preview tunnels to a real port (port=8765) succeed repeatedly in the same log. Only the refused-upgrade response, which carries the header, seems to be lost.

Steps to reproduce

  1. Machine A (environment) runs the T3 server, 0.1.11. Machine B runs the desktop app, 0.1.11, on a different network, linked to A through T3 Connect (relay).
  2. On A, run any server on loopback, e.g. python3 -m http.server 18765 --bind 127.0.0.1.
  3. On B, open a thread on A and open thread details, then Servers.
  4. The forward button never appears on the server row (also not on hover). Forwarding from elsewhere shows "This environment can't be reached right now. Try again once it reconnects."
  5. In A's server.trace.ndjson, each probe shows as a failed PreviewTunnel.connect for a random high port, and a 502 on GET /api/preview/tunnel.

Version

0.1.11 (environment server and desktop app)

Environment

Environment: macOS 27.0 (Mac Studio, arm64), T3 server 0.1.11. Client: T3 Code (Beta) desktop 0.1.11 on a MacBook Air (arm64, macOS). Connection: T3 Connect relay; the machines are on different networks; no Tailscale.

Evidence

Environment server.trace.ndjson (redacted; times are local, UTC+9):

23:08:24 PreviewTunnel.connect {"port":58209} Failure: PreviewTunnelConnectError: Nothing accepted a connection on loopback port 58209.
23:10:24 PreviewTunnel.connect {"port":58416} Failure: PreviewTunnelConnectError: Nothing accepted a connection on loopback port 58416.

{"name":"GET","kind":"server","attributes":{"http.route":"/api/preview/tunnel","http.request.method":"GET",
 "url.full":"http://prod-<redacted>.t3coderelay.com/api/preview/tunnel?wsTicket=<redacted>&port=58416",
 "client.address":"127.0.0.1","http.response.status_code":502},
 "exit":{"_tag":"Failure","cause":"HttpServerError: ResponseError (502 GET /api/preview/tunnel)"}}

# same route, real port, same session: succeeds
22:59:00..23:03:47 PreviewTunnel.connect {"port":8765} Success (x13)

Header names match on both sides in 0.1.11:

desktop main.cjs:  PORT_REFUSED_HEADER = "x-t3-tunnel-port-refused"
server:            PREVIEW_TUNNEL_PORT_REFUSED_HEADER = "x-t3-tunnel-port-refused"
                   PreviewTunnelConnectError -> { status: 502, headers: PORT_REFUSED_HEADERS }

I did not capture the client-side response, because the relay hop needs a ticket only the app holds. So whether Cloudflare replaces the origin 502 or only strips the header is still to be confirmed. Possible fixes: carry the refusal in a way that survives the relay (e.g. accept the upgrade and send a close frame with a refusal code or reason), or treat a relay 502 on the probe port as "refused".

Related issues

#39546: same error and probe path, closed as no-repro. It was tested over a direct remote link only, and its last comment asks exactly whether a relay drops x-t3-tunnel-port-refused. This report is the T3 Connect case, with server-side evidence that the header is sent.

Fix applied or workaround

None in-app. Forwarding to an outside browser over T3 Connect is blocked. Workarounds outside T3: Tailscale on both machines, or a separate tunnel.

Filed by

Claude (Opus 5.5) via Claude Code in T3 Code, on behalf of the user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions