Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): surface Tailscale Serve setup failures with admin link #4552

ClosedGenKerensky(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/4552/headopened View on GitHub

Summary

  • Preflight tailscale serve when enabling Tailscale HTTPS in the desktop app, so setup failures fail the Enable action instead of silently restarting with an unchecked toggle.
  • Extract safe CLI diagnostics (including the login.tailscale.com/f/serve configure URL) without leaking raw stderr secrets.
  • Show an error toast with the CLI-style message and an Open setup action that opens the admin URL.

Problem

Enable persisted tailscaleServeEnabled: true and relaunched the app, but the child server swallowed tailscale serve failures as warnings. The UI toggle is driven by HTTPS probe success, so it stayed off with no user-visible error. Locally this was:

Serve is not enabled on your tailnet.
To enable, visit:
  https://login.tailscale.com/f/serve?node=...

Test plan

  • vp run --filter @t3tools/tailscale test
  • DesktopServerExposure unit tests (including Serve-not-enabled preflight failure)
  • typecheck for tailscale, desktop, server, web
  • Manual: with Serve disabled on the tailnet, open Settings → Connections → Tailscale HTTPS → Enable → confirm toast shows the error text and Open setup opens the Tailscale admin URL
  • Manual: after enabling Serve in the admin console, Enable succeeds, app relaunches, toggle becomes checked when HTTPS is reachable

Note

  • When setTailscaleServeEnabled fails, a new DesktopTailscaleServeConfigureError is thrown with a user-readable reason and optional configureUrl extracted from sanitized CLI output (never raw stderr).
  • The failure toast in ConnectionsSettings.tsx now includes an action button to open the Tailscale Admin Serve URL in the browser when one is present in the error.
  • New utilities in tailscale.ts (extractTailscaleServeDiagnostics, formatTailscaleServeUserMessage, extractTailscaleServeConfigureUrl) parse and sanitize CLI errors into structured diagnostics and human-readable messages.
  • Behavioral Change: setTailscaleServeEnabled now performs a preflight ensureTailscaleServe check before persisting settings, and always returns requiresRelaunch=true on successful enable even when settings are unchanged.
📊 Macroscope summarized 4a0919b. 4 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted

🗂️ Filtered Issues

No issues evaluated.

    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: 1a257345-0db8-431f-be14-35b9b825b7d1

      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
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

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

    3. The Effect Service Conventions check found one issue in the new DesktopTailscaleServeConfigureError. Details inline.

      Posted via Macroscope — Effect Service Conventions
    4. The Effect Service Conventions check found one issue in the new DesktopTailscaleServeConfigureError. Details inline.

      Posted via Macroscope — Effect Service Conventions
    5. @@ -495 +574,21 @@
      574+ Effect.mapError((cause) => {
      575+ // Lift only safe structural diagnostics from the CLI error; keep the
      576+ // full TailscaleCommandError as cause for the error chain/stack.
      577+ const exitDetail =
      578+ cause._tag === "TailscaleCommandExitError" ? cause.detail : undefined;
      579+ const configureUrl =
      580+ cause._tag === "TailscaleCommandExitError" ? (cause.configureUrl ?? null) : null;
      581+ return new DesktopTailscaleServeConfigureError({
      582+ enabled: true,
      583+ port: servePort,
      584+ localPort,
      585+ ...(exitDetail === undefined ? {} : { detail: exitDetail }),
      586+ configureUrl,
      587+ cause,
      588+ });
      589+ }),
      590+ );
      591+ preflightedServePort = servePort;
      592+ }
      593+
      495594 const result = yield* desktopSettings
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High backend/DesktopServerExposure.ts:594

      When enabling Tailscale Serve, the rollback uses Effect.tapError, which only fires on typed errors. If desktopSettings.setTailscaleServe is interrupted or throws a defect after ensureTailscaleServe has already opened the HTTPS mapping, the rollback to disableTailscaleServe never runs — leaving Serve active while the UI and settings still show it as disabled. Consider using Effect.ensuring or an acquire-release pattern so the cleanup executes on all non-success exits, not just typed persistence errors.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/desktop/src/backend/DesktopServerExposure.ts around line 594:
      
      When enabling Tailscale Serve, the rollback uses `Effect.tapError`, which only fires on typed errors. If `desktopSettings.setTailscaleServe` is interrupted or throws a defect after `ensureTailscaleServe` has already opened the HTTPS mapping, the rollback to `disableTailscaleServe` never runs — leaving Serve active while the UI and settings still show it as disabled. Consider using `Effect.ensuring` or an acquire-release pattern so the cleanup executes on all non-success exits, not just typed persistence errors.
    6. @@ -0,0 +3,21 @@
      3+ readonly args: string[];
      4+}
      5+
      6+/**
      7+ * Resolve Electron relaunch options for the current packaging mode.
      8+ *
      9+ * AppImage mounts the payload under a temporary directory and sets `APPIMAGE`
      10+ * to the outer `.AppImage` path. `process.execPath` / `process.argv` point at
      11+ * the mount, which is unmounted when the process exits — so relaunching with
      12+ * those paths exits and never comes back. Prefer `$APPIMAGE` with empty args.
      13+ */
      14+export function resolveDesktopRelaunchOptions(input: {
      15+ readonly appImagePath?: string | null | undefined;
      16+ readonly execPath: string;
      17+ readonly argv: readonly string[];
      18+}): DesktopRelaunchOptions {
      19+ const appImagePath = input.appImagePath?.trim();
      20+ if (appImagePath) {
      21+ return {
      22+ execPath: appImagePath,
      23+ args: [],
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium app/resolveDesktopRelaunchOptions.ts:23

      The AppImage branch returns args: [], dropping all command-line arguments. When the app is launched with a meaningful argument (e.g. a file path or runtime switch) and then relaunches, the relaunched instance starts with no arguments and skips the requested startup behavior. The fix is to preserve argv.slice(1) in both branches, since switching execPath to $APPIMAGE doesn't require discarding args.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/desktop/src/app/resolveDesktopRelaunchOptions.ts around line 23:
      
      The AppImage branch returns `args: []`, dropping all command-line arguments. When the app is launched with a meaningful argument (e.g. a file path or runtime switch) and then relaunches, the relaunched instance starts with no arguments and skips the requested startup behavior. The fix is to preserve `argv.slice(1)` in both branches, since switching `execPath` to `$APPIMAGE` doesn't require discarding args.

Sign in to join this conversation.