Skip to content

Read only the clients and agents a change names, so creating agents stops pinning every process (CHOO-3667) - #1229

Closed
abeldantas wants to merge 3 commits into
mainfrom
churn-point-reads
Closed

abeldantas wants to merge 3 commits into
mainfrom
churn-point-reads

Conversation

@abeldantas

Copy link
Copy Markdown
Collaborator

When an agent is registered, renamed or deleted, every process read every client of the workspace again and, with a messaging app connected, every agent too, back to back for as long as changes kept coming. Every process also read every client every 30 seconds. Creating 10,000 agents kept every process at full CPU for 17 minutes, and their health checks started failing.

In this PR we:

  • name the changed clients in the client.changed signal, so each process reads only those rows (ClientLifecycleService.reconcile_clients)
  • keep each bridge's agents as it last read them and read only the ones named (CollaborationCore._update_agent_identities); the platform calls stay the ones a full read makes
  • compare a fingerprint of the workspace's clients and agents before the 30-second full read (ClientLifecycleService.recheck_all), so a change no signal names, such as an agent's description edited in another process, is still read within 30 seconds

A process from before this sends client.changed without ids, and that still reads the whole workspace.

Load test with 10,000 agents behind 498 controllers on 12 pods, main plus #1220 to #1225:

before after
creating the 10,000 agents 17 min, every pod at 100% CPU 5 min, pods at about 75%
failed liveness checks over the run 15, and on another run 3 pods restarted 1, no restarts
idle CPU 23% 15%
the whole run, teardown included 64 min 21 min

…tops pinning every process (CHOO-3667)

Registering, renaming or deleting an agent made every process read every
client of the workspace and, with a messaging app connected, every agent
too, back to back while changes kept coming. Creating 10,000 agents kept
every process at full CPU until its health checks started failing.

The client.changed signal now names the clients it changed and each
process reads only those rows (ClientLifecycleService.reconcile_clients).
A bridge keeps the agents as it last read them and reads only the named
ones (CollaborationCore._update_agent_identities). The 30-second re-check
compares a fingerprint of the workspace's clients and agents before
reading them all (ClientLifecycleService.recheck_all). A signal that names
no clients, as an older process sends, still reads the whole workspace.
…cks to use

The client re-check's fingerprint (a row count and the sum of a 60-bit
hash of the columns acted on) moves to switch_core/db/fingerprint.py, so
the other families' 30-second re-checks can compare one before reading
everything. No change in behavior.
Copilot AI lite review requested due to automatic review settings November 1, 2026 17:07

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 critical concurrency flaw allows full reconciliation to overwrite newer named changes with stale client and agent identities.

1 open issue
What changed in this PR

This pull request reduces cross-process reconciliation load during client and agent lifecycle changes by propagating affected client IDs, performing targeted reads, and using fingerprints to detect unsignaled changes.

Changes:

  • Adds client-ID-aware lifecycle signals with backward-compatible full-tenant reconciliation.
  • Adds targeted client and collaboration-agent updates with periodic fingerprint checks.
  • Expands regression coverage for signals, fingerprints, identity changes, retries, and rolling deployments.
  • Documents the performance improvement.
File Summary
core/​tests/​switch_core/​management/​harness.py Updates the lifecycle test harness for named client announcements.
core/​tests/​switch_core/​db/​stores/​test_client_store.py Tests client and agent fingerprints and change detection.
core/​tests/​switch_core/​clients/​test_client_signals.py Tests targeted signals, legacy fallback, reconciliation, and periodic rechecks.
core/​tests/​switch_core/​bridges/​collaboration/​test_bridge_inbound_tenant_binding.py Ensures bridge startup performs the initial full identity read.
core/​tests/​switch_core/​bridges/​collaboration/​test_bridge_identity_changes.py Tests targeted agent identity reads and updates.
core/​tests/​switch_core/​bridges/​collaboration/​test_bridge_identity_backfill.py Updates bridge fixtures for tracked identity state.
core/​tests/​switch_core/​bridges/​agent/​test_api_key_cache.py Updates lifecycle test compatibility for named announcements.
core/​tests/​switch_core/​bridges/​agent/​protocol/​test_room_roster_authz.py Updates lifecycle test compatibility for named announcements.
core/​tests/​switch_core/​bridges/​agent/​protocol/​test_register_overwrite_owner_guard.py Updates lifecycle test compatibility for named announcements.
core/​tests/​switch_core/​bridges/​agent/​protocol/​test_bridge_identity_tenant_scope.py Updates lifecycle test compatibility for named announcements.
core/​tests/​switch_core/​bridges/​agent/​protocol/​test_agent_tenant_scoped_admin.py Updates lifecycle test compatibility for named announcements.
core/​tests/​switch_core/​bridges/​agent/​protocol/​registration_harness.py Updates the registration harness for named announcements.
core/​switch_core/​db/​stores/​client_store.py Adds targeted client queries and aggregate fingerprints.
core/​switch_core/​db/​fingerprint.py Provides PostgreSQL row-hash fingerprinting utilities.
core/​switch_core/​clients/​client_signals.py Publishes, aggregates, chunks, and reconciles named client changes.
core/​switch_core/​clients/​client_lifecycle_service.py Implements targeted reconciliation and fingerprint-based checks. Moderate: the member-client filter can cause explicitly unsupported member actors to be treated as deleted. Critical: concurrent full and named reconciliations can apply stale snapshots over newer changes.
core/​switch_core/​bridges/​collaboration/​lifecycle_service.py Forwards named agent changes to tenant bridges.
core/​switch_core/​bridges/​collaboration/​collaboration_core.py Maintains an agent view and incrementally updates platform identities.
core/​switch_core/​bridges/​agent/​protocol/​agent_core.py Names affected clients during registration, rename, and deletion announcements.
CHANGELOG.md Documents the reduced reconciliation workload.

This pull request requires changes.

Review effort: Lite

Comment on lines +413 to +417
async def reconcile_clients(
self, tenant_id: str, client_ids: Collection[str]
) -> None:
"""`reconcile_tenant` for the named clients only: their rows are read,
and each is started, stopped or renamed here to match, where the full
@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