Repository navigation
Take an agent's head from the notification of its new event (CHOO-3667) - #1246
Closed
abeldantas wants to merge 1 commit into
Closed
abeldantas wants to merge 1 commit into
abeldantas wants to merge 1 commit into
Conversation
Each delivery to an agent behind a controller read the heads of all the controller's agents first. The notification of a new agent event already carries its number, so the event buffer now keeps it as the agent's head while the listener listens, and the controller's stream reads heads only after an idle interval, when it attaches an agent, and after the listener reconnects. In our load test that read was one transaction per delivery, about three per message.
abeldantas
requested review from
agent-runner353,
amaudruz,
christian-mcdermott,
lbangalosbt,
massimo-sandboxaq,
niall-sandboxaq,
petr-sandbox,
raullopez-sandbox and
simonflk-sb
as code owners
November 1, 2026 01:38
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The change affects cross-process PostgreSQL notification ordering, reconnect races, and controller cursor bounds, while focused tests do not replace production-like concurrency and notification-loss validation.
No open issues 🎉
What changed in this PR
This PR reduces database reads during controller-based agent delivery by treating committed event notifications as authoritative head updates while the listener is connected, while retaining fresh reads on startup, idle recovery, and reconnects.
Changes:
- Added sequence-aware notification handling and per-agent cached heads in
EventBuffer. - Updated controller streams to use cached heads and refresh only at recovery boundaries.
- Added router/listener integration tests and documented the performance improvement.
| File | Description |
|---|---|
| core/tests/switch_core/management/test_stream.py | Updated as part of this pull request. |
| core/tests/switch_core/delivery/test_router_sessions.py | Updated as part of this pull request. |
| core/tests/switch_core/bridges/agent/protocol/test_agent_event_listener.py | Updated as part of this pull request. |
| core/switch_core/delivery/router.py | Updated as part of this pull request. |
| core/switch_core/bridges/agent/protocol/event_buffer.py | Updated as part of this pull request. |
| core/switch_core/bridges/agent/protocol/controller_stream.py | Updated as part of this pull request. |
| core/switch_core/bridges/agent/protocol/agent_event_listener.py | Updated as part of this pull request. |
| CHANGELOG.md | Updated as part of this pull request. |
Review effort: Lite
This was referenced Nov 1, 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.
Each delivery to an agent behind a controller started with a read of the heads of all the controller's agents, to see which had new events. The notification of a new agent event already carries the event's number, and the stream used it only to wake up.
In this PR we:
EventBuffer.ring,EventBuffer.heads)A notification lost without its connection dropping still costs at most one idle interval, as a lost wake did before.
In a local run of the load harness (200 agents behind 10 controllers, 2 processes, 5 msg/s), that read was 2.8 transactions per message, and it is gone.
Stack (merge order)