Skip to content

Commit bac8741

Browse files
radroidclaude
andcommitted
feat(coil): move the relay, keeping the old hostname alive as a proxy (#71)
coil-update-relay becomes the real Worker and DEFAULT_RELAY_URL points at it. The t3x hostname is NOT retired — it is redeployed from the same package as a pass-through, and it has to keep serving indefinitely. That is not caution. DEFAULT_RELAY_URL is compiled in, the env override that could repoint an install is never set in practice (a .app launched from Finder inherits launchd's environment, not a shell's), and a build that stops finding its relay has no remaining channel through which to be told about a new one. Renaming it in one shot silently strands every build ever shipped. The shim proxies rather than redirects, which the issue left open as "proxy or 302". They are not equivalent here: relayClient.ts talks through Effect's HttpClient, not fetch, and classifies any non-2xx as bad-status on both the /latest poll and the long-lived /events stream. Whether that client follows a 307, and whether it does so on a text/event-stream response it means to keep open, cannot be established against builds already on other people's machines — and being wrong does not degrade them, it strands them. A pass-through raises no such question: the bytes, the status and the streaming behaviour are the upstream response. It forwards every method and path, /notify included. The release workflow is supposed to post to the new host, but that target lives in a repo variable this repository cannot read, so forwarding costs one line and removes an assumption. The HMAC covers body and timestamp, not hostname. UpdateChannel is still exported from the shim although nothing reaches it: this deploys OVER the existing Worker, whose migration history has the class, and dropping the export would make the deploy an implicit class deletion that Cloudflare refuses without a deleted_classes migration. Keeping it makes both the cutover and the rollback ordinary code deploys. Deploy order matters and the README says so: coil-update-relay first, notify it once, shim second. Reversed, every installed build is briefly pointed at a relay whose /latest is null — which reads as "nothing to act on" rather than an error, so nothing breaks, but nobody sees an update until the next release. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 9435bb7 commit bac8741

8 files changed

Lines changed: 190 additions & 8 deletions

File tree

‎apps/coil-home/src/lib/releases.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
* desktop app's updater consumes, so the site and the app agree on what "latest" means by
88
* construction rather than by coincidence.
99
*/
10-
// This hostname is `t3x`-named on purpose: it is the live relay every installed desktop build
11-
// polls, and renaming it would strand them. Issue #71 migrates it. Do not sweep it into a rename.
12-
const MANIFEST_URL = "https://t3x-update-relay.businesses.workers.dev/latest";
10+
// Moved to the renamed relay by #71. Safe to move here, unlike in the desktop app: this page is
11+
// fetched fresh on every visit, so it has no old copies of itself in the field. The old hostname
12+
// still answers — it proxies to this one for builds that predate the rename — but pointing the
13+
// site through a shim it does not need would just add a hop.
14+
const MANIFEST_URL = "https://coil-update-relay.businesses.workers.dev/latest";
1315
const CACHE_KEY = "coil-latest-manifest";
1416

1517
export const RELEASES_URL = "https://github.com/radroid/t3code/releases";

‎apps/desktop/src/coil/updateDelivery/config.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ import { SHORT_SHA_LENGTH } from "./manifest.ts";
2020
* metadata, it is stable across every build, and baking it in through the packaged `package.json`
2121
* would mean editing `scripts/build-desktop-artifact.ts` — an upstream file this fork does not
2222
* touch, and a seam row that buys nothing.
23+
*
24+
* Being hardcoded is also why the #71 rename could not simply move it. Every build shipped before
25+
* this line changed has the OLD hostname compiled in, cannot be reconfigured (the override below
26+
* is never set on a normal install), and has no other channel through which to be told. So the old
27+
* hostname was not renamed — it stays deployed, permanently, as a pass-through to this one. See
28+
* `infra/coil-update-relay/src/legacyWorker.ts`. Changing this constant is safe precisely because
29+
* that file exists; changing it without one would be a silent, unrecoverable strand.
2330
*/
24-
export const DEFAULT_RELAY_URL = "https://t3x-update-relay.businesses.workers.dev";
31+
export const DEFAULT_RELAY_URL = "https://coil-update-relay.businesses.workers.dev";
2532

2633
export const RELAY_URL_ENV_VAR = "T3X_UPDATE_RELAY_URL";
2734

‎infra/coil-update-relay/README.md‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ reconnects immediately and gets the current payload replayed on connect.
6161

6262
```bash
6363
pnpm dlx wrangler@4 secret put T3X_UPDATE_HMAC_SECRET
64-
pnpm --filter t3x-update-relay deploy
64+
pnpm --filter coil-update-relay deploy
6565
```
6666

6767
`wrangler` is deliberately **not** a dependency. It drags ~500 lines into `pnpm-lock.yaml`, which
@@ -72,10 +72,31 @@ needed at deploy time. `pnpm dlx` fetches it for that one command instead.
7272
> the Workers free plan only in their SQLite-backed form, and since 2026-07 new KV-backed
7373
> namespaces are refused outright. The wrong one fails at deploy time, not review time.
7474
75+
### The legacy hostname
76+
77+
This Worker was called `t3x-update-relay` until #71. That hostname is **not** retired, and cannot
78+
be: `DEFAULT_RELAY_URL` is compiled into every desktop build, the env override that could point an
79+
install elsewhere is never set in practice, and a build that stops finding its relay has no
80+
remaining channel through which to be told about a new one.
81+
82+
So the old hostname is redeployed as a pass-through to this one, from this same package:
83+
84+
```bash
85+
pnpm --filter coil-update-relay deploy:legacy
86+
```
87+
88+
Order matters. Deploy `coil-update-relay` first, notify it at least once (publish a release, or
89+
POST `/notify` by hand), and only then deploy the shim — otherwise every installed build is briefly
90+
pointed at a relay whose `/latest` is `null`. That reads as "nothing to act on" rather than an
91+
error, so nothing breaks, but no client sees an update until the next release.
92+
93+
Retire it only when the Worker's request log shows no `/events` or `/latest` traffic on the old
94+
hostname. There is no deadline by which that becomes true.
95+
7596
## Testing
7697

7798
```bash
78-
pnpm --filter t3x-update-relay test
99+
pnpm --filter coil-update-relay test
79100
```
80101

81102
Covers signature verification (including a replayed request whose timestamp header was swapped for

‎infra/coil-update-relay/package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
2-
"name": "t3x-update-relay",
2+
"name": "coil-update-relay",
33
"private": true,
44
"type": "module",
55
"scripts": {
66
"//deploy": "wrangler is run via `pnpm dlx`, not depended on. It drags ~500 lines into pnpm-lock.yaml, which SEAMS.md records as the second-worst rebase-conflict surface in this fork — and it is only ever needed at deploy time, on CI, where a one-shot fetch costs nothing.",
77
"deploy": "pnpm dlx wrangler@4 deploy",
8+
"//deploy:legacy": "Redeploys the pre-#71 t3x-update-relay hostname as a pass-through to this one. Builds shipped before the rename have that hostname compiled in and cannot be told about a new one, so it serves indefinitely. Deploy it only AFTER coil-update-relay is live and populated.",
9+
"deploy:legacy": "pnpm dlx wrangler@4 deploy --config wrangler.legacy.jsonc",
810
"dev": "pnpm dlx wrangler@4 dev",
911
"test": "vp test run",
1012
"typecheck": "tsgo --noEmit"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { describe, expect, it, vi } from "vite-plus/test";
2+
3+
// Same stand-in, and for the same reason, as worker.test.ts: the entry module re-exports the
4+
// Durable Object class because wrangler requires it, which drags in `cloudflare:workers` — a
5+
// runtime-only module with no node equivalent. The shim never touches the class; it is exported
6+
// only so deploying over the existing Worker is not read as a class deletion.
7+
vi.mock("cloudflare:workers", () => ({
8+
DurableObject: class {
9+
protected readonly ctx = undefined;
10+
},
11+
}));
12+
13+
import { rewriteToUpstream, UPSTREAM_ORIGIN } from "./legacyWorker.ts";
14+
15+
describe("rewriteToUpstream", () => {
16+
it("keeps the path and moves only the origin", () => {
17+
expect(rewriteToUpstream("https://t3x-update-relay.businesses.workers.dev/latest")).toBe(
18+
`${UPSTREAM_ORIGIN}/latest`,
19+
);
20+
expect(rewriteToUpstream("https://t3x-update-relay.businesses.workers.dev/events")).toBe(
21+
`${UPSTREAM_ORIGIN}/events`,
22+
);
23+
});
24+
25+
it("forwards /notify too, so the shim is correct whichever host the release posts to", () => {
26+
// The release workflow's target lives in a repo variable, not in this repository. Forwarding
27+
// this path costs nothing and removes an assumption about a value nobody here can read. The
28+
// HMAC covers the body and timestamp, not the hostname, so it survives the hop.
29+
expect(rewriteToUpstream("https://t3x-update-relay.businesses.workers.dev/notify")).toBe(
30+
`${UPSTREAM_ORIGIN}/notify`,
31+
);
32+
});
33+
34+
it("preserves the query string", () => {
35+
expect(rewriteToUpstream("https://t3x-update-relay.businesses.workers.dev/latest?x=1&y=2")).toBe(
36+
`${UPSTREAM_ORIGIN}/latest?x=1&y=2`,
37+
);
38+
});
39+
40+
it("does not smuggle the old host into the target", () => {
41+
// A rewrite built by string concatenation rather than by URL would happily produce
42+
// `https://coil-.../https://t3x-...`. Asserted because the failure mode is a 404 on every
43+
// request from every installed build.
44+
const target = new URL(rewriteToUpstream("https://t3x-update-relay.businesses.workers.dev/latest"));
45+
expect(target.host).toBe(new URL(UPSTREAM_ORIGIN).host);
46+
expect(target.pathname).toBe("/latest");
47+
});
48+
49+
it("points at the renamed relay, not back at itself", () => {
50+
// A shim that forwards to its own hostname is an infinite loop that Cloudflare bills for.
51+
expect(UPSTREAM_ORIGIN).not.toContain("t3x-update-relay");
52+
expect(UPSTREAM_ORIGIN).toContain("coil-update-relay");
53+
});
54+
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* The `t3x-update-relay` hostname, after #71 moved the real relay to `coil-update-relay`.
3+
*
4+
* This exists because `DEFAULT_RELAY_URL` is compiled into the app. Every build ever shipped has
5+
* `https://t3x-update-relay.businesses.workers.dev` baked in, the env override that could point
6+
* them elsewhere is never set on a normal install (a `.app` launched from Finder inherits
7+
* launchd's environment, not a shell's), and an app that stops finding its relay has no remaining
8+
* channel through which to be told. So this hostname has to keep answering for as long as any
9+
* build that predates the rename is still running — which is indefinitely, and certainly longer
10+
* than it will feel necessary.
11+
*
12+
* ## Why a proxy and not a redirect
13+
*
14+
* The obvious shim is a 301/307 to the new host. It is the wrong one here, and the reason is
15+
* specific rather than stylistic: `relayClient.ts` does not use `fetch`. It goes through Effect's
16+
* `HttpClient`, and it classifies any non-2xx response as `bad-status` on BOTH tiers — the
17+
* `/latest` poll and the long-lived `/events` stream. Whether that client transparently follows a
18+
* redirect, and whether it does so on a `text/event-stream` response it intends to keep open, is
19+
* not a property that can be tested against builds that are already installed on other people's
20+
* machines. Being wrong about it does not degrade those builds, it strands them, permanently and
21+
* without a symptom — which is the exact failure this whole file exists to prevent.
22+
*
23+
* A pass-through has no such question attached. From the client's side the bytes, the status and
24+
* the streaming behaviour are what they were before the rename, because they are literally the
25+
* upstream response.
26+
*
27+
* ## Why it forwards every method and path
28+
*
29+
* Including `/notify`, which only the release workflow calls. The workflow is *supposed* to post
30+
* to the new host, but that target lives in a repo variable rather than in this repository, so
31+
* "supposed to" is an assumption about a value nobody here can see. Forwarding it costs one line
32+
* and makes the shim correct whichever host the workflow was pointed at. The HMAC signature
33+
* covers the body and the timestamp, not the hostname, so it survives the hop unchanged.
34+
*
35+
* ## Why `UpdateChannel` is still exported
36+
*
37+
* It is unreachable from here — nothing below touches the binding. It stays because this Worker is
38+
* deployed OVER the existing `t3x-update-relay`, which already has the Durable Object class in its
39+
* migration history. Dropping the export would make the deploy an implicit class deletion, which
40+
* Cloudflare rejects without an explicit `deleted_classes` migration; keeping it makes the cutover
41+
* a plain code deploy, and makes rolling back to the real relay a plain code deploy too.
42+
*/
43+
44+
export { UpdateChannel } from "./UpdateChannel.ts";
45+
46+
/**
47+
* Where the real relay now lives.
48+
*
49+
* Hardcoded rather than bound through `wrangler.legacy.jsonc`, so that the shim and the Worker it
50+
* fronts cannot be configured apart. This file and `wrangler.jsonc`'s `name` are the two halves of
51+
* one fact and they live in the same package for that reason.
52+
*/
53+
export const UPSTREAM_ORIGIN = "https://coil-update-relay.businesses.workers.dev";
54+
55+
/** The forwarded request: same method, headers, body and path — only the origin changes. */
56+
export function rewriteToUpstream(requestUrl: string): string {
57+
const url = new URL(requestUrl);
58+
const target = new URL(UPSTREAM_ORIGIN);
59+
target.pathname = url.pathname;
60+
target.search = url.search;
61+
return target.toString();
62+
}
63+
64+
export default {
65+
fetch(request: Request): Promise<Response> {
66+
return fetch(new Request(rewriteToUpstream(request.url), request));
67+
},
68+
} satisfies ExportedHandler;

‎infra/coil-update-relay/wrangler.jsonc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "node_modules/wrangler/config-schema.json",
3-
"name": "t3x-update-relay",
3+
"name": "coil-update-relay",
44
"main": "src/worker.ts",
55
"compatibility_date": "2026-06-01",
66
"observability": { "enabled": true },
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
// The pre-#71 hostname, deployed as a pass-through to `coil-update-relay`.
3+
//
4+
// Same package, same source tree, different entrypoint — see src/legacyWorker.ts for why this
5+
// hostname can never be retired on a schedule, and why the shim proxies instead of redirecting.
6+
//
7+
// Deploy with `pnpm run deploy:legacy`, and only after `coil-update-relay` is live AND has been
8+
// notified at least once. Deploying it earlier would point every installed build at a relay that
9+
// answers `/latest` with `null` — harmless, since that reads as "nothing to act on", but it
10+
// means no client sees an update until the next release rather than immediately.
11+
"$schema": "node_modules/wrangler/config-schema.json",
12+
"name": "t3x-update-relay",
13+
"main": "src/legacyWorker.ts",
14+
"compatibility_date": "2026-06-01",
15+
"observability": { "enabled": true },
16+
17+
// Both blocks are carried over from wrangler.jsonc unchanged, and neither is used at runtime.
18+
//
19+
// This config deploys OVER the existing `t3x-update-relay`, whose migration history already
20+
// contains UpdateChannel. Omitting them here would make the deploy an implicit class deletion,
21+
// which Cloudflare refuses without an explicit `deleted_classes` migration. Keeping them makes
22+
// the cutover an ordinary code deploy — and, just as importantly, makes rolling back to the real
23+
// relay an ordinary code deploy rather than a migration.
24+
"durable_objects": {
25+
"bindings": [{ "name": "UPDATE_CHANNEL", "class_name": "UpdateChannel" }]
26+
},
27+
"migrations": [{ "tag": "v1", "new_sqlite_classes": ["UpdateChannel"] }]
28+
}

0 commit comments

Comments
 (0)