Repository navigation
Read a room's context in one transaction, not three (CHOO-3667) - #1258
Closed
abeldantas wants to merge 1 commit into
Closed
abeldantas wants to merge 1 commit into
abeldantas wants to merge 1 commit into
Conversation
read_context read the room's newest message number, checked the agent is a member and read the history, each in a session of its own: three pool checkouts and three transactions for one read. They now share one session (shared_tenant_session), in the same order, so the number is still read before the history. Without a bound tenant AgentCore opens its own session as before.
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 04:05
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are present, and the changes include a regression test covering shared-session usage while preserving history behavior.
No open issues 🎉
What changed in this PR
This pull request reduces read_context database overhead by sharing one tenant-bound SQLAlchemy session across room-head lookup, membership authorization, and history retrieval while preserving read ordering.
Changes:
- Added shared-session support for room membership and context reads.
- Grouped related reads within
shared_tenant_session. - Added a regression test for session checkout count.
- Documented the optimization in the changelog.
| File | Description |
|---|---|
core/tests/switch_core/bridges/agent/operations/test_read_context_room_argument.py |
Verifies context reads use one session while preserving expected history behavior. |
core/switch_core/bridges/agent/protocol/agent_core.py |
Reuses the active tenant-bound session for membership and history reads. |
core/switch_core/bridges/agent/operations/definitions.py |
Shares one session across room-head and context-read operations. |
CHANGELOG.md |
Documents the reduced transaction cost for room-context reads. |
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.
read_contextread the room's newest message number, checked membership and read the history in three sessions of their own. In this PR they share one, in the same order, so the number is still read before the history.In a local load test (400 agents, 20 messages a second) context reads were 0.9 of the 6.5 transactions a message cost.