Repository navigation
Keep the Switch Trust settings until they change (CHOO-3667) - #1249
Closed
abeldantas wants to merge 1 commit into
Closed
abeldantas wants to merge 1 commit into
abeldantas wants to merge 1 commit into
Conversation
Every message an agent sends is checked against Switch Trust, and the check read the settings row each time: a transaction per message for a row that hardly ever changes. Each process now keeps what it read, and the gateway's settings routes tell every process when the row changes (TrustSettingsSignals), so a change still takes effect on the next message. A process that reconnects forgets the settings, and they are read again after 30 seconds at most, for a signal that was lost.
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.
🟡 Changes recommended
Approval is blocked by an unresolved concurrency issue in cache refreshes and a critical test setup defect that prevents notification behavior from being verified.
2 open issues
What changed in this PR
This pull request reduces Switch Trust database load by caching settings per process while preserving timely updates through cross-process signals, reconnect resynchronization, and a 30-second refresh limit.
Changes:
- Adds
DynamicTrustClientcaching with invalidation and expiry handling. - Adds
TrustSettingsSignalsfor local, remote, and reconnect-based invalidation. - Wires gateway settings updates through dependency and application setup.
- Adds tests and changelog documentation for the new behavior.
| File | Summary | Final review finding |
|---|---|---|
core/tests/switch_core/trust/test_signals.py |
Tests local, remote, and reconnect invalidation. | No final comment. |
core/tests/switch_core/trust/test_client.py |
Tests caching, invalidation, expiry, races, and read failures. | No final comment. |
core/tests/switch_core/gateway/test_trust_settings.py |
Tests authorization and post-commit notifications. | Critical (1 vote): _client() creates an app that overwrites the monkeypatched callback, so the notification assertions do not exercise the spy. Preserve the callback through app construction or install it after each app is created. |
core/switch_core/trust/signals.py |
Propagates settings changes between processes. | No final comment. |
core/switch_core/trust/setup.py |
Builds and exposes the dynamic Trust client. | No final comment. |
core/switch_core/trust/client.py |
Caches Trust settings and refreshes them after invalidation or expiry. | Moderate (3 votes): Concurrent checks can all observe an expired or missing cache and open separate settings transactions while the first refresh is still pending. Serialize refreshes with a lock or shared in-flight task, then re-check the cache or generation. |
core/switch_core/main.py |
Registers Trust signal handling and gateway invalidation wiring. | No final comment. |
core/switch_core/gateway/trust_settings.py |
Publishes invalidation signals after committed settings updates and deletions. | No final comment. |
core/switch_core/gateway/dependencies.py |
Stores and exposes the Trust settings change callback. | No final comment. |
core/switch_core/gateway/app.py |
Passes the callback into gateway dependency initialization. | No final comment. |
CHANGELOG.md |
Documents the reduced settings-read frequency and invalidation behavior. | No final comment. |
Review effort: Lite
Comment on lines
+171
to
+173
| monkeypatch.setitem( | ||
| gw_deps._state, "trust_settings_changed", lambda: told.append("changed") | ||
| ) |
Comment on lines
+189
to
+192
| read_at = self._read_at | ||
| if read_at is not None and time.monotonic() - read_at < self._max_age_seconds: | ||
| return self._checker | ||
| generation = self._generation |
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 message an agent sends is checked against Switch Trust, and each check read the settings row first: a transaction per message for a row that hardly ever changes.
In this PR we:
DynamicTrustClient)TrustSettingsSignals), so a change still takes effect on the next messageIn a local run of the load harness (200 agents, 2 processes, 5 msg/s), that read was 1 transaction per message, and it is gone.