t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: First open of a session deterministically fails with DesktopLocalEnvironmentAuthSessionBootstrapError (Failed to create the local desktop bearer session)

Open fesalves opened this issue 1 month ago • 5 comments

What happened

Every time I open T3 Code for the first time in a session (first window of the day/app launch), the app shows the full-screen error page with PrimaryEnvironmentRequestError. Reopening the app (quit and open again) always works, and "Try again"/"Reload app" also recovers it.

The window shows:

T3 Code (Nightly) 0.1.4-nightly.20261027.3770
Path: /

PrimaryEnvironmentRequestError
    at e.fromCause (t3code://app/assets/primary-CtrV7huJ.js:1:790)
    at t3code://app/assets/primary-CtrV7huJ.js:1:2167
    at async X (t3code://app/assets/primary-CtrV7huJ.js:1:3192)
    at async Q (t3code://app/assets/primary-CtrV7huJ.js:1:3455)
    at async Object.beforeLoad (t3code://app/assets/main-ChezRqOl.js:27:21790)
    at async Te (t3code://app/assets/Match-Z7hs_Pw5.js:1:9841)
    at async t3code://app/assets/Match-Z7hs_Pw5.js:1:29016

Caused by:
Error: Error invoking remote method 'desktop:get-local-environment-bearer-token': DesktopLocalEnvironmentAuthSessionBootstrapError: Failed to create the local desktop bearer session.

This looks like the same race family as #17367 and #23378 (desktop's bearer-session bootstrap racing a not-yet-ready local backend), but the surface here is the renderer's root beforeLoad failing inside the desktop main process IPC call itself (desktop:get-local-environment-bearer-token → DesktopLocalEnvironmentAuthSessionBootstrapError), not an HTTP 500 from a fetch. Marking the other issues as possibly related for triage; I did not dig into the sources.

Steps to reproduce

Not perfectly deterministic, but it has failed on every first open of a session so far on this machine:

  1. Open T3 Code (Nightly) fresh, as the first window of a session.
  2. The app shows the full-screen PrimaryEnvironmentRequestError page at path /.
  3. Quit and reopen the app: it loads normally.

Reopening consistently fixes it, so the failure is confined to the very first cold bootstrapping of the local desktop bearer session.

Expected behavior

The first window should load normally, or the desktop should retry the local bearer session bootstrap transparently (and only surface the error page after actual persistent failures) instead of putting up a full-screen error on the very first open of a session.

Actual behavior

The very first open of a session deterministically fails with:

Error: Error invoking remote method 'desktop:get-local-environment-bearer-token': DesktopLocalEnvironmentAuthSessionBootstrapError: Failed to create the local desktop bearer session.

wrapped as PrimaryEnvironmentRequestError in the renderer's root beforeLoad (t3code://app/assets/primary-*.js) — full screen error page. Reopening always loads fine.

Impact

Minor bug or occasional failure.

Version or commit

Desktop 0.1.4-nightly.20261027.3770

Environment

Windows 11 Home 10.0.26200 (win32 x64), desktop app.

Logs or stack traces

Renderer error page (above).

Workaround

Quit and reopen the app after the error appears — the next open loads normally.

fesalves avatar Oct 27 '26 22:10 fesalves

What do you see on screen? On the first open of a session, before you quit or Reload, what does the window show the whole time?

NotAnNvidiaFan avatar Oct 28 '26 02:10 NotAnNvidiaFan

The only thing shown on screen was exactly the stack trace I already included in the issue description. It was the full-screen PrimaryEnvironmentRequestError page at Path: / with the following cause:

Error: Error invoking remote method 'desktop:get-local-environment-bearer-token': DesktopLocalEnvironmentAuthSessionBootstrapError: Failed to create the local desktop bearer session.

I tried to reproduce it again by opening T3 Code for the first time in a new session, but it didn't happen this time, so I no longer have the screenshot to attach.

I'm currently on the latest nightly. This error happened multiple times on the previous nightly build.

One detail I noticed every time it occurred: alongside the desktop app's error screen, a separate Google Chrome window would open automatically and load the T3 Code interface.

fesalves avatar Oct 28 '26 07:10 fesalves

Image

fesalves avatar Oct 29 '26 22:10 fesalves

After running t3 triage, I identified the root cause of the startup failure.

Issue: DesktopLocalEnvironmentAuthSessionBootstrapError: Failed to create the local desktop bearer session.

Root cause: T3 Code Desktop generates a new in-memory desktopBootstrapSecret on every launch and derives a rotating bootstrap token from it. If an orphaned local backend from a previous session is still listening on port 3773 (common after a Windows reboot or if the app wasn't fully quit), that backend was started with the old secret and rejects the new token with invalid_credential. This causes the desktop auth handshake to fail.

Workaround:

  1. Fully quit T3 Code Desktop (close the window and exit from the system tray).
  2. Relaunch the app. In most cases, it will start a fresh backend with the newly generated secret and the error will disappear.

Notes:

  • The desktop instance and the backend must share the same bootstrap secret. There is currently no persistence for this secret between launches, so a stale backend will always cause this mismatch.
  • This is especially common on the first launch after booting Windows.

fesalves avatar Oct 30 '26 15:10 fesalves

This is the same problem as #16826, so I'm closing it in favour of that one. If it is different, say how and it will be reopened.

juliusmarminge avatar Nov 12 '26 07:11 juliusmarminge