Skip to content

fix: stabilize local dev auth startup#3252

Open
huxcrux wants to merge 4 commits into
pingdotgg:mainfrom
huxcrux:dev-fix
Open

fix: stabilize local dev auth startup#3252
huxcrux wants to merge 4 commits into
pingdotgg:mainfrom
huxcrux:dev-fix

Conversation

@huxcrux

@huxcrux huxcrux commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • Prevent Clerk-dependent desktop/web code from loading when Clerk local config is absent.
  • Register the desktop app scheme independently so local desktop startup no longer depends on Clerk side effects.
  • Route desktop custom-scheme requests through the app protocol using the Effect/Undici HTTP client.
  • Load the diff worker via the portable worker entry to avoid Vite worker default-export failures.
  • Route configured local-dev HTTP requests through the Vite origin while preserving direct WebSocket targets.
  • Harden pairing bootstrap by deduping same-token submits and tolerating already-authenticated stale token retries.

Why

Local development could fail when Clerk config was missing or when running the web dev flow through vp run dev. Clerk was being loaded too eagerly, desktop scheme registration depended on Clerk bridge setup, diff worker imports could fail under Vite, and pairing-token exchange could consume a one-time token before the browser session was observable on the correct origin.

This keeps local startup resilient without Clerk config, avoids CORS/cookie-origin issues by using the web/Vite origin for browser HTTP requests, and preserves direct loopback WebSockets where required.

UI Changes

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk
Touches auth bootstrap, desktop protocol proxying, and environment URL resolution—important for cookies and pairing—but changes are scoped with broad test coverage.

Overview
Stabilizes local dev and desktop auth by decoupling startup from Clerk, fixing how API URLs are resolved, and hardening pairing-token exchange.

Desktop: When Clerk is not configured, the custom app scheme is registered at startup via registerDesktopSchemePrivileges, and the Clerk SDK bridge is skipped through makeDesktopClerkLayer / desktopClerkBridgeEnabled. Custom-scheme proxying moves from Electron.net.fetch to Effect HttpClient (Undici), with streamed bodies, hop-by-hop header stripping, and cache: no-store.

Web: Primary environment HTTP targets loopback through the Vite dev origin when VITE_DEV_SERVER_URL applies, and through t3code-dev://app when the renderer runs on the desktop custom scheme (WebSocket bases stay direct). Pairing submit dedupes concurrent same-token calls, waits for session establishment after exchange, and treats 401 as success if the session is already authenticated. Clerk UI, cloud auth root, connections settings, and diff workers load lazily (portable worker URL) so missing Clerk config does not break vp run dev. Vite exposes VITE_DEV_SERVER_URL and sets HMR clientPort.

Reviewed by Cursor Bugbot for commit 6593a5f. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix local dev auth startup by stabilizing protocol, URL resolution, and credential submission

  • Rewrites ElectronProtocol.proxyRequest to use HttpClient instead of Electron.net.fetch, streaming response bodies and stripping hop-by-hop headers; adds registerDesktopSchemePrivileged to configure the custom scheme at startup when the Clerk bridge is disabled
  • Introduces desktopClerkBridgeEnabled in DesktopClerk and gates Clerk SDK bridge acquisition on that flag via makeDesktopClerkLayer
  • Rewrites resolveHttpRequestBaseUrl in target.ts to prefer the Vite dev server origin for loopback targets in local dev and the custom desktop scheme origin (t3code-dev://app) when running in the desktop dev app
  • Deduplicates concurrent pairing token submissions in submitServerAuthCredential and adds a grace path that accepts an already-authenticated session on 401 when a duplicate token is submitted
  • Lazily loads ConfiguredCloudAuthRoot, sidebar Clerk components, and connection settings to defer Clerk initialization

Macroscope summarized 6593a5f.

huxcrux and others added 2 commits June 20, 2026 11:23
Gate Clerk-dependent renderer and desktop bridge setup when local config is absent, register the desktop schemes independently, proxy custom-scheme requests through the app protocol, and load the diff worker via the portable package worker entry.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Route configured loopback HTTP requests through the Vite origin so browser-session cookies are scoped to the page origin, while preserving direct WebSocket targets. Dedupe same-token pairing submits and tolerate stale one-time-token retries when a session is already authenticated.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

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

Run ID: 3abce5a7-b66c-4885-967f-37e045186c32

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 and usage tips.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jun 20, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cd0056b. Configure here.

Comment thread apps/desktop/src/electron/ElectronProtocol.ts
Comment thread apps/web/src/environments/primary/auth.ts
@huxcrux huxcrux marked this pull request as draft June 20, 2026 09:42
Comment thread apps/web/src/environments/primary/auth.ts
@macroscopeapp

macroscopeapp Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR modifies authentication flow logic including credential submission, session validation, and desktop auth bridge enablement. Two unresolved medium-severity review comments identify potential bugs in proxy response buffering and session establishment timing. Changes to authentication code paths warrant human review.

You can customize Macroscope's approvability policy. Learn more.

Stream desktop protocol proxy responses instead of buffering complete bodies, and wait for browser sessions to become observable after manual pairing exchanges.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@huxcrux huxcrux marked this pull request as ready for review June 20, 2026 09:52
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant