docs(mesh): warn on shadowed remote routes, and tell the truth about mesh
Local routes are merged ahead of remote ones, so a local twin wins. That precedence is worth keeping — your own code beating an imported one is how you override a teapot — but it was an accident of [...local, ...remote] ordering with nothing said, so a shadowed export looked like a broken teapot from the outside. Warn, name the teapot, and leave the call to the developer. The docs had gone stale in the way that started all of this. runtimes.md claimed four times that mesh is Node-only; the mesh guide said finalization is deferred to listen(); the changelog said "WebSocket and mesh remain Node-only". All false now. The mesh guide gains what was enforced but never written down — which is how the listen() trap got made in the first place, when the previous plan's "document it" never landed: - runs on Node/Deno/Bun, teapot and teacup, any combination; not on edge, and why - no listen() required: the graph boots on first use - buffered routes only, and why streams cannot cross an RPC hop - one teapot per route, local-over-remote precedence, and the protocol version Refs .specs/2026-07-15-green-tea-mesh-cross-runtime-plan.md Task 9 Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
5 files changed
+159
-11
No files matched your search
@@ -11,6 +11,19 @@ A **teacup** can depend on a token that physically lives on another node — a *
|
||||
|
||||
Exports are opt-in (`export: true`) and the control channel is gated by a shared secret.
|
||||
|
||||
## What runs where
|
||||
|
||||
Mesh runs on **Node, Deno and Bun**, as both teapot and teacup, in any combination — a Deno teapot can serve a Node teacup. The wire is JSON over a WebSocket, so peers only have to agree on the protocol version, not the runtime.
|
||||
|
||||
**Edge (Cloudflare Workers) is not supported.** The teapot's secret comparison uses `node:crypto`'s `timingSafeEqual`, which workerd's `nodejs_compat` does not provide.
|
||||
|
||||
You do **not** need `listen()`. The graph boots on first use, so `Deno.serve`/`Bun.serve` work through `app.fetch`/`app.upgrade` like any other route:
|
||||
|
||||
```typescript
|
||||
serveDeno(teapot, { port: 3002 }); // control channel served via app.upgrade
|
||||
serveBun(teacup, { port: 3003 }); // teapots connected on the first request
|
||||
```
|
||||
|
||||
## Node A — teapot (exposes `config`, `auth`, and a route)
|
||||
|
||||
```typescript
|
||||
@@ -60,7 +73,37 @@ await teacup.listen(3003);
|
||||
- A **provider** export is **app-scope** — resolved once and cached.
|
||||
- A **step** export is **request-scope** — one RPC per request, carrying the request envelope.
|
||||
|
||||
Remote tokens become synthetic nodes in the local graph with RPC-backed runners, so the rest of the pipeline is unchanged. For non-mesh apps `createApp` stays synchronous; mesh apps defer graph finalization to `listen()` so remote scopes can join first.
|
||||
Remote tokens become synthetic nodes in the local graph with RPC-backed runners, so the rest of the pipeline is unchanged. For non-mesh apps `createApp` stays synchronous; a mesh app defers graph finalization until it boots — connecting to teapots is network I/O — and boots on whichever comes first: `app.fetch`, `app.upgrade` or `listen()`. Whoever triggers it, it happens once.
|
||||
|
||||
## Buffered routes only
|
||||
|
||||
Mesh proxies **buffered** endpoints. `@Sse`, `@Stream` and `@Ws` routes are not exportable: a remote route is registered as `transport: 'buffer'`, and a handler that returns an `AsyncIterable` over a mesh call fails with `cannot proxy a streaming route`. Streams are a live socket between client and server; there is no meaningful way to relay one through an RPC hop today.
|
||||
|
||||
## One teapot per route
|
||||
|
||||
A route must be exported by exactly **one** teapot. If two export the same `method + pattern`, the boot **fails**, naming the route and both teapots:
|
||||
|
||||
```
|
||||
mesh: route 'GET /api/svc/ping' is exported by more than one teapot
|
||||
(ws://a/__mesh__/control and ws://b/__mesh__/control) — load balancing across
|
||||
teapots is not implemented yet, so green-tea will not choose one for you.
|
||||
```
|
||||
|
||||
This is a hard error rather than a silent pick because there is no load balancing to fall back on: choosing one would be an arbitrary answer you could come to depend on. Scope tokens (`@Provider`/`@Step`) are unique for the same reason — and balancing them would be meaningless anyway, since an app-scope export is resolved once and cached.
|
||||
|
||||
**Local routes win.** If you declare a route locally *and* import it from a teapot, yours takes precedence — that is how you override a teapot — and green-tea warns so a shadowed export doesn't look like a broken one:
|
||||
|
||||
```
|
||||
[green-tea] mesh: route 'GET /api/svc/ping' is exported by teapot ws://a/… but also
|
||||
declared locally — the local route takes precedence and the remote one will not be
|
||||
reached. Remove one if that is not what you meant.
|
||||
```
|
||||
|
||||
## Protocol version
|
||||
|
||||
Peers are separate processes on separate deploy cadences, so the wire is versioned: `MESH_PROTOCOL_VERSION` travels in the `hello` and `manifest` frames, and a mismatch is refused on both sides with both versions named. A teapot checks the version **before** the secret — a skewed peer is not an authentication failure, and reporting it as one would send you hunting the wrong bug.
|
||||
|
||||
Bump the version and old peers refuse the connection loudly instead of misreading a frame.
|
||||
|
||||
:::note[Skeleton limitations (by design)]
|
||||
No discovery, load-balancing, or failover yet; app-scope remote values are not reconciled on reconnect; the request envelope omits `req.url`.
|
||||
|
||||
@@ -27,8 +27,9 @@ and body for the same request (enforced by a parity test suite).
|
||||
|
||||
**All four runtimes now have full WebSocket support:** Node, Deno, and Bun via `serveDeno` /
|
||||
`serveBun`, and Cloudflare Workers / edge via `edgeHandler` (see below) — same graph, same
|
||||
`@Ws` handlers, same rooms/channels everywhere. `app.listen()`, TLS, per-request timeouts,
|
||||
and mesh remain Node-only; on Deno/Bun/edge you get `app.fetch` + the runtime's adapter.
|
||||
`@Ws` handlers, same rooms/channels everywhere. `app.listen()`, TLS and per-request timeouts
|
||||
remain Node-only; on Deno/Bun/edge you get `app.fetch` + the runtime's adapter. **Mesh (alpha)
|
||||
runs on Node, Deno and Bun** — teapot and teacup, in any combination — but not on edge.
|
||||
|
||||
**Body-size enforcement differs slightly:** on `app.fetch`, an oversized body is read in full
|
||||
before the `413` is returned, whereas Node aborts mid-stream once the limit is hit — so on
|
||||
@@ -58,8 +59,9 @@ Any runtime can build a `WsSocket` capability (`inbound`, `abort`, `isOpen`, `se
|
||||
`close`, `terminate`) and drive the graph — `serveBun` and `edgeHandler` build on the
|
||||
same primitive (see below).
|
||||
|
||||
**Still Node-only:** `app.listen()`, TLS, per-request timeouts, and mesh. On Deno you
|
||||
get `app.fetch` + `serveDeno`.
|
||||
**Still Node-only:** `app.listen()`, TLS and per-request timeouts. On Deno you get
|
||||
`app.fetch` + `serveDeno`. [Mesh](/guides/mesh/) works here: the control channel is
|
||||
served through `app.upgrade` and the teacup connects with Deno's global `WebSocket`.
|
||||
|
||||
## WebSocket on Bun
|
||||
|
||||
@@ -80,8 +82,8 @@ serveBun(app, { port: 8000 });
|
||||
`app.upgrade` — the same graph, the same `@Ws` handlers, the same rooms/channels you
|
||||
run on Node and Deno. Behaviour matches the Node reference.
|
||||
|
||||
**Still Node-only:** `app.listen()`, TLS, per-request timeouts, and mesh. On Bun you
|
||||
get `app.fetch` + `serveBun`.
|
||||
**Still Node-only:** `app.listen()`, TLS and per-request timeouts. On Bun you get
|
||||
`app.fetch` + `serveBun`. [Mesh](/guides/mesh/) works here too.
|
||||
|
||||
## Cloudflare Workers / edge
|
||||
|
||||
@@ -113,7 +115,9 @@ compatibility_date = "2024-09-23" # or later
|
||||
Green Tea's core statically imports Node built-ins that workerd only provides under
|
||||
this flag; without it, the Worker fails to load.
|
||||
|
||||
**Still Node-only:** `app.listen()`, TLS, per-request timeouts, and mesh. Cloudflare's
|
||||
**Still Node-only:** `app.listen()`, TLS and per-request timeouts. [Mesh](/guides/mesh/)
|
||||
is **not** supported on edge: the teapot's secret comparison needs `node:crypto`'s
|
||||
`timingSafeEqual`, which `nodejs_compat` does not provide. Cloudflare's
|
||||
Durable Objects and WebSocket Hibernation are **not** used — `edgeHandler` accepts
|
||||
WebSockets with the standard `WebSocketPair` model, so a Worker holds the connection
|
||||
open for its lifetime rather than hibernating between messages.
|
||||
|
||||
Reference in new issue
Block a user