fix(mobile): parse pasted pairing links #5596
main fromrefs/pull/5596/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
DominicVonk(GitHub profile, opens in a new tab) changed the title
- packages/client-runtime/src/connection/registry.ts line 684OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -652,7 +681,4 @@652681 ),653682 ),654683 );655- yield* connectivity.changes.pipe(656- Stream.runForEach((status) => SubscriptionRef.set(networkStatus, status)),657- Effect.forkScoped,658- );684+ yield* Connectivity.followNetworkStatus({
- packages/client-runtime/src/platform/persistence.ts lines 58 to 70OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -55,3 +55,16 @@5555 }5656 >()("@t3tools/client-runtime/platform/persistence/ConnectionRegistrationStore") {}575758+export class ConnectionActivationStore extends Context.Service<59+ ConnectionActivationStore,60+ {61+ readonly listDisabled: Effect.Effect<ReadonlySet<EnvironmentId>, ConnectionPersistenceError>;62+ readonly setEnabled: (63+ environmentId: EnvironmentId,64+ enabled: boolean,65+ ) => Effect.Effect<void, ConnectionPersistenceError>;66+ readonly reconcile: (67+ environmentIds: ReadonlySet<EnvironmentId>,68+ ) => Effect.Effect<void, ConnectionPersistenceError>;69+ }70+>()("@t3tools/client-runtime/platform/persistence/ConnectionActivationStore") {}apps/mobile/src/connection/storage.ts lines 54 to 75OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -51,0 +55,21 @@55+ Effect.map((document) => new Set(document.disabledEnvironmentIds)),56+ Effect.mapError((error) => targetPersistenceError("list-targets", error)),57+ ),58+ setEnabled: (environmentId, enabled) =>59+ catalog60+ .update((document) => ({61+ ...document,62+ disabledEnvironmentIds: enabled63+ ? document.disabledEnvironmentIds.filter((candidate) => candidate !== environmentId)64+ : [...new Set([...document.disabledEnvironmentIds, environmentId])],65+ }))66+ .pipe(Effect.mapError((error) => targetPersistenceError("register-connection", error))),67+ reconcile: (environmentIds) =>68+ catalog69+ .update((document) => ({70+ ...document,71+ disabledEnvironmentIds: document.disabledEnvironmentIds.filter((environmentId) =>72+ environmentIds.has(environmentId),73+ ),74+ }))75+ .pipe(Effect.mapError((error) => targetPersistenceError("register-connection", error))),apps/web/src/connection/storage.ts lines 375 to 396OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -372,0 +376,21 @@376+ Effect.map((document) => new Set(document.disabledEnvironmentIds)),377+ Effect.mapError((cause) => persistenceError("list-targets", cause)),378+ ),379+ setEnabled: (environmentId, enabled) =>380+ catalog381+ .update((document) => ({382+ ...document,383+ disabledEnvironmentIds: enabled384+ ? document.disabledEnvironmentIds.filter((candidate) => candidate !== environmentId)385+ : [...new Set([...document.disabledEnvironmentIds, environmentId])],386+ }))387+ .pipe(Effect.mapError((cause) => persistenceError("register-connection", cause))),388+ reconcile: (environmentIds) =>389+ catalog390+ .update((document) => ({391+ ...document,392+ disabledEnvironmentIds: document.disabledEnvironmentIds.filter((environmentId) =>393+ environmentIds.has(environmentId),394+ ),395+ }))396+ .pipe(Effect.mapError((cause) => persistenceError("register-connection", cause))),
- apps/mobile/src/connection/storage.ts lines 60 to 81OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -51,0 +61,21 @@61+ Effect.map((document) => new Set(document.disabledEnvironmentIds)),62+ Effect.mapError((error) => targetPersistenceError("list-targets", error)),63+ ),64+ setEnabled: (environmentId, enabled) =>65+ catalog66+ .update((document) => ({67+ ...document,68+ disabledEnvironmentIds: enabled69+ ? document.disabledEnvironmentIds.filter((candidate) => candidate !== environmentId)70+ : [...new Set([...document.disabledEnvironmentIds, environmentId])],71+ }))72+ .pipe(Effect.mapError((error) => targetPersistenceError("reconcile-activation", error))),73+ reconcile: (environmentIds) =>74+ catalog75+ .update((document) => ({76+ ...document,77+ disabledEnvironmentIds: document.disabledEnvironmentIds.filter((environmentId) =>78+ environmentIds.has(environmentId),79+ ),80+ }))81+ .pipe(Effect.mapError((error) => targetPersistenceError("register-connection", error))),apps/mobile/src/connection/storage.ts lines 46 to 53OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -36,11 +43,11 @@3643 const targetStore = ConnectionTargetStore.of({3744 list: catalog.read.pipe(3845 Effect.map((document) => document.targets),39- Effect.mapError((error) => targetPersistenceError("list-targets", error)),46+ Effect.mapError((error) => targetPersistenceError("list-activation", error)),4047 ),4148 });4249 const registrationStore = ConnectionRegistrationStore.of({4350 register: (registration) =>4451 catalog4552 .update((document) => registerConnectionInCatalog(document, registration))46- .pipe(Effect.mapError((error) => targetPersistenceError("register-connection", error))),53+ .pipe(Effect.mapError((error) => targetPersistenceError("set-activation", error))),
- packages/client-runtime/src/connection/registry.ts line 582OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -556,3 +579,4 @@556579 ? yield* profiles.get(target.connectionId)557580 : Option.none();558581582+ yield* activation.setEnabled(environmentId, true);
- apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx line 87OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -55,3 +55,3 @@5555 }, [pairingConnectionError]);56565757 const handleHostChange = useCallback((value: string) => {
- packages/client-runtime/src/connection/connectivity.ts lines 32 to 35OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -17,3 +21,15 @@17211822 export const layer = (service: Connectivity["Service"]) =>1923 Layer.succeed(Connectivity, make(service));24+25+/**26+ * Follows reported connectivity changes and repairs status drift whenever the27+ * application becomes active. Mobile platforms can suspend network listeners,28+ * which is especially visible while a VPN tunnel is restoring in the29+ * background. A report that arrives during the asynchronous status read always30+ * wins over that older snapshot.31+ */32+export const followNetworkStatus = Effect.fnUntraced(function* (options: {33+ readonly connectivity: Connectivity["Service"];34+ readonly wakeups: ConnectionWakeups.ConnectionWakeups["Service"];35+ readonly apply: (status: NetworkStatus) => Effect.Effect<void>;
- packages/client-runtime/src/connection/connectivity.ts lines 52 to 53OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -19,0 +33,21 @@33+ readonly apply: (status: NetworkStatus) => Effect.Effect<void>;34+}) {35+ const connectivity = yield* Connectivity;36+ const wakeups = yield* ConnectionWakeups.ConnectionWakeups;37+ const reportCount = yield* Ref.make(0);38+ const appliedStatus = yield* Ref.make<Option.Option<NetworkStatus>>(Option.none());39+ const applyLock = yield* Semaphore.make(1);40+41+ const applyStatus = Effect.fnUntraced(function* (status: NetworkStatus) {42+ const changed = yield* Ref.modify(appliedStatus, (current) =>43+ Option.isSome(current) && current.value === status44+ ? ([false, current] as const)45+ : ([true, Option.some(status)] as const),46+ );47+ if (changed) {48+ yield* options.apply(status);49+ }50+ });51+52+ yield* connectivity.changes.pipe(53+ Stream.runForEach((status) =>
- apps/mobile/src/state/use-remote-environment-registry.ts line 143OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -140,3 +140,4 @@140140 connectionState: environment.connectionState,141141 connectionError: environment.connectionError,142142 connectionErrorTraceId: environment.connectionErrorTraceId,143+ enabled: environment.connectionState !== "available",packages/client-runtime/src/relay/discovery.ts line 323OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -321,6 +320,4 @@321320 : Ref.get(hasRefreshed).pipe(322321 Effect.flatMap((shouldRefresh) => (shouldRefresh ? refresh : Effect.void)),323322 ),324- ),325- Effect.forkScoped,326- );323+ });
- packages/client-runtime/src/relay/discovery.ts line 320OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -309,18 +309,12 @@309309 ),310310 );311311312- yield* connectivity.changes.pipe(313- Stream.changes,314- Stream.runForEach((networkStatus) =>312+ yield* Connectivity.followNetworkStatus({313+ apply: (networkStatus) =>315314 networkStatus === "offline"316315 ? SubscriptionRef.update(state, (current) => ({317316 ...current,318317 refreshing: false,319318 offline: true,320319 }))321- : Ref.get(hasRefreshed).pipe(322- Effect.flatMap((shouldRefresh) => (shouldRefresh ? refresh : Effect.void)),323- ),324- ),325- Effect.forkScoped,326- );320+ : Effect.gen(function* () {
- packages/client-runtime/src/state/presentation.ts line 44OutdatedResolvedby DominicVonk(GitHub profile, opens in a new tab)@@ -35,3 +38,7 @@3538 if (entry === undefined) {3639 return null;3740 }41+ const enabled = Option.getOrNull(AsyncResult.value(get(input.enabledAtom(environmentId))));42+ if (enabled === null) {43+ return null;44+ }packages/client-runtime/src/connection/registry.ts line 546OutdatedResolvedby DominicVonk(GitHub profile, opens in a new tab)@@ -440,7 +479,3 @@440479 target.environmentId,441480 );442481 if (persistedTarget !== undefined) {443- yield* registrations.remove(persistedTarget).pipe(444- Effect.tap(() =>445- Ref.update(persistedTargetsByEnvironment, (current) => {446- const next = new Map(current);apps/mobile/src/features/connection/pairing.ts line 84OutdatedResolvedby DominicVonk(GitHub profile, opens in a new tab)@@ -70,3 +70,7 @@7070 }7171 }727273+export function parsePairingFields(host: string, code: string): { host: string; code: string } {74+ const parsed = parsePairingUrl(host);75+ return parsed.code.length > 0 ? parsed : { host, code };76+}
- packages/client-runtime/src/connection/registry.ts line 387OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -348,4 +368,20 @@368+ yield* activation.reconcile(369+ new Set([370+ ...currentTargets.map((target) => target.environmentId),371+ ...(yield* Ref.get(platformEnvironmentIds)),372+ ]),373+ );374+ const reconciledDisabledEnvironmentIds = yield* activation.listDisabled;375+ disabledEnvironmentIds.clear();376+ for (const environmentId of reconciledDisabledEnvironmentIds) {377+ disabledEnvironmentIds.add(environmentId);378+ }379+ yield* Ref.set(started, true);380+ return currentTargets;381+ }),382+ );383+ if (targetsToStart === null) {348384 return;349385 }350386 yield* Effect.forEach(351- persistedTargets,387+ targetsToStart,
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/mobile/src/features/connection/CloudEnvironmentRows.tsx line 271OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -223,4 +268,4 @@223268 props.onDisconnect();224269 }}225270 onToggleError={props.onToggleError}226- value={props.environment.connectionState !== "available"}271+ value={props.environment.enabled}
- apps/web/src/components/settings/ConnectionsSettings.tsx line 1437OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1403,3 +1420,18 @@14031420 // environment you connect to or remove here — its lifecycle is driven by the14041421 // WSL on/off + distro picker on this page.14051422 const isWslEnvironment = isDesktopLocalConnectionTarget(environment.entry.target);1423+ const isEditableBearer = environment.entry.target._tag === "BearerConnectionTarget";1424+1425+ const handleEditDialogOpenChange = useCallback(1426+ (open: boolean) => {1427+ if (!open && isSaving) return;1428+ setEditDialogOpen(open);1429+ if (open) {1430+ setLabel(environment.label);1431+ setDisplayUrl(environment.displayUrl ?? "");1432+ }1433+ },1434+ [environment.displayUrl, environment.label, isSaving],1435+ );1436+1437+ const handleSave = useCallback(async () => {
- apps/web/src/components/settings/ConnectionsSettings.tsx lines 1555 to 1562OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1488,0 +1542,21 @@1542+ <DialogDescription>1543+ Update how this device connects to {environment.label}.1544+ </DialogDescription>1545+ </DialogHeader>1546+ <DialogPanel>1547+ <div className="flex flex-col gap-4">1548+ <div className="flex items-center justify-between gap-4 rounded-md bg-muted/30 px-3 py-2">1549+ <div className="flex flex-col gap-0.5">1550+ <p className="text-sm font-medium text-foreground">Enabled</p>1551+ <p className="text-xs text-muted-foreground">1552+ Connect to this environment from this device.1553+ </p>1554+ </div>1555+ <Switch1556+ aria-label={`${environment.label} enabled`}1557+ checked={editEnabled}1558+ onCheckedChange={(nextEnabled) => {1559+ setEditEnabled(nextEnabled);1560+ void onSetEnabled(environmentId, nextEnabled);1561+ }}1562+ />
- packages/client-runtime/src/connection/onboarding.ts lines 148 to 171OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -148 +151,21 @@151+ Effect.fail(152+ new ConnectionBlockedError({153+ reason: "configuration",154+ detail: "The saved environment is no longer registered.",155+ }),156+ ),157+ ),158+ );148159 yield* registry.register(registration);160+ if (!wasEnabled) {161+ yield* registry.setEnabled(input.environmentId, false).pipe(162+ Effect.catchTag("EnvironmentNotRegisteredError", () =>163+ Effect.fail(164+ new ConnectionBlockedError({165+ reason: "configuration",166+ detail: "The saved environment is no longer registered.",167+ }),168+ ),169+ ),170+ );171+ }
- packages/client-runtime/src/connection/onboarding.ts line 171OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -148 +151,21 @@151+ Effect.fail(152+ new ConnectionBlockedError({153+ reason: "configuration",154+ detail: "The saved environment is no longer registered.",155+ }),156+ ),157+ ),158+ );148159 yield* registry.register(registration);160+ if (!wasEnabled) {161+ yield* registry.setEnabled(input.environmentId, false).pipe(162+ Effect.catchTag("EnvironmentNotRegisteredError", () =>163+ Effect.fail(164+ new ConnectionBlockedError({165+ reason: "configuration",166+ detail: "The saved environment is no longer registered.",167+ }),168+ ),169+ ),170+ );171+ }
- packages/client-runtime/src/connection/onboarding.ts line 151OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -145,4 +145,15 @@145145 entry: Option.fromUndefinedOr(entry),146146 credential,147147 });148+ const wasEnabled = yield* registry.state(input.environmentId).pipe(149+ Effect.map((state) => state.desired),150+ Effect.catchTag("EnvironmentNotRegisteredError", () =>151+ Effect.fail(152+ new ConnectionBlockedError({153+ reason: "configuration",154+ detail: "The saved environment is no longer registered.",155+ }),156+ ),157+ ),158+ );148159 yield* registry.register(registration);
- packages/client-runtime/src/connection/registry.ts line 638OutdatedResolvedby DominicVonk(GitHub profile, opens in a new tab)@@ -486,8 +626,13 @@486- const next = new Map(current);487- next.delete(environmentId);488- return next;489- });490- if (entry !== undefined && entry.target._tag === "BearerConnectionTarget") {491- yield* credentials.remove(entry.target.connectionId).pipe(492- Effect.catch((error) =>493- Effect.logWarning("Could not clear the platform bearer credential.", {626+ const removePlatformEnvironment = Effect.fn(627+ "EnvironmentRegistry.removePlatformEnvironment",628+ )(function* (environmentId: EnvironmentId) {629+ yield* withLeaseLock(630+ environmentId,631+ Effect.gen(function* () {632+ const entry = (yield* SubscriptionRef.get(entries)).get(environmentId);633+ yield* Ref.update(platformEnvironmentIds, (current) => {634+ const next = new Set(current);635+ next.delete(environmentId);636+ return next;637+ });638+ yield* closeServiceScope(environmentId);
- packages/client-runtime/src/connection/registry.ts line 539OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -435,3 +522,18 @@435- ),436- );437- }522+ const updateRegistration = Effect.fn("EnvironmentRegistry.updateRegistration")(function* (523+ registration: ConnectionRegistration,524+ ) {525+ const environmentId = registration.target.environmentId;526+ yield* withLeaseLock(527+ environmentId,528+ Effect.gen(function* () {529+ yield* getEntry(environmentId);530+ if ((yield* Ref.get(platformEnvironmentIds)).has(environmentId)) {531+ return;532+ }533+ yield* installRegistrationLocked(534+ registration,535+ !disabledEnvironmentIds.has(environmentId),536+ );537+ }),538+ );539+ });
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
DominicVonk(GitHub profile, opens in a new tab) changed the title
DominicVonk(GitHub profile, opens in a new tab) changed the title
- apps/mobile/src/features/connection/pairing.ts line 57OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -47,4 +49,9 @@4749 if (!trimmed) return { host: "", code: "" };48504951 try {50- const parsed = new URL(trimmed);52+ const authority = trimmed.split(/[/?#]/, 1)[0] ?? trimmed;53+ const parsed = new URL(54+ trimmed.includes("://")55+ ? trimmed56+ : `${isIpLiteral(authority) ? "http" : "https"}://${trimmed}`,57+ );
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge closed this
juliusmarminge reopened this
maria-rcks closed this
Sign in to join this conversation.




Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
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: Advanced
Run ID:
9396770e-648f-4573-9d06-6e1dabb89b59📥 Commits
Reviewing files that changed from the base of the PR and between 5cc99e1c23980d7995a13c47f969b47cb68ed1be and f92dc1762496a852aec21dcee03098a1b9263d04.
📒 Files selected for processing (3)
apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsxapps/mobile/src/features/connection/pairing.test.tsapps/mobile/src/features/connection/pairing.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
Pairing URL construction and parsing now normalize inputs that lack a scheme. The connection form parses host and pairing-code fields on blur and before submission, then builds the pairing URL from the parsed values.
Changes#
Pairing input handling
apps/mobile/src/features/connection/pairing.ts,apps/mobile/src/features/connection/pairing.test.tsparsePairingFieldsreturns parsed fields when parsing finds a code, and otherwise preserves the supplied fields. Tests cover these cases.apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsxPriority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
juliusmarmingeMerge Risk: ⚪ Minimal · up to
f92dcThe pairing input normalization is mergeable after normal checks. Supported tokens are preserved, and blur and submission consistently use parsed fields.
Security Architecture Review#
Security architecture risk: 🟡 Moderate · up to
f92dcA pasted hosted pairing link containing a schemeless IP backend can now select unencrypted HTTP where the previous submission path selected HTTPS. This can expose pairing and session credentials on untrusted networks. Explicitly specified schemes and the existing pairing checks remain intact.
Retained concerns
Security review details
Security Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)#
✅ Passed checks (3 passed)
Full details: Description check
Explanation
The description thoroughly explains the problem, implementation, verification steps, test results, and UI evidence. It does not provide the required scope-and-approval information or explain why this focused fix qualifies for an exemption.
Resolution
Add a Scope and approval section with a triaged issue or maintainer approval comment. If no prior issue or discussion exists, explain why this focused, obvious bug fix qualifies for the exemption. Organize the existing problem and change details under the template headings if needed.
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.