feat(desktop): attach to a running local backend - #8115
feat(desktop): attach to a running local backend#8115Pedro-Revez-Silva wants to merge 6 commits into
Conversation
Detect an already-running T3 Code server on this machine and connect the desktop app to it instead of spawning a second environment. The behavior is on by default and can be toggled in Settings → Connections.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
There was a problem hiding this comment.
Reviewed the new attach-to-running-backend Effect code against the service conventions. Three violations in the changed scope: a wrapped failure that loses its cause and rebuilds its message from cause.message, and two Effect.catchTag uses that should be Effect.catchTags. Dependency passing (fileSystem/path/httpClient in input objects) matches the established pattern in this package, so it is not flagged.
Posted via Macroscope — Effect Service Conventions
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff0be38fb6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ff0be38. Configure here.
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — The PR introduces a default-on local-backend attachment workflow spanning Desktop startup, server authentication grants, bearer-session handling, IPC/contracts, recovery, and the Connections UI. Its cross-cutting runtime and security-sensitive behavior requires human review. You can add or adjust custom eligibility rules. Learn more. |
There was a problem hiding this comment.
UI Consistency: 1 issue found
One concrete regression in the changed Connections settings scope: a failed attachment-state IPC call silently removes existing desktop backend controls instead of degrading to a visible, recoverable state.
Everything else in scope looks consistent — the new row uses the shared SettingsRow + Switch primitives with an aria-label, no primitive geometry/focus-ring overrides, and the search catalog entry is registered via searchableSetting with desktopOnly.
Posted via Macroscope — UI Consistency
There was a problem hiding this comment.
Two compatibility re-export shims were introduced while moving declarations to their new canonical modules. Conventions ask that the moved declaration have a single canonical path with every consumer updated mechanically, rather than leaving a re-export behind.
Posted via Macroscope — Effect Service Conventions
There was a problem hiding this comment.
One finding on the new Connections row: the attach toggle immediately relaunches Desktop, but nothing in the row says so and there is no confirmation, unlike the equally consequential "WSL only" switch in the same section.
Posted via Macroscope — UI Consistency
There was a problem hiding this comment.
One finding on the changed session-scope derivation in ConnectionsSettings.tsx. The rest of the new attach row (shared SettingsRow + Switch, searchableSetting title/anchor, restart wording, load-failure fallback) matches the existing Connections patterns.
Posted via Macroscope — UI Consistency

What Changed
Packaged Desktop now discovers a live same-machine background service or
t3 serveruntime and attaches to it instead of starting a second backend. The attachment uses a process-scoped grant to establish an administrative Desktop session while continuing to serve the renderer bundled with the installed app.Desktop development remains isolated. Settings → Connections exposes an opt-out, reports the attached state, and leaves network-exposure controls with the server that owns them.
Attached backends are rediscovered after a restart or port change. Transient failures are retried silently; persistent secure-pairing failures offer Try Again, Start Separate Backend, Open in Browser, or Quit. Starting separately uses isolated state for that launch.
The background-service user documentation now covers Desktop attachment, ownership, recovery, and the escape hatch.
Why
A headless T3 Code server can be the durable environment used from web and mobile, but opening Desktop on the same machine currently creates a separate environment with different threads and settings. Desktop should be able to act as another client for the existing local environment without weakening development isolation or silently falling back when secure attachment fails.
Starting-point proposal: #8114
UI Changes
Before
Desktop manages its own backend, so Connections begins with its network controls and has no running-server attachment state.
After
Desktop is attached to the disposable local server. The page shows the attachment control and makes network exposure read-only because the external server owns it.
Service restart recovery
The attached server stops, Desktop retries and reloads its bundled renderer, and the same thread returns automatically without a decision dialog.
reconnect-recovery.mp4
Verification
git diff --checkpassedChecklist
Implemented and reviewed with GPT-5.6 through the Codex harness in T3 Code.
Note
High Risk
Changes desktop startup, OAuth pairing, and server auth grants for local attachment; mis-handling could spawn duplicate backends or fail secure reconnection in production.
Overview
Packaged Desktop can attach to an already-running local T3 Code server (background service or
t3 serve) instead of always spawning its own backend, so the same environment can be used from Desktop without a duplicate process.Discovery reads
server-runtime.json(and systemd/launchdT3CODE_HOMEhints), validates the server via/.well-known/t3/environment, and pairs with a new per-processdesktopAttachTokenexchanged for a bearer session. The server seeds that token inPairingGrantStoreand persists it in runtime state; Desktop usesmanageProcess: falsewith HTTP health watching, invalidates stale attachments on loss, and can reload the bundled renderer (local protocol handler) while API traffic goes to the attached origin. Development never auto-attaches; a newattachExistingLocalBackendsetting (default on) plus IPC exposes attachment state and relaunches on toggle.Bootstrap and runtime recovery add dialogs: retry pairing, start a separate backend (isolated
desktop-independenthome + port scan via extractedDesktopBackendPort), open in browser, or quit. The backend pool retries pairing silently before offering “start separate” on persistent failures.Reviewed by Cursor Bugbot for commit ed06cc2. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add Desktop app support for attaching to a running local backend
desktopAttachToken, avoiding a second server spawngetExistingLocalBackendStateandsetAttachExistingLocalBackendlet the renderer query and toggle attachment; toggling relaunches the appDesktopBackendManagergains an attached-runner mode (manageProcess: false) with health probes every 2s and callbacks for configuration failure and unexpected shutdownElectronProtocolserves the bundled renderer locally whenrendererRootis set, with MIME types, CSP, and path-traversal protection, instead of proxying from the attached serverPairingGrantStoreseeds a reusable admin grant (100-year TTL) from the configureddesktopAttachToken; server runtime state is persisted with file mode0600DesktopLocalEnvironmentAuth,desktopAuth) caches bearer tokens keyed by URL + token +authSessionKeyand reuses the attached token without a bootstrap exchangeExistingLocalBackendPairingErrorthe pool prompts the userDesktopBackendConfigurationinterface members (resolveExistingLocalBackend,invalidateExistingLocalBackendAttachment,useIndependentBackendForLaunch) require all implementations and test mocks to provide them;DesktopSettingsdefaultsattachExistingLocalBackendtotrue, so existing users without the key will begin attaching on next launchMacroscope summarized ed06cc2.