diff --git a/CHANGELOG.md b/CHANGELOG.md index c65bb14..cee632e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,17 +32,28 @@ npm treats versions as semver and semver forbids leading zeros. caution, it was arithmetic: an app-scope value has to resolve *at boot*, because there is no later to resolve it in. A step is nothing but later. The `bootTimeoutMs` grace still waits, since "the container is thirty seconds behind" and "the teapot does not exist" look identical for the first - thirty seconds; exhausting it now warns and starts without that teapot, whose steps and routes - answer `503`. Refusing to start took down the half of the teacup that never needed that teapot at - all, and moved a `503` on some requests into an outage on every one of them. + thirty seconds; exhausting it now warns and starts without that teapot. - Two conditions still fail the boot, both deliberately. A **permanent refusal** — a wrong secret, - a protocol mismatch — is the teapot's decision rather than the network's, and it will be the same - decision in thirty seconds; retrying only spends the deploy's patience to arrive at the identical - error. And a local step that **needs a token nothing provides** still fails, because that check is - what catches a typo in a token name, and a typo does not come good by waiting. That error now - names the teapots that did not connect, and says "local or connected mesh" rather than "local or - mesh" — the old wording claimed a search that had not happened. + What that buys is narrower than it sounds, and worth stating exactly. A teapot that never + connected sent no manifest, so the teacup learned nothing about it — no step runners, no routes, + a graph identical to the one it would have had if that teapot were never configured. Its routes + therefore **404**, through the ordinary unmatched-route path, because nothing was ever registered + to match. And any local step or handler that needs one of its tokens **still fails the boot**, + naming the teapot that did not connect. `503` is what a teapot that connected and *later* died + answers: that link exists, its steps and routes are registered, and the dead link is what returns + the status. Never reachable and reachable-then-gone are different situations, and they read + differently on purpose. + + So the change is for the teacup that does *not* depend on that teapot: it starts, rather than + refusing over a dependency it never had. It is not graceful degradation of the dependency, and + cannot be — answering `503` for an absent teapot's tokens means knowing what it *would* have + exported, and only a declaration can say. That declaration is the `expects` list in + `docs/plans/2026-08-18-mesh-degrade-plan.md`, which is planned and not built. Two things are + unchanged: a **permanent refusal** — a wrong secret, a protocol mismatch — still fails the boot + without spending the grace, because it is the teapot's decision rather than the network's and will + be the same decision in thirty seconds; and the missing-token error, which now says "local or + connected mesh" rather than "local or mesh", the old wording having claimed a search that never + happened. - **Mesh (alpha): the manifest carries step names.** `{ scopes: [{ token, scope }], routes }` is now `{ steps: string[], routes }`. Every export is request-scope after the change above, so the diff --git a/README.md b/README.md index 3fe23b3..1a4883d 100644 --- a/README.md +++ b/README.md @@ -286,7 +286,7 @@ green-tea is **beta**, on the road to a release candidate. Express and Fastify h **mesh is alpha.** Distributed DI works, but discovery, load-balancing, and failover are not built, and its API and wire protocol may change between releases. It is gated behind an explicit opt-in — `createApp({ mesh, experimental: true })` — and `createApp` throws if you configure `mesh` without it. Don't ship mesh to production yet. -**What a teapot exports: steps and routes, and nothing else.** A `@Provider` marked `export: true` fails the boot with an error that says why — a provider's value *is* the object it builds, a pool or a client or a `db`, and the mesh moves data, not objects. Export a `@Step` instead: it runs on the teapot, per request, and its result is what comes back. That is also what makes an absent teapot survivable. A remote step holds nothing between requests, so a teacup whose teapot never answers still boots once the `bootTimeoutMs` grace runs out — it warns, starts without it, and that teapot's steps and routes answer `503` until it arrives. What still fails the boot is a local step that `@needs` a token *nothing* provides, and that is deliberate: it is the check that catches a typo in a token name, which no amount of waiting will fix. The error names the teapots that did not connect, so the two cases read differently. +**What a teapot exports: steps and routes, and nothing else.** A `@Provider` marked `export: true` fails the boot with an error that says why — a provider's value *is* the object it builds, a pool or a client or a `db`, and the mesh moves data, not objects. Export a `@Step` instead: it runs on the teapot, per request, and its result is what comes back. That is also what lets a teacup boot without its teapot: a remote step holds nothing between requests, so a teacup whose teapot never answers still starts once the `bootTimeoutMs` grace runs out — it warns and carries on. Be precise about what that means, because it is narrower than it sounds. A teapot that never connected sent no manifest, so nothing of it reached the graph: its routes **404** rather than `503`, since nothing was registered to match, and a local step that `@needs` one of its tokens **still fails the boot**, naming the teapot that did not connect. That failure is deliberate — it is the check that catches a typo in a token name, which no amount of waiting will fix. `503` is what you get from a teapot that connected and *later* died, where the link and its exports do exist. So what the change buys is the teacup that does *not* depend on that teapot starting anyway, rather than refusing over a dependency it never had. Keeping a *needed* token serving while its teapot is legitimately away is a known gap, not an oversight: the intended answer is the `expects` list in [the mesh degrade plan](./docs/plans/2026-08-18-mesh-degrade-plan.md), which is planned and not built. **What is settled, and what is still moving.** Present state, not a roadmap and not the API freeze — this is spare-time work by one person, and a schedule it cannot keep would cost more than it earns. The **graph is the settled part**: `needs`/`provides`, the order derived from them, and the boot-time failure when nothing provides a key have not changed since the beta hardening on 7 July, and `@Provider`, `@Step`, `@Route` and handler shapes still mean what they meant then — the decorator *set* has grown (`@Head`, `@Options`, `@Html`), which only ever adds. **Still moving:** the plugin API, which gained `onShutdown` this week; `createApp`'s options, which gain fields most months; and the pipeline context, which in July became one object mutated in place rather than copied per step — so a step that captured it now sees later steps' writes. **Alpha:** mesh, above. Legacy decorators are a standing *external* risk rather than a green-tea one — see [Why legacy decorators](#why-legacy-decorators). The [matcha](https://github.com/Expressive-Tea/matcha) CLI ships from its own repository on its own version line, so nothing here speaks for it. diff --git a/src/app/index.ts b/src/app/index.ts index b19fe52..fdacab7 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -755,18 +755,21 @@ function assertNeedsSatisfiable( * * The grace exists because "the container is thirty seconds behind" and "the teapot does not * exist" look identical for the first thirty seconds, and only one of them should stop a deploy. - * When the deadline passes it still throws: a provider the graph depends on is not optional, and - * booting without it would only move the failure to the first request, where it becomes a caller's - * 503 instead of the deploy's error. * * Each failed attempt is both logged and emitted as `mesh:boot:retry` — logged so an operator * watching a deploy sees why it is taking so long, emitted so the wait is visible to whatever * collects lifecycle events rather than only to whoever is reading a terminal. * - * Exhausting the budget no longer throws (D4 keeps the one exception: a permanent refusal still - * does). Every export a teapot makes is now lazy — a request-scope step or a proxied route — so - * nothing needs it resolved by boot; an absent teapot only costs a 503 on the requests that need - * it, and a teacup that refuses to start would take down the half of itself that never did. + * Exhausting the budget returns `undefined` rather than throwing (D4 keeps the one exception: a + * permanent refusal still does). Every export a teapot makes is lazy now — a request-scope step or + * a proxied route — so nothing needed this link resolved by boot, and a teacup that refuses to + * start takes down the half of itself that never needed the teapot. + * + * Returning `undefined` is not the same as degrading it. The caller registers nothing for a link it + * never got, because a teapot that did not connect sent no manifest and so nobody knows what it + * would have exported. Its routes 404 like any unregistered path, and a local node that needs one + * of its tokens still fails the boot in finalize(), named. Serving 503 for those tokens instead + * needs an `expects` declaration — see docs/plans/2026-08-18-mesh-degrade-plan.md, still planned. */ async function connectUntilDeadline( mesh: MeshConfig, @@ -795,12 +798,16 @@ async function connectUntilDeadline( } // The budget is a grace for a co-deploy, not a requirement. Every export is a lazy step or a - // proxied route now, so an absent teapot costs a 503 on the requests that need it — and a - // teacup that refuses to start takes down the half of itself that never needed the teapot. + // proxied route now, so nothing needed this link resolved by boot, and a teacup that refuses + // to start takes down the half of itself that never needed the teapot. What starting does NOT + // do is degrade the dependency: an absent teapot sent no manifest, so it contributes no nodes + // at all — its routes 404 and a local `needs` on its tokens still fails in finalize(). if (remaining <= 0) { logger.warn( `mesh: teapot unreachable after ${attempts} attempt(s) over ${budgetMs}ms ` + - `(${(error as Error).message}) — starting without it; its steps and routes will 503`, + `(${(error as Error).message}) — starting without it. It sent no manifest, so none of ` + + `its steps or routes are in this graph: its routes 404, and the boot still fails if ` + + `anything local needs one of its tokens.`, ); return undefined; } diff --git a/src/app/types.ts b/src/app/types.ts index 6e9626c..1483896 100644 --- a/src/app/types.ts +++ b/src/app/types.ts @@ -136,10 +136,14 @@ export interface MeshConfig { * so 30s). Attempts use the same backoff as reconnection. * * A teapot that is merely slow to start — a container scheduled a moment later, a network that - * has not settled — should not fail a deploy, and this is the grace for that. A teapot that is - * genuinely absent still fails the boot when the deadline passes, because a provider the graph - * depends on is not optional: booting without it would only move the failure to the first - * request, where it is somebody else's 503 instead of your deploy's error. + * has not settled — should not fail a deploy, and this is the grace for that. When the deadline + * passes the teacup warns and starts anyway: every export is a step or a proxied route, so + * nothing needed that link resolved by boot. + * + * Starting is not degrading, though. A teapot that never connected sent no manifest, so none of + * its steps or routes are registered: its routes 404 rather than 503, and a local node that needs + * one of its tokens still fails the boot, naming it. A permanent refusal — a wrong secret, a + * protocol mismatch — fails at once without spending the grace. * * `0` restores the old behaviour of a single attempt. */