@kylewillett/troupe 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CHANGELOG.md +21 -2
  2. package/README.md +132 -2
  3. package/dist/ask.d.ts +5 -1
  4. package/dist/ask.js +16 -0
  5. package/dist/backstage/index.d.ts +2 -1
  6. package/dist/backstage/index.js +1 -0
  7. package/dist/backstage/source.d.ts +1 -1
  8. package/dist/backstage/source.js +65 -2
  9. package/dist/backstage/types.d.ts +65 -4
  10. package/dist/backstage/types.js +2 -1
  11. package/dist/backstage-ui/assets/index-CG896RLZ.css +1 -0
  12. package/dist/backstage-ui/assets/index-DF_Xnc1u.js +9 -0
  13. package/dist/backstage-ui/index.html +2 -2
  14. package/dist/cell.d.ts +16 -14
  15. package/dist/cell.js +38 -13
  16. package/dist/checks.d.ts +10 -0
  17. package/dist/checks.js +34 -2
  18. package/dist/cluster/index.d.ts +6 -0
  19. package/dist/cluster/index.js +4 -0
  20. package/dist/cluster/leases.d.ts +37 -0
  21. package/dist/cluster/leases.js +132 -0
  22. package/dist/cluster/membership.d.ts +100 -0
  23. package/dist/cluster/membership.js +559 -0
  24. package/dist/cluster/memory.d.ts +31 -0
  25. package/dist/cluster/memory.js +187 -0
  26. package/dist/cluster/placement.d.ts +10 -0
  27. package/dist/cluster/placement.js +30 -0
  28. package/dist/cluster/postgres/index.d.ts +1 -0
  29. package/dist/cluster/postgres/index.js +3 -0
  30. package/dist/cluster/postgres/schema.d.ts +7 -0
  31. package/dist/cluster/postgres/schema.js +33 -0
  32. package/dist/cluster/postgres/schema.sql +18 -0
  33. package/dist/cluster/postgres/store.d.ts +28 -0
  34. package/dist/cluster/postgres/store.js +124 -0
  35. package/dist/cluster/region.d.ts +103 -0
  36. package/dist/cluster/region.js +843 -0
  37. package/dist/cluster/remoting.d.ts +79 -0
  38. package/dist/cluster/remoting.js +755 -0
  39. package/dist/cluster/shard-memory.d.ts +14 -0
  40. package/dist/cluster/shard-memory.js +92 -0
  41. package/dist/cluster/shard-store.d.ts +62 -0
  42. package/dist/cluster/shard-store.js +36 -0
  43. package/dist/cluster/shard.d.ts +54 -0
  44. package/dist/cluster/shard.js +278 -0
  45. package/dist/cluster/sharding.d.ts +109 -0
  46. package/dist/cluster/sharding.js +278 -0
  47. package/dist/cluster/table.d.ts +29 -0
  48. package/dist/cluster/table.js +74 -0
  49. package/dist/cluster/transport.d.ts +29 -0
  50. package/dist/cluster/transport.js +4 -0
  51. package/dist/cluster/wire.d.ts +90 -0
  52. package/dist/cluster/wire.js +177 -0
  53. package/dist/hash.d.ts +7 -0
  54. package/dist/hash.js +25 -0
  55. package/dist/internal.d.ts +134 -2
  56. package/dist/internal.js +12 -1
  57. package/dist/json.d.ts +44 -0
  58. package/dist/json.js +143 -0
  59. package/dist/node/cluster/frames.d.ts +31 -0
  60. package/dist/node/cluster/frames.js +73 -0
  61. package/dist/node/cluster/index.d.ts +1 -0
  62. package/dist/node/cluster/index.js +3 -0
  63. package/dist/node/cluster/tcp.d.ts +101 -0
  64. package/dist/node/cluster/tcp.js +416 -0
  65. package/dist/persistence/actor.js +1 -1
  66. package/dist/persistence/backend.d.ts +1 -10
  67. package/dist/persistence/backend.js +4 -34
  68. package/dist/persistence/postgres/index.d.ts +2 -1
  69. package/dist/persistence/postgres/index.js +1 -1
  70. package/dist/persistence/postgres/pool.d.ts +44 -0
  71. package/dist/persistence/postgres/pool.js +65 -0
  72. package/dist/persistence/postgres/postgres.d.ts +1 -33
  73. package/dist/persistence/postgres/postgres.js +4 -63
  74. package/dist/system.d.ts +1 -1
  75. package/dist/system.js +190 -24
  76. package/dist/types.d.ts +86 -3
  77. package/package.json +25 -4
  78. package/dist/backstage-ui/assets/index-Bg0MCiqs.css +0 -1
  79. package/dist/backstage-ui/assets/index-CeefBsDh.js +0 -9
  80. package/dist/persistence/json.d.ts +0 -7
  81. package/dist/persistence/json.js +0 -75
package/CHANGELOG.md CHANGED
@@ -1,8 +1,27 @@
1
1
  # Changelog
2
2
 
3
- This project follows [Semantic Versioning](https://semver.org/). Under 0.x, a minor version can break the API, and it will in milestone 4. Each design choice behind these entries has a record in [docs/decisions](https://github.com/Fours/troupe/tree/main/docs/decisions).
3
+ This project follows [Semantic Versioning](https://semver.org/). Under 0.x, a minor version can break the API. 1.0 comes after milestone 5 ([0032](https://github.com/Fours/troupe/blob/main/docs/decisions/0032-1-0-comes-after-rehearsal.md)). Each design choice behind these entries has a record in [docs/decisions](https://github.com/Fours/troupe/tree/main/docs/decisions).
4
4
 
5
- ## 0.1.0 (unreleased)
5
+ ## 0.2.0 (2026-11-24)
6
+
7
+ Milestone 4: multi-node. Three new entry points, `/cluster`, `/cluster/postgres` and `/cluster/tcp`, for cluster sharding across Node processes with at most one live instance of each entity. Still no runtime dependencies, and `/cluster` and `/cluster/postgres` run on any runtime. The core changes that can break code are marked **Breaking**: the `deadLetter` reasons, the new `SystemEvent` types, and Backstage's protocol version.
8
+
9
+ - **Breaking:** `deadLetter`'s `reason` gains `unreachable`, `unserializable` and `invalid`, for messages that can't reach another node, can't be sent as JSON plus refs, or fail an entity type's schema. A `switch` over the reasons that has no `default` needs the new cases ([0025](https://github.com/Fours/troupe/blob/main/docs/decisions/0025-messages-on-the-wire-are-json-plus-refs.md)).
10
+ - `@kylewillett/troupe/cluster/tcp`: `tcpTransport({ port, host, advertise, secret })`, a transport for nodes in separate processes, on `node:net` with length-prefixed JSON frames. Peers prove a shared secret by challenge and response before anything else, and it never crosses the wire. It listens on `127.0.0.1` by default, and doesn't encrypt, so keep cluster traffic on a private network ([0027](https://github.com/Fours/troupe/blob/main/docs/decisions/0027-nodes-talk-tcp-with-a-shared-secret.md)).
11
+ - `@kylewillett/troupe/cluster`, for any runtime: `joinCluster(system, { name, transport, seeds })` joins a cluster through its seeds, and returns a `Cluster` with `self`, `members()`, `whenUp` and `leave()`. Membership is gossiped with no leader. Nodes heartbeat each other, a member unheard for `unreachableAfterMs` is unreachable, and one unreachable for `downAfterMs` more is downed, which ends watches on it. Only the first seed forms a cluster alone. It also exports `inMemoryNetwork({ scheduler, latencyMs })`, nodes in one process on one scheduler, and the `Transport` and `Connection` interfaces ([0028](https://github.com/Fours/troupe/blob/main/docs/decisions/0028-membership-is-gossiped-with-automatic-downing.md)).
12
+ - **Breaking:** `SystemEvent` gains `memberUp`, `memberLeaving`, `memberDown`, `memberRemoved` and `reachability`, published only by a system in a cluster. A `switch` over event types that has no `default` needs the new cases ([0028](https://github.com/Fours/troupe/blob/main/docs/decisions/0028-membership-is-gossiped-with-automatic-downing.md)).
13
+ - Shard leases: the `ShardStore` interface and `inMemoryShardStore({ clock })` in `@kylewillett/troupe/cluster`, and a new entry point, `@kylewillett/troupe/cluster/postgres`, for any runtime, with `postgresShardStore({ pool, schema })` on the same `pg`-compatible pool as the journal. Its tables can share the journal's schema, its `setup()` is safe alongside the journal's, and its SQL ships as `dist/cluster/postgres/schema.sql`. A lease's expiry is judged on the store's own clock, Postgres's `clock_timestamp()`, never a node's ([0029](https://github.com/Fours/troupe/blob/main/docs/decisions/0029-a-shard-is-owned-by-whoever-holds-its-lease.md)).
14
+ - Cluster sharding: `cluster.sharding.init({ type, entity, shardCount, supervision, host, schema, bufferSize })` registers an entity type, and its `ref(id)` gives an `ActorRef` to the entity with that id, wherever it lives. Entity refs travel in messages and outlive shard moves. Messages to entities are always encoded, even on one node, so one that isn't JSON plus refs is an `unserializable` dead letter wherever its entity is, and one that fails the type's Standard Schema is `invalid`. Shards go to the member with the highest rendezvous score, through a lease. `joinCluster` gains `shards`, the `ShardStore` every node shares, and `leases: { ttlMs, renewMs, marginMs }`, and `Cluster` gains `sharding`. `sharding.init` also takes `passivation: { idleMs }`, `remember`, `rebalanceMs` and `maxHandoffs`. Nodes rebalance: a shard whose desired owner is another node is handed off, a few at a time. A node that leaves, or whose system terminates, hands off every shard before it goes. A handoff stops the shard's entities once they've handled what they have, a persist included, then releases the lease, and messages that arrived meanwhile follow the shard ([0030](https://github.com/Fours/troupe/blob/main/docs/decisions/0030-shards-are-placed-by-rendezvous-hashing.md)).
15
+ - **Breaking:** `SystemEvent` gains `shardAcquired` and `shardReleased`, with the entity type, shard, node and lease token, and a release's reason ([0030](https://github.com/Fours/troupe/blob/main/docs/decisions/0030-shards-are-placed-by-rendezvous-hashing.md)).
16
+ - `ActorRef.path`'s TSDoc says what a ref to another node has: the full `troupe://<cluster>@<address>#<uid><path>` form, so two refs with the same path are the same actor. An entity ref's path is `/sharding/<type>/<id>` on every node ([0025](https://github.com/Fours/troupe/blob/main/docs/decisions/0025-messages-on-the-wire-are-json-plus-refs.md)).
17
+ - **Breaking:** Backstage's protocol is version 2, and `PROTOCOL` exports its number. `hello` gains `cluster`, a `ClusterInfo` with this node's address and uid, the members as it sees them (`MemberInfo`) and each entity type's shard owners (`EntityTypeInfo`), or `null` for a system with no cluster. A third frame, `{ type: 'cluster', cluster }`, comes whenever that view changes. A client that rejects frames it doesn't know needs the new one. The UI, served by `serveBackstage`, shows a Cluster panel on a cluster node, with the members and a grid of shard owners, and the sharding tree above `/user`. The UI still reads version 1 ([0021](https://github.com/Fours/troupe/blob/main/docs/decisions/0021-backstage-only-watches.md)).
18
+ - `ctx.watch` and a probe's `watch` accept refs to actors on other nodes, and signal `terminated` when the actor stops or its node goes. Watching a ref that isn't an actor still throws `TypeError` ([0026](https://github.com/Fours/troupe/blob/main/docs/decisions/0026-remoting-is-at-most-once-behind-a-transport.md)).
19
+
20
+ ## 0.1.1 (2026-11-23)
21
+
22
+ - The package's `homepage` is the demo site, <https://troupe.kylewillett.com/>, and the README links to the demo and to the design write-up, "How Troupe works", there. No code changed.
23
+
24
+ ## 0.1.0 (2026-11-22)
6
25
 
7
26
  The first published version. ESM only, for Node 22.18 or later, with no runtime dependencies. Everything but the SQLite backend and the Backstage server runs on any JavaScript runtime.
8
27
 
package/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # Troupe
2
2
 
3
- Typed actors for TypeScript, in the spirit of Akka: hierarchies, supervision, `ask`, timers, a testkit that runs on virtual time, and event-sourced persistent actors on an in-memory, SQLite or Postgres journal. Cluster sharding comes next.
3
+ Typed actors for TypeScript, in the spirit of Akka: hierarchies, supervision, `ask`, timers, a testkit that runs on virtual time, and event-sourced persistent actors on an in-memory, SQLite or Postgres journal, and cluster sharding across Node processes, with at most one live instance of each entity.
4
4
 
5
- > **Status:** 0.x, so a minor version can change the API, and milestone 4 will. See the [changelog](CHANGELOG.md), the [roadmap](docs/roadmap.md), and the specs for [milestone 1](docs/milestone-1.md), [milestone 2](docs/milestone-2.md) and [milestone 3](docs/milestone-3.md).
5
+ > **Status:** 0.x, so a minor version can change the API. 1.0 comes after milestone 5, Rehearsal, has tested the cluster against injected faults ([0032](docs/decisions/0032-1-0-comes-after-rehearsal.md)). See the [changelog](CHANGELOG.md), the [roadmap](docs/roadmap.md), and the specs for milestones [1](docs/milestone-1.md), [2](docs/milestone-2.md), [3](docs/milestone-3.md) and [4](docs/milestone-4.md).
6
+
7
+ **[See it run](https://troupe.kylewillett.com/):** opening night at a box office, a Troupe system running live in your browser with no backend, inspected by Backstage. Crash a show and watch it restart and recover from its journal, take the journal down, and scrub a show's events back through time. Then [festival night](https://troupe.kylewillett.com/cluster/): a dozen shows on three nodes in the page, with buttons that kill, restart and add nodes.
8
+
9
+ **[How it works](https://troupe.kylewillett.com/how-it-works/):** the design write-up, "How Troupe works", tells the [decision records](docs/decisions/) as one story, from actors as a state and a reducer to the benchmark's numbers, and links every claim to its record.
6
10
 
7
11
  - **Typed:** each actor has one message type, and refs are checked against it.
8
12
  - **No runtime dependencies**, and the core runs on any JavaScript runtime, not only Node.
@@ -25,6 +29,9 @@ It needs Node 22.18 or later, and is ESM only. Each release is published from CI
25
29
  | `@kylewillett/troupe/persistence/postgres` | the Postgres backend, on your own `pg` pool | any runtime with a pool |
26
30
  | `@kylewillett/troupe/backstage` | Backstage, the inspector: its protocol and an in-process source | any runtime |
27
31
  | `@kylewillett/troupe/backstage/server` | `serveBackstage`, the inspector's UI over HTTP | Node |
32
+ | `@kylewillett/troupe/cluster` | joining a cluster, cluster sharding, the in-memory network and shard store | any runtime |
33
+ | `@kylewillett/troupe/cluster/postgres` | the Postgres shard store, on your own `pg` pool | any runtime with a pool |
34
+ | `@kylewillett/troupe/cluster/tcp` | `tcpTransport`, nodes in separate processes, on `node:net` | Node |
28
35
 
29
36
  None of them has a runtime dependency.
30
37
 
@@ -321,6 +328,89 @@ An entity's events must form one stream. If two actors with the same `id` both w
321
328
 
322
329
  That's where supervision comes in. A restart replays the journal, so the loser catches up on the winner's events and carries on after them. Use **`restartWithBackoff`** for persistent actors. A conflict, or a database that's down, won't clear up in the next microtask, and every restart reads the whole stream again. Backoff spaces out those reads, with jitter so a fleet of entities doesn't retry in step, instead of hammering a journal that's already in trouble.
323
330
 
331
+ ## Clusters
332
+
333
+ `@kylewillett/troupe/cluster` spreads entities, such as accounts or shows, across several Node processes. You address an entity by its type and ID from any node, and `tell` or `ask` it as if it were local. Its ref works wherever the entity lives, and keeps working when it moves. If a node dies, its entities start again on the others, recovered from the journal.
334
+
335
+ ### Joining a cluster
336
+
337
+ Every node needs a transport, the same list of seeds, and the same shard store, which is where shard ownership lives:
338
+
339
+ ```ts
340
+ import pg from 'pg';
341
+ import { createActorSystem } from '@kylewillett/troupe';
342
+ import { joinCluster } from '@kylewillett/troupe/cluster';
343
+ import { postgresShardStore } from '@kylewillett/troupe/cluster/postgres';
344
+ import { tcpTransport } from '@kylewillett/troupe/cluster/tcp';
345
+ import { postgresPersistence } from '@kylewillett/troupe/persistence/postgres';
346
+
347
+ const secret = process.env.CLUSTER_SECRET;
348
+ if (!secret) throw new Error('CLUSTER_SECRET must be set');
349
+
350
+ const pool = new pg.Pool();
351
+ const persistence = postgresPersistence({ pool, schema: 'troupe' });
352
+ const shards = postgresShardStore({ pool, schema: 'troupe' });
353
+ await persistence.setup(); // both are safe on every start, from every node at once
354
+ await shards.setup();
355
+
356
+ const system = createActorSystem({ name: 'bank' });
357
+ const cluster = joinCluster(system, {
358
+ name: 'bank',
359
+ transport: tcpTransport({ port: 2552, host: '10.0.0.1', secret }),
360
+ seeds: ['10.0.0.1:2552', '10.0.0.2:2552', '10.0.0.3:2552'],
361
+ shards,
362
+ });
363
+ await cluster.whenUp;
364
+ ```
365
+
366
+ - **Seeds.** A node joins through any seed that answers. Only the first seed may form a cluster on its own, after `seedTimeoutMs` (5 s) with no other seed answering, so two halves can't each form one at start-up. Give every node the same list.
367
+ - **Membership is gossiped, with no leader.** Nodes heartbeat each other every `heartbeatMs` (1 s). One unheard for `unreachableAfterMs` (5 s) is unreachable, and one unreachable for `downAfterMs` (10 s) more is marked down, automatically. That's safe here because being marked down never decides who owns a shard: the lease does ([0028](docs/decisions/0028-membership-is-gossiped-with-automatic-downing.md)). A node that learns it was marked down leaves, and comes back only by restarting.
368
+ - **Leaving.** `cluster.leave()`, or `system.terminate()`, hands every shard this node holds to its next owner, after each entity finishes what it's doing, a persist included, then leaves. Call it on SIGTERM.
369
+ - `cluster.members()` is this node's view of the members, and the system's event stream has `memberUp`, `memberLeaving`, `memberDown`, `memberRemoved`, `reachability`, `shardAcquired` and `shardReleased`.
370
+
371
+ For nodes in one process, such as tests or a browser, `inMemoryNetwork({ scheduler })` gives each node a transport and `inMemoryShardStore()` a store, and the same code runs on the testkit's virtual time.
372
+
373
+ ### Sharding an entity type
374
+
375
+ ```ts
376
+ import type { ActorRef } from '@kylewillett/troupe';
377
+
378
+ // account(id) is the persistent account from "Defining one", on the Postgres persistence above.
379
+ const accounts = cluster.sharding.init({ type: 'account', entity: account, shardCount: 64 });
380
+
381
+ const alice: ActorRef<AccountCmd> = accounts.ref('alice');
382
+ await alice.ask<Receipt>((replyTo) => ({ type: 'deposit', amount: 10, replyTo }), { timeoutMs: 5_000 });
383
+ ```
384
+
385
+ - An entity's ID is hashed into one of `shardCount` shards, and each shard lives on one node. Every node that calls `init` for a type hosts some of its shards. `host: false` makes a node that only routes, such as a web server. `shardCount` must be the same on every node, and can't change on a running cluster.
386
+ - A shard goes to the member with the highest rendezvous hash of the shard and the member, so every node computes the same owner without a coordinator, and a new node takes only the shards it now tops, about one in N ([0030](docs/decisions/0030-shards-are-placed-by-rendezvous-hashing.md)). Shards move by handoff, a few at a time every `rebalanceMs`.
387
+ - An entity starts on its first message, and again after it stops. `passivation: { idleMs }` stops idle ones. `remember: true` starts a shard's entities as soon as the shard lands on a node, rather than on their next message.
388
+ - `schema` checks every message an entity gets with any Standard Schema library, after it crosses the wire. One that fails is an `invalid` dead letter.
389
+ - `supervision` is the type's, as for any child. The default is `supervise.stop()`, and the next message starts the entity again.
390
+
391
+ ### What's guaranteed, and what isn't
392
+
393
+ - **At most one live instance of each entity.** A shard is owned by whoever holds its lease in the shard store, never by whoever membership thinks is alive. Postgres judges a lease's expiry on its own clock, and the holder gives it up a margin earlier on its own, so no two clocks are compared. A node cut off from Postgres stops its shards before anyone else can start them ([0029](docs/decisions/0029-a-shard-is-owned-by-whoever-holds-its-lease.md)). If a node pauses past its lease and wakes to write once more, the journal's sequence check fails one of the two writes ([0013](docs/decisions/0013-sequence-check-is-the-single-writer-backstop.md)).
394
+ - **At most once delivery.** Nothing is retried or acknowledged. A message on a connection that breaks, or sent to a node in the seconds before anyone notices it died, is lost, and an `ask` for it times out. If a request must happen, ask again, and make it safe to repeat ([0026](docs/decisions/0026-remoting-is-at-most-once-behind-a-transport.md)).
395
+ - **Order per pair.** Messages from one node to one actor arrive in the order they were sent. While an entity's shard moves, messages already on their way can be reordered, but never delivered twice.
396
+ - **Messages are JSON plus refs.** Every message to an entity is encoded, even when the entity is on the same node, so one with a `Map`, a class instance or a function fails on your laptop, not in production when its shard moves. It becomes an `unserializable` dead letter, and a warning names the bad path ([0025](docs/decisions/0025-messages-on-the-wire-are-json-plus-refs.md)). Refs can go anywhere in a message, and arrive as refs.
397
+ - **Not guaranteed:** exactly-once delivery; availability while Postgres is unreachable, since every shard stops at its lease deadline rather than risk a second copy; a split-brain strategy, so while a partition lasts, the side that can't reach a shard's holder waits for it to heal, or for the holder to learn it was marked down and leave; encryption between nodes.
398
+ - **Not built:** spawning an actor on another node, looking an actor up by path on another node, and cluster singletons. Refs travel in messages, or come from sharding.
399
+
400
+ ### The secret, and the private network
401
+
402
+ `tcpTransport` frames JSON on `node:net`, with nothing but Node underneath. Before anything else, each side proves it knows `secret` by answering a random challenge with an HMAC, so the secret itself never crosses the wire ([0027](docs/decisions/0027-nodes-talk-tcp-with-a-shared-secret.md)). A node that can't prove it is disconnected.
403
+
404
+ > **Nothing between nodes is encrypted.** Remoting lets a node tell any actor anything, so keep cluster traffic on a private network that only your nodes can reach, and keep the secret out of source control. `tcpTransport` listens on `127.0.0.1` unless you set `host`. When the address other nodes should dial differs from the one it listens on, as in Docker or behind NAT, set `advertise` to it.
405
+
406
+ ### Failover
407
+
408
+ With the default leases (`ttlMs` 10,000, renewed every 3,000, given up 2,000 early), a node killed with `kill -9` has its entities back on the others once its leases expire. Over 60 kills of three nodes on TCP and Postgres, 20 on each of Node 22, 24 and 26, an entity on the killed node answered from another node after 10.4 to 11.0 s at the median, and 11.7 s at worst ([0031](docs/decisions/0031-failover-waits-for-the-lease-not-for-downing.md)). A graceful leave is much quicker: the handoff takes milliseconds, and no ask is lost.
409
+
410
+ Shorter leases fail over faster, at a price: a node that stalls, in a long GC pause or a slow Postgres, for longer than `ttlMs` minus `marginMs` loses every lease it holds. Pass `leases: { ttlMs, renewMs, marginMs }` to `joinCluster`, the same on every node, and keep `unreachableAfterMs` shorter than `ttlMs` minus `renewMs`.
411
+
412
+ Backstage works on a cluster node too. It adds a Cluster panel, with the members as this node sees them and a grid of who holds each shard, and shows the sharding tree above `/user`.
413
+
324
414
  ## Pitfalls
325
415
 
326
416
  - **Don't await an `ask` inside `receive` to an actor that might ask you back.** An async `receive` holds the mailbox until it settles. If the other actor asks this one in turn, neither can answer until the ask times out. Use `pipeToSelf` for requests between actors: the mailbox stays open while the reply is on its way. Under the testkit, a piped ask also runs entirely on virtual time ([0010](docs/decisions/0010-piped-asks-stay-on-the-scheduler.md)). An awaited ask that can only time out makes `settle` throw.
@@ -355,6 +445,45 @@ A malformed request crashes `hamlet`, which restarts with backoff and recovers i
355
445
 
356
446
  One thing doesn't come back exactly: a recovered hold gets a fresh timer for the full hold time, because holds don't remember how long they had left. Durable timers are a later idea. [test/examples/box-office.test.ts](test/examples/box-office.test.ts) runs the same story under the testkit, with two systems sharing one in-memory backend.
357
447
 
448
+ ## Festival night in Docker
449
+
450
+ Three nodes, a crowd and Postgres, from this repository's `examples/cluster/`, in Docker Compose. Each show is an entity, and the crowd, a node that hosts nothing, buys seats at a dozen shows over and over. You need Docker and Node 22.18 or later.
451
+
452
+ ```bash
453
+ npm ci
454
+ npm run cluster:up
455
+ ```
456
+
457
+ It builds the package into an image, starts everything, and follows the log in plain words: who's up, which node has which shows, and what happens when something goes wrong. Each node serves Backstage on its own port, so open <http://127.0.0.1:7071/> for node-1, 7072 and 7073 for the others, and 7074 for the crowd, whose shard grid is its routing table.
458
+
459
+ In another terminal, kill a node:
460
+
461
+ ```bash
462
+ docker compose -f docker-compose.cluster.yml kill node-2
463
+ ```
464
+
465
+ node-2's shows stop answering, and the crowd's asks to them time out for about ten seconds, until their leases run out. Then they answer from node-1 and node-3, with every sale they had confirmed:
466
+
467
+ ```text
468
+ 17.6s the-tempest didn't answer in time. The crowd keeps asking.
469
+ 20.0s node-2 stopped answering heartbeats. Its shows can't be reached.
470
+ 25.1s the-tempest answers again, now from node-3, 9.8 s after its last sale on node-2. It picked up at sale 85, so its 82 confirmed sales survived.
471
+ ```
472
+
473
+ Start it again, and shows move back to it, a few at a time:
474
+
475
+ ```bash
476
+ docker compose -f docker-compose.cluster.yml start node-2
477
+ ```
478
+
479
+ Stop one gracefully, and it hands its shows off before it exits, with no ask lost:
480
+
481
+ ```bash
482
+ docker compose -f docker-compose.cluster.yml stop node-3
483
+ ```
484
+
485
+ `npm run cluster:down` removes it all. The log is JSON lines underneath: `docker compose -f docker-compose.cluster.yml logs crowd` shows them as written. The nodes share a demo secret, which you can change with `CLUSTER_SECRET` in a `.env` file. `npm run cluster:smoke` runs the same story as a check, and CI runs it on every push.
486
+
358
487
  ## Development
359
488
 
360
489
  ```bash
@@ -367,6 +496,7 @@ The Postgres tests need a database. `npm run postgres:up` starts one on port 544
367
496
  ```bash
368
497
  npm run postgres:up
369
498
  npm run test:integration && npm run coverage
499
+ npm run test:cluster # real node processes on TCP and that Postgres, killed and restarted
370
500
  npm run postgres:down
371
501
  ```
372
502
 
package/dist/ask.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { EventBus } from './events.js';
2
- import type { ActorRef, AskOptions, Result } from './types.js';
2
+ import type { ActorRef, AnyRef, AskOptions, Result } from './types.js';
3
3
  /** What an {@link Asker} needs from its system. */
4
4
  export interface AskerHost {
5
5
  readonly events: EventBus;
@@ -20,6 +20,10 @@ export declare class Asker {
20
20
  constructor(host: AskerHost);
21
21
  /** Freezes `path` and `tell` into a ref, with an `ask` that targets it. */
22
22
  ref<M>(path: string, tell: (msg: M) => void): ActorRef<M>;
23
+ /** Whether this asker made `ref`: a cell's, an ask's, a probe's, or one made through `ref`. */
24
+ owns(ref: unknown): boolean;
25
+ /** The temporary ref at `path`, while its ask waits for a reply or its timeout. */
26
+ temp(path: string): AnyRef | undefined;
23
27
  /**
24
28
  * Rejects every pending ask, and every later one, with `ActorSystemTerminatedError`. It does
25
29
  * this at once rather than after `/user` has stopped: an actor whose async `receive` awaits an
package/dist/ask.js CHANGED
@@ -15,6 +15,11 @@ export class Asker {
15
15
  // Rejects each ask that's still waiting, for terminate().
16
16
  #pending = new Set();
17
17
  #outcomes = new WeakMap();
18
+ // Every ref this asker made, so the wire can refuse refs from another system (decision 0025).
19
+ #made = new WeakSet();
20
+ // The temporary refs of asks still waiting, by path, so a reply from another node can find
21
+ // its ask (decision 0025).
22
+ #temps = new Map();
18
23
  #generated = 0;
19
24
  #terminated = false;
20
25
  constructor(host) {
@@ -27,8 +32,17 @@ export class Asker {
27
32
  tell,
28
33
  ask: (build, opts) => this.ask(ref, build, opts),
29
34
  });
35
+ this.#made.add(ref);
30
36
  return ref;
31
37
  }
38
+ /** Whether this asker made `ref`: a cell's, an ask's, a probe's, or one made through `ref`. */
39
+ owns(ref) {
40
+ return typeof ref === 'object' && ref !== null && this.#made.has(ref);
41
+ }
42
+ /** The temporary ref at `path`, while its ask waits for a reply or its timeout. */
43
+ temp(path) {
44
+ return this.#temps.get(path);
45
+ }
32
46
  /**
33
47
  * Rejects every pending ask, and every later one, with `ActorSystemTerminatedError`. It does
34
48
  * this at once rather than after `/user` has stopped: an actor whose async `receive` awaits an
@@ -79,6 +93,7 @@ export class Asker {
79
93
  done = true;
80
94
  cancelTimer();
81
95
  this.#pending.delete(fail);
96
+ this.#temps.delete(path);
82
97
  return true;
83
98
  };
84
99
  const fail = (error) => {
@@ -111,6 +126,7 @@ export class Asker {
111
126
  fail(new AskTimeoutError(target.path, timeoutMs));
112
127
  }, timeoutMs);
113
128
  this.#pending.add(fail);
129
+ this.#temps.set(path, replyTo);
114
130
  target.tell(msg);
115
131
  });
116
132
  this.#outcomes.set(promise, outcome);
@@ -1,4 +1,5 @@
1
1
  export { backstage } from './source.js';
2
2
  export { encode } from './encode.js';
3
+ export { PROTOCOL } from './types.js';
3
4
  export type { WireValue } from './encode.js';
4
- export type { ActorInfo, ActorStatus, BackstageError, BackstageOptions, BackstageRequest, BackstageResponse, BackstageSource, Frame, TimelineEvent, WireEvent, } from './types.js';
5
+ export type { ActorInfo, ActorStatus, BackstageError, BackstageOptions, BackstageRequest, BackstageResponse, BackstageSource, ClusterInfo, EntityTypeInfo, Frame, MemberInfo, TimelineEvent, WireEvent, } from './types.js';
@@ -2,3 +2,4 @@
2
2
  // It runs in any runtime (decision 0004). Backstage only watches (decision 0021).
3
3
  export { backstage } from './source.js';
4
4
  export { encode } from './encode.js';
5
+ export { PROTOCOL } from './types.js';
@@ -1,5 +1,5 @@
1
1
  import type { ActorSystem } from '../types.js';
2
- import type { BackstageOptions, BackstageSource } from './types.js';
2
+ import { type BackstageOptions, type BackstageSource } from './types.js';
3
3
  /**
4
4
  * Attaches an inspector to a system. Runs in any runtime. It subscribes with `{ messages: true }`,
5
5
  * so message events are on until {@link BackstageSource.close}. Backstage only watches: nothing it
@@ -2,9 +2,10 @@
2
2
  // message events on, encodes each event once as it happens (a message may change afterwards), and
3
3
  // keeps a ring of lifecycle events so a page opened after a crash still shows it (decision 0021).
4
4
  import { checkInt, checkKeys } from '../checks.js';
5
- import { inspectSystem } from '../internal.js';
5
+ import { inspectSystem, } from '../internal.js';
6
6
  import { encode } from './encode.js';
7
7
  import { answer, failure } from './requests.js';
8
+ import { PROTOCOL, } from './types.js';
8
9
  const OPTIONS = new Set(['history']);
9
10
  const DEFAULT_HISTORY = 500;
10
11
  /** The events a new connection's history keeps. Message events aren't: the UI keeps its own. */
@@ -16,6 +17,13 @@ const LIFECYCLE = new Set([
16
17
  'persisted',
17
18
  'recovered',
18
19
  'deadLetter',
20
+ 'memberUp',
21
+ 'memberLeaving',
22
+ 'memberDown',
23
+ 'memberRemoved',
24
+ 'reachability',
25
+ 'shardAcquired',
26
+ 'shardReleased',
19
27
  ]);
20
28
  /**
21
29
  * Attaches an inspector to a system. Runs in any runtime. It subscribes with `{ messages: true }`,
@@ -41,6 +49,30 @@ export function backstage(system, opts) {
41
49
  }
42
50
  }
43
51
  };
52
+ // The cluster view, sent as a `cluster` frame once the changes of one turn have settled, and
53
+ // only when it differs from the last one sent: a region relearning the same holders sends none.
54
+ let lastCluster;
55
+ let flushQueued = false;
56
+ const flush = () => {
57
+ flushQueued = false;
58
+ if (closed)
59
+ return;
60
+ const view = inspection.cluster();
61
+ if (view === undefined)
62
+ return;
63
+ const cluster = clusterInfo(view);
64
+ const text = JSON.stringify(cluster);
65
+ if (text === lastCluster)
66
+ return;
67
+ lastCluster = text;
68
+ deliver({ type: 'cluster', cluster }, listeners);
69
+ };
70
+ const stopClusterChanges = inspection.onClusterChange(() => {
71
+ if (flushQueued || listeners.length === 0)
72
+ return;
73
+ flushQueued = true;
74
+ queueMicrotask(flush);
75
+ });
44
76
  const unsubscribe = system.events.subscribe((event) => {
45
77
  const lifecycle = LIFECYCLE.has(event.type);
46
78
  // Nobody connected and nothing to keep: skip the encoding.
@@ -61,12 +93,19 @@ export function backstage(system, opts) {
61
93
  listeners = [...listeners, listener];
62
94
  const hello = {
63
95
  type: 'hello',
64
- protocol: 1,
96
+ protocol: PROTOCOL,
65
97
  system: system.name,
66
98
  now: inspection.scheduler.now(),
67
99
  actors: inspection.walk().map(actorInfo),
68
100
  history: history.items(),
101
+ cluster: currentCluster(inspection),
69
102
  };
103
+ // With nobody connected, changes weren't followed, so this hello is now the last view sent.
104
+ // With others connected, any change since their last view has a flush queued, which sends
105
+ // everyone the same view, this one included.
106
+ if (hello.cluster !== null && listeners.length === 1) {
107
+ lastCluster = JSON.stringify(hello.cluster);
108
+ }
70
109
  deliver(hello, [listener]);
71
110
  let connected = true;
72
111
  return () => {
@@ -90,6 +129,7 @@ export function backstage(system, opts) {
90
129
  closed = true;
91
130
  listeners = [];
92
131
  unsubscribe();
132
+ stopClusterChanges();
93
133
  },
94
134
  });
95
135
  }
@@ -101,6 +141,29 @@ function checkOptions(opts) {
101
141
  checkInt(history, 'backstage: history', { min: 0 });
102
142
  return history;
103
143
  }
144
+ function currentCluster(inspection) {
145
+ const view = inspection.cluster();
146
+ return view === undefined ? null : clusterInfo(view);
147
+ }
148
+ /** The view, copied into plain frames, so a later change can't reach a frame already sent. */
149
+ function clusterInfo(view) {
150
+ return {
151
+ address: view.address,
152
+ uid: view.uid,
153
+ members: view.members().map(({ address, uid, status, reachable }) => ({
154
+ address,
155
+ uid,
156
+ status,
157
+ reachable,
158
+ })),
159
+ types: view.entityTypes().map(({ type, shardCount, host, owners }) => ({
160
+ type,
161
+ shardCount,
162
+ host,
163
+ shards: owners.map(([shard, owner]) => ({ shard, owner })),
164
+ })),
165
+ };
166
+ }
104
167
  function actorInfo(cell) {
105
168
  const { path, status, depth, persistent } = cell;
106
169
  return persistent === undefined
@@ -42,22 +42,83 @@ type Wire<E> = E extends unknown ? {
42
42
  } : never;
43
43
  /** A {@link SystemEvent} with what it carries (messages, errors) encoded as {@link WireValue}s. */
44
44
  export type WireEvent = Wire<SystemEvent>;
45
+ /** One member of a cluster, as the node a source is attached to sees it. */
46
+ export interface MemberInfo {
47
+ /** The address other nodes reach it at. */
48
+ readonly address: string;
49
+ /** Its uid, new on every start. With the address, it names the holder `<address>#<uid>`. */
50
+ readonly uid: number;
51
+ /** `up`, `leaving` gracefully, or `down`. */
52
+ readonly status: 'up' | 'leaving' | 'down';
53
+ /** Whether this node hears its heartbeats: this node's own view. */
54
+ readonly reachable: boolean;
55
+ }
56
+ /** One entity type on the node, and the owners of its shards as that node knows them. */
57
+ export interface EntityTypeInfo {
58
+ /** The type's name, such as `show`. */
59
+ readonly type: string;
60
+ /** How many shards the type's entities are spread over. */
61
+ readonly shardCount: number;
62
+ /** Whether this node hosts the type's shards, or only routes to them. */
63
+ readonly host: boolean;
64
+ /**
65
+ * Each shard whose owner this node knows, in shard order, with its holder, `<address>#<uid>`:
66
+ * the shards this node runs, and the holders its region last learned for the others. A shard
67
+ * that isn't listed has no owner this node knows of.
68
+ */
69
+ readonly shards: readonly {
70
+ readonly shard: number;
71
+ readonly owner: string;
72
+ }[];
73
+ }
74
+ /** The node's place in its cluster, as a `hello` or a `cluster` frame gives it. */
75
+ export interface ClusterInfo {
76
+ /** This node's address. */
77
+ readonly address: string;
78
+ /** This node's uid. */
79
+ readonly uid: number;
80
+ /** The members as this node sees them, itself included, sorted by address. */
81
+ readonly members: readonly MemberInfo[];
82
+ /** The entity types this node has registered, in the order it registered them. */
83
+ readonly types: readonly EntityTypeInfo[];
84
+ }
85
+ /** The protocol's version: 2 since milestone 4, which added the cluster. */
86
+ export declare const PROTOCOL = 2;
45
87
  /** What a source sends a connection. */
46
88
  export type Frame = {
47
89
  readonly type: 'hello';
48
- /** The protocol's version. */
49
- readonly protocol: 1;
90
+ /**
91
+ * The protocol's version. Version 1 had no `cluster` and no `cluster` frames, and an
92
+ * inspector can read it as a system with no cluster.
93
+ */
94
+ readonly protocol: typeof PROTOCOL;
50
95
  /** The system's name. */
51
96
  readonly system: string;
52
97
  /** The system scheduler's time when the frame was made. */
53
98
  readonly now: number;
54
- /** Every live actor under `/user`, each parent before its children. */
99
+ /**
100
+ * Every live actor under `/user`, then under `/system/sharding` (a cluster's regions,
101
+ * shards and entities), each parent before its children.
102
+ */
55
103
  readonly actors: readonly ActorInfo[];
56
- /** Lifecycle events since the source attached, oldest first, at most `history`. */
104
+ /**
105
+ * Lifecycle events since the source attached, oldest first, at most `history`: member and
106
+ * shard events among them.
107
+ */
57
108
  readonly history: readonly WireEvent[];
109
+ /** The node's place in its cluster, or `null` for a system that isn't in one. */
110
+ readonly cluster: ClusterInfo | null;
58
111
  } | {
59
112
  readonly type: 'event';
60
113
  readonly event: WireEvent;
114
+ }
115
+ /**
116
+ * The node's view of its cluster has changed: a member, its reachability, or a shard owner it
117
+ * knows of. Sent once the change has settled, never twice in a row with the same view.
118
+ */
119
+ | {
120
+ readonly type: 'cluster';
121
+ readonly cluster: ClusterInfo;
61
122
  };
62
123
  /** A question for a source. None of them changes anything. */
63
124
  export type BackstageRequest =
@@ -1,3 +1,4 @@
1
1
  // The Backstage protocol (decision 0021): JSON frames from a source to an inspector, and read-only
2
2
  // requests back. Refs travel as paths, so milestone 4 can send all of it from another node.
3
- export {};
3
+ /** The protocol's version: 2 since milestone 4, which added the cluster. */
4
+ export const PROTOCOL = 2;
@@ -0,0 +1 @@
1
+ .backstage{--bs-bg:#fff;--bs-panel:#faf9fc;--bs-fg:#1c1b22;--bs-muted:#5d5b66;--bs-line:#e3e1ea;--bs-accent:#7a2e3a;--bs-select:#f3e6e8;--bs-changed:#f6dfa4;--bs-running:#2f7d4f;--bs-starting:#2b63b5;--bs-restarting:#b86e00;--bs-stopped:#8f8c99;--bs-error:#b3261e;--bs-bar:#c9768a;--bs-flow:#7a2e3a;--bs-mono:ui-monospace, "SF Mono", Menlo, Consolas, monospace;--bs-node-0:#2b63b5;--bs-node-1:#b4531c;--bs-node-2:#2f7d4f;--bs-node-3:#8a3ea8;--bs-node-4:#a8770b;--bs-node-5:#1f7f86;color:var(--bs-fg);min-width:0;container-type:inline-size}.bs-grid{grid-template-columns:minmax(19rem,1fr) minmax(0,1.25fr) minmax(0,1.25fr);align-items:start;gap:1rem;display:grid}@media (prefers-color-scheme:dark){.backstage{--bs-bg:#17161c;--bs-panel:#1e1d24;--bs-fg:#ecebf1;--bs-muted:#a3a1ad;--bs-line:#2f2d38;--bs-accent:#d77a88;--bs-select:#3a2328;--bs-changed:#5b4714;--bs-running:#6fcf97;--bs-starting:#8ab4f8;--bs-restarting:#f2b04c;--bs-stopped:#6d6a78;--bs-error:#f2b8b5;--bs-bar:#b0566c;--bs-flow:#e8a0ab;--bs-node-0:#8ab4f8;--bs-node-1:#f29b6b;--bs-node-2:#6fcf97;--bs-node-3:#cf9be6;--bs-node-4:#e6c15c;--bs-node-5:#6ccfd6}}.backstage h2{margin:0 0 .25rem;font-size:1.05rem}.backstage h3{margin:.25rem 0;font-size:1rem}.backstage h4{text-transform:uppercase;letter-spacing:.04em;color:var(--bs-muted);margin:1rem 0 .35rem;font-size:.85rem}.bs-panel{background:var(--bs-panel);border:1px solid var(--bs-line);border-radius:8px;min-width:0;padding:.75rem}.bs-explain{margin:0 0 .25rem;font-size:.9rem}.bs-more{color:var(--bs-muted);margin-bottom:.5rem;font-size:.85rem}.bs-more summary{cursor:pointer}.bs-more p{margin:.25rem 0}.bs-empty,.bs-note{color:var(--bs-muted);font-size:.85rem}.bs-error{color:var(--bs-error);font-size:.9rem}.bs-path{font-family:var(--bs-mono);color:var(--bs-muted);overflow-wrap:anywhere;font-size:.8rem;font-weight:400}.bs-summary{margin:0 0 .5rem;font-size:.9rem}.bs-tabs{display:none}.bs-tree{min-height:30px;max-height:34rem;position:relative;overflow:hidden auto;container:bs-tree/inline-size}.bs-flows{pointer-events:none;position:absolute;top:0;left:0}.bs-flow{fill:none;stroke:var(--bs-flow);stroke-width:1.5px;animation:.7s ease-out forwards bs-flow}@keyframes bs-flow{0%{opacity:1}to{opacity:0}}.bs-tree-list{margin:0;padding:0;list-style:none}.bs-row{cursor:pointer;white-space:nowrap;border-radius:4px;align-items:center;gap:.4rem;height:30px;padding-right:.25rem;font-size:.9rem;animation:.3s ease-out bs-appear;display:flex}.bs-row:hover{background:var(--bs-line)}.bs-row:focus-visible{outline:2px solid var(--bs-accent);outline-offset:-2px}.bs-row.bs-selected{background:var(--bs-select)}@keyframes bs-appear{0%{opacity:0;transform:translate(-6px)}}.bs-dot{background:var(--bs-running);border-radius:50%;flex:none;width:.6rem;height:.6rem}.bs-starting .bs-dot{background:var(--bs-starting)}.bs-restarting .bs-dot,.bs-stopping .bs-dot{background:var(--bs-restarting);animation:.6s ease-in-out infinite alternate bs-pulse}.bs-stopped{animation:1.5s ease-in forwards bs-fade}.bs-stopped .bs-dot{background:var(--bs-stopped)}@keyframes bs-pulse{to{transform:scale(1.5)}}@keyframes bs-fade{to{opacity:.25}}.bs-name{text-overflow:ellipsis;overflow:hidden}.bs-name,.bs-phase,.bs-tag{text-overflow:ellipsis;flex:0 auto;min-width:0;overflow:hidden}.bs-name{min-width:2.5em}.bs-tag{flex-shrink:3}@container bs-tree (width<=20rem){.bs-row{gap:.25rem}.bs-row:not(.bs-running) .bs-tag{display:none}}.bs-phase{color:var(--bs-restarting);font-size:.75rem}.bs-stopped .bs-phase{color:var(--bs-stopped)}.bs-failures{color:var(--bs-error);flex:none;font-size:.75rem}.bs-tag{border:1px solid var(--bs-line);color:var(--bs-muted);border-radius:999px;padding:0 .3rem;font-size:.7rem}.bs-mailbox{flex:0 6 auto;align-items:center;gap:.3rem;margin-left:auto;display:flex}.bs-bar{background:var(--bs-line);border-radius:999px;flex:0 4rem;min-width:1.25rem;height:.45rem;overflow:hidden}.bs-fill{background:var(--bs-bar);height:100%;transition:width .12s linear;display:block}.bs-depth{text-align:right;font-variant-numeric:tabular-nums;min-width:1.6rem;color:var(--bs-muted);flex:none;font-size:.8rem}.bs-value{font-family:var(--bs-mono);background:var(--bs-bg);border:1px solid var(--bs-line);white-space:pre-wrap;overflow-wrap:anywhere;border-radius:6px;max-height:18rem;margin:0;padding:.5rem;font-size:.8rem;line-height:1.45;overflow:auto}.bs-entries{padding-left:1.2em;display:block}.bs-entry{display:block}.bs-key{color:var(--bs-muted)}.bs-string{color:var(--bs-running)}.bs-number,.bs-boolean{color:var(--bs-starting)}.bs-null{color:var(--bs-stopped)}.bs-chip{font-family:var(--bs-mono);border:1px solid var(--bs-line);background:var(--bs-panel);border-radius:4px;padding:0 .35rem;font-size:.75rem}.bs-chip-ref{color:var(--bs-accent)}.bs-chip-error{color:var(--bs-error)}.bs-chip-cut,.bs-chip-cycle,.bs-chip-value{color:var(--bs-muted)}.bs-changed{background:var(--bs-changed);color:inherit;outline:1px solid var(--bs-restarting);border-radius:3px}.bs-changed.bs-block{vertical-align:top;display:inline-block}.bs-removed{color:var(--bs-muted);text-decoration:line-through}.bs-chart{margin:0}.bs-chart svg{width:100%;height:56px;display:block}.bs-chart figcaption{color:var(--bs-muted);font-size:.75rem}.bs-axis{stroke:var(--bs-line)}.bs-line{fill:none;stroke:var(--bs-bar);stroke-width:2px}.bs-scroll{overflow-x:auto}.bs-messages{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;font-size:.8rem}.bs-messages th,.bs-messages td{text-align:left;border-bottom:1px solid var(--bs-line);white-space:nowrap;padding:.15rem .4rem .15rem 0}.bs-messages th{color:var(--bs-muted);font-weight:600}.bs-message code{font-family:var(--bs-mono);font-size:.75rem}.bs-outcome-failed td,.bs-outcome-dropped td{color:var(--bs-error)}.bs-outcome-waiting td,.bs-outcome-skipped td{color:var(--bs-muted)}.bs-failure-list{margin:0;padding-left:1.5rem;font-size:.85rem}.bs-failure-list time{font-variant-numeric:tabular-nums;color:var(--bs-muted)}.bs-scrubber{align-items:center;gap:.5rem;margin:.5rem 0;display:flex}.bs-scrubber input{accent-color:var(--bs-accent);flex:1;min-width:0}.backstage button{font:inherit;color:inherit}.bs-scrubber button{border:1px solid var(--bs-line);background:var(--bs-bg);cursor:pointer;border-radius:6px;padding:.2rem .7rem}.bs-scrubber button[aria-pressed=true]{background:var(--bs-accent);border-color:var(--bs-accent);color:var(--bs-bg)}.bs-events{max-height:16rem;margin:0;padding:0;list-style:none;overflow-y:auto}.bs-event{text-align:left;cursor:pointer;background:0 0;border:none;border-radius:4px;align-items:center;gap:.5rem;width:100%;padding:.15rem .25rem;font-size:.8rem;display:flex}.bs-event:hover{background:var(--bs-line)}.bs-event[aria-current=true]{background:var(--bs-select)}.bs-event code{font-family:var(--bs-mono);text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0;font-size:.75rem;overflow:hidden}.bs-seq{text-align:right;font-variant-numeric:tabular-nums;width:2.5rem;color:var(--bs-muted);flex:none}.bs-event time{color:var(--bs-muted);font-variant-numeric:tabular-nums;flex:none}.bs-section{box-sizing:border-box;text-transform:uppercase;letter-spacing:.04em;height:30px;color:var(--bs-muted);white-space:nowrap;text-overflow:ellipsis;align-items:flex-end;padding-bottom:.2rem;font-size:.75rem;display:flex;overflow:hidden}.bs-panel-cluster{grid-column:1/-1}.bs-cluster{grid-template-columns:minmax(16rem,auto) minmax(0,1fr);align-items:start;gap:.5rem 1.5rem;display:grid}.bs-members{border-collapse:collapse;font-size:.85rem}.bs-members th,.bs-members td{text-align:left;border-bottom:1px solid var(--bs-line);white-space:nowrap;padding:.2rem .6rem .2rem 0}.bs-members thead th{color:var(--bs-muted);font-size:.75rem;font-weight:400}.bs-members tbody th{font-weight:600}.bs-members .bs-tag{margin-left:.35rem;font-weight:400}.bs-uid{font-family:var(--bs-mono);color:var(--bs-muted);margin-left:.35rem;font-size:.75rem;font-weight:400}.bs-members tr[data-status=down] th,.bs-members tr[data-status=down] td{color:var(--bs-stopped)}.bs-status-leaving{color:var(--bs-restarting)}.bs-status-down,.bs-unreachable{color:var(--bs-error)}.bs-swatch{vertical-align:-.05rem;background:var(--bs-node);border-radius:3px;width:.7rem;height:.7rem;margin-right:.4rem;display:inline-block}.bs-shard-type h3{font-size:.9rem}.bs-shard-type .bs-note{font-weight:400}.bs-shards{grid-template-columns:repeat(auto-fill,minmax(1.9rem,1fr));gap:3px;margin:0;padding:0;list-style:none;display:grid}.bs-shard{font-variant-numeric:tabular-nums;height:1.6rem;color:var(--bs-bg);background:var(--bs-node);border-radius:3px;justify-content:center;align-items:center;font-size:.7rem;transition:background-color .4s;display:flex}.bs-unowned{color:var(--bs-muted);border:1px dashed var(--bs-line);background:0 0}.bs-shard.bs-gone{background:repeating-linear-gradient(-45deg, var(--bs-node), var(--bs-node) 3px, var(--bs-panel) 3px, var(--bs-panel) 6px);color:var(--bs-fg)}.bs-moved{animation:1.5s ease-out bs-moved}@keyframes bs-moved{0%{box-shadow:0 0 0 3px var(--bs-accent);transform:scale(1.35)}to{transform:none;box-shadow:0 0 #0000}}.bs-node-0{--bs-node:var(--bs-node-0)}.bs-node-1{--bs-node:var(--bs-node-1)}.bs-node-2{--bs-node:var(--bs-node-2)}.bs-node-3{--bs-node:var(--bs-node-3)}.bs-node-4{--bs-node:var(--bs-node-4)}.bs-node-5{--bs-node:var(--bs-node-5)}@media (prefers-reduced-motion:reduce){.bs-moved{outline:2px solid var(--bs-accent);animation:none}.bs-shard{transition:none}.bs-row,.bs-flow,.bs-restarting .bs-dot,.bs-stopping .bs-dot{animation:none}.bs-stopped{opacity:.4;animation:none}}@container (width<=68rem){.bs-grid{grid-template-columns:minmax(18rem,1fr) minmax(0,1.4fr)}.bs-panel-tree{grid-row:span 2}}@container (width<=40rem){.bs-grid{display:block}.bs-tabs{gap:.25rem;margin-bottom:.5rem;display:flex}.bs-tabs button{border:1px solid var(--bs-line);background:var(--bs-panel);cursor:pointer;border-radius:6px;flex:1;padding:.5rem}.bs-tabs button[aria-selected=true]{background:var(--bs-accent);border-color:var(--bs-accent);color:var(--bs-bg)}.bs-panel:not(.bs-active){display:none}.bs-tree{max-height:none}.bs-cluster{display:block}.bs-members{width:100%;margin-bottom:.75rem}}:root{--bg:#fff;--fg:#1c1b22;--muted:#5d5b66;--line:#e3e1ea;--live:#2f7d4f;--warn:#b86e00;--lightningcss-light:initial;--lightningcss-dark: ;color-scheme:light dark;font-family:system-ui,-apple-system,Segoe UI,sans-serif;line-height:1.5}@media (prefers-color-scheme:dark){:root{--lightningcss-light: ;--lightningcss-dark:initial;--bg:#17161c;--fg:#ecebf1;--muted:#a3a1ad;--line:#2f2d38;--live:#7fcf9c;--warn:#f0b45a}}*{box-sizing:border-box}body{background:var(--bg);color:var(--fg);margin:0}main{max-width:120rem;margin:0 auto;padding:1rem 1rem 3rem}.bar{border-bottom:1px solid var(--line);flex-wrap:wrap;align-items:baseline;gap:.25rem 1rem;margin-bottom:1rem;padding-bottom:.75rem;display:flex}h1{margin:0;font-size:1.5rem}.status{color:var(--muted);margin:0}.status-open{color:var(--live)}.status-reconnecting,.status-closed{color:var(--warn)}