Repository navigation
Read a controller's agents' heads once per delivery, not three times (CHOO-3667) - #1220
Closed
abeldantas wants to merge 1 commit into
Closed
abeldantas wants to merge 1 commit into
abeldantas wants to merge 1 commit into
Conversation
…(CHOO-3667) Each delivery made the controller's stream read the heads of all its agents three times, each in its own transaction: to find the work, again after delivering, and again before waiting. In a load test with 10,000 agents behind controllers that was 9 of the ~50 transactions a message cost. The pass now clears its agents' doorbells before its one read of the heads, so an event added after that read rings again and the wait returns at once. It reads again without waiting only when a delivery stopped short of the head (the batch size, or a gap).
abeldantas
requested review from
amaudruz,
christian-mcdermott and
petr-sandbox
as code owners
October 31, 2026 13:40
abeldantas
requested review from
agent-runner353,
lbangalosbt,
massimo-sandboxaq,
niall-sandboxaq,
raullopez-sandbox and
simonflk-sb
as code owners
October 31, 2026 13:40
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The race-sensitive async/Postgres delivery-loop optimization depends on notification timing around the head snapshot and lacks runtime or load-test verification.
No open issues 🎉
What changed in this PR
This pull request reduces redundant agent-head reads during controller-backed deliveries while preserving prompt wakeups and backlog catch-up behavior.
Changes:
- Clears doorbells before the consolidated head read.
- Rechecks heads only when delivery remains behind the captured head.
- Adds stream coverage for read counts, mid-pass arrivals, and multi-batch backlogs.
- Documents the transaction reduction in the changelog.
| File | Review |
|---|---|
core/tests/switch_core/management/test_stream.py |
Adds coverage for single-read delivery, concurrent arrivals, and backlog handling. |
core/switch_core/bridges/agent/protocol/controller_stream.py |
Updates delivery scheduling and wake handling. A moderate race remains: an event committed between doorbell clearing and the head snapshot can leave the bell set after delivery, causing a redundant pass and head read. |
CHANGELOG.md |
Documents the reduced controller delivery transaction and head-read cost. |
This pull request requires changes.
Review effort: Lite
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.
A delivery to an agent behind a controller made the controller's stream read the heads of all its agents, about 20, three times, each in a transaction of its own: to find the work, again after delivering, and again before waiting.
In this PR we:
Measured together with the rest of this set, in a load test of 3,000 agents behind 150 controllers on 12 pods, rooms of 4, before and after on the same day:
Stack (merge order)