Hermes has a first-class "home channel": the default destination for output nobody asked for at a specific address — a cron result, an agent-initiated `send_message`, a gateway lifecycle notice, a `/handoff`. The T3 plugin opted out, suppressing Hermes' "Type /sethome" nudge without designating anything. A cron job with `deliver=t3` went nowhere, `send_message` to a bare `t3` target errored, and `/handoff t3` hard-failed. Each enrolled instance now gets one Home thread, pinned first in its agent project, fully conversational, undeletable, created automatically. Protocol v3. `connection.hello` gains `role: "gateway" | "delivery"`; `connection.accepted` carries `homeThreadId`. Two new frames: `home.deliver` and `home.deliver.ack`. Designation converges on read, like agent projects — a precondition every handshake runs rather than an event one caller owns, so an instance enrolled before this shipped, or one whose thread creation failed once, heals on the next connect. It lives in the instance's settings blob beside `connectorUrl` and `revoked`; the plugin's `T3_HOME_CHANNEL` is a cache of it, reconciled every handshake. The existence check deliberately ignores archive state. Every other thread read filters `archived_at IS NULL`, which is right for "what should the user see" and wrong for "does this row exist" — an archived Home read as deleted and the self-healing path replaced it, stranding the history in a thread the user had merely parked. A delivery to an archived Home now un-archives it, the same way incoming activity wakes a settled or snoozed thread. Deliveries bypass the turn machinery entirely. One may arrive while the home thread has a live user turn, so it appends as a turnless assistant message carrying `notification` provenance rather than joining the turn — attributing it would fold it away behind that turn's "Worked for …". Everything except a lifecycle notice un-settles the thread and pushes; lifecycle notices land quietly. Idempotency is load-bearing, because the plugin's durable queue retries anything it has not seen acked. T3 dedupes on `deliveryId` against `projection_thread_messages` before dispatching — the decider's own scan sees the in-memory read model, which is built with `messages: []`, so it cannot catch a replay after a restart. The ack is sent only after the write lands. An out-of-process cron run dials in with `role: "delivery"`: authenticated identically, but never registered as the instance's primary connection, so it cannot displace a live gateway socket or answer its pending requests. Plugin side, the proactive branch in `send()` gates on provenance rather than turn absence. The naive rule — "no active turn, so deliver" — would let a notify-stamped cron delivery complete a user's live turn with cron output as its answer. A bare session-key mismatch is not enough either, since `HERMES_SESSION_KEY` resolves empty whenever the context did not propagate; that would tear a genuine reply out of its turn. Bypassing a live turn requires positively identified cron/lifecycle/handoff provenance. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
T3 Connect Relay
Warning
T3 Connect is currently in private beta. Join the waitlist in the app under Settings > T3 Connect.
The relay is the hosted control plane for T3 Connect. It helps clients discover and connect to remote environments, manages the cloud-side records needed for those connections, and delivers optional mobile notifications and Live Activities.
The relay is intentionally not in the hot path for normal T3 Code traffic. After a client connects, regular API and WebSocket traffic goes directly between that client and the selected environment. See the T3 Connect architecture overview for the larger system design.
Responsibilities
The relay currently owns:
- Linking T3 Code environments to a cloud account.
- Provisioning and tracking managed environment endpoints.
- Issuing short-lived credentials used to connect clients to linked environments.
- Listing linked environments and registered mobile devices for an account.
- Registering mobile notification preferences and APNs tokens.
- Receiving published agent activity and delivering notifications or Live Activity updates.
- Persisting relay state and exposing relay-specific traces for diagnostics.
The environment server and relay have separate credentials and trust boundaries. Read Environment Authentication Profile before changing token, credential, or authorization behavior.
Code Map
alchemy.run.tsdefines the deployed Alchemy stack.src/worker.tswires Cloudflare bindings, runtime layers, queues, and HTTP APIs.src/http/Api.tscontains the relay HTTP handlers and authentication boundaries.src/environmentscontains environment linking, credentials, endpoint provisioning, and connection flows.src/agentActivitycontains mobile device registration, activity state, APNs delivery, and queue processing.src/authcontains relay token and DPoP proof handling.src/persistence/schema.tsdefines persisted relay state. Keep schema and migration changes together.
Shared request and response schemas live in
packages/contracts/src/relay.ts. Shared client-side relay
calls live in
packages/client-runtime/src/relay/managedRelay.ts.
Working Locally
Install dependencies from the repository root, then run relay-focused checks from this directory:
vp install
cd infra/relay
vp test run
vp run typecheck
To run a smaller test set while iterating:
vp test run src/environments/EnvironmentLinker.test.ts
Before considering a change complete, run the repository-wide checks from the root:
vp check
vp run typecheck
Backend changes should include tests. Prefer testing the real business logic with external dependencies represented at their boundary rather than mocking internal behavior.
Deployment
The relay deploys through Alchemy:
vp run --filter t3code-relay deploy
The stack provisions the Cloudflare Worker and queues, managed endpoint resources, database
connectivity, and relay tracing resources. Copy infra/relay/.env.example to
infra/relay/.env and fill in the deployment-specific values before deploying. Alchemy loads that
file from the relay directory. Runtime secrets include Clerk and APNs credentials. Production adopts
the configured API and tunnel DNS zones as retained Cloudflare resources. Personal stages reference
the production-owned zones.
The prod Alchemy stage owns the retained PlanetScale database and is the shared hosted relay for
stable and nightly clients. Every other stage references that database and provisions an isolated
PlanetScale branch and runtime role for local development, so deploy prod before creating
developer stages:
vp run --filter t3code-relay deploy -- --stage prod
vp run --filter t3code-relay deploy -- --env-file .env.local
Alchemy defaults personal deployments to the dev_$USER stage. Relay custom domains apply the same
DNS-safe sanitization as Alchemy physical resource names, so prod uses
relay.<RELAY_API_ZONE_NAME> and dev_julius uses
relay-dev-julius.<RELAY_API_ZONE_NAME>. Managed environment endpoints are provisioned below
RELAY_TUNNEL_ZONE_NAME, which may be a different Cloudflare zone. Production tunnel hostnames use
prod-<digest>.<RELAY_TUNNEL_ZONE_NAME>; personal stages use
<stage>-<digest>.<RELAY_TUNNEL_ZONE_NAME>. RELAY_DOMAIN remains available as an explicit API
domain override.
After a successful deploy, the wrapper updates the repository-root .env file with the derived relay
URL. That makes subsequent source builds point at the relay that was just deployed without copying
the URL manually.
Deployment CI
The relay is versioned separately from client releases. .github/workflows/deploy-relay.yml deploys
the shared Alchemy prod stage on every push to main. Stable and nightly release builds both
resolve their static public config from the same
production GitHub environment. Pull requests do not deploy relay stages. Developers can
deploy personal non-production stages locally with any stage name other than prod.
The repository must define these Actions variables shared by relay deployments:
CLOUDFLARE_ACCOUNT_IDPLANETSCALE_ORGANIZATIONAXIOM_ORG_ID
The repository must define these Actions secrets shared by relay deployments:
CLOUDFLARE_API_TOKENPLANETSCALE_API_TOKEN_IDPLANETSCALE_API_TOKENAXIOM_TOKEN
The production GitHub environment must define these Actions variables:
RELAY_API_ZONE_NAMERELAY_TUNNEL_ZONE_NAMERELAY_DOMAINif overriding the derived production relay domainCLERK_PUBLISHABLE_KEYCLERK_JWT_AUDIENCECLERK_JWT_TEMPLATEAPNS_ENVIRONMENTAPNS_TEAM_IDAPNS_KEY_IDAPNS_BUNDLE_ID
The production GitHub environment must define these Actions secrets:
CLERK_SECRET_KEYAPNS_PRIVATE_KEY
The account-scoped repository credentials are consumed by Alchemy while provisioning relay stages; they
are not bound into the relay Worker. The production deployment uses an Axiom personal access token,
so AXIOM_ORG_ID must accompany AXIOM_TOKEN. The release workflow reads the production relay's
derived public URL and Clerk publishable key from the same environment for downstream desktop, CLI,
and hosted web builds.
See:
- T3 Connect Clerk Setup for Clerk keys, JWT templates, and waitlist setup.
- Relay Observability for deployment tracing and diagnostics.
- T3 Connect Architecture Overview for the full link, connect, endpoint, and notification flows.