TypeScript
feat(connect): tell users when an idle tunnel was removed (#13567)
Julius Marminge6b456a9618c3
diff --git a/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.test.ts b/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.test.tsindex ebd418da7b4..f78cecc0671 100644--- a/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.test.ts+++ b/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.test.ts@@ -2,6 +2,8 @@ import { EnvironmentId, ORCHESTRATION_PROTOCOL_VERSION } from "@t3tools/contractimport type { RelayEnvironmentStatusResponse } from "@t3tools/contracts/relay";import { describe, expect, it } from "vite-plus/test";+import { RELAY_TUNNEL_RELEASED_MESSAGE } from "@t3tools/client-runtime/relay";+import { availableCloudEnvironmentPresentation } from "./cloudEnvironmentPresentation";function relayStatus(@@ -111,4 +113,23 @@ describe("available cloud environment presentation", () => {connectionErrorTraceId: "trace-status",});});++ it("tells the user to update a host whose idle tunnel was removed", () => {+ const status = {+ ...relayStatus("offline", "Managed endpoint health request failed.", "trace-released"),+ offlineReason: "tunnel_released",+ } satisfies RelayEnvironmentStatusResponse;+ expect(+ availableCloudEnvironmentPresentation({+ isStatusPending: false,+ status,+ statusError: null,+ statusErrorTraceId: null,+ }),+ ).toMatchObject({+ connectionState: "error",+ statusText: RELAY_TUNNEL_RELEASED_MESSAGE,+ connectionErrorTraceId: "trace-released",+ });+ });});diff --git a/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.ts b/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.tsindex 3e958b6453d..49e1e790c50 100644--- a/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.ts+++ b/apps/mobile/src/features/cloud/cloudEnvironmentPresentation.ts@@ -3,6 +3,7 @@ import {orchestrationProtocolCompatibilityError,type EnvironmentConnectionPhase,} from "@t3tools/client-runtime/connection";+import { relayOfflineReasonMessage } from "@t3tools/client-runtime/relay";export interface AvailableCloudEnvironmentPresentation {readonly connectionError: string | null;@@ -39,7 +40,8 @@ export function availableCloudEnvironmentPresentation(input: {}if (input.status?.status === "offline") {- const connectionError = input.status.error ?? "Relay is offline.";+ const connectionError =+ relayOfflineReasonMessage(input.status) ?? input.status.error ?? "Relay is offline.";return {connectionError,connectionErrorTraceId: input.status.traceId ?? null,diff --git a/apps/web/src/components/cloud/CloudEnvironmentConnectList.test.tsx b/apps/web/src/components/cloud/CloudEnvironmentConnectList.test.tsxindex d596866efc5..f6ea5be6229 100644--- a/apps/web/src/components/cloud/CloudEnvironmentConnectList.test.tsx+++ b/apps/web/src/components/cloud/CloudEnvironmentConnectList.test.tsx@@ -1,4 +1,4 @@-import type { Discovery } from "@t3tools/client-runtime/relay";+import { RELAY_TUNNEL_RELEASED_MESSAGE, type Discovery } from "@t3tools/client-runtime/relay";import type { AtomCommandResult } from "@t3tools/client-runtime/state/runtime";import { EnvironmentId, ORCHESTRATION_PROTOCOL_VERSION } from "@t3tools/contracts";import * as Option from "effect/Option";@@ -152,6 +152,40 @@ afterEach(async () => {vi.unstubAllGlobals();});+describe("cloud environment offline reasons", () => {+ it("tells the user to update a computer whose idle tunnel was removed", async () => {+ const base = linkedMachines.get(newMachineId)!;+ const offlineEntry = (offlineReason?: "tunnel_released") => ({+ ...base,+ availability: "offline" as const,+ status: Option.some({+ environmentId: newMachineId,+ endpoint: base.environment.endpoint,+ status: "offline" as const,+ checkedAt: "2026-09-15T00:00:00Z",+ error: "Managed endpoint health request failed.",+ ...(offlineReason ? { offlineReason } : {}),+ }),+ });+ const rowText = () =>+ renderer!.root.findAllByType("p").flatMap((paragraph) => paragraph.children);++ discovery.listEnvironments.mockResolvedValue(new Map([[newMachineId, offlineEntry()]]));+ await mount();+ expect(rowText()).toContain("T3 Connect · Not added · Relay offline");++ await act(async () => {+ publish({+ environments: new Map([[newMachineId, offlineEntry("tunnel_released")]]),+ refreshing: false,+ offline: false,+ error: Option.none(),+ });+ });+ expect(rowText()).toContain(RELAY_TUNNEL_RELEASED_MESSAGE);+ });+});+describe("cloud onboarding discovery", () => {it("signals that the section can expand after initial discovery settles", async () => {let finishDiscovery!: (environments: DiscoveredEnvironments) => void;diff --git a/apps/web/src/components/cloud/CloudEnvironmentConnectList.tsx b/apps/web/src/components/cloud/CloudEnvironmentConnectList.tsxindex fe5eb783623..ddff0de446b 100644--- a/apps/web/src/components/cloud/CloudEnvironmentConnectList.tsx+++ b/apps/web/src/components/cloud/CloudEnvironmentConnectList.tsx@@ -5,6 +5,7 @@ import {RelayConnectionTarget,orchestrationProtocolCompatibilityError,} from "@t3tools/client-runtime/connection";+import { relayOfflineReasonMessage } from "@t3tools/client-runtime/relay";import {isAtomCommandInterrupted,squashAtomCommandFailure,@@ -335,7 +336,14 @@ export function CloudEnvironmentConnectRows({// A connected machine's own config (with the user's icon pick) wins. Before// that, the relay's health probe already carries the server's descriptor, so// a machine can wear its detected glyph before this device ever connects.- const descriptor = status === undefined ? undefined : Option.getOrNull(status)?.descriptor;+ const relayStatus = status === undefined ? null : Option.getOrNull(status);+ const descriptor = relayStatus?.descriptor;+ // Why the relay reports this environment offline, when it knows more than+ // "no answer". Shown for saved and unsaved rows alike.+ const offlineReason =+ availability === "offline" && relayStatus !== null+ ? relayOfflineReasonMessage(relayStatus)+ : null;const machineKind = resolveEnvironmentMachineKind(savedEnvironment?.serverConfig ??(descriptor === undefined ? null : { environment: descriptor }),@@ -361,16 +369,18 @@ export function CloudEnvironmentConnectRows({const statusText =unsupported && !savedEnvironment? `T3 Connect · ${notAdded} · Client not supported`- : savedConnection- ? savedConnection.statusText- : availability === "online"- ? `T3 Connect · ${notAdded} · Relay online`- : availability === "offline"- ? `T3 Connect · ${notAdded} · Relay offline`- : availability === "checking"- ? `T3 Connect · ${notAdded} · Checking relay status…`- : (Option.getOrNull(error)?.message ??- `T3 Connect · ${notAdded} · Relay status unavailable`);+ : offlineReason !== null+ ? offlineReason+ : savedConnection+ ? savedConnection.statusText+ : availability === "online"+ ? `T3 Connect · ${notAdded} · Relay online`+ : availability === "offline"+ ? `T3 Connect · ${notAdded} · Relay offline`+ : availability === "checking"+ ? `T3 Connect · ${notAdded} · Checking relay status…`+ : (Option.getOrNull(error)?.message ??+ `T3 Connect · ${notAdded} · Relay status unavailable`);if (selection) {return (<label@@ -435,15 +445,17 @@ export function CloudEnvironmentConnectRows({tooltipText={unsupportedDetail !== null? unsupportedDetail- : savedConnection- ? savedConnection.statusText- : availability === "online"- ? "Relay online"- : availability === "offline"- ? "Relay offline"- : availability === "checking"- ? "Checking relay status"- : (Option.getOrNull(error)?.message ?? "Relay status unavailable")+ : offlineReason !== null+ ? offlineReason+ : savedConnection+ ? savedConnection.statusText+ : availability === "online"+ ? "Relay online"+ : availability === "offline"+ ? "Relay offline"+ : availability === "checking"+ ? "Checking relay status"+ : (Option.getOrNull(error)?.message ?? "Relay status unavailable")}/><EnvironmentMachineIcondiff --git a/docs/user/remote-access.md b/docs/user/remote-access.mdindex 2192a239344..a5f8bbae3af 100644--- a/docs/user/remote-access.md+++ b/docs/user/remote-access.md@@ -194,6 +194,11 @@ and keeps the same address. When the host starts again or wakes, T3 Connectcreates a replacement tunnel on its own. You do not need to pair again. Cleanupusually runs five to ten minutes after the tunnel goes down.+T3 Connect also removes the tunnel of an environment running an older version of+T3 Code once it has been offline for seven days. That environment shows a message+asking you to update. Start T3 Code on that computer and update it to the latest+version; it reconnects at the same address without pairing again.+On a command-line host, `t3 connect unlink` disables exposure while retainingyour login; `t3 connect logout` also clears that login. Background-service[removal](./background-service.md#manage-the-service) is separate.diff --git a/infra/relay/migrations/postgres/20261005232034_managed_endpoint_tunnel_released_at/migration.sql b/infra/relay/migrations/postgres/20261005232034_managed_endpoint_tunnel_released_at/migration.sqlnew file mode 100644index 00000000000..66f0de5797d--- /dev/null+++ b/infra/relay/migrations/postgres/20261005232034_managed_endpoint_tunnel_released_at/migration.sql@@ -0,0 +1 @@+ALTER TABLE "relay_managed_endpoint_allocations" ADD COLUMN "tunnel_released_at" varchar(64);\ No newline at end of filediff --git a/infra/relay/migrations/postgres/20261005232034_managed_endpoint_tunnel_released_at/snapshot.json b/infra/relay/migrations/postgres/20261005232034_managed_endpoint_tunnel_released_at/snapshot.jsonnew file mode 100644index 00000000000..5f4673a9879--- /dev/null+++ b/infra/relay/migrations/postgres/20261005232034_managed_endpoint_tunnel_released_at/snapshot.json@@ -0,0 +1,1594 @@+{+ "version": "8",+ "dialect": "postgres",+ "id": "7b10c420-1566-4dfc-8e9c-c73efa561d3b",+ "prevIds": ["13972659-45db-4ce9-9818-523b450bceca"],+ "ddl": [+ {+ "isRlsEnabled": false,+ "name": "relay_agent_activity_rows",+ "entityType": "tables",+ "schema": "public"+ },+ {+ "isRlsEnabled": false,+ "name": "relay_delivery_attempts",+ "entityType": "tables",+ "schema": "public"+ },+ {+ "isRlsEnabled": false,+ "name": "relay_dpop_proofs",+ "entityType": "tables",+ "schema": "public"+ },+ {+ "isRlsEnabled": false,+ "name": "relay_environment_credentials",+ "entityType": "tables",+ "schema": "public"+ },+ {+ "isRlsEnabled": false,+ "name": "relay_environment_links",+ "entityType": "tables",+ "schema": "public"+ },+ {+ "isRlsEnabled": false,+ "name": "relay_live_activities",+ "entityType": "tables",+ "schema": "public"+ },+ {+ "isRlsEnabled": false,+ "name": "relay_managed_endpoint_allocations",+ "entityType": "tables",+ "schema": "public"+ },+ {+ "isRlsEnabled": false,+ "name": "relay_managed_tunnel_limits",+ "entityType": "tables",+ "schema": "public"+ },+ {+ "isRlsEnabled": false,+ "name": "relay_mobile_devices",+ "entityType": "tables",+ "schema": "public"+ },+ {+ "type": "varchar(191)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "environment_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_agent_activity_rows"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "environment_public_key",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_agent_activity_rows"+ },+ {+ "type": "varchar(512)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "thread_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_agent_activity_rows"+ },+ {+ "type": "jsonb",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "state_json",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_agent_activity_rows"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "updated_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_agent_activity_rows"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "created_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_agent_activity_rows"+ },+ {+ "type": "varchar(36)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "created_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "type": "varchar(255)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "user_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "type": "varchar(191)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "environment_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "type": "varchar(512)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "thread_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "type": "varchar(255)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "device_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "kind",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "source_job_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "type": "varchar(16)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "token_suffix",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "type": "integer",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "apns_status",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "apns_reason",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "type": "varchar(128)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "apns_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "transport_error",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "type": "varchar(128)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "thumbprint",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_dpop_proofs"+ },+ {+ "type": "varchar(255)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "jti",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_dpop_proofs"+ },+ {+ "type": "integer",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "iat",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_dpop_proofs"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "expires_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_dpop_proofs"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "created_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_dpop_proofs"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "credential_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_credentials"+ },+ {+ "type": "varchar(191)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "environment_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_credentials"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "environment_public_key",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_credentials"+ },+ {+ "type": "varchar(191)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "credential_hash",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_credentials"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "revoked_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_credentials"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "created_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_credentials"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "updated_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_credentials"+ },+ {+ "type": "varchar(191)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "user_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "varchar(191)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "environment_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": "'T3 Environment'",+ "generated": null,+ "identity": null,+ "name": "environment_label",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "environment_public_key",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "endpoint_http_base_url",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "endpoint_ws_base_url",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "varchar(32)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "endpoint_provider_kind",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "boolean",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": "true",+ "generated": null,+ "identity": null,+ "name": "notifications_enabled",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "boolean",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": "true",+ "generated": null,+ "identity": null,+ "name": "live_activities_enabled",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "boolean",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": "false",+ "generated": null,+ "identity": null,+ "name": "managed_tunnels_enabled",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "boolean",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": "false",+ "generated": null,+ "identity": null,+ "name": "hold_webhooks_while_offline",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "varchar(191)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "created_by_device_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "revoked_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "created_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "updated_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "type": "varchar(255)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "user_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_live_activities"+ },+ {+ "type": "varchar(255)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "device_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_live_activities"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "activity_push_token",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_live_activities"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "remote_start_queued_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_live_activities"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "remote_started_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_live_activities"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "ended_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_live_activities"+ },+ {+ "type": "jsonb",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "last_aggregate_json",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_live_activities"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "last_live_activity_delivery_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_live_activities"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "created_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_live_activities"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "updated_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_live_activities"+ },+ {+ "type": "varchar(191)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "user_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "varchar(191)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "environment_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "hostname",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "varchar(191)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "tunnel_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "tunnel_name",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "varchar(191)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "dns_record_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "ready_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "recovery_enabled_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "recovery_environment_public_key",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "tunnel_released_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "jsonb",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "origin",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "integer",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": "0",+ "generated": null,+ "identity": null,+ "name": "generation",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "created_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "updated_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "type": "varchar(191)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "user_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_tunnel_limits"+ },+ {+ "type": "integer",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "max_tunnels",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_tunnel_limits"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "created_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_tunnel_limits"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "updated_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_managed_tunnel_limits"+ },+ {+ "type": "varchar(255)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "user_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "type": "varchar(255)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "device_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": "'iOS device'",+ "generated": null,+ "identity": null,+ "name": "label",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "type": "varchar(16)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "platform",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "type": "integer",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "ios_major_version",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "type": "integer",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "android_api_level",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "app_version",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "type": "varchar(255)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "bundle_id",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "type": "varchar(16)",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "aps_environment",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "push_token",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "type": "text",+ "typeSchema": null,+ "notNull": false,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "push_to_start_token",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "type": "jsonb",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "preferences_json",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "created_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "type": "varchar(64)",+ "typeSchema": null,+ "notNull": true,+ "dimensions": 0,+ "default": null,+ "generated": null,+ "identity": null,+ "name": "updated_at",+ "entityType": "columns",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "nameExplicit": true,+ "columns": [+ {+ "value": "updated_at",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ }+ ],+ "isUnique": false,+ "where": null,+ "with": "",+ "method": "btree",+ "concurrently": false,+ "name": "idx_relay_agent_activity_rows_updated",+ "entityType": "indexes",+ "schema": "public",+ "table": "relay_agent_activity_rows"+ },+ {+ "nameExplicit": true,+ "columns": [+ {+ "value": "environment_id",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ },+ {+ "value": "thread_id",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ },+ {+ "value": "created_at",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ }+ ],+ "isUnique": false,+ "where": null,+ "with": "",+ "method": "btree",+ "concurrently": false,+ "name": "idx_relay_delivery_attempts_environment",+ "entityType": "indexes",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "nameExplicit": true,+ "columns": [+ {+ "value": "source_job_id",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ }+ ],+ "isUnique": true,+ "where": null,+ "with": "",+ "method": "btree",+ "concurrently": false,+ "name": "idx_relay_delivery_attempts_source_job",+ "entityType": "indexes",+ "schema": "public",+ "table": "relay_delivery_attempts"+ },+ {+ "nameExplicit": true,+ "columns": [+ {+ "value": "expires_at",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ }+ ],+ "isUnique": false,+ "where": null,+ "with": "",+ "method": "btree",+ "concurrently": false,+ "name": "idx_relay_dpop_proofs_expires_at",+ "entityType": "indexes",+ "schema": "public",+ "table": "relay_dpop_proofs"+ },+ {+ "nameExplicit": true,+ "columns": [+ {+ "value": "credential_hash",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ }+ ],+ "isUnique": true,+ "where": null,+ "with": "",+ "method": "btree",+ "concurrently": false,+ "name": "idx_relay_environment_credentials_hash",+ "entityType": "indexes",+ "schema": "public",+ "table": "relay_environment_credentials"+ },+ {+ "nameExplicit": true,+ "columns": [+ {+ "value": "environment_id",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ },+ {+ "value": "revoked_at",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ }+ ],+ "isUnique": false,+ "where": null,+ "with": "",+ "method": "btree",+ "concurrently": false,+ "name": "idx_relay_environment_credentials_environment",+ "entityType": "indexes",+ "schema": "public",+ "table": "relay_environment_credentials"+ },+ {+ "nameExplicit": true,+ "columns": [+ {+ "value": "environment_id",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ },+ {+ "value": "environment_public_key",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ },+ {+ "value": "revoked_at",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ }+ ],+ "isUnique": false,+ "where": null,+ "with": "",+ "method": "btree",+ "concurrently": false,+ "name": "idx_relay_environment_credentials_environment_key",+ "entityType": "indexes",+ "schema": "public",+ "table": "relay_environment_credentials"+ },+ {+ "nameExplicit": true,+ "columns": [+ {+ "value": "environment_id",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ },+ {+ "value": "revoked_at",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ }+ ],+ "isUnique": false,+ "where": null,+ "with": "",+ "method": "btree",+ "concurrently": false,+ "name": "idx_relay_environment_links_environment",+ "entityType": "indexes",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "nameExplicit": true,+ "columns": [+ {+ "value": "activity_push_token",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ }+ ],+ "isUnique": true,+ "where": null,+ "with": "",+ "method": "btree",+ "concurrently": false,+ "name": "idx_relay_live_activities_activity_push_token",+ "entityType": "indexes",+ "schema": "public",+ "table": "relay_live_activities"+ },+ {+ "nameExplicit": true,+ "columns": [+ {+ "value": "hostname",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ }+ ],+ "isUnique": true,+ "where": null,+ "with": "",+ "method": "btree",+ "concurrently": false,+ "name": "idx_relay_managed_endpoint_allocations_hostname",+ "entityType": "indexes",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "nameExplicit": true,+ "columns": [+ {+ "value": "tunnel_name",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ }+ ],+ "isUnique": true,+ "where": null,+ "with": "",+ "method": "btree",+ "concurrently": false,+ "name": "idx_relay_managed_endpoint_allocations_tunnel_name",+ "entityType": "indexes",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "nameExplicit": true,+ "columns": [+ {+ "value": "push_token",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ }+ ],+ "isUnique": true,+ "where": null,+ "with": "",+ "method": "btree",+ "concurrently": false,+ "name": "idx_relay_mobile_devices_push_token",+ "entityType": "indexes",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "nameExplicit": true,+ "columns": [+ {+ "value": "push_to_start_token",+ "isExpression": false,+ "asc": true,+ "nullsFirst": false,+ "opclass": null+ }+ ],+ "isUnique": true,+ "where": null,+ "with": "",+ "method": "btree",+ "concurrently": false,+ "name": "idx_relay_mobile_devices_push_to_start_token",+ "entityType": "indexes",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "columns": ["environment_id", "environment_public_key", "thread_id"],+ "nameExplicit": false,+ "name": "relay_agent_activity_rows_pkey",+ "entityType": "pks",+ "schema": "public",+ "table": "relay_agent_activity_rows"+ },+ {+ "columns": ["thumbprint", "jti"],+ "nameExplicit": false,+ "name": "relay_dpop_proofs_pkey",+ "entityType": "pks",+ "schema": "public",+ "table": "relay_dpop_proofs"+ },+ {+ "columns": ["user_id", "environment_id"],+ "nameExplicit": false,+ "name": "relay_environment_links_pkey",+ "entityType": "pks",+ "schema": "public",+ "table": "relay_environment_links"+ },+ {+ "columns": ["user_id", "device_id"],+ "nameExplicit": false,+ "name": "relay_live_activities_pkey",+ "entityType": "pks",+ "schema": "public",+ "table": "relay_live_activities"+ },+ {+ "columns": ["user_id", "environment_id"],+ "nameExplicit": false,+ "name": "relay_managed_endpoint_allocations_pkey",+ "entityType": "pks",+ "schema": "public",+ "table": "relay_managed_endpoint_allocations"+ },+ {+ "columns": ["user_id", "device_id"],+ "nameExplicit": false,+ "name": "relay_mobile_devices_pkey",+ "entityType": "pks",+ "schema": "public",+ "table": "relay_mobile_devices"+ },+ {+ "columns": ["id"],+ "nameExplicit": false,+ "name": "relay_delivery_attempts_pkey",+ "schema": "public",+ "table": "relay_delivery_attempts",+ "entityType": "pks"+ },+ {+ "columns": ["credential_id"],+ "nameExplicit": false,+ "name": "relay_environment_credentials_pkey",+ "schema": "public",+ "table": "relay_environment_credentials",+ "entityType": "pks"+ },+ {+ "columns": ["user_id"],+ "nameExplicit": false,+ "name": "relay_managed_tunnel_limits_pkey",+ "schema": "public",+ "table": "relay_managed_tunnel_limits",+ "entityType": "pks"+ }+ ],+ "renames": []+}diff --git a/infra/relay/src/environments/EnvironmentConnector.test.ts b/infra/relay/src/environments/EnvironmentConnector.test.tsindex 71e4f1eed34..71170196e94 100644--- a/infra/relay/src/environments/EnvironmentConnector.test.ts+++ b/infra/relay/src/environments/EnvironmentConnector.test.ts@@ -191,6 +191,7 @@ function makeAllocations(origin: { localHttpHost: "127.0.0.1", localHttpPort: 3773 },updatedAt: "2026-05-25T00:00:00.000Z",generation: 1,+ tunnelReleasedAt: null,},): ManagedEndpointAllocations.ManagedEndpointAllocations["Service"] {return {@@ -480,6 +481,7 @@ describe("EnvironmentConnector", () => {origin: null,updatedAt: "2026-05-25T00:00:00.000Z",generation: 1,+ tunnelReleasedAt: null,}),}),),@@ -550,9 +552,40 @@ describe("EnvironmentConnector", () => {error: "Managed endpoint health request failed: Environment is unavailable.",traceId: expect.any(String),});+ expect(result).not.toHaveProperty("offlineReason");}).pipe(Effect.provide(layerConnectorTest(execute)));});+ it.effect("reports a released tunnel as the reason an environment is offline", () => {+ const execute = (request: HttpClientRequest.HttpClientRequest) =>+ Effect.succeed(+ HttpClientResponse.fromWeb(request, new Response("tunnel not found", { status: 530 })),+ );+ const allocations = makeAllocations({+ userId: "user_123",+ environmentId: "env-connector-test",+ hostname: "env.example.test",+ tunnelId: "tunnel-id",+ tunnelName: "tunnel-name",+ dnsRecordId: "dns-record-id",+ readyAt: "2026-05-25T00:00:00.000Z",+ origin: { localHttpHost: "127.0.0.1", localHttpPort: 3773 },+ updatedAt: "2026-05-25T00:00:00.000Z",+ generation: 2,+ tunnelReleasedAt: "2026-05-26T00:00:00.000Z",+ });++ return Effect.gen(function* () {+ const connector = yield* EnvironmentConnector.EnvironmentConnector;+ const result = yield* connector.status({+ userId: "user_123",+ environmentId: "env-connector-test",+ });++ expect(result).toMatchObject({ status: "offline", offlineReason: "tunnel_released" });+ }).pipe(Effect.provide(layerConnectorTest(execute, { allocations })));+ });+it.effect("rejects health responses with a mismatched top-level environment id", () => {const execute = (request: HttpClientRequest.HttpClientRequest) =>Effect.sync(() => {diff --git a/infra/relay/src/environments/EnvironmentConnector.ts b/infra/relay/src/environments/EnvironmentConnector.tsindex f2edf1bc722..9d06b8b074a 100644--- a/infra/relay/src/environments/EnvironmentConnector.ts+++ b/infra/relay/src/environments/EnvironmentConnector.ts@@ -163,6 +163,16 @@ const isEnvironmentHealthError = Schema.is(]),);+/**+ * Cleanup deleted this environment's tunnel and nothing has recorded a new+ * one, so the host is unreachable until it updates and requests recovery.+ */+function offlineReasonFor(+ allocation: ManagedEndpointAllocations.ManagedEndpointAllocation | null,+): { readonly offlineReason?: "tunnel_released" } {+ return allocation?.tunnelReleasedAt ? { offlineReason: "tunnel_released" } : {};+}+function environmentHealthRequestFailureMessage(cause: unknown): string {return isEnvironmentHealthError(cause)? `Managed endpoint health request failed: ${cause.message}`@@ -510,6 +520,7 @@ const make = Effect.gen(function* () {status: "offline" as const,checkedAt,error: "Managed endpoint health request timed out.",+ ...offlineReasonFor(allocation),traceId,};}@@ -532,6 +543,7 @@ const make = Effect.gen(function* () {status: "offline" as const,checkedAt,error: environmentHealthRequestFailureMessage(responseOption.value.cause),+ ...offlineReasonFor(allocation),traceId,};}diff --git a/infra/relay/src/environments/ManagedEndpointAllocations.test.ts b/infra/relay/src/environments/ManagedEndpointAllocations.test.tsindex 105b10cc6a9..f2d00b95c1a 100644--- a/infra/relay/src/environments/ManagedEndpointAllocations.test.ts+++ b/infra/relay/src/environments/ManagedEndpointAllocations.test.ts@@ -19,6 +19,7 @@ describe("ManagedEndpointAllocations", () => {readonly readyAt: unknown;readonly recoveryEnabledAt: unknown;readonly recoveryEnvironmentPublicKey: unknown;+ readonly tunnelReleasedAt: unknown;}| undefined;const fakeDb = {@@ -30,6 +31,7 @@ describe("ManagedEndpointAllocations", () => {readonly readyAt: unknown;readonly recoveryEnabledAt: unknown;readonly recoveryEnvironmentPublicKey: unknown;+ readonly tunnelReleasedAt: unknown;}) => {updated = values;return {@@ -53,6 +55,8 @@ describe("ManagedEndpointAllocations", () => {}),).toBe(8);expect(updated?.tunnelId).toBe("replacement-tunnel");+ // Any recorded tunnel ends a released state, so status stops reporting it.+ expect(updated?.tunnelReleasedAt).toBeNull();const query = new PgDialect().sqlToQuery(updated?.readyAt as never);expect(query.sql).toBe('case when "relay_managed_endpoint_allocations"."tunnel_id" = $1 then "relay_managed_endpoint_allocations"."ready_at" else null end',@@ -250,6 +254,38 @@ describe("ManagedEndpointAllocations", () => {}).pipe(Effect.provide(layerWithDb(fakeDb)));});+ it.effect.each([+ { markReleased: true, released: true },+ { markReleased: undefined, released: false },+ ] as const)(+ "marks the tunnel released only for the claim that deletes it ($markReleased)",+ ({ markReleased, released }) => {+ let updated: Record<string, unknown> | undefined;+ const fakeDb = {+ update: () => ({+ set: (values: Record<string, unknown>) => {+ updated = values;+ return {+ where: () => ({ returning: () => Effect.succeed([{ generation: 4 }]) }),+ };+ },+ }),+ } as unknown as RelayDb.RelayDb["Service"];++ return Effect.gen(function* () {+ const allocations = yield* ManagedEndpointAllocations.ManagedEndpointAllocations;+ yield* allocations.claimRelease({+ userId: "user-1",+ environmentId: "environment-1",+ tunnelId: "tunnel-1",+ generation: 3,+ ...(markReleased === undefined ? {} : { markReleased }),+ });+ expect(typeof updated?.tunnelReleasedAt === "string").toBe(released);+ }).pipe(Effect.provide(layerWithDb(fakeDb)));+ },+ );+it.effect("returns a claim generation only when deprovision wins the allocation CAS", () => {const fakeDb = {update: (table: unknown) => {diff --git a/infra/relay/src/environments/ManagedEndpointAllocations.ts b/infra/relay/src/environments/ManagedEndpointAllocations.tsindex e2d8475a1b2..b4a93836a08 100644--- a/infra/relay/src/environments/ManagedEndpointAllocations.ts+++ b/infra/relay/src/environments/ManagedEndpointAllocations.ts@@ -24,6 +24,8 @@ export interface ManagedEndpointAllocation {readonly origin: RelayManagedEndpointOrigin | null;readonly updatedAt: string;readonly generation: number;+ /** When cleanup deleted the recorded tunnel; null once a tunnel is recorded again. */+ readonly tunnelReleasedAt: string | null;}export interface ManagedEndpointTunnelAllocation extends ManagedEndpointAllocation {@@ -111,6 +113,8 @@ interface MarkManagedEndpointReadyInput extends ManagedEndpointAllocationKey {interface ClaimManagedEndpointReleaseInput extends ManagedEndpointAllocationKey {readonly tunnelId: string;readonly generation: number;+ /** Record that the tunnel is being deleted; set only by the claim that deletes it. */+ readonly markReleased?: boolean;}interface EnableManagedEndpointRecoveryInput extends ManagedEndpointAllocationKey {@@ -202,6 +206,7 @@ const allocationSelection = {origin: relayManagedEndpointAllocations.origin,updatedAt: relayManagedEndpointAllocations.updatedAt,generation: relayManagedEndpointAllocations.generation,+ tunnelReleasedAt: relayManagedEndpointAllocations.tunnelReleasedAt,};const whereAllocation = (input: ManagedEndpointAllocationKey) =>@@ -326,6 +331,7 @@ export const make = Effect.gen(function* () {// again before the reaper may treat it as recoverable.recoveryEnabledAt: sql`case when ${relayManagedEndpointAllocations.tunnelId} = ${input.tunnelId} then ${relayManagedEndpointAllocations.recoveryEnabledAt} else null end`,recoveryEnvironmentPublicKey: sql`case when ${relayManagedEndpointAllocations.tunnelId} = ${input.tunnelId} then ${relayManagedEndpointAllocations.recoveryEnvironmentPublicKey} else null end`,+ tunnelReleasedAt: null,updatedAt: DateTime.formatIso(yield* DateTime.now),generation: sql`${relayManagedEndpointAllocations.generation} + 1`,})@@ -534,11 +540,13 @@ export const make = Effect.gen(function* () {claimRelease: Effect.fn("relay.managed_endpoint_allocations.claim_release")(function* (input: ClaimManagedEndpointReleaseInput,) {+ const now = DateTime.formatIso(yield* DateTime.now);const claimed = yield* db.update(relayManagedEndpointAllocations).set({- updatedAt: DateTime.formatIso(yield* DateTime.now),+ updatedAt: now,generation: sql`${relayManagedEndpointAllocations.generation} + 1`,+ ...(input.markReleased === true ? { tunnelReleasedAt: now } : {}),}).where(and(diff --git a/infra/relay/src/environments/ManagedEndpointProvider.test.ts b/infra/relay/src/environments/ManagedEndpointProvider.test.tsindex af8a7a21ad9..29aaefa7b9d 100644--- a/infra/relay/src/environments/ManagedEndpointProvider.test.ts+++ b/infra/relay/src/environments/ManagedEndpointProvider.test.ts@@ -221,6 +221,7 @@ function makeAllocations(calls: AllocationCall[] = []) {origin: null,updatedAt: `generation-${++generation}`,generation: 0,+ tunnelReleasedAt: null,};allocations.set(allocationKey(input), allocation);return allocation;@@ -968,6 +969,38 @@ describe("ManagedEndpointProvider", () => {"updateRecord",]);expect(allocationCalls.map((call) => call.operation)).not.toContain("remove");+ // An ordinary release, such as a host shutting down, must not tell the+ // user to update: that host gets a new tunnel when it starts again.+ const claims = allocationCalls.filter((call) => call.operation === "claimRelease");+ expect(claims.map((call) => (call.input as { markReleased?: boolean }).markReleased)).toEqual(+ [undefined, undefined],+ );+ }).pipe(Effect.provide(layer));+ });++ it.effect("marks the release on the claim that deletes the tunnel when asked", () => {+ const allocationCalls: AllocationCall[] = [];+ const layer = layerProvider(+ makePersistentTunnelClient(),+ makeDnsClient(),+ makeAllocations(allocationCalls),+ );++ return Effect.gen(function* () {+ const provider = yield* ManagedEndpointProvider.ManagedEndpointProvider;+ const key = { userId: "user_ABC", environmentId: "env_ABC" } as const;+ yield* provider.provision({+ ...key,+ origin: { localHttpHost: "127.0.0.1", localHttpPort: 3773 },+ });+ expect(yield* provider.release({ ...key, markReleased: true })).toBe(true);++ // The first claim only reserves the release; the second, taken with the+ // row locked right before the delete, is the one that records it.+ const claims = allocationCalls.filter((call) => call.operation === "claimRelease");+ expect(claims.map((call) => (call.input as { markReleased?: boolean }).markReleased)).toEqual(+ [undefined, true],+ );}).pipe(Effect.provide(layer));});@@ -1502,6 +1535,53 @@ describe("ManagedEndpointProvider", () => {}).pipe(Effect.provide(layer));});+ it.effect.each([+ { name: "the tunnel is gone", tunnelRemoved: true, released: true },+ { name: "the tunnel still exists", tunnelRemoved: false, released: false },+ ] as const)(+ "resolves a delete whose response was lost by checking whether $name",+ ({ tunnelRemoved, released }) => {+ const persistent = makePersistentTunnelClient();+ const lostResponse = new ManagedEndpointProvider.ManagedEndpointTunnelClientError({+ operation: "delete",+ tunnelId: "tunnel-id",+ cause: { _tag: "TimeoutError" },+ });+ // Cloudflare may or may not have applied the delete before the+ // response was lost; the client only sees the timeout.+ const tunnelClient = ManagedEndpointProvider.ManagedEndpointTunnelClient.of({+ ...persistent,+ delete: (tunnelId) =>+ (tunnelRemoved ? persistent.delete(tunnelId) : Effect.void).pipe(+ Effect.andThen(Effect.fail(lostResponse)),+ ),+ });+ const allocationCalls: AllocationCall[] = [];+ const layer = layerProvider(tunnelClient, makeDnsClient(), makeAllocations(allocationCalls));++ return Effect.gen(function* () {+ const provider = yield* ManagedEndpointProvider.ManagedEndpointProvider;+ const key = { userId: "user_ABC", environmentId: "env_ABC" } as const;+ yield* provider.provision({+ ...key,+ origin: { localHttpHost: "127.0.0.1", localHttpPort: 3773 },+ });+ const result = yield* Effect.result(provider.release({ ...key, markReleased: true }));++ if (released) {+ // Succeeding commits the marked claim, so status can explain it.+ expect(result).toMatchObject({ _tag: "Success", success: true });+ } else {+ // Failing rolls the claim back; the tunnel is still there to retry.+ expect(result).toMatchObject({+ _tag: "Failure",+ failure: { stage: "delete-tunnel", cause: lostResponse },+ });+ }+ }).pipe(Effect.provide(layer));+ },+ );+it.effect("surfaces non-not-found tunnel deletion failures when releasing", () => {const failure = new ManagedEndpointProvider.ManagedEndpointTunnelClientError({operation: "delete",diff --git a/infra/relay/src/environments/ManagedEndpointProvider.ts b/infra/relay/src/environments/ManagedEndpointProvider.tsindex 2192b47e1fd..aba8b426ab5 100644--- a/infra/relay/src/environments/ManagedEndpointProvider.ts+++ b/infra/relay/src/environments/ManagedEndpointProvider.ts@@ -193,6 +193,11 @@ export class ManagedEndpointProvider extends Context.Service<readonly expectedTunnelId?: string;readonly expectedInactiveBefore?: string;readonly expectedStatus?: "inactive" | "down";+ /**+ * Record that cleanup removed a legacy host's tunnel, so status tells the+ * user to update. Other releases leave hosts that recover on their own.+ */+ readonly markReleased?: boolean;}) => Effect.Effect<boolean, ManagedEndpointDeprovisioningFailed>;}>()("t3code-relay/environments/ManagedEndpointProvider") {}@@ -808,6 +813,19 @@ export const make = Effect.gen(function* () {if (claimedGeneration === null) {return false;}+ // After a failed delete: succeed if the tunnel is gone, since the delete+ // then took effect and only its response was lost; otherwise keep the+ // delete's error.+ const confirmTunnelGone = (+ failure: ManagedEndpointDeprovisioningFailed,+ ): Effect.Effect<void, ManagedEndpointDeprovisioningFailed> =>+ tunnels.get(tunnelId).pipe(+ Effect.andThen(Effect.fail(failure)),+ Effect.catchTags({+ ManagedEndpointTunnelClientError: (lookupFailure) =>+ isManagedEndpointNotFound(lookupFailure.cause) ? Effect.void : Effect.fail(failure),+ }),+ );const deleteTunnel = ignoreNotFound(tunnels.delete(tunnelId)).pipe(Effect.mapError((cause) =>@@ -877,6 +895,7 @@ export const make = Effect.gen(function* () {environmentId: input.environmentId,tunnelId,generation: claimedGeneration,+ ...(input.markReleased === true ? { markReleased: true } : {}),}).pipe(Effect.mapError(@@ -895,12 +914,21 @@ export const make = Effect.gen(function* () {// A connector still attached means the tunnel is not released. That// is the same answer as losing the claim: the caller keeps its config,// and the reaper deletes the tunnel once it has been down long enough.+ // A delete whose response is lost (a timeout) may still have+ // removed the tunnel. Ask Cloudflare before rolling back: if the+ // tunnel is gone, the delete happened and the claim, including any+ // released marker, must commit, since no later sweep can find+ // this tunnel again to retry.return yield* deleteTunnel.pipe(Effect.as(true),Effect.catchIf((error) => isManagedEndpointTunnelInUse(error.cause),() => Effect.succeed(false),),+ Effect.catchTags({+ ManagedEndpointDeprovisioningFailed: (failure) =>+ confirmTunnelGone(failure).pipe(Effect.as(true)),+ }),);}),)diff --git a/infra/relay/src/environments/ManagedEndpointReaper.test.ts b/infra/relay/src/environments/ManagedEndpointReaper.test.tsindex c71811a553d..4e4c6996d9f 100644--- a/infra/relay/src/environments/ManagedEndpointReaper.test.ts+++ b/infra/relay/src/environments/ManagedEndpointReaper.test.ts@@ -55,6 +55,7 @@ function allocation(input: {origin: { localHttpHost: "127.0.0.1", localHttpPort: 3773 },updatedAt: "2026-08-25T11:00:00.000Z",generation: 1,+ tunnelReleasedAt: null,recoveryEnabled: input.recoveryEnabled,};}@@ -296,6 +297,8 @@ describe("ManagedEndpointReaper", () => {failed: 0,});expect(state.deleted).toEqual(["down-1", "inactive-1"]);+ // A host that registered recovery gets a new tunnel on its own.+ expect(state.releases.some((release) => release.markReleased === true)).toBe(false);expect(state.releases.map((request) => request.expectedTunnelId)).toEqual(["down-1","inactive-1",@@ -582,6 +585,8 @@ describe("ManagedEndpointReaper", () => {deleted: 2,});expect([...state.deleted].sort()).toEqual(["legacy-never", "legacy-old"]);+ // A legacy host needs an update to recover, so its user is told why.+ expect(state.releases.every((release) => release.markReleased === true)).toBe(true);// The release re-checks each tunnel against the 7-day cutoff, not// the 5-minute cutoff used for recoverable tunnels.for (const release of state.releases) {diff --git a/infra/relay/src/environments/ManagedEndpointReaper.ts b/infra/relay/src/environments/ManagedEndpointReaper.tsindex f1c9ccc84e7..eea1f98145d 100644--- a/infra/relay/src/environments/ManagedEndpointReaper.ts+++ b/infra/relay/src/environments/ManagedEndpointReaper.ts@@ -386,6 +386,8 @@ export const make = Effect.gen(function* () {expectedTunnelId: candidate.tunnel.id,expectedInactiveBefore: candidate.inactiveBefore,expectedStatus: candidate.status,+ // Only a legacy host needs an update to recover; tell its user so.+ ...(candidate.legacy ? { markReleased: true } : {}),}).pipe(Effect.result);if (result._tag === "Failure") {diff --git a/infra/relay/src/hooks/HeldHooks.test.ts b/infra/relay/src/hooks/HeldHooks.test.tsindex 02e5c2c240e..8ad291c269c 100644--- a/infra/relay/src/hooks/HeldHooks.test.ts+++ b/infra/relay/src/hooks/HeldHooks.test.ts@@ -31,6 +31,7 @@ const allocationFor = (tunnelName: `t3coderelay-managedendpoint-dev-${key}`,dnsRecordId: "dns-record-id",readyAt: ready ? "2026-05-25T00:00:00.000Z" : null,+ tunnelReleasedAt: null,origin: { localHttpHost: "127.0.0.1", localHttpPort: 3773 },updatedAt: "2026-05-25T00:00:00.000Z",generation: 1,diff --git a/infra/relay/src/hooks/HookForwarder.test.ts b/infra/relay/src/hooks/HookForwarder.test.tsindex 427a73275af..b00b4f9d750 100644--- a/infra/relay/src/hooks/HookForwarder.test.ts+++ b/infra/relay/src/hooks/HookForwarder.test.ts@@ -66,6 +66,7 @@ const readyAllocation: ManagedEndpointAllocations.ManagedEndpointAllocation = {tunnelName: `t3coderelay-managedendpoint-dev-${endpointKey}`,dnsRecordId: "dns-record-id",readyAt: "2026-05-25T00:00:00.000Z",+ tunnelReleasedAt: null,origin: { localHttpHost: "127.0.0.1", localHttpPort: 3773 },updatedAt: "2026-05-25T00:00:00.000Z",generation: 1,diff --git a/infra/relay/src/http/Api.test.ts b/infra/relay/src/http/Api.test.tsindex b49bc09cefe..b0e047bd829 100644--- a/infra/relay/src/http/Api.test.ts+++ b/infra/relay/src/http/Api.test.ts@@ -822,6 +822,7 @@ describe("relay managed tunnel recovery", () => {origin: { localHttpHost: "127.0.0.1", localHttpPort: 3773 },updatedAt: "replacement-generation",generation: 3,+ tunnelReleasedAt: null,} satisfies ManagedEndpointProvider.ManagedEndpointDeprovisionTarget;return Effect.gen(function* () {@@ -924,6 +925,7 @@ describe("relay environment unlink", () => {tunnelName: `t3coderelay-managedendpoint-dev-${endpointKey}`,dnsRecordId: "dns-1",readyAt: "2026-07-28T00:00:00.000Z",+ tunnelReleasedAt: null,origin: null,updatedAt: "2026-07-28T00:00:00.000Z",generation: 1,@@ -962,6 +964,7 @@ describe("relay environment unlink", () => {origin: { localHttpHost: "127.0.0.1", localHttpPort: 3773 },updatedAt: "generation-before-unlink",generation: 1,+ tunnelReleasedAt: null,} satisfies ManagedEndpointProvider.ManagedEndpointDeprovisionTarget;return Effect.gen(function* () {@@ -1108,6 +1111,7 @@ describe("relay environment unlink", () => {origin: { localHttpHost: "127.0.0.1", localHttpPort: 3773 },updatedAt: "original-generation",generation: 1,+ tunnelReleasedAt: null,} satisfies ManagedEndpointProvider.ManagedEndpointDeprovisionTarget;return Effect.gen(function* () {diff --git a/infra/relay/src/persistence/schema.ts b/infra/relay/src/persistence/schema.tsindex e24bb1a5c4c..eb6357bfa5d 100644--- a/infra/relay/src/persistence/schema.ts+++ b/infra/relay/src/persistence/schema.ts@@ -99,6 +99,8 @@ export const relayManagedEndpointAllocations = pgTable(readyAt: varchar("ready_at", { length: 64 }),recoveryEnabledAt: varchar("recovery_enabled_at", { length: 64 }),recoveryEnvironmentPublicKey: text("recovery_environment_public_key"),+ // Set when cleanup deletes the recorded tunnel; cleared when a tunnel is recorded again.+ tunnelReleasedAt: varchar("tunnel_released_at", { length: 64 }),origin: jsonb("origin").$type<RelayManagedEndpointOrigin>(),generation: integer("generation").notNull().default(0),createdAt: varchar("created_at", { length: 64 }).notNull(),diff --git a/packages/client-runtime/src/relay/errorPresentation.ts b/packages/client-runtime/src/relay/errorPresentation.tsindex b9a53e5ce8b..1e578cf4534 100644--- a/packages/client-runtime/src/relay/errorPresentation.ts+++ b/packages/client-runtime/src/relay/errorPresentation.ts@@ -1,5 +1,5 @@import type { DpopFailureReason } from "@t3tools/contracts";-import type { RelayProtectedError } from "@t3tools/contracts/relay";+import type { RelayEnvironmentStatusResponse, RelayProtectedError } from "@t3tools/contracts/relay";export const DPOP_CLOCK_HINT ="Hint: Check that automatic date and time is enabled on both devices, then try again.";@@ -64,3 +64,21 @@ export function relayProtectedErrorMessage(error: RelayProtectedError): string {return `Relay encountered an internal error (${error.reason}).`;}}++// A host with a current build gets a new tunnel on its own within minutes of+// coming back, which clears this reason. While it is still reported, the host+// is either still off or running a build too old to do that.+export const RELAY_TUNNEL_RELEASED_MESSAGE =+ "Offline for a while, so its T3 Connect tunnel was removed. Start T3 Code on that computer and update it to the latest version to reconnect.";++/** User-facing text for an offline status, or null when the relay gave no known reason. */+export function relayOfflineReasonMessage(+ status: Pick<RelayEnvironmentStatusResponse, "offlineReason">,+): string | null {+ switch (status.offlineReason) {+ case "tunnel_released":+ return RELAY_TUNNEL_RELEASED_MESSAGE;+ case undefined:+ return null;+ }+}diff --git a/packages/contracts/src/relay.ts b/packages/contracts/src/relay.tsindex f5cb83b4f8d..916893c54fb 100644--- a/packages/contracts/src/relay.ts+++ b/packages/contracts/src/relay.ts@@ -823,6 +823,14 @@ export type RelayEnvironmentConnectResponse = typeof RelayEnvironmentConnectRespexport const RelayEnvironmentStatusValue = Schema.Literals(["online", "offline"]);export type RelayEnvironmentStatusValue = typeof RelayEnvironmentStatusValue.Type;+/**+ * Why an environment is offline, when the relay knows more than "the host+ * did not answer". `tunnel_released`: the relay deleted the environment's+ * idle tunnel, and the host needs a current T3 Code build to get a new one.+ */+const RelayEnvironmentOfflineReason = Schema.Literals(["tunnel_released"]);+type RelayEnvironmentOfflineReason = typeof RelayEnvironmentOfflineReason.Type;+export const RelayEnvironmentStatusResponse = Schema.Struct({environmentId: EnvironmentId,endpoint: RelayManagedEndpoint,@@ -830,6 +838,7 @@ export const RelayEnvironmentStatusResponse = Schema.Struct({checkedAt: TrimmedNonEmptyString,descriptor: Schema.optional(ExecutionEnvironmentDescriptor),error: Schema.optional(TrimmedNonEmptyString),+ offlineReason: Schema.optional(RelayEnvironmentOfflineReason),traceId: Schema.optional(TrimmedNonEmptyString),});export type RelayEnvironmentStatusResponse = typeof RelayEnvironmentStatusResponse.Type;