t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[4/5] fix(mobile): parse pasted pairing links

Open DominicVonk opened this issue 3 months ago • 2 comments

Problem

The mobile Add Environment form understands pairing links loaded from storage and QR scans, but pasting a complete direct pairing URL into the Host field leaves the token embedded in that field instead of splitting it into the host and pairing-code inputs.

Solution

Run the existing mobile pairing-link parser when the Host field loses focus or the form is submitted. When the input contains a valid fragment or query token, populate the normalized backend origin and pairing-code field together. Ordinary host typing remains literal and unchanged.

The implementation reuses the established parser, including hosted pairing requests and #token= handling, instead of adding a second URL format.

User impact

Users can paste the same complete pairing link on mobile that they use on desktop, without manually separating the host and token.

Stack

This PR is 4/5. Depends on layers 1–3, ending with 3/5, #5598.

Please review and merge the upstream PRs in order from 1 through 5. Because this repository does not have native stacked PRs enabled and cross-fork branches cannot be upstream base refs, the upstream diffs are cumulative. The corresponding fork PRs use the true dependent bases and provide the clean per-layer diffs.

Layer Upstream PR Clean stacked diff
1 #5597 — network-status recovery fork #1
2 #5600 — persistent environment activation fork #2
3 #5598 — environment-management UI fork #3
4 #5596 — pasted pairing-link parsing fork #4
5 #5599 — composer-pill activation fork #5

Validation

apps/mobile
Test Files  1 passed (1)
Tests       10 passed (10)
tsc --noEmit: passed

Regression coverage verifies direct and hosted pairing links, QR payloads, IP defaults, explicit schemes, embedded-token field normalization, and preservation of separately entered host/code values. Pairing URLs remain literal while typing and are normalized on blur or submit.

Integrated stack validation after rebasing onto latest upstream main: 14 test files passed with 124 tests; client-runtime, web, and mobile typechecks passed.

UI evidence

Mobile pairing link parsed into host and pairing code

Captured on an iOS Simulator from the integrated stack. The full URL was entered in the Host field; the UI normalized the host and populated the Pairing Code field automatically. The displayed code is synthetic and grants no access.

Latest review pass

The parser now accepts schemeless pairing links as well as fully qualified URLs. LAN IP literals default to HTTP, so inputs such as 192.168.1.100:3773/#token=... normalize correctly without weakening the HTTPS default for hostnames.

Latest integrated verification: client-runtime 47 test files / 598 tests passed; mobile 100 test files / 622 tests passed; client-runtime, web, and mobile typechecks passed.

Model: GPT-5; harness: Codex.


[!NOTE] Medium Risk Changes connection lifecycle (disable vs remove), catalog schema, and registry startup/serialization; broad mobile, web, and client-runtime touchpoints but covered by expanded tests.

Overview This PR extends connection management so environments can stay registered while being disabled on a device, and improves mobile pairing plus network status handling.

Activation persists disabledEnvironmentIds in the connection catalog via ConnectionActivationStore (mobile and web storage). The environment registry honors disabled state at startup (with reconciliation and serialized activation/removal), exposes setEnabled, and bearer updates preserve prior disabled state. Presentations and workspace models now carry an enabled flag.

Mobile and web UI wire toggles and reconnect flows: cloud rows disable instead of removing registrations; local environment rows get an Enable control, expanded Enabled switch, and a shared ConnectionEnvironmentList. Web Connections adds per-row edit (label/URL + enable) and updateBearerConnection.

Pairing (mobile) improves parsePairingUrl for schemeless hosts (HTTP for IP literals) and adds parsePairingFields so a full pasted URL in Host splits into normalized host + token on blur/submit.

Connectivity adds followNetworkStatus (initial read, stream updates, refresh on app-active wakeups with revision guards). Mobile drops the extra AppState network poll on the connectivity stream; registry startup retries on transient activation failures.

Reviewed by Cursor Bugbot for commit 8cd3edcbdba7a1a48ae818d6eff77b3b5d958617. Bugbot is set up for automated code reviews on this repo. Configure here.

[!NOTE]

Parse pasted pairing links and support enabling/disabling environments in mobile and web

  • Adds parsePairingFields to pairing.ts to extract embedded pairing tokens from the host input field; called on blur and submit in ConnectionsNewRouteScreen
  • Adds parsePairingUrl support for schemeless URLs (including bare host:port) by inferring http for IP literals and https otherwise
  • Introduces an enabled flag for environments across the registry, catalog, presentation, workspace model, and UI — persisted via a new ConnectionActivationStore backed by disabledEnvironmentIds in the storage document
  • Mobile "disconnect" now disables an environment rather than removing it; the row shows a "Disabled" label, an Enable button, and a settings toggle; update/remove actions are hidden while disabled
  • Web settings row gains an enable/disable switch and editable label/URL fields for bearer connections via a new updateBearerConnection command
  • Adds followNetworkStatus in connectivity.ts to serialize network status application, refresh on app-active wakeup, and replace direct stream subscriptions across the registry, supervisor, and relay discovery
  • Behavioral Change: EnvironmentRegistry.start now returns a persistence error and retries with exponential backoff; platform registration clears any disabled flag for shadowed environments

Macroscope summarized 8cd3edc.

DominicVonk avatar Aug 07 '26 10:08 DominicVonk

Review in Change Stack →

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.tsx
  • apps/mobile/src/features/connection/pairing.test.ts
  • apps/mobile/src/features/connection/pairing.ts

Included 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

Layer / File(s) Summary
Normalize and parse pairing URLs
apps/mobile/src/features/connection/pairing.ts, apps/mobile/src/features/connection/pairing.test.ts
Pairing URL construction and parsing normalize protocol-relative inputs to HTTPS, preserve inputs with a scheme, and add HTTP for IP-literal hosts or HTTPS otherwise. parsePairingFields returns parsed fields when parsing finds a code, and otherwise preserves the supplied fields. Tests cover these cases.
Normalize connection form fields
apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx
The form parses its host and code fields on blur and before submission. Submission builds the pairing URL from the parsed values.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: juliusmarminge

Merge Risk: ⚪ Minimal · up to f92dc

The 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 f92dc

A 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

  • Medium · security · inferred: Normalizing a pasted hosted link with a schemeless IP backend changes a previously HTTPS-resolved target into HTTP. The bootstrap credential and returned bearer session then use that unencrypted target, and registration carries forward HTTP/WS endpoints. This newly affects manual pasted-link submission; the corresponding QR behavior and direct manual IP default predate this PR.
Security review details

Security Blast Radius

  • inferred — The identified exposure concerns one submitted backend registration: its bootstrap credential, returned bearer session, and resulting connection endpoints. Exploitation requires network observation or interference where HTTP is permitted; no additional backend privilege is needed to observe plaintext traffic. Broader tenant or infrastructure authority expansion was not established.

Security Findings and Attack Paths

  • inferred — For example, a pasted hosted URL whose host parameter is 192.0.2.10:3773 and whose fragment carries a valid token previously reached shared resolution unchanged and selected HTTPS. Head extraction and rebuilding select HTTP instead. After descriptor compatibility succeeds, the token exchange sends the credential as subject_token to /oauth/token. Where that HTTP request succeeds, an on-path observer can capture credentials; placing the original token in a URL fragment does not protect this subsequent exchange.

Trust Boundaries and Controls

  • observed — Shared resolution still requires a token and limits backend protocols to HTTP, HTTPS, WS, and WSS; it does not require encrypted transport. Explicit HTTPS links retain their scheme. Base manual IP building and QR hosted-link extraction already supported HTTP, limiting the introduced concern to the newly normalized pasted-hosted-link path rather than all pairing traffic.

Resilience and Maintainability Implications

  • observed — Registry registration delegates durable writes to ConnectionRegistrationStore before updating its in-memory target map and installing the entry. The inspected interface does not establish transactional crash recovery or cleanup of a bearer session issued before a persistence failure; these guarantees remain unresolved, not introduced findings.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning 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 … 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 de…
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: parsing pasted pairing links on mobile.
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.

  • [ ] Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create a new PR
  • [ ] Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot] avatar Aug 07 '26 10:08 coderabbitai[bot]

Approvability

Verdict: Approved 055f151

Small, self-contained bug fix adding URL parsing for pasted pairing links on mobile. Changes include helper functions and comprehensive unit tests. The open review comments reference either unrelated files or scenarios covered by tests.

You can customize Macroscope's approvability policy. Learn more.

macroscopeapp[bot] avatar Aug 07 '26 11:08 macroscopeapp[bot]

[!NOTE] This comment is posted by Julius' dot

Closing for missing UI verification. The parser tests are useful, but this also rewrites the visible Host and Pairing Code fields on blur and submit. Please add before/after screenshots and a short recording of pasting a complete link, leaving Host, and connecting with a dummy token, then request reconsideration.

juliusmarminge avatar Oct 01 '26 17:10 juliusmarminge

@juliusmarminge Added the requested UI verification to the PR description for the unchanged head commit 9bdff53.

  • Before / after: with the same complete dummy-token link pasted into Host, leaving Host now extracts the token into Pairing Code. The before capture has this PR's patch reversed.
  • 37-second recording: native Paste menu → leave Host → extracted fields → Add Environment → expected “The environment credential is invalid.” response from a disposable local backend.

Verified in T3 Code Dev on an iOS 27 simulator. Pairing tests (14), mobile typecheck, and targeted lint pass. Only a dummy token appears in the evidence; no successful authentication is claimed. Android was not exercised.

Could you reconsider reopening this PR now that the missing evidence is supplied?

DominicVonk avatar Oct 01 '26 17:10 DominicVonk

Reopened. Please resolve conflcits

juliusmarminge avatar Oct 01 '26 17:10 juliusmarminge

@juliusmarminge Merged current main and resolved the two conflicts in f92dc17624. GitHub now reports the PR as mergeable. The resolution preserves main’s refactored form, connection cleanup/development automation, and updated Effect API; the PR remains a three-file pairing fix.

Rebuilt the matching iOS native client and replaced the PR’s UI evidence with fresh before/after screenshots and a 36-second recording for this merge commit. The recording shows native paste → leave Host → extracted token → Add Environment → expected invalid-dummy-credential error.

All 14 pairing tests and mobile typecheck pass. Targeted lint has zero errors and the same four warnings as main. Android was not exercised.

DominicVonk avatar Oct 01 '26 17:10 DominicVonk

[!NOTE] Written by claude-opus-5-5 on behalf of Maria

Hi! We are cleaning up open PRs, and this one appears to have been created with an older model (gpt-5-codex). If this change is really important, we recommend rebuilding the PR with a newer model if possible.

maria-rcks avatar Oct 11 '26 02:10 maria-rcks