Skip to content

Keep usage-analytics lookups long enough to be reused in a large workspace (CHOO-3667) - #1225

Closed
abeldantas wants to merge 1 commit into
mainfrom
telemetry-room-facts
Closed

abeldantas wants to merge 1 commit into
mainfrom
telemetry-room-facts

Conversation

@abeldantas

Copy link
Copy Markdown
Collaborator

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.

…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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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
@abeldantas

Copy link
Copy Markdown
Collaborator Author

Combined into #1307 with the other scaling PRs.

@abeldantas abeldantas closed this Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants