Make serve a read-only consumer of the on-disk cache#33
Merged
Conversation
Serve and setup each hold their own in-memory dict of the on-disk cache. Without coordination, serve's cache.save() on a lookup miss overwrites setup's freshly pruned state with serve's older dict — resurrecting the stale entries the prune step in PR #32 just removed. Observed on the test server: cache grew back to 15k+ entries within minutes of setup pruning it down to ~500. Drop the cache.save() call on the serve cache-miss path. Values still populate the in-memory dict (cache.set), so subsequent lookups for the same secret in the same process still hit, and tests asserting on in-memory presence still pass. The disk file is owned exclusively by setup, which prunes on every run. Tradeoff: a secret lazily cached during serve runtime (e.g. an HSM-stored secret outside config.workloads) is lost on serve restart and will miss the cache on its next lookup. Acceptable — the cache's purpose is surviving provider outages for workload secrets, and those are always populated by setup.
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
Serve and setup each hold their own in-memory dict of the on-disk cache. Without coordination, serve's
cache.save()on a lookup miss overwrites setup's freshly pruned state with serve's older dict — resurrecting the stale entries PR #32's prune step just removed.Observed on the test server immediately after deploying PR #32: cache grew back to 15k+ entries within minutes of setup pruning it down to ~500.
Fix: drop the
cache.save()call on the serve cache-miss path. Values still populate the in-memory dict viacache.set(), so subsequent lookups for the same secret in the same process still hit the cache, and existing tests asserting on in-memory presence still pass. The disk file is now owned exclusively by setup, which prunes on every run.Tradeoff
A secret lazily cached during serve runtime (e.g. an HSM-stored secret outside
config.workloads) is lost on serve restart and will miss the cache on its next lookup. Acceptable — the cache's purpose is surviving provider outages for workload secrets, and those are always populated by setup.Test plan
pytest tests/test_serve.py tests/test_serve_offline.py tests/test_setup.py— all 38 tests pass, includingtest_cache_miss_falls_through_to_providerwhich asserts the in-memory cache still gets populated after a miss.ruff check/ty check— clean.