Initialize worker cache before first request#670
Merged
Conversation
teta2k
marked this pull request as ready for review
July 23, 2026 11:21
teta2k
force-pushed
the
agent/sync-worker-cache-before-first-request
branch
from
July 23, 2026 18:00
69d3d32 to
33070b6
Compare
teta2k
force-pushed
the
agent/sync-worker-cache-before-first-request
branch
from
July 23, 2026 19:11
33070b6 to
8afb1c2
Compare
teta2k
force-pushed
the
agent/sync-worker-cache-before-first-request
branch
from
July 23, 2026 19:46
8afb1c2 to
5c75f9e
Compare
teta2k
force-pushed
the
agent/sync-worker-cache-before-first-request
branch
from
July 23, 2026 20:29
3baadca to
e0f1cc1
Compare
hansott
reviewed
Jul 24, 2026
hansott
approved these changes
Jul 24, 2026
Co-authored-by: Hans Ott <hansott@hotmail.be>
tomaisthorpe
approved these changes
Jul 24, 2026
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.
Summary
Root cause
The Python agent has three relevant local components:
ThreadCachein every application worker processPreviously, the first HTTP request handled by a worker process could use its local cache before configuration had been copied from the background process. Starting the periodic synchronization thread did not guarantee that configuration was already available: the background process might not have fetched it yet, or the bounded IPC operation might not return it.
Worker-thread existence and local-cache readiness are therefore independent. The loader now synchronizes an uninitialized local cache immediately before checking whether the periodic thread already exists. A process-local lock serializes this operation so concurrent request threads cannot synchronize simultaneously or start duplicate periodic threads.
Impact
When a request reaches a worker process whose local cache has not received configuration, the agent performs a bounded synchronous IPC exchange with the shared background process instead of waiting for the next periodic synchronization. Once configuration has been received, normal requests do not perform this additional IPC operation.
If IPC fails or the background process still has no configuration, the request remains fail-open and the periodic synchronization thread continues its normal 15-second loop.
Validation
test-allowed-ip-for-routes: passed all initial-policy and runtime-update phases, 1/1 passed in 208.76s using Python's established 100-second configuration propagation delaymain: 28 of 100 requests from a non-allowed IP incorrectly returned200403mainand passes with this patchpytest aikido_zen/thread aikido_zen/middleware -q— 33 passedmain: 26 passed, 8 skipped, 0 failedtest-user-rate-limiting-1-minute-without-x-forwarded-forpassed in 18.64sSummary by Aikido
⚡ Enhancements
🐛 Bugfixes
🔧 Refactors
More info