Repository navigation
Keep a controller token's rows until a signal says they changed (CHOO-3667) - #1259
Closed
abeldantas wants to merge 4 commits into
Closed
abeldantas wants to merge 4 commits into
abeldantas wants to merge 4 commits into
Conversation
…-3667) Every request a controller makes reads its controller row, to refuse a revoked one, and acting as an agent, that agent's row. Both were kept for 5 seconds. A controller's requests are spread over every process, so with 12 processes each saw a given controller about once a minute and a given agent less often: the cache missed on nearly every request, at two transactions each. An entry read while the signal bus listens is now kept for as long as that same connection listens, and dropped when a signal names it. Triggers on agents, and on a controller's owner, credential and revocation, send agent.changed and controller.auth_changed, so no writer can skip them. An entry read without a listening bus, or kept past a reconnect, lasts the TTL as before. A miss reads every agent bound to the controller at once (AgentStore.get_many), and the agent rows have a bound of their own, CONTROLLER_AUTH_CACHE_MAX_AGENTS.
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:28
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The change spans authorization caching across PostgreSQL trigger/NOTIFY delivery, reconnect gaps, and migration-created DDL, requiring end-to-end validation of multi-process races and rollout behavior that automated review cannot provide.
No open issues 🎉
What changed in this PR
This PR replaces the fixed five-second controller-auth cache TTL with signal-driven invalidation and batches agent authorization reads for improved performance across processes.
Changes:
- Adds signal-aware cache retention with TTL fallback across disconnects and reconnects.
- Adds PostgreSQL notification triggers, migration support, and cache wiring.
- Adds bounded bulk agent lookups, configuration, tests, and changelog documentation.
- Review finding: when
AGENT_AUTH_CACHE_TTL_SECONDS=0, the authentication path still performs the bulk agent lookup on every request; it should retain the single-agent lookup when caching is disabled.
| File | Summary |
|---|---|
core/tests/switch_core/management/test_controller_auth_cache.py |
Adds integration coverage for batched reads, signal invalidation, reconnect behavior, and trigger payloads. |
core/tests/switch_core/bridges/agent/test_controller_auth_cache.py |
Tests cache tickets, signal lifetimes, bounds, reconnect handling, and invalidation. |
core/switch_core/signals.py |
Tracks signal-listener connection generations. |
core/switch_core/migrations/versions/bad5099ef32b_auth_rows_notify.py |
Installs authorization-row notification functions and triggers. |
core/switch_core/management/wiring.py |
Connects the authorization cache to the signal bus and configures its agent bound. |
core/switch_core/management/auth.py |
Uses read tickets when caching controller authorization rows. |
core/switch_core/db/stores/agent_store.py |
Adds a bulk agent lookup method. |
core/switch_core/db/models.py |
Registers authorization notification DDL for test schema creation. |
core/switch_core/db/auth_rows_notify_ddl.py |
Defines authorization-row notification functions, triggers, and signal constants. |
core/switch_core/config.py |
Adds configuration for the maximum cached controller-agent rows. |
core/switch_core/bridges/agent/controller_auth_cache.py |
Implements signal-aware, bounded controller and agent row caching. |
core/switch_core/bridges/agent/auth.py |
Loads and caches agents bound to a controller on cache misses; the disabled-cache path requires adjustment noted above. |
CHANGELOG.md |
Documents the improved controller authentication caching behavior and configuration. |
Review effort: Lite
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 request a controller makes reads its controller row (to refuse a revoked one) and, when it acts as an agent, that agent's row. Both were kept for 5 seconds. A controller's requests are spread over every core process, so a process sees a given controller or agent too rarely for 5 seconds to help: with 12 processes and 10,000 agents each sending a message every 2 minutes, a process sees a given agent about once every 24 minutes, and the cache missed on nearly every request.
In this PR we:
agents, and on a controller's owner, credential and revocation, sendagent.changedandcontroller.auth_changed, so no writer can forget toLocally (2 processes, 400 agents, 20 messages a second), this and #1258 take CPU per message from 13.8 to 13.2 ms. With more processes the saving should be larger; not measured yet.