Use schema codecs for relay runtime state#3657
Draft
cursor[bot] wants to merge 1 commit into
Draft
Conversation
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
| @@ -235,24 +245,18 @@ function requireClerkToken( | |||
|
|
|||
| function statusKey(input: { | |||
Contributor
There was a problem hiding this comment.
🟡 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
Schema.fromJsonStringcodec.Optioninternally before adapting to the existing publicapplyConfig(null)API.Why
These are small idiomatic Effect improvements: schema-based JSON encoding/decoding avoids unchecked casts and parsing, and
Optionmodels missing persisted config explicitly while preserving the existing external behavior.UI Changes
Not applicable; this PR does not change UI.
Checklist
Validation:
PATH="/home/ubuntu/.nvm/versions/node/v24.18.0/bin:$PATH" pnpm exec vp test run src/relay/managedRelayState.test.ts(frompackages/client-runtime)PATH="/home/ubuntu/.nvm/versions/node/v24.18.0/bin:$PATH" pnpm exec vp test run src/cloud/ManagedEndpointRuntime.test.ts(fromapps/server)PATH="/home/ubuntu/.nvm/versions/node/v24.18.0/bin:$PATH" pnpm exec vp checkPATH="/home/ubuntu/.nvm/versions/node/v24.18.0/bin:$PATH" pnpm exec vp run typecheckNote
Replace
JSON.stringifywith schema codecs for relay runtime state keysRuntimeConfigKeyPayloadandManagedRelayStatusKeyPayloadas EffectSchema.Structdefinitions inManagedEndpointRuntime.tsandmanagedRelayState.ts, replacing rawJSON.stringify/JSON.parsefor key serialization.tunnelId,tunnelName) so that absent values produce consistent keys, fixing a deduplication bug for Cloudflare connector configs with missing optional fields.readRuntimeConfignow returnsOption.none()instead ofnullwhen a secret is absent, aligning error handling with Effect conventions.📊 Macroscope summarized 17f8437. 2 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted
🗂️ Filtered Issues
No issues evaluated.