Skip to content

Use schema codecs for relay runtime state#3657

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/idiomatic-effect-patterns-8b50
Draft

Use schema codecs for relay runtime state#3657
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/idiomatic-effect-patterns-8b50

Conversation

@cursor

@cursor cursor Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • Replaced ad-hoc JSON stringify/parse for managed relay environment status atom keys with a hoisted Schema.fromJsonString codec.
  • Replaced ad-hoc JSON stringify for managed endpoint runtime config comparison keys with a schema codec.
  • Changed persisted managed endpoint runtime config reads to return Option internally before adapting to the existing public applyConfig(null) API.
  • Added focused tests for relay status refresh keying and managed runtime config deduplication.

Why

These are small idiomatic Effect improvements: schema-based JSON encoding/decoding avoids unchecked casts and parsing, and Option models missing persisted config explicitly while preserving the existing external behavior.

UI Changes

Not applicable; this PR does not change UI.

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.18.0/bin:$PATH" pnpm exec vp test run src/relay/managedRelayState.test.ts (from packages/client-runtime)
  • PATH="/home/ubuntu/.nvm/versions/node/v24.18.0/bin:$PATH" pnpm exec vp test run src/cloud/ManagedEndpointRuntime.test.ts (from apps/server)
  • PATH="/home/ubuntu/.nvm/versions/node/v24.18.0/bin:$PATH" pnpm exec vp check
  • PATH="/home/ubuntu/.nvm/versions/node/v24.18.0/bin:$PATH" pnpm exec vp run typecheck
Open in Web View Automation 

Note

Replace JSON.stringify with schema codecs for relay runtime state keys

  • Introduces RuntimeConfigKeyPayload and ManagedRelayStatusKeyPayload as Effect Schema.Struct definitions in ManagedEndpointRuntime.ts and managedRelayState.ts, replacing raw JSON.stringify/JSON.parse for key serialization.
  • Schema-based encoding normalizes optional fields (e.g. tunnelId, tunnelName) so that absent values produce consistent keys, fixing a deduplication bug for Cloudflare connector configs with missing optional fields.
  • readRuntimeConfig now returns Option.none() instead of null when a secret is absent, aligning error handling with Effect conventions.
  • New tests cover the deduplication fix and verify that environment status atoms use schema-encoded keys correctly.
📊 Macroscope summarized 17f8437. 2 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted

🗂️ Filtered Issues

No issues evaluated.

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:M 30-99 changed lines (additions + deletions). labels Jul 2, 2026
@@ -235,24 +245,18 @@ function requireClerkToken(

function statusKey(input: {

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.

🟡 Medium relay/managedRelayState.ts:246

statusKey now calls encodeManagedRelayStatusKey, which runs Schema.encodeSync on the entire RelayClientEnvironmentRecord. An environment object with a runtime-invalid value in any field (e.g. an untrimmed label or linkedAt) throws an exception, preventing environmentStatusAtom and refreshEnvironmentStatus from even creating the atom key. Previously JSON.stringify serialized without validation, so only the fields actually used later (environmentId and endpoint) mattered. Consider narrowing the schema to only the fields consumed by parseStatusKey and the downstream query, so non-essential field validation doesn't block status lookups.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @packages/client-runtime/src/relay/managedRelayState.ts around line 246:

`statusKey` now calls `encodeManagedRelayStatusKey`, which runs `Schema.encodeSync` on the entire `RelayClientEnvironmentRecord`. An environment object with a runtime-invalid value in any field (e.g. an untrimmed `label` or `linkedAt`) throws an exception, preventing `environmentStatusAtom` and `refreshEnvironmentStatus` from even creating the atom key. Previously `JSON.stringify` serialized without validation, so only the fields actually used later (`environmentId` and `endpoint`) mattered. Consider narrowing the schema to only the fields consumed by `parseStatusKey` and the downstream query, so non-essential field validation doesn't block status lookups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 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.

1 participant