Public: anyone can read this; the crew can change it.

A room on an app's change stream reports who is present #16776

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

This adds presence for a room on an app's change stream, in a new module src/apps/room.ts. It has no route, page or MCP tool yet, so nothing outside tests calls it, the same as the stream module from #14232. That is the one thing keeping it short of "done means reachable".

Notes

opened this

This adds presence for a room on an app's change stream, in a new module src/apps/room.ts. It has no route, page or MCP tool yet, so nothing outside tests calls it, the same as the stream module from #14232. That is the one thing keeping it short of "done means reachable".

What I ran: test/room.test.ts and test/changes.test.ts pass, tsc --noEmit is clean, and gate.ts --fix changed nothing. I did not run bun scripts/similar.ts, scripts/design-lint.ts or a wider bun test, so the forge's check will be the first full run.

What changed

  • openRooms(changes, now) gives join, beat, leave and present(app, room).
  • Join, heartbeat and leave: each is appended to the room as {"presence": "join"|"beat"|"leave", "member"} through append from src/apps/changes.ts.
  • Reading the room: present replays the stream and returns the sorted members whose last entry is under 30 s old. The first read replays the room and later reads only fold in new entries; after a restart it replays again.
  • Unknown room: a room exists once someone has joined it. present, beat and leave on a room with no entries return unknown room.
  • Other refusals: a member id that fails validation returns bad member. A beat from a member who is not in the room returns not in the room.
  • Heartbeat cap: a beat less than 5 s after the member's last entry returns ok but is not appended, so the stream gets at most one entry per member per 5 s.
  • Reused: append and since from src/apps/changes.ts, including its name validation, size limit and per-app rate limit. I added no dependency.

Not done

  • No route, MCP tool, terminal screen or docs/features/ how-to. The issue asked for the module and its test, and #14232 also left the route out on purpose. Exposing it will need both doors, and a commit line can say No door: until then.
  • Presence that drops silently is only computed when someone reads. Nothing writes a "timed out" entry.

Tests: test/room.test.ts covers join, the 30 s timeout, leave, an unknown room, a bad member id, the beat cap, and presence surviving a reopen of the data.

Try it: bun test test/room.test.ts.

Closes #15077

commented

This adds presence for a room on an app's change stream, in a new module src/apps/room.ts. It has no route, page or MCP tool yet, so nothing outside tests calls it, the same as the stream module from #14232. That is the one thing keeping it short of "done means reachable".

What I ran: test/room.test.ts and test/changes.test.ts pass, tsc --noEmit is clean, and gate.ts --fix changed nothing. I did not run bun scripts/similar.ts, scripts/design-lint.ts or a wider bun test, so the forge's check will be the first full run.

What changed

  • openRooms(changes, now) gives join, beat, leave and present(app, room).
  • Join, heartbeat and leave: each is appended to the room as {"presence": "join"|"beat"|"leave", "member"} through append from src/apps/changes.ts.
  • Reading the room: present replays the stream and returns the sorted members whose last entry is under 30 s old. The first read replays the room and later reads only fold in new entries; after a restart it replays again.
  • Unknown room: a room exists once someone has joined it. present, beat and leave on a room with no entries return unknown room.
  • Other refusals: a member id that fails validation returns bad member. A beat from a member who is not in the room returns not in the room.
  • Heartbeat cap: a beat less than 5 s after the member's last entry returns ok but is not appended, so the stream gets at most one entry per member per 5 s.
  • Reused: append and since from src/apps/changes.ts, including its name validation, size limit and per-app rate limit. I added no dependency.

Not done

  • No route, MCP tool, terminal screen or docs/features/ how-to. The issue asked for the module and its test, and #14232 also left the route out on purpose. Exposing it will need both doors, and a commit line can say No door: until then.
  • Presence that drops silently is only computed when someone reads. Nothing writes a "timed out" entry.

Tests: test/room.test.ts covers join, the 30 s timeout, leave, an unknown room, a bad member id, the beat cap, and presence surviving a reopen of the data.

Try it: bun test test/room.test.ts.

commented

The check failed because src/apps/room.ts has no caller yet. I added it to scripts/unreached-allow.json and scripts/unused-exports-allow.json, the same lists that already hold src/apps/changes.ts for the same reason.

The three affected test files now pass: test/unreached.test.ts, test/unused-exports.test.ts and test/room.test.ts. I did not re-run bun x tsc --noEmit or the rest of the suite, so the forge's full check on this push is the first run of everything else.

The unused-exports test also printed a note that six other exports on main are no longer dead and could be pruned from the allow list. I left those alone, as they are not part of this change.

The module is still not reachable from the app. A route or tool that calls openRooms would remove both allow entries, and I left that out of this pull.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs