Repository navigation
Keep what a post checks first until a signal says it changed (CHOO-3667) - #1269
Closed
abeldantas wants to merge 2 commits into
Closed
abeldantas wants to merge 2 commits into
abeldantas wants to merge 2 commits into
Conversation
Every post checks that its agent is in the room and that no budget covering it has run out, and a controller relaying the post checks the membership again for the room it names: two transactions per post, on rows that rarely change. Each process now keeps those answers the way it keeps a controller token's rows. Triggers on `room_agents`, `rooms` and `usage_budgets` signal every change, an answer is kept while the signal connection listens and for the TTL otherwise, and a refusal is never kept. The bookkeeping both caches share moves to `held_rows.py`.
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 14:31
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A critical active issue leaves the positive cache fast path able to authorize posts after local membership, archive, or budget changes commit, allowing stale authorization decisions.
1 open issue
What changed in this PR
This pull request adds process-local caching for room-membership and “no budget applies” checks during agent posts, using PostgreSQL notifications for invalidation and shared cache bookkeeping with controller authorization.
Changes:
- Added
HeldRowsandRoomAccessCachewith TTL, bounded storage, and signal-based invalidation. - Added room, membership, and budget notification DDL, migrations, configuration, and application wiring.
- Updated budget checks, agent authorization flow, tests, and changelog documentation.
Status: This pull request requires changes.
| File | Summary |
|---|---|
core/tests/switch_core/management/test_room_access_cache.py |
Adds PostgreSQL-backed tests for cache reuse, refusals, and trigger invalidation. |
core/tests/switch_core/management/test_controller_auth_cache.py |
Updates management cache tests to use shared bookkeeping. |
core/tests/switch_core/bridges/agent/test_room_access_cache.py |
Tests cache TTL, bounds, tenant isolation, invalidation, and refusal behavior. |
core/tests/switch_core/bridges/agent/test_controller_auth_cache.py |
Updates controller-cache tests for the shared implementation. |
core/switch_core/migrations/versions/4103210581d6_room_access_notify.py |
Adds production notification functions and triggers. Moderate issue: the migration DDL is not covered by the frozen-DDL parity check. |
core/switch_core/main.py |
Creates and wires the process-wide room-access cache and signal listener. |
core/switch_core/db/room_access_notify_ddl.py |
Defines reusable room-access notification DDL. |
core/switch_core/db/models.py |
Registers room-access triggers for test schema creation. |
core/switch_core/config.py |
Adds the room-access cache capacity setting. |
core/switch_core/budgets.py |
Reports whether any budget covers an agent. |
core/switch_core/bridges/agent/room_access_cache.py |
Implements cached membership and budget access checks. |
core/switch_core/bridges/agent/protocol/agent_core.py |
Uses cached room and budget checks during agent operations. Critical issue: local membership, room, and budget writes can leave positive entries usable until asynchronous signal dispatch invalidates them. |
core/switch_core/bridges/agent/held_rows.py |
Provides shared TTL, signal-generation, listening-connection, and bounded-entry mechanics. |
core/switch_core/bridges/agent/dependencies.py |
Passes the room-access cache through dependency initialization. |
core/switch_core/bridges/agent/controller_auth_cache.py |
Refactors controller authorization caching onto HeldRows. |
core/switch_core/bridges/agent/app.py |
Accepts and injects the room-access cache into AgentCore. |
CHANGELOG.md |
Documents the new post-check caching behavior and configuration. |
Review effort: Lite
Comment on lines
+1474
to
+1476
| room = access.member(tenant_id, agent_id, room_id) | ||
| if room is not None and access.unbudgeted(tenant_id, agent_id): | ||
| return room |
…ccess # Conflicts: # CHANGELOG.md
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.

Every post checks that its agent is in the room and that no budget covering it has run out, and a controller relaying the post checks the membership once more, for the room it names. That's two transactions per post, reading rows that rarely change.
In this PR we keep those answers in each process, the way #1259 keeps a controller token's rows: triggers on
room_agents,roomsandusage_budgetssignal every change, and an answer is kept while the signal connection listens, and for 5 s otherwise. A refusal is never kept, so an agent outside the room, a missing room or a budget that covers the agent always reaches the database. The bookkeeping #1259 added moves toheld_rows.py, which both caches now share.Local A/B on two pods, 400 agents behind 20 controllers at 20 msg/s, rooms of 4, a fresh database, 150 s windows, two rounds interleaved:
Stack (merge order)