Skip to content

feat(integrations): pair T3 Code directly through Matrix - #1126

Draft
HamedMP wants to merge 27 commits into
mainfrom
codex/t3-connect
Draft

feat(integrations): pair T3 Code directly through Matrix#1126
HamedMP wants to merge 27 commits into
mainfrom
codex/t3-connect

Conversation

@HamedMP

@HamedMP HamedMP commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Summary

  • replace the T3 Connect/Clerk relay flow with direct T3 environment pairing through Matrix OS
  • run the pinned upstream T3 server on 127.0.0.1:3773 in the canonical Matrix Terminal/Zellij session
  • expose only bounded T3 pairing, OAuth, API, asset, and WebSocket paths through /vm/<handle>/api/integrations/t3/
  • derive the validated Matrix handle from the active owner-scoped VM route when the terminal environment omits it
  • preserve URL-triggered setup actions while persisted Terminal windows replace transient launch windows during hydration
  • print a normal one-time pairing URL and QR code for T3 desktop, web, and mobile
  • route preview-VPS pairing through the isolated platform preview while production bundles continue using their own app origin
  • keep preview Clerk handshakes pinned to the configured public HTTPS origin instead of Cloud Run's internal hostname

User story

  1. In T3 Code, the user selects Set up Matrix OS.
  2. Matrix opens its canonical Terminal and asks for consent before installing the pinned T3 CLI preview.
  3. Matrix asks an existing loopback T3 server for a fresh pairing link, or starts t3 serve and prints one.
  4. The user scans the QR code on mobile or pastes the link into T3 desktop/web.
  5. T3 performs its existing one-time credential exchange, saves the Matrix environment, and connects through Matrix's scoped HTTPS/WebSocket proxy.

This flow does not use T3 Connect, a T3 account, Cloudflare Tunnel, or a long-lived Matrix-specific T3 fork. Matrix OS itself still uses Clerk for Matrix account authentication.

Tests

  • focused Matrix/T3 gateway, platform, and shell suite: 5 files / 200 tests passed
  • terminal preview-origin tests: 16 tests passed
  • bun run check:patterns: 0 violations (existing general warnings only)
  • git diff --check: passed
  • changed-scope React Doctor: no errors; 10 existing branch warnings
  • root and shell typechecks are blocked before the changed file by existing linked-worktree @matrix-os/contracts export-resolution errors
  • broad Node 24 test execution was attempted; existing Codex app-server/control tests time out outside this patch, while the complete changed-scope suite passes

Invariants

Source of truth

  • T3 owns environment sessions, one-time pairing credentials, DPoP verification, and WebSocket tickets.
  • Matrix owns runtime routing and loopback-to-public path mapping; it stores no T3 account credential.
  • A build-scoped proxy origin is accepted only as a clean HTTPS origin; unsafe values fail closed to the normal app origin.

Lock/transaction scope

  • No database writes or multi-store transactions are introduced.
  • Gateway proxy state is bounded in memory and scoped to each live request or WebSocket connection.

Acceptable orphan states

  • If setup is canceled before consent, nothing is installed or started.
  • If the Terminal closes, the direct environment is offline until setup restarts the named session; no external relay remains.
  • Pairing links expire and are one-time credentials enforced by T3.

Auth source of truth

  • Matrix session auth remains authoritative for setup and normal VM access.
  • The narrow public integration route delegates pairing/session authorization to T3; paths outside the explicit allowlist fail closed.
  • The proxy does not trust forwarded client identity headers and does not forward Matrix credentials upstream.
  • Preview builds advertise the isolated preview platform; production builds do not receive that override.

Deferred scope

  • Publishing the first upstream T3 release containing path-prefix and --pairing-base-url support is a rollout dependency.
  • Background boot persistence and a Matrix-owned relay are not part of this direct-pairing flow.

Paired PR

Test plan

  1. Open https://app.matrix-os.com/vm/pr-1126?launch=__terminal__&terminal_action=t3-connect.
  2. Approve setup and verify the pairing URL uses https://preview.matrix-os.com/vm/pr-1126/api/integrations/t3/.
  3. Scan the QR in T3 mobile or paste it into T3 desktop/web.
  4. Confirm pr-1126 appears as a normal remote environment without a T3 account.
  5. Open a project and verify HTTP actions, assets, and the live WebSocket session.
  6. Stop the Matrix Terminal session and verify the environment goes offline without leaving a managed relay.

Summary:
- preserve a bounded T3 Connect request through auth and billing
- open the canonical Terminal across desktop, Canvas, and mobile
- require confirmation before running the pinned T3 CLI

Rationale:
- let T3 clients bootstrap a persistent Matrix OS environment
- keep credentials out of the handoff and prevent replay or unsafe actions

Tests:
- focused platform auth, billing, and redirect tests
- focused desktop, Canvas, mobile, queue, and command tests
- @matrix-os/platform build
HamedMP added 5 commits July 31, 2026 14:55
Summary:
- exercise the exact handoff URL at the ShellHome boundary
- verify both desktop and mobile renderers receive the canonical Terminal action

Tests:
- tests/shell/shell-home-launch.test.tsx
- focused Matrix handoff suites
Summary:
- create T3 setup as a canonical named Zellij shell session
- link the T3 account before starting the long-running relay server
- cover consent, command quoting, and canonical session creation

Rationale:
- Matrix VPSes do not expose a user systemd manager for T3 persistence
- keeping serve attached to Zellij survives browser disconnects and remains
  visible to the user

Tests:
- pnpm exec vitest run tests/shell/terminal-launch.test.ts
  tests/shell/terminal-mobile-actions.test.tsx
Summary:
- preserve a bounded T3 Connect request through auth and billing
- open the canonical Terminal across desktop, Canvas, and mobile
- require confirmation before running the pinned T3 CLI

Rationale:
- let T3 clients bootstrap a persistent Matrix OS environment
- keep credentials out of the handoff and prevent replay or unsafe actions

Tests:
- focused platform auth, billing, and redirect tests
- focused desktop, Canvas, mobile, queue, and command tests
- @matrix-os/platform build
Summary:
- exercise the exact handoff URL at the ShellHome boundary
- verify both desktop and mobile renderers receive the canonical Terminal action

Tests:
- tests/shell/shell-home-launch.test.tsx
- focused Matrix handoff suites
Summary:
- create T3 setup as a canonical named Zellij shell session
- link the T3 account before starting the long-running relay server
- cover consent, command quoting, and canonical session creation

Rationale:
- Matrix VPSes do not expose a user systemd manager for T3 persistence
- keeping serve attached to Zellij survives browser disconnects and remains
  visible to the user

Tests:
- pnpm exec vitest run tests/shell/terminal-launch.test.ts
  tests/shell/terminal-mobile-actions.test.tsx
HamedMP added 3 commits August 3, 2026 09:36
Summary:
- expose a bounded HTTP and WebSocket proxy to a loopback T3 server
- launch T3 pairing from the canonical Matrix terminal without Clerk
- preserve explicit VM routing and document the direct-pairing contract
- cap requests, frames, buffers, handshakes, and active connections

Rationale:
- users should pair normal T3 clients with their Matrix computer without a
  T3 account or the managed T3 Connect relay
- the T3 server stays loopback-only while Matrix owns public routing and
  T3 continues to authenticate pairing and session credentials

Tests:
- 208 focused gateway, platform, and shell tests passed
- bun run check:patterns (0 violations)
- changed package typechecks passed; root desktop baseline has two existing
  implicit-any errors in untouched files
- bun run test reached unrelated existing Codex workspace-provider failures
@HamedMP HamedMP changed the title feat(shell): add secure T3 Connect handoff feat(integrations): pair T3 Code directly through Matrix Aug 3, 2026
@HamedMP HamedMP added preview-vps Deploy a disposable preview VPS (pr-<N>) running this PR's host bundle preview-platform Deploy a zero-traffic platform preview revision to the preview Cloud Run service labels Aug 3, 2026
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Platform preview revision deployed

Runs as the preview runtime SA against the staging database with Stripe TEST-mode keys; production service, SA, database, and live Stripe keys are untouched.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Preview VPS deployed

  • Shell: https://app.matrix-os.com/vm/pr-1126
  • Bundle: v2026.08.04-pr1126-fa047fc
  • Logs (from the ops box): ./scripts/preview-logs.sh --handle pr-1126 (enroll first with ./scripts/enable-vps-logship.sh pr-1126 preview)

The VPS is deleted when this PR closes, or by the daily reaper after 72h.

@HamedMP HamedMP removed the preview-vps Deploy a disposable preview VPS (pr-<N>) running this PR's host bundle label Aug 3, 2026
@HamedMP HamedMP removed the preview-platform Deploy a zero-traffic platform preview revision to the preview Cloud Run service label Aug 3, 2026
HamedMP added a commit that referenced this pull request Aug 3, 2026
## Summary

- ask first-time users where they heard about Matrix inside the Settings-owned onboarding surface
- offer a bounded source list for TikTok, Instagram, YouTube, X/Twitter, Reddit, search, friend/colleague, and other
- record a viewed event, a submitted event, and set-once PostHog person properties for first-touch attribution
- align acquisition sources and coding agents into compact numbered rows
- support `1`-`8` source selection, `1`-`4` agent toggles, and Enter-to-continue/build with minimal button hints
- add staggered, reduced-motion-safe entrance and selection feedback
- use the main shell's default Moraine Lake wallpaper behind Settings in every pre-VPS onboarding path
- allow that wallpaper through the platform-owned shell's prefixed public-asset route
- continue directly into the coding-agent chooser from merged parent PR #1086
- restore explicit callback types in two current-main desktop components so the restacked head passes strict typecheck
- leave reused add-computer install flows unchanged

## Screenshots

### 1. Acquisition question inside Settings

TikTok is selected here to show the active row, number shortcut, minimal Enter hint, and the production default shell wallpaper.

![Keyboard-first acquisition source question over the Matrix wallpaper](https://raw.githubusercontent.com/HamedMP/matrix-os/035159b98b/specs/099-onboarding-journey/screenshots/settings-acquisition-source-desktop.png)

### 2. Immediate handoff to coding-agent selection

Continue keeps the user in the same Settings shell and moves directly into numbered coding-agent rows from #1086.

![Numbered coding-agent install choices over the Matrix wallpaper](https://raw.githubusercontent.com/HamedMP/matrix-os/035159b98b/specs/099-onboarding-journey/screenshots/settings-acquisition-source-handoff-desktop.png)

## Tests

- `pnpm exec vitest run --reporter=dot tests/deploy/cloud-workspace-runtime.test.ts tests/shell/onboarding-acquisition-source.test.tsx tests/shell/posthog-session-replay.test.tsx tests/shell/settings-panel.test.tsx tests/shell/platform-shell-assets.test.ts tests/shell/boot-sequence.test.tsx tests/shell/billing-gate.test.tsx tests/shell/runtime-manager.test.tsx tests/observability/telemetry-events.test.ts` (94 passed on rebased head)
- `pnpm exec vitest run --reporter=dot tests/gateway/coding-agents-codex-app-server-contract.test.ts tests/gateway/coding-agents-codex-events.test.ts tests/scripts/check-codex-provider-contracts.test.ts tests/deploy/cloud-workspace-runtime.test.ts tests/gateway/agent-launcher.test.ts` (43 passed on rebased head)
- `pnpm exec vitest run tests/desktop/command-palette.test.tsx tests/desktop/panel-strip.test.ts tests/desktop/panel-strip-render.test.tsx` (20 passed)
- `bun run typecheck` (passed)
- `bun run check:patterns` (0 violations; existing warning groups only)
- local full sweep: 9,209 passed; 11 platform/integration timeouts caused by an overlapping host test run all passed in single-worker isolation; six unrelated `tests/ui/*` suites remain blocked locally by the shared pnpm store failing to resolve `vitest` from `@testing-library/jest-dom`, while exact-head Core CI is the canonical clean install

## Review/Monitoring

- parent PR #1086 merged through Graphite; this PR is rebased directly onto its squash commit on `main`
- temporary current-main Hermes and Codex compatibility backports dropped cleanly during the rebase because `main` already contains them
- audited all open PRs by changed file before implementation
- avoids #1096's signup/billing handoff files beyond the inherited parent work
- does not change #985's broader Agent Settings work or #1126's T3 Connect behavior
- the initial stack merge landed #1086 and stopped on the child's post-squash conflict; this head is the conflict-free restack for final exact-head review and CI

## Invariants

- **Source of truth:** PostHog's identified event stream and set-once person properties are the attribution source of truth; the UI keeps only transient selection state.
- **Lock/transaction scope:** no database or multi-write persistence is introduced.
- **Acceptable orphan states:** analytics capture may be unavailable or consent-limited without blocking onboarding or VPS provisioning.
- **Auth source of truth:** the existing Clerk-identified shell session remains authoritative; telemetry continues through the existing same-origin PostHog relay and consent configuration.
- **Deferred scope:** no free-text attribution, platform database column, historical backfill, add-computer prompt, campaign dashboard, or public documentation change is included.
@HamedMP HamedMP added preview-vps Deploy a disposable preview VPS (pr-<N>) running this PR's host bundle preview-platform Deploy a zero-traffic platform preview revision to the preview Cloud Run service labels Aug 3, 2026
Resolve manual preview deployments against the requested pull request head and bake the configured Clerk publishable key into the shell image. Add regression coverage for both invariants.
Carry the disposable preview's validated owner and collaborator Clerk IDs into the isolated Cloud Run route. Reuse the preview provisioning schema so malformed, duplicate, or owner-overlapping access lists fail closed.
HamedMP added 2 commits August 3, 2026 15:57
Treat an omitted preview collaborator list as empty while still requiring and validating the real owner identity. This keeps older fleet records deployable without broadening access.
Set the public Matrix app URL on the running preview auth shell so Clerk redirects never inherit Cloud Run's internal host. Add workflow regression coverage for the runtime configuration.

Tests: focused preview workflow test; YAML parse; diff check; pattern scan. Repo-wide checks remain blocked by existing Node 22/24 and native module mismatches plus unrelated desktop type errors.
Move the Matrix return URL out of Clerk's reserved redirect_url query parameter and pass an absolute, allowlisted public VM handoff to the sign-in and sign-up components.

Tests: 45 focused shell tests pass; pattern scan passes. React Doctor reports no findings in the changed auth files. Production build remains blocked by unrelated local Langium dependency links.
Summary:
- pin Clerk forwarded origin headers to the configured public app URL
- cover Cloud Run internal-host handshakes with a regression test

Rationale:
- prevent Clerk from rejecting preview redirects derived from the internal Cloud Run service origin

Tests:
- vitest auth handoff suite (46 passed)
- bun run check:patterns (0 violations)
- production build attempted; blocked by unrelated missing linked Langium dependency
Summary:
- merge the latest origin/main into the T3 integration branch
- preserve direct T3 handoff behavior on the new action-based terminal API
- retain new Hermes and OpenClaw setup actions across desktop and mobile

Rationale:
- resolve PR 1126 conflicts without dropping either the T3 flow or current main behavior

Tests:
- 6 focused shell files, 101 tests passed
- react-doctor changed scope: 0 errors, 10 warnings
- git diff --check
Use the owner-scoped /vm/:handle route as a validated fallback when MATRIX_HANDLE is absent from the terminal shell. This keeps the direct pairing URL scoped to the active preview or customer computer.

Add an executable regression test for the missing-environment case and align the mobile action assertions with the pinned T3 preview package.
Queue URL-triggered setup actions without a transient Terminal window ID so the canonical desktop or mobile Terminal that survives hydration can drain the one-shot handoff.

Add a regression that simulates the persisted Terminal replacing the initial launch target. Validated with 106 focused tests, the pattern scan, diff checks, and changed-scope React Doctor.
Summary:
- allow a validated build-scoped HTTPS origin for T3 pairing links
- configure preview VPS bundles to advertise preview.matrix-os.com
- cover safe override and unsafe fallback behavior

Rationale:
- PR preview clients must reach the credentialless platform changes under
  test instead of the production Clerk-gated route
- production bundles remain unchanged when no preview origin is configured

Tests:
- pnpm exec vitest run tests/shell/terminal-launch.test.ts
- focused Matrix/T3 suite: 200 tests passed
- bun run check:patterns (0 violations)
- typecheck attempted; blocked by unrelated stale contracts build errors
HamedMP added a commit that referenced this pull request Aug 4, 2026
The guidance claimed Greptile never runs without an @greptileai mention and
that an unreviewed PR "will sit indefinitely". Observed behavior across six
PRs contradicts that: opening a non-draft PR spends one automatic review on
the initial head. PR #1134 was reviewed 29 minutes before its first mention,
and #1128 was reviewed with no mention anywhere; the draft PR #1126 got none.

Only later commits require an explicit mention -- which is why this PR's own
5/5 was stale against its second commit. The absolute framing pushed agents
to pay for a mention on freshly opened PRs where a free review was already
inbound, inverting the cost goal of the original change.

Also adds the check that a review's footer names the commit it covers, so a
5/5 against a superseded head is not mistaken for satisfying the merge gate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview-platform Deploy a zero-traffic platform preview revision to the preview Cloud Run service preview-vps Deploy a disposable preview VPS (pr-<N>) running this PR's host bundle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant