Skip to content

Refactor managed relay session to idiomatic Effect#3506

Closed
cursor[bot] wants to merge 4 commits into
mainfrom
cursor/idiomatic-effect-patterns-ea87
Closed

Refactor managed relay session to idiomatic Effect#3506
cursor[bot] wants to merge 4 commits into
mainfrom
cursor/idiomatic-effect-patterns-ea87

Conversation

@cursor

@cursor cursor Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • Refactored managed relay session token reads to return Option<string> from an Effect-native provider instead of string | null and a local Promise cache.
  • Replaced session errors with granular Schema.TaggedErrorClass errors and switched relay timing constants to Duration.
  • Updated web/mobile Clerk boundaries to convert their Promise token APIs into Effect/Option at the edge.
  • Added TestClock coverage for cached Clerk token expiry and converted touched relay session tests to Effect-native token readers.

Why

This keeps the managed relay session core in Effect end-to-end: cache reuse, concurrent read deduplication, provider refresh, and expiry behavior are now testable with Effect primitives instead of Promise coordination and nullable values.

UI Changes

No 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

Validation:

  • PATH="/home/ubuntu/.nvm/versions/node/v24.17.0/bin:$PATH" pnpm run test -- src/relay/managedRelayState.test.ts from packages/client-runtime
  • PATH="/home/ubuntu/.nvm/versions/node/v24.17.0/bin:$PATH" pnpm run test -- src/cloud/managedAuth.test.ts from apps/web
  • PATH="/home/ubuntu/.nvm/versions/node/v24.17.0/bin:$PATH" pnpm exec vp check
  • PATH="/home/ubuntu/.nvm/versions/node/v24.17.0/bin:$PATH" pnpm exec vp run typecheck
  • PATH="/home/ubuntu/.nvm/versions/node/v24.17.0/bin:$PATH" pnpm exec vp run lint:mobile
Open in Web View Automation 

Note

Refactor managed relay session token handling to use Effect and Option types

  • Replaces Promise<string|null> with Effect<Option<string>, ManagedRelaySessionError> for readClerkToken across managedRelayState.ts, managedAuth.tsx, and CloudAuthProvider.tsx.
  • Introduces ManagedRelaySessionTokenReadError and ManagedRelaySessionTokenUnavailableError as tagged Schema error classes, replacing generic errors for missing session and missing token cases.
  • Rewrites token caching in createManagedRelaySession to deduplicate concurrent reads via Deferred, cache tokens until JWT expiry (with a 5s skew), and propagate provider errors through the typed error union.
  • Replaces raw millisecond constants with Duration-based constants (DEFAULT_STALE_TIME, DEFAULT_IDLE_TTL, CLERK_TOKEN_EXPIRY_SKEW) in managedRelayState.ts.
  • Behavioral Change: callers of setManagedRelaySession must now provide readClerkToken as an Effect returning Option<string> rather than a Promise<string|null>.

Macroscope summarized 6ebcdda.

cursoragent and others added 4 commits June 22, 2026 16:08
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jun 22, 2026
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:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants