Repository navigation
Commit b8a2800
authored
feat(directory): add a per-project Lobby cell beside the directory (#335)
* feat(directory): add a per-project Lobby cell beside the directory
The directory's Worker gains a Lobby Durable Object, one per project ID, at
GET /lobbies/<project> behind the same ACE_SECRET. Hosts hold one socket per
project: they replace their owner's presence, which lives only in hibernation
attachments, and send channel lifecycle events, which the lobby numbers with
one seq per project and keeps as a 30-day, 2,000-event resume buffer. A host
resuming from a pruned or unknown seq is told to read listings again. Pings
are auto-answered and an alarm evicts sockets silent for 90 s. The Directory
object and its contract are unchanged. Refs #17, #14.
Why: services/directory/src/lobby.ts#const MIGRATIONS | Durable Object SQLite refuses PRAGMA user_version, so the schema version lives in the kv `version` key; never edit a shipped migration
Why: services/directory/src/lobby.ts#method webSocketMessage | seq lives in kv apart from the rows so pruning every event never reuses a seq a host resumes from
Why: services/directory/src/lobby.ts#type Attachment | presence must never reach SQLite; it lives only in socket attachments
* lane: sync lobby-cell memory
* fix(directory): keep lobby sweeps, clocks, and attachments within bounds
Re-arm the 60 s sweep when a host joins a lobby whose alarm waits on the
oldest event, prune by the lobby's own receipt time, fit presence into the
2 KiB hibernation attachment, replace sockets only within one host
process, and answer a malformed project ID with 400.
Why: services/directory/src/lobby.ts#method fetch | a joining host must re-arm the sweep when the alarm is further than SWEEP away, or silent sockets stay here until the oldest event expires
Why: services/directory/src/lobby.ts#function fit | serializeAttachment throws above 2 KiB, so presence must be trimmed to fit before every serialize
Why: services/directory/src/lobby.ts#method webSocketMessage | the events.at column is the lobby's receipt time, never the host's clock, since retention and resync depend on it
* lane: sync lobby-cell memory
* lane: sync lobby-cell memory
* fix(directory): sweep lobbies every 5 minutes to bound alarm writes
Each sweep re-arms the alarm, which Durable Objects bill as one row write, so
a 60 s sweep cost 1,440 writes a day per project with a host connected. Every
5 minutes costs 288. Silent sockets still close after 90 s without a ping, now
within about 6.5 minutes.
Why: services/directory/src/lobby.ts#const SWEEP | the alarm re-arm is the lobby's only steady storage write; pings and presence must never write, and the sweep must not run more often than the write budget allows
* lane: sync lobby-cell memory1 parent e65cd91 commit b8a2800
16 files changed
Lines changed: 460 additions & 6 deletions
File tree
- .lane
- attic/services/directory/src/lobby.ts
- memory/services/directory/src/lobby.ts
- docs
- services/directory
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
0 commit comments