The bus is reachable from a plugin but not from the graph, and nothing says so #67

Closed
opened 2026-08-20 17:53:19 +00:00 by chrnx · 0 comments
Owner

app.bus is public and Bus is an exported type, but bus is not a token in the graph — so @needs('bus') fails at boot, and nothing tells you that before it does.

What happens

handler 'h' needs 'bus' but nothing (local or mesh) provides it

provideBuiltins (src/app/index.ts:537) registers exactly two tokens: logger and rooms. The bus is reachable in two other places — app.bus after createApp returns, and api.bus.on inside a plugin — but not from inside the graph, which is where a provider, a step or a handler lives.

Why it matters

The framework's answer for "I need the framework's own logger" is @needs('logger'), and the doc comment sells it as such: "one object, two access paths". That teaches a user the pattern, so the first instinct for "I need the framework's own events" is @needs('bus'), and the boot error is the first news that it is not the same shape.

There is a real reason for the difference, and it is a good one: PluginApi hands over bus.on and deliberately not emit — "Hand the plugin ONLY on(), add() and onShutdown()" (src/plugin.ts:34). Putting the Bus instance in the graph would hand emit to every node and turn a one-way observation channel into something anything can forge events on.

So the answer is "observability is a plugin, not a provider" — a design decision that is nowhere written down. It is inferable only by reading provideBuiltins and mountPlugin and noticing what is absent from each.

Scope

Pick one:

  1. Just document it. A sentence on PluginApi and on the observability section: events are subscribed to from a plugin; bus is not a graph token, and that is on purpose so nobody can emit.
  2. Provide a read-only token, e.g. events bound to { on } — the same narrowing plugins already get. It would make @needs('events') work the way @needs('logger') does, and preserve the isolation the current design is protecting.

Option 2 is only worth it if subscribing from inside the graph is something users should be doing; a plugin is arguably the right home for it, in which case option 1 is the whole fix.

Related

Found while writing metrics.plugin.ts for the green-desk demo. It ended up as a plugin — the correct outcome — reached by hitting the boot error first.

`app.bus` is public and `Bus` is an exported type, but `bus` is not a token in the graph — so `@needs('bus')` fails at boot, and nothing tells you that before it does. ## What happens ``` handler 'h' needs 'bus' but nothing (local or mesh) provides it ``` `provideBuiltins` (`src/app/index.ts:537`) registers exactly two tokens: `logger` and `rooms`. The bus is reachable in two other places — `app.bus` after `createApp` returns, and `api.bus.on` inside a plugin — but not from inside the graph, which is where a provider, a step or a handler lives. ## Why it matters The framework's answer for "I need the framework's own logger" is `@needs('logger')`, and the doc comment sells it as such: *"one object, two access paths"*. That teaches a user the pattern, so the first instinct for "I need the framework's own events" is `@needs('bus')`, and the boot error is the first news that it is not the same shape. There is a real reason for the difference, and it is a good one: `PluginApi` hands over `bus.on` and deliberately not `emit` — *"Hand the plugin ONLY on(), add() and onShutdown()"* (`src/plugin.ts:34`). Putting the `Bus` instance in the graph would hand `emit` to every node and turn a one-way observation channel into something anything can forge events on. So the answer is "observability is a plugin, not a provider" — a design decision that is nowhere written down. It is inferable only by reading `provideBuiltins` and `mountPlugin` and noticing what is absent from each. ## Scope Pick one: 1. **Just document it.** A sentence on `PluginApi` and on the observability section: events are subscribed to from a plugin; `bus` is not a graph token, and that is on purpose so nobody can `emit`. 2. **Provide a read-only token**, e.g. `events` bound to `{ on }` — the same narrowing plugins already get. It would make `@needs('events')` work the way `@needs('logger')` does, and preserve the isolation the current design is protecting. Option 2 is only worth it if subscribing from inside the graph is something users should be doing; a plugin is arguably the right home for it, in which case option 1 is the whole fix. ## Related Found while writing `metrics.plugin.ts` for the `green-desk` demo. It ended up as a plugin — the correct outcome — reached by hitting the boot error first.
chrnx closed this issue 2026-09-04 13:32:29 +00:00
Sign in to join this conversation.