Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): surface Tailscale Serve failures and fix AppImage restarts on Linux #4698

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

Two Linux desktop problems, both of which end with the user staring at an app that silently did nothing.

Closes #2830 — that report is this exact pair of symptoms: enabling Tailscale HTTPS either hangs or restarts the app "with seemingly no effect", with "no visible errors" while tailscale serve --bg --https=… was failing underneath with "Serve is not enabled on your tailnet."

Supersedes #4552 (closed draft); that branch's head is many commits behind this one.

1. Enabling Tailscale HTTPS failed silently

tailscale serve was configured by the child backend on boot. If the tailnet refused — Serve not enabled, no HTTPS certs, CLI missing — the failure landed in a log line the user never sees. The app restarted and the toggle simply stayed off.

Enabling now preflights tailscale serve in the main process before persisting, so it can fail loudly with the CLI's own guidance and the login.tailscale.com/f/serve admin link. The failure surfaces three ways: a toast, an inline alert inside the setup dialog (which stays open so you can retry), and a status line on the row. The setup URL is shown in full and is selectable, with an Open setup button as a shortcut.

Related fixes in the same area:

  • Disable now tears Serve down from the main process. It previously relied on the child server's acquireRelease finalizer, which only exists if that child booted with Serve enabled. After a failed relaunch it doesn't, so toggling off persisted enabled: false while tailscale serve --https=<port> stayed live on the tailnet. A teardown that fails now refuses to record itself as done, and says the backend may still be reachable.
  • The switch reflects the persisted setting, not endpoint reachability. status comes from an HTTP probe of the MagicDNS URL, so a cert still provisioning or a brief tailnet blip rendered the switch off while Serve was live — and since disabling sits behind the on state, there was no way to turn it off.
  • The toggle renders without LAN network access. Serve only proxies to loopback, so it never depended on network-accessible mode; it was hidden anyway. MagicDNS is still resolved only on explicit opt-in, preserving the #2745 macOS TCC gate.
  • Failed CLI spawns report "Could not run the tailscale CLI. Is Tailscale installed and on PATH?" instead of a generic port message — the most common failure, previously the least explained.
  • A persistence failure no longer tears down a pre-existing working binding, and the MagicDNS cache is invalidated on user-initiated resolve so "start Tailscale and try again" isn't defeated by a 60s stale miss.

2. AppImage restarts never came back

app.relaunch() re-execs process.execPath, which under AppImage points inside the FUSE mount that is unmounted as the process exits — so the restart died with "Cannot mount AppImage, please check your FUSE setup."

The AppImage path now schedules a detached, delayed re-exec of $APPIMAGE after the current process exits, anchored at cwd: / so it isn't holding the mount. The spawn is awaited, so a failure is logged instead of falling through to exit(0) and vanishing. The single-instance lock is released only once the relaunch is committed, so a failure leaves the app running with the lock rather than letting the next launch open a second instance.

Testing

Unit tests cover the new behavior: eager teardown asserts the exact serve --https=<port> off invocation, a failed teardown keeps enabled: true and carries the exposure warning, the missing-binary case produces the PATH hint, and the relaunch helper resolves only after a real spawn.

Verified end-to-end by driving the built desktop app against a live tailnet:

  • Tailscale absent from PATH → toast, toggle stays off.
  • Tailnet refuses Serve → dialog stays open with the inline alert, full URL, and Open setup; error anchored to the Tailscale HTTPS row.
  • Happy path → enable put https://<magicdns> → proxy http://127.0.0.1:<port> in tailscale serve status, the endpoint returned 200, the app relaunched and came back with the toggle on; disable returned No serve config with the endpoint unreachable and the toggle off.
  • openExternal confirmed to resolve true/false rather than reject, which is why the old .catch() fallback was dead code.

On a real AppImage

Built with dist:desktop:linux and run from the packaged artifact (genuine FUSE mount), across two relaunch cycles:

  • Each relaunch logged kind: appimage-delayed re-execing $APPIMAGE, and the app came back every time with zero "Cannot mount AppImage" errors.
  • Serve re-bound to the relaunched instance's new backend port on enable, and returned No serve config on disable.

This surfaced one more bug, fixed here: the restart worked, but every cycle stranded the previous mount, with its runtime process parked in fuse_dev_do_read forever. Chromium keeps fds open without CLOEXEC and spawn cannot close them, so the detached helper carried nine of them — app.asar, icudtl.dat, the .pak files, the mount directory — into the new process tree, pinning a mount nothing needed. The helper now closes every fd above 2 before sleeping. After the fix: one mount and one runtime process across both cycles.


🤖 Generated with Claude Code

https://claude.ai/code/session_015ajcLHZtGhRQRD6BwscU9R


Note

High Risk Changes Tailscale Serve enable/disable, persistence rollback, and main-process network exposure in security-sensitive paths, plus process exit/relaunch and single-instance locking on Linux AppImage.

Overview Tailscale HTTPS no longer fails quietly: enabling preflights tailscale serve in the main process before settings are saved, surfaces DesktopTailscaleServeConfigureError with safe CLI-derived text and an optional admin setup URL (toast, dialog alert, row status), and disables Serve from the main process so a failed child relaunch cannot leave the tailnet exposed while settings say off. Rollback on failed persistence/interrupt, resolveTailscaleHttpsEndpoint for on-demand MagicDNS (new IPC), toggle driven by persisted tailscaleServeEnabled (not HTTP probe), Serve independent of LAN network access, and isShareableOrigin so custom-scheme desktop origins are not offered as pairing links.

Linux AppImage relaunch avoids FUSE mount races via a delayed detached re-exec of $APPIMAGE (bash closes inherited fds when available), awaits helper spawn before exit, and releases the single-instance lock on success or relaunch failure.

@t3tools/tailscale adds stderr diagnostics (serve-not-enabled, no-https-certs), sanitized configure URL extraction, and formatTailscaleServeUserMessage.

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

Note

Surface Tailscale Serve failures with actionable errors and fix AppImage restarts on Linux

  • When enabling/disabling Tailscale Serve fails, a structured DesktopTailscaleServeConfigureError is returned with a sanitized user-facing message, optional Tailscale admin configureUrl, and the original CLI error — replacing silent failures.
  • The Connections settings UI displays inline Tailscale Serve errors with an optional 'Open setup' button that safely opens the Tailscale admin page; the Serve toggle now reflects the persisted tailscaleServeEnabled state and shows a spinner during updates.
  • Enabling Serve runs a CLI preflight before persisting settings; on persistence failure, the tailnet binding is rolled back; on successful enable, requiresRelaunch is set to force child process rebind.
  • AppImage relaunch on Linux now spawns a detached shell helper with a delay to avoid FUSE unmount races, and explicitly releases the single-instance lock before exit.
  • Adds a new resolveTailscaleHttpsEndpoint IPC method and desktop bridge call so the renderer can trigger an on-demand MagicDNS resolve for Tailscale HTTPS setup.
  • Behavioral Change: setTailscaleServeEnabled now actively calls tailscale serve ... off when disabling (instead of relying only on child process finalizers), and re-enabling always sets requiresRelaunch=true.
Macroscope summarized 7e0e879.
    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: 6ca354f7-9c93-4661-a832-6f5a28948133

      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. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      1 blocking correctness issue found. This PR introduces significant new runtime behavior including Linux AppImage relaunch logic, Tailscale Serve error handling with preflight/rollback, and new IPC methods. An unresolved high-severity comment identifies a potential network exposure issue when relaunch fails after persistence succeeds. These changes warrant careful human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Pushed 529d2a6e9 (review fixes) and fdaa00855 (merge with main). All four inline findings are addressed and replied to individually; conflicts resolved and the PR is mergeable again.

      On the Bugbot dash finding — it was right and my reasoning was wrong, so calling it out rather than burying it in a thread. I had claimed eval made the multi-digit exec N>&- parse-safe. It is not a parse error: dash reads 10 as a command name, and a failed exec terminates a non-interactive shell before || true is ever evaluated. On Debian/Ubuntu the helper would have died before the re-exec, after the parent released the single-instance lock and exited — the app gone for good, which is the exact bug this PR exists to fix. Reproduced in debian:stable-slim with an inherited multi-digit fd (dash cannot even open one itself, so it has to come from the parent):

      shaperesult
      with fd cleanupexit=127, relaunch never reached
      withoutREACHED_RELAUNCH, exit=0

      The cleanup is now emitted only when the helper runs under bash.

      On the merge — worth flagging because it was not mechanical. #4556 replaced detail/configureUrl on TailscaleCommandExitError with a closed stderrDiagnostic label set, since stderr can carry auth keys and the field is logged. This PR needs to name a Serve failure and link the admin page, so instead of picking a side I extended the label set with serve-not-enabled and no-https-certs, added describeTailscaleStderrDiagnostic for prose at the UI edge, and kept the shared message generic — #4556's test asserting that still passes unchanged. configureUrl is back as a separate field, exempt from the label-only rule because it is pattern-matched and validated to https://login.tailscale.com/f/serve... rather than lifted from stderr. Happy to revisit if you would rather the URL travel some other way.

      Not mine, but visible on this branch: DesktopObservability and DesktopBackendManager tests fail, and packages/shared/httpReadiness.ts plus scripts/lib/dev-share.test.ts have typecheck errors. All are in main's own files — reverting main's OtlpExporter.layerFlusher line locally makes DesktopBackendManager pass again. I left them alone rather than widen this diff.

    5. @@ -494,0 +619,21 @@
      619+ const exitDetail =
      620+ cause._tag === "TailscaleCommandExitError"
      621+ ? describeTailscaleServeExitCause(cause)
      622+ : formatTailscaleServeUserMessage(cause);
      623+ const configureUrl =
      624+ cause._tag === "TailscaleCommandExitError" ? (cause.configureUrl ?? null) : null;
      625+ return new DesktopTailscaleServeConfigureError({
      626+ enabled: true,
      627+ port: servePort,
      628+ localPort,
      629+ ...(exitDetail === undefined ? {} : { detail: exitDetail }),
      630+ configureUrl,
      631+ cause,
      632+ });
      633+ }),
      634+ );
      635+ // Only roll back a binding this preflight actually created. When Serve
      636+ // was already enabled on the same port, `tailscale serve --bg` is a
      637+ // no-op and disabling it on a persistence failure would tear down a
      638+ // working HTTPS endpoint that settings still record as enabled.
      639+ preflightedServePort =
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High backend/DesktopServerExposure.ts:639

      When the user toggles Tailscale Serve enable and specifies a new servePort, ensureTailscaleServe creates a binding on the new port in the preflight, but the preflighted port is only recorded for rollback when a persistence failure occurs. If persistence succeeds but the subsequent lifecycle.relaunch fails (a scenario this code explicitly handles on the disable path), the new-port binding remains live on the tailnet with no child finalizer to remove it — the still-running child only cleans up the old port on shutdown. Consider tracking the preflighted binding through the relaunch step so it is torn down when relaunch fails, or transferring ownership of the new binding without relying solely on a successful relaunch.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/desktop/src/backend/DesktopServerExposure.ts around line 639:
      
      When the user toggles Tailscale Serve enable and specifies a new `servePort`, `ensureTailscaleServe` creates a binding on the new port in the preflight, but the preflighted port is only recorded for rollback when a *persistence failure* occurs. If persistence succeeds but the subsequent `lifecycle.relaunch` fails (a scenario this code explicitly handles on the disable path), the new-port binding remains live on the tailnet with no child finalizer to remove it — the still-running child only cleans up the old port on shutdown. Consider tracking the preflighted binding through the relaunch step so it is torn down when relaunch fails, or transferring ownership of the new binding without relying solely on a successful relaunch.

      I don't think this one is a defect — pushing back rather than changing it, but happy to be shown wrong.

      The scenario is: enable with a new servePort, preflight binds it, persistence succeeds, then lifecycle.relaunch fails. Two things make the outcome consistent rather than leaked:

      1. The new-port binding matches persisted settings. After a successful write, settings say enabled: true, port: <new> and stateRef is updated to result.settings.tailscaleServePort (DesktopServerExposure.ts:738-742). A live binding on that port is the state the user asked for. That is also why the rollback is deliberately scoped to persistence failure: once the write lands, tearing the binding down would be undoing the user's request. The invariant this PR is defending is "settings and the tailnet agree", and here they do.

      2. The old-port binding is removed by the child that created it. The finalizer disables configured.servePort — the port that child bound at boot (apps/server/src/server.ts:450) — so the stale binding goes away whenever that child stops, including on the exit path a failed relaunch now takes (689814ae3).

      A later disable also targets the right port, since stateRef carries the new one, so the binding never becomes unreachable to the user.

      The one edge I'll concede: if the relaunch fails, the app exits and the new-port binding stays live pointing at a backend that is no longer running. That is a refused connection rather than an exposure, and the next launch re-binds it from the same persisted settings — so I don't think it warrants tracking the binding through the relaunch step. If you'd rather it be torn down in that window anyway, say so and I'll add it; it would mean treating a successful persist as provisional until the relaunch lands, which is a bigger design change than I want to make unilaterally.

      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    6. One Effect convention issue found: a newly introduced Effect.catchTag in the Tailscale Serve teardown path. Per the check conventions, statically-known tagged failures should be caught with Effect.catchTags({ ... }) (even for a single tag).

      Posted via Macroscope — Effect Service Conventions
    7. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      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 4a9c9e4d0ff212009d482cd4a55cdf0914b06789. Configure [here](https://www.cursor.com/dashboard/bugbot).
    8. Closing in favour of two focused PRs, per CONTRIBUTING's "do not mix unrelated fixes together" and the size guidance:

      • #4918 — AppImage restarts on Linux (10 files, 445 lines)
      • #4919 — Tailscale Serve failures surfacing to the user (17 files, 1453 lines), closes #2830

      They share no code, so either can be reviewed and merged independently. Every line of this PR is accounted for in one of the two (445 + 1453 = 1898), and both were verified to typecheck, lint, and pass tests standalone against current main.

      Thanks to @cursor and @macroscopeapp — the findings raised here are all carried into the split branches.

Sign in to join this conversation.