fix(collab-server): stop /metrics reporting a stale peer count for an unloaded room
Merged
PE
3mo ago+64+64+01234567890123456789-2-2-0123456789
Summary
peersGauge(collab_room_peers) inpackages/collab-server/src/server.tsis keyed byroomId— an identifier the connecting peer picks (the websocket URL path). Every/metricsscrape re-setthe gauge for each currently-loaded room, but nothing ever removed a series for a room that had since unloaded, socollab_room_peers{room="<id>"}kept reporting that room's last-known (non-zero) peer count forever, and the registry grew one label series per distinct room id ever visited over the life of a long-running server, instead of tracking only currently-loaded rooms.MetricsRegistry's gauge now exposesreset()(packages/collab-server/src/metrics.ts), and the/metricshandler resetspeersGaugebefore repopulating it from the live room list on each scrape (packages/collab-server/src/server.ts).
Evidence
RED (new test, before the fix): a room is loaded with one peer (collab_room_peers{room="ghost-room"} 1), the peer disconnects and the room idle-unloads (collab_rooms 0, room no longer in roomManager.list()), but the next /metrics scrape still contains collab_room_peers{room="ghost-room"} 1 — a stale, wrong value for a room that no longer exists.
GREEN (after the fix): the same scrape no longer mentions room="ghost-room" once the room has unloaded.
Full @ifc-lite/collab-server suite: 186/186 passing. node scripts/check-module-size.mjs: OK (exit 0), server.ts at exactly its 677-line budget.
Test plan
-
pnpm exec vitest runinpackages/collab-server— 186/186 passing, including the new regression test intest/metrics.test.ts -
node scripts/check-module-size.mjs— OK - Changeset added (
@ifc-lite/collab-serveris published)
https://claude.ai/code/session_01QPHChk3Ve9N519A4kY7436
Summary by CodeRabbit
-
Bug Fixes
- Fixed metrics reporting so unloaded rooms no longer retain stale peer-count entries.
- Room peer metrics now reflect only currently active rooms.
-
Tests
- Added coverage confirming that peer metrics are removed after a room unloads.
-
Documentation
- Documented the metrics update in the release changeset.