refactor(coding-agent): query agent peers on demand instead of broadcasting mirrors - #1748
refactor(coding-agent): query agent peers on demand instead of broadcasting mirrors#1748snimu wants to merge 8 commits into
Conversation
…d-agent-peers # Conflicts: # packages/coding-agent/test/daemon-mode.test.ts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f39d98f. Configure here.
| this.remoteAgentPeers.set(peer.activeSessionId, peer); | ||
| } | ||
| this.writeWorkerSuccess(client, command); | ||
| return; |
There was a problem hiding this comment.
Mixed-version peer sync can hang
Medium Severity
Removing worker_sync_agent_peers leaves that command unmatched. Worker sockets still route any worker_* type into handleWorkerCommand, which now returns without writing a response. An older supervisor still broadcasts this command and waits 5s per sync, so list, create, and recovery stall for the whole mixed-version window instead of failing fast.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit f39d98f. Configure here.


What was wrong
The supervisor owns the roster of agents across workers, but it also pushed a mutable copy (
remoteAgentPeers) into every worker via a per-worker sync queue and aworker_sync_agent_peersmessage — O(n²) replication with 13 broadcast triggers whose failures were swallowed. Workers made list/reachability decisions from arbitrarily stale mirrors (root cause of the rename bug fixed in #1702) (audit: overlap.md finding 1 ≡ dup-truth.md finding 2).The fix
The mirror, sync queue, message type, and all 13 broadcast triggers are deleted (+101/−312). Workers now issue an authenticated, read-only
list_agent_peersquery to the supervisor only when a list/family catalog is actually requested — request-scoped, never cached, so strictly fresher than the old mirror. Local rows keep precedence. Daemon schema revision bumped to 23; mixed-version windows degrade cleanly in both directions during update-restart.Latency pre-check (plan gate): p50 0.071ms / p95 0.111ms over a real Unix-socket connect+hello harness — three orders of magnitude inside the interactive list budget.
How it's verified
Reviewer enumerated all 6 former mirror readers and all 13 triggers on the base and accounted for each; confirmed no response caching, complete schema-rev machinery, honest mixed-version degradation, preserved local precedence, and untouched #1702/passive-hydration paths. Focused suites green with the 5 remaining failures reproducing identically at the exact base commit. Two-model implement/review loop, approved first pass.
Stacked on #1746 (test the whole stack at the leaf; merge base-first).
Note: intentionally no Linear ticket for this cleanup stack, so that check stays red.
Note
Medium Risk
Changes multi-worker daemon protocol and agent targeting/list behavior; schema bump 22→23 needs compatible rollout, but the change is read-only on the query path with graceful empty-peer fallback.
Overview
Replaces supervisor-driven peer roster broadcasting with on-demand queries so cross-worker agent lists stay current without O(n²)
worker_sync_agent_peerspushes or a staleremoteAgentPeerscache on each worker.Workers call the supervisor via authenticated
list_agent_peers(daemon schema revision 23) when building agent message lists and family catalogs; remote root sessions are merged with local rows (locals win, closing sessions excluded). Failures degrade to an empty peer list.syncAgentPeers, the sync queue, and all lifecycle triggers are removed from the supervisor.Reviewed by Cursor Bugbot for commit f39d98f. Bugbot is set up for automated code reviews on this repo. Configure here.
Linear ticket: ENG-5664
(ticket linked above)
Note
Replace broadcast peer sync with on-demand
list_agent_peersquery inAgentDaemonlist_agent_peerscommand, instead of receiving pushed peer rosterssyncAgentPeerspush method onDaemonSupervisor, theremoteAgentPeerscache onAgentDaemon, and theworker_sync_agent_peersworker commandlist_agent_peersrequests by matching the suppliedworkerTokento a registered worker, then returns summaries of other live, ready, connected workers; failures on the worker side yield an empty peer listDAEMON_SCHEMA_REVISIONfrom 22 to 23 and registerslist_agent_peerswithminSchemaRevision23 in daemon-protocol.tslist_agent_peers; the removedworker_sync_agent_peerscommand is no longer accepted by workersMacroscope summarized f39d98f.