Repository navigation
Keep usage-analytics lookups long enough to be reused in a large workspace (CHOO-3667) - #1225
Closed
abeldantas wants to merge 1 commit into
Closed
abeldantas wants to merge 1 commit into
abeldantas wants to merge 1 commit into
Conversation
…space (CHOO-3667) With usage reporting on, each message looked up its room's platform and member counts, its sender's kind and the agent's runtime, each kept for five minutes in caches capped at 10,000 entries. In a load test with 3,000 agents these were about three of the queries every message cost: quiet rooms missed every time, and at 10,000 agents the caches evicted entries before they were asked again. A room's facts are now kept for fifteen minutes, a sender's kind and an agent's runtime, which do not change, for an hour, and up to 50,000 of each.
abeldantas
requested review from
agent-runner353,
amaudruz,
christian-mcdermott,
lbangalosbt,
massimo-sandboxaq,
niall-sandboxaq,
petr-sandbox,
raullopez-sandbox and
simonflk-sb
as code owners
October 31, 2026 13:40
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A moderate active issue remains because changing an agent's metadata can leave the runtime cache stale for up to one hour, causing incorrect message classification unless the field is immutable or the cache is invalidated.
1 open issue
What changed in this PR
This pull request reduces usage-analytics database load in large workspaces by extending lookup-cache lifetimes and increasing cache capacity.
Changes:
- Caches room facts for 15 minutes.
- Caches sender kinds and agent runtimes for one hour.
- Increases cache capacity from 10,000 to 50,000 entries.
- Adds TTL coverage and updates telemetry documentation and changelog entries.
The agent-runtime cache does not account for agent metadata changes, so updates to known_agent_type may remain stale for up to one hour.
| File | Summary |
|---|---|
docs/old/telemetry-events.md |
Documents the updated lookup-cache behavior and freshness guarantees. |
core/tests/switch_core/telemetry/test_message_events.py |
Verifies the different room and identity cache expiration periods. |
core/switch_core/telemetry/messages.py |
Applies the new cache TTLs and increased capacity; contains the agent-runtime cache invalidation concern. |
CHANGELOG.md |
Records the usage-analytics performance improvement. |
Review effort: Lite
Comment on lines
181
to
+182
| self._agent_runtimes: _TtlCache[tuple[str, str], str] = _TtlCache( | ||
| _CACHE_TTL_SECONDS, _CACHE_MAX_ENTRIES | ||
| _IDENTITY_TTL_SECONDS, _CACHE_MAX_ENTRIES |
This was referenced Oct 31, 2026
Collaborator
Author
|
Combined into #1307 with the other scaling PRs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

With usage reporting on, each message looked up its room's platform and member counts, its sender's kind and the agent's runtime, each kept for five minutes in caches of at most 10,000. In a load test with 3,000 agents these were about three of the queries every message cost: quiet rooms missed every time, and at 10,000 agents the caches evicted what they were about to be asked again.
In this PR we keep a room's facts for fifteen minutes, a sender's kind and an agent's runtime, which do not change, for an hour, and up to 50,000 of each.