feat(mesh): carry the caller's identity across the wire, and bound what an unauthenticated peer can do
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 18s
CI / build (pull_request) Successful in 24s
CI / runtimes (edge) (pull_request) Successful in 11s
CI / runtimes (deno) (pull_request) Successful in 18s

The observability release gave every request an id and lost it at the process
boundary — in the one place a distributed trace is the entire point. The RPC
envelope now carries requestId, traceId and url, and the teapot adopts them
instead of opening its own investigation.

Both fields are optional on the wire, so the protocol version does not move.
That decision needed a rule rather than a judgement call, so the rule is now
written beside the constant: bump when an old peer would misparse or misbehave
silently, not when work happened. Bumping per change would make the number
mean the opposite of what it is for.

Three things found while in here:

- mesh:rpc:error emitted the per-link counter where every other emitter puts a
  name, so the two sides of one failure could not be matched up.
- The teapot had no handshake deadline, so an unauthenticated peer could hold
  a socket by saying nothing, and no frame size cap, so it could make the
  process JSON.parse up to whatever the socket layer allowed — 100 MiB with
  the ws defaults, before authenticating.
- The remote-route envelope was cast from the internal request object, putting
  ip and protocol on the wire as fields the protocol never declared.

The cleartext warning is a warning and not a refusal on purpose: a private
network already doing mutual TLS is legitimate, and green-tea cannot tell it
apart from an exposed one.

4 of the 8 new tests verified to fail against the old code; the rest are the
negative cases, which should pass both before and after. The Deno test drives
the teapot's frame loop with a raw client, because server-side close codes are
where these runtimes have already differed once.

431 vitest / 12 Deno / 7 Bun / edge / JSR dry run.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-08-18 11:15:54 -05:00
1 parent 1ccbf6cadf
commit f2cb411eac
8 files changed
+472 -10

No files matched your search

+31 -3
View File
@@ -1,18 +1,46 @@
/**
* Version of the mesh wire protocol. Peers are separate processes on separate deploy
* cadences — possibly on different runtimes — so the frame shapes are a contract between
* green-tea versions, not an internal detail. Bump on any breaking frame change; peers
* refuse each other on mismatch rather than misparsing downstream.
* green-tea versions, not an internal detail. Peers refuse each other on mismatch rather
* than misparsing downstream.
*
* **This is a compatibility boundary, not a changelog.** Bump it only when a peer running the
* old version would *misparse a frame or misbehave silently*:
*
* - removing or renaming a field, or changing its type or meaning;
* - adding a **required** field;
* - adding a frame type that expects an answer — an old peer cannot decode it, drops it as
* undecodable, and the sender waits for a reply that will never come.
*
* Adding an **optional** field is not one of those: `decode` validates only the fields a frame
* type requires and passes extras through untouched, so an old peer ignores what it does not
* know and keeps answering. That is degraded, not broken, and does not earn a bump.
*
* Bumping per change would make the number mean "work happened" rather than "we are
* incompatible", which is the one thing it is here to say.
*/
export const MESH_PROTOCOL_VERSION = 1;
/** Serialized request context sent across the mesh for a scope or route RPC. */
/**
* Serialized request context sent across the mesh for a scope or route RPC.
*
* `correlation` and `url` are optional by protocol, not by intent: a teapot running an older
* green-tea simply ignores them, which costs the correlation of that hop and nothing else.
*/
export interface RequestEnvelope {
method: string;
params: Record<string, string>;
query: Record<string, string>;
body: unknown;
headers: Record<string, string | string[] | undefined>;
/** The requested URL, so a teapot's handler sees the same path its caller did. */
url?: string;
/**
* The caller's request identity, so a request that crosses the mesh keeps one id end to end.
* Without it every hop opens a new investigation, in the one place a distributed trace is
* the whole point.
*/
correlation?: { requestId?: string; traceId?: string };
}
/** Manifest entry for an exported scope token and its lifetime. */