Skip to content

feat(cloud): enable the fork-owned Connect relay and release config - #476

Merged
shuv1337 merged 2 commits into
mainfrom
t3/enable-s2connect-relay
Nov 22, 2026
Merged

shuv1337 merged 2 commits into
mainfrom
t3/enable-s2connect-relay

Conversation

@shuv1337

Copy link
Copy Markdown
Owner

Problem

The vendored Connect relay (infra/relay) unconditionally refused deployment, release workflows could not wire fork-owned Connect configuration (including the fork's pinned T3CODE_CLOUD_MINT_PUBLIC_KEY) into desktop and CLI builds, and client/server code paths still assumed a hosted web origin or upstream PlanetScale/Axiom accounts.

How this fixes it

  • Relay ownership preflight, mint key export & Postgres backends (Sections A & F):
    • Replaced the unconditional throw in infra/relay/alchemy.run.ts with assertForkRelayDeploymentEnv (infra/relay/src/forkOwnership.ts), running before Alchemy.Stack constructs providers or state: pins CLOUDFLARE_ACCOUNT_ID on Cloudflare.state({ accountId }), rejects upstream domains and RFC 2606 placeholders (example.com, .example, .invalid, .test), validates CLERK_PUBLISHABLE_KEY, and fails closed if neither external Postgres (RELAY_DB_HOST) nor PlanetScale (PLANETSCALE_ORGANIZATION) is configured.
    • Exported CloudMintKeyPair from infra/relay/src/worker.ts, included cloudMintPublicKey in stack outputs, and updated PublishClientConfig (infra/relay/src/clientConfig.ts) to write single-line \n-escaped T3CODE_CLOUD_MINT_PUBLIC_KEY.
    • Parameterized PlanetScale sizing in infra/relay/src/db.ts / dbConfig.ts (RELAY_DB_CLUSTER_SIZE default PS_5, RELAY_DB_REPLICAS default 0 instead of PS_160 / 2 replicas) and added external Postgres mode selected by RELAY_DB_HOST supporting both Cloudflare Access + Tunnel (AccessOrigin) and public (PublicOrigin) Hyperdrive origins with configurable RELAY_DB_CONNECTION_LIMIT (default 20 for external, 40 for PlanetScale). External mode fails clearly on non-prod stages.
    • Added an Alchemy/Drizzle-compatible Postgres migration runner (infra/relay/src/postgresMigrations.ts, infra/relay/scripts/migrate-postgres.ts, vp run --filter t3code-relay migrate:postgres) writing the exact relay_migrations schema and SHA-256 bookkeeping so databases stay portable between external Postgres and PlanetScale.
  • No-Axiom observability & optional OTLP traces (Section G):
    • When AXIOM_TOKEN is unset, no Axiom datasets/tokens/views/monitors or mobile source-map R2 bucket/credentials are created (infra/relay/src/observability.ts, alchemy.run.ts, worker.ts), mobile observe routes respond 503 mobile_telemetry_not_configured (MobileTelemetry.layerDisabled), and PublishClientConfig writes only T3CODE_RELAY_URL and T3CODE_CLOUD_MINT_PUBLIC_KEY.
    • Added optional generic OTLP/HTTP Worker trace export via Alchemy.Telemetry.layerOtlp when RELAY_OTLP_TRACES_URL (and optional RELAY_OTLP_TRACES_TOKEN) is configured. With AXIOM_TOKEN set, upstream Axiom behavior stays intact.
  • Workflows (Section B):
    • Restored .github/workflows/deploy-relay.yml for shuv1337/s2code refs/heads/main on ubuntu-24.04 inside environment: production with concurrency (cancel-in-progress: false), path-filtered push (skipping cleanly while vars.RELAY_API_ZONE_NAME is empty), external Postgres migration step over cloudflared access tcp before deploy, APNS_ENABLED defaulting to false, no APNs/FCM/T3Chat secrets, and a final step writing only public T3CODE_RELAY_URL and single-line T3CODE_CLOUD_MINT_PUBLIC_KEY to $GITHUB_STEP_SUMMARY.
    • Gated every job in .github/workflows/relay-preview.yml and .github/workflows/relay-preview-cleanup.yml on github.repository == 'shuv1337/s2code' && vars.RELAY_PREVIEWS_ENABLED == 'true'. .github/workflows/web-preview.yml remains notice-only.
    • Wired all-or-nothing public Connect repository variables into release.yml (preflight, build_bundle, and all four release-desktop.yml callers), release-desktop.yml (new cloud_mint_public_key and hosted_app_url inputs for CLI build-exe), and encrypted-windows-build.yml, without entering environment: production.
  • Client/server/packaging gaps & docs (Sections C, D & E):
    • Added CLOUD_MINT_PUBLIC_KEY to PUBLIC_CONFIG_KEYS (packages/shared/src/productIdentity.ts) and mapped T3CODE_CLOUD_MINT_PUBLIC_KEY + T3CODE_HOSTED_APP_URL -> VITE_HOSTED_APP_URL in scripts/lib/public-config.ts.
    • Updated hasCloudPublicConfig (apps/server/src/cloud/publicConfig.ts) to require a pinned mint public key instead of T3CODE_HOSTED_APP_URL, and updated authorizeCli (apps/server/src/cli/connect.ts) to fall back to Clerk's device-authorization flow when no hosted app URL is configured.
    • Keyed macOS passkey signing (scripts/build-desktop-artifact.ts) on T3CODE_MACOS_PROVISIONING_PROFILE or T3CODE_CLERK_PASSKEY_RP_DOMAINS so signed macOS builds with T3CODE_CLERK_PUBLISHABLE_KEY do not fail without a provisioning profile.
    • Updated unconfigured copy (HOSTED_UNAVAILABLE_MESSAGE, binCli.ts), added browser-origin guidance on web when a pk_live_ build runs on a private origin (SavedEnvironmentRows.tsx + all 10 locale catalogs), and updated docs/operations/hosted-fork.md, docs/operations/connect-setup.md, infra/relay/.env.example, and .env.example.

What stays off

  • With no variables set: Connect remains off, nightlies build cloudless, direct/Tailscale pairing is untouched, and push deploys skip cleanly.
  • Hosted static web / Vercel (web-preview.yml stays notice-only), relay PR previews (RELAY_PREVIEWS_ENABLED unset), APNs/FCM push (APNS_ENABLED=false), T3 Chat account linking, mobile store builds, and Axiom paging monitors remain off.
  • Broad "T3 Connect" -> "S2 Connect" UI rename (Branding: remaining T3 Code leftovers outside #380 #462) and guest-share porting remain out of scope.

Operator variables and secrets

GitHub Environment: production (used only by deploy-relay.yml)

  • Core secrets: CLOUDFLARE_API_TOKEN, CLERK_SECRET_KEY
  • Core variables: CLOUDFLARE_ACCOUNT_ID, RELAY_API_ZONE_NAME (also set as a repository variable to enable path-filtered push deploys on main; keeping it only in production restricts deploys to workflow_dispatch), RELAY_TUNNEL_ZONE_NAME, CLERK_PUBLISHABLE_KEY, CLERK_JWT_AUDIENCE (t3-code-relay), optional RELAY_DOMAIN, APNS_ENABLED (false), RELAY_TUNNEL_CLEANUP_MODE, RELAY_LEGACY_TUNNEL_CLEANUP_MODE
  • Self-hosted Postgres (selected when RELAY_DB_HOST is set):
    • Variables: RELAY_DB_HOST, RELAY_DB_NAME, RELAY_DB_USER, optional RELAY_DB_PORT (public origin only), optional RELAY_DB_CONNECTION_LIMIT (default 20)
    • Secrets: RELAY_DB_PASSWORD, plus RELAY_DB_ACCESS_CLIENT_ID and RELAY_DB_ACCESS_CLIENT_SECRET (both set for Cloudflare Tunnel + Access AccessOrigin, or both unset for PublicOrigin)
  • Optional self-hosted Worker OTLP traces (when AXIOM_TOKEN is unset): variable RELAY_OTLP_TRACES_URL, optional secret RELAY_OTLP_TRACES_TOKEN
  • Optional upstream PlanetScale + Axiom mode (leave unset on self-hosted stack): variables PLANETSCALE_ORGANIZATION, RELAY_DB_CLUSTER_SIZE (default PS_5), RELAY_DB_REPLICAS (default 0), AXIOM_ORG_ID; secrets PLANETSCALE_API_TOKEN_ID, PLANETSCALE_API_TOKEN, AXIOM_TOKEN

GitHub Repository Variables (public build config read by release.yml and encrypted-windows-build.yml)

Validated all-or-nothing (all five required, or all unset for cloudless builds):

  • T3CODE_RELAY_URL
  • T3CODE_CLOUD_MINT_PUBLIC_KEY (single-line \n-escaped PEM from the deploy-relay.yml summary)
  • T3CODE_CLERK_PUBLISHABLE_KEY
  • T3CODE_CLERK_JWT_TEMPLATE (t3-relay)
  • T3CODE_CLERK_CLI_OAUTH_CLIENT_ID
  • T3CODE_HOSTED_APP_URL (optional)

Refs #331

Rat-stack pages followed

  • ratstack://lore/testing-ladder
  • ratstack://skills/security-audit
  • ratstack://lore/agent-source-first-workflow
  • ratstack://skills/learn-alchemy

Verification

  • Focused unit tests (nice -n 19 vp test run --maxWorkers=4 across 14 changed test files, including PGlite migration tests): 14/14 files, 213/213 tests passed.
  • Encrypted Windows workflow tests (node --test .github/scripts/encrypted-windows-delivery.test.cjs): 7/7 passed.
  • i18n catalog check (vp run i18n:check): passed for apps/web, apps/mobile, apps/desktop.
  • Affected-package typechecks (t3code-relay, @t3tools/shared, t3, @t3tools/web, @t3tools/scripts): 5/5 passed.
  • nice -n 19 node scripts/check-changed.ts --concurrency 2: passed (unused patches, format, lint, knip 1/2, knip 2/2, graphql, typecheck 43/43, test 18 files / 234 tests, react compiler 2 files).

Implemented by gemini-4-neon (Cursor harness via T3 Code).

shuv1337 and others added 2 commits November 21, 2026 23:08
Co-authored-by: Cursor <cursoragent@cursor.com>
…reflight

Co-authored-by: Cursor <cursoragent@cursor.com>
@shuv1337
shuv1337 merged commit e98f583 into main Nov 22, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant