Repository navigation
Read a workspace's telemetry facts at once, not one room at a time (CHOO-3667) - #1256
abeldantas wants to merge 1 commit into
Conversation
…HOO-3667) Message telemetry looks up the room a message was said in, who sent it and the sending agent's runtime, and keeps each answer for 15 minutes or an hour. In a workspace of thousands of agents and rooms a process reports on most of them before it reports a second message about any, so the cache missed for most messages: a load test spent 1.4 transactions a message on these lookups. The first lookup that misses now reads every open room, client and agent of the workspace at once (MessageTelemetry._read_tenant), again once the rooms would expire; a room or client made since is looked up on its own as before, and a read that fails counts as the lookup's failure.
There was a problem hiding this comment.
🟡 Changes recommended
A moderate finding in core/switch_core/telemetry/messages.py (line 521) shows that a successful whole-tenant read does not reset the consecutive-failure counter, so scattered per-key failures could be counted as one streak and wrongly pause lookups.
1 open issue
What changed in this PR
This PR speeds up message telemetry in large workspaces. Today, each room, sender, and agent lookup runs its own database query, so most messages still cost a query. With this change, the first lookup that misses reads every open room, client, and agent of the workspace in one pass and fills the caches from that read. The room facts are read again once their cache TTL has passed. Rooms and clients created after a read are still looked up on their own. It builds on #1225, which lengthens how long these facts are cached.
Changes:
- Adds
MessageTelemetry._read_tenant, which reads a tenant's rooms, member counts, client kinds, and agent runtimes together and stores them in the existing caches. - Calls the bulk read from the room, sender, and agent lookups. A failed read counts as a failure of the lookup that asked.
- Adds tests for the bulk read. Older failure tests now stub out the bulk read so they still exercise the per-key path.
| File | Description |
|---|---|
| core/tests/switch_core/telemetry/test_message_events.py | Adds tests for the bulk read and its expiry. Older tests stub out the bulk read so they still cover the per-key queries. |
| core/switch_core/telemetry/messages.py | Adds the whole-tenant read and calls it before the room, sender, and agent queries. Tracks when each tenant can next be read. |
| CHANGELOG.md | Adds a changelog entry for the faster workspace-wide lookups. |
Review effort: Lite
| ).where(Agent.tenant_id == tenant_id) | ||
| ) | ||
| ).all() | ||
| self._tenants_read[tenant_id] = time.monotonic() + _ROOM_TTL_SECONDS |
|
Combined into #1307 with the other scaling PRs. |

Message telemetry looks up the room a message was said in, who sent it and the sending agent's runtime, and keeps each answer for 15 minutes or an hour. In a workspace of thousands of agents and rooms a process reports on most of them before it reports a second message about any, so the cache missed for most messages: a local run of the load harness spent 1.4 transactions a message on these lookups.
In this PR the first lookup that misses reads every open room, client and agent of the workspace at once (
MessageTelemetry._read_tenant), and again once the rooms would expire. A room or client made since is looked up on its own as before, and a read that fails counts as the failure of the lookup that asked.Stack (merge order)