feat(desktop): the renderer's bootstrap token rotates every 12 hours #16275
t3/desktop-bootstrap-1-stop-retrying fromrefs/pull/16275/head·merged by juliusmarminge View on GitHubStack 2/2, on top of #16273.
Problem#
The desktop handed the renderer one admin-scoped bootstrap token for its whole lifetime, and backends accepted it for 24h. A leaked token could mint sessions for a day, and once it expired a desktop left running could not connect a backend that restarted, since it had no valid token to hand out.
Fix#
- The desktop generates a 32-byte secret per desktop process and sends it to every backend in the bootstrap envelope (
desktopBootstrapSecret, over fd3/stdin like the token). The renderer never sees it. - Both sides derive the token for the current 12-hour window with HMAC-SHA256 (
@t3tools/shared/desktopBootstrapToken). A backend accepts the current and previous window's token, compared in constant time. getLocalEnvironmentBootstrapsalways hands the renderer the current window's token, so any token works for at most 24 hours and a running desktop never ends up holding an expired one.- A backend launched with a secret no longer accepts the fixed launch token on its own. Backends launched by an older desktop, without the secret, keep the previous fixed-token behaviour. Every backend the desktop launches (primary, staged or mounted WSL runtime) is the server build bundled with that desktop, so a new desktop never hands rotating tokens to an older server.
- The desktop main process (
DesktopLocalEnvironmentAuth) also derives the current window's token, so its first exchange works even if it runs long after launch (e.g. after a suspend).
An earlier version of this stack also added a session-renewal endpoint (#16274). Adversarial review showed it let a stolen desktop session renew itself forever, and rotation alone keeps a long-running desktop connected, so it was dropped.
Tests: shared desktopBootstrapToken.test.ts (rotation and window acceptance), server PairingGrantStore.test.ts (accepts current-window tokens after 5 days, rejects stale ones and the bare launch token), desktop DesktopBackendConfiguration.test.ts, window.test.ts and DesktopLocalEnvironmentAuth.test.ts (secret in the envelope, current token over IPC, delayed first exchange uses the current token).
Not verified in a running desktop with WSL; that needs a Windows machine.
Claude Opus 5.5 via Claude Code
🤖 Generated with Claude Code
- 1
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
ℹ️ No successful
mainbaseline artifact is available yet. This run establishes the initial measurement.Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire — 5.0 KiB — 6.8 KiB ✅ Codex Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅ Codex Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅ Codex Live turn WebSocket decoded — 20.9 KiB — 29.3 KiB ✅ Codex Live turn messages — 2 — 8 ✅ Claude Total thread wire — 5.0 KiB — 6.8 KiB ✅ Claude Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅ Claude Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅ Claude Live turn WebSocket decoded — 21.2 KiB — 29.3 KiB ✅ Claude Live turn messages — 2 — 8 ✅ Baseline: unavailable · PR result:
480a2cb· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
- Review profile: CHILL
- Plan: Team
- Run ID:
1686a7c2-54f0-4434-b232-cd1155068ba3
📥 Commits
Reviewing files that changed from the base of the PR and between 4858df14af1d41855e4be12321be5e5da91522af and 90e4d10d8a8c3486c037d32408cf520e4a029cf1.
📒 Files selected for processing (3)
apps/desktop/src/backend/DesktopBackendPool.test.tsapps/desktop/src/wsl/DesktopWslBackend.test.tsapps/server/src/auth/PairingGrantStore.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
📝 Walkthrough
Walkthrough#
Desktop backends now receive a shared bootstrap secret and derive time-windowed tokens from it. The desktop publishes the current token in bootstrap results and uses it for local-environment authentication. The server validates rotating tokens and issues desktop-bootstrap grants.
Changes#
Desktop bootstrap token rotation
Layer / File(s) Summary Token contract and derivation
packages/contracts/src/desktopBootstrap.ts,packages/shared/src/desktopBootstrapToken.ts,packages/shared/src/desktopBootstrapToken.test.ts,packages/shared/package.jsonThe bootstrap contract adds an optional secret. Shared utilities derive HMAC-SHA256 tokens for 12-hour windows and validate tokens from the previous, current, or next window. Tests cover rotation, validity boundaries, clock skew, and invalid inputs. Desktop secret and token distribution
apps/desktop/src/backend/DesktopBackendConfiguration.ts,apps/desktop/src/ipc/methods/window.ts,apps/desktop/src/backend/DesktopBackendConfiguration.test.ts,apps/desktop/src/ipc/methods/window.test.ts,apps/desktop/src/backend/DesktopBackendPool.test.ts,apps/desktop/src/wsl/DesktopWslBackend.test.tsThe desktop caches a 32-byte secret and passes it to Windows and WSL bootstrap payloads. It derives the current token and uses it in bootstrap results when the backend has a secret. Tests cover token derivation and bootstrap results, and update configuration stubs. Desktop local-environment authentication
apps/desktop/src/backend/DesktopLocalEnvironmentAuth.ts,apps/desktop/src/backend/DesktopLocalEnvironmentAuth.test.tsWhen a backend has a bootstrap secret, local-environment authentication derives the exchange credential from the secret and current time. Otherwise, it uses the configured launch token. The test checks the submitted token after the launch token window has elapsed. Server secret propagation and token validation
apps/server/src/config.ts,apps/server/src/cli/config.ts,apps/server/src/auth/PairingGrantStore.ts,apps/server/src/auth/PairingGrantStore.test.tsServer configuration carries the optional secret. PairingGrantStore validates rotating tokens and issues a desktop-bootstrap grant. Tests cover acceptance of a current-window token and rejection of an older token and the configured launch token. Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Feature
Suggested reviewers:
t3dotggSequence Diagram(s)#
sequenceDiagram participant DesktopBackendConfiguration participant currentDesktopBootstrapToken participant getLocalEnvironmentBootstraps participant Renderer DesktopBackendConfiguration->>currentDesktopBootstrapToken: derive token from secret and current time getLocalEnvironmentBootstraps->>DesktopBackendConfiguration: request current token DesktopBackendConfiguration-->>getLocalEnvironmentBootstraps: return current token getLocalEnvironmentBootstraps-->>Renderer: include token in bootstrap resultMerge Risk: ⚪ Minimal · up to
90e4dThe reviewed changes show no actionable issue preventing merge after normal checks.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 15 files. Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
Check name Status Explanation Title check ✅ Passed The title clearly and concisely describes the main change: 12-hour rotation of the desktop renderer’s bootstrap token. Description check ✅ Passed The description explains the problem, the fix across components, and the focused tests and verification limits. It gives stack context, but does not include a distinct Scope and approval section or st… Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. - Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
- Commit to this branch
- Create a new PR
🛠️ Fix failing CI checks 💡
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
- Commit to this branch
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.- apps/server/src/auth/http.ts line 399OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -383,3 +383,17 @@383383 ),384384 ),385385 )386+ .handle(387+ "renewSession",388+ Effect.fn("environment.auth.renewSession")(389+ function* (args) {390+ yield* annotateEnvironmentRequest(args.endpoint.name);391+ const request = yield* HttpServerRequest.HttpServerRequest;392+ const session = yield* EnvironmentAuthenticatedPrincipal;393+ yield* appendCredentialResponseHeaders;394+ return yield* serverAuth.renewDesktopSession(395+ { ...session, scopes: [...session.scopes] },396+ deriveAuthClientMetadata({ request }),397+ );398+ },399+ Effect.catchTag("ServerAuthSessionNotRenewableError", () =>
The renewal handler catches statically known tagged failures with
Posted via Macroscope — Effect Service ConventionscatchTagand a schema-basedcatchIf. Please useEffect.catchTagsinstead; narrowrenewDesktopSession's declared error channel toServerAuthSessionNotRenewableError | ServerAuthSessionRenewalErrorso the two tagged handlers cover it. This fix spans both the service declaration and handler, so there is no single-hunk suggestion.Outdated: this targets the session-renewal handler, which was dropped from the stack (#16274 closed after adversarial review).
renewSession/renewDesktopSessionno longer exist on this branch, so there is nothing to change. juliusmarminge merged this5afe18e
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This PR changes the default desktop authentication path by introducing shared secrets and rotating administrative bootstrap tokens across the renderer, desktop backends, WSL, and server auth. The authentication-sensitive runtime impact and unresolved error-handling review concern warrant human review.
Notes:
No code changes detected at
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).480a2cb. Prior analysis still applies.