ragleap-optimizer 0.1.1: per-tenant cache budgets
Design: #1423. Code: PR #1435. Fixes two gaps in ExactCache found in a multi-tenant audit. Cached answers were already tenant-isolated (the key includes the scope); these were fairness and memory gaps.
The gaps this fixes (reproduced with the published 0.1.0 from PyPI)
- One global LRU let one tenant evict everyone: with max_entries=10, tenant acme cached 3 entries, tenant globex wrote 30, and acme kept 0 of 3. With 0.1.1 acme keeps 3 of 3.
- No cap on value size: 5 entries of 40 MB each from one tenant grew the process by about 191 MB. With 0.1.1 they are refused and the process does not grow.
Behaviour changes (read first)
- Default eviction is "fair": when the cache is full, the scope holding the most entries loses its least recently used entry. eviction="lru" is the 0.1.0 order.
- Default max_value_bytes is 1 MiB. A bigger value is not stored (put() returns False). Sizes are measured as JSON, so a value that is not JSON serializable now raises InvalidRequestError. max_value_bytes=None restores the 0.1.0 behaviour.
- put() returns True or False instead of None.
What is new
- max_entries_per_scope, max_bytes_per_scope, max_bytes, and stats(scope) (that scope only). erase(scope) also clears that scope's counters.
- By bytes, the scope holding the most bytes loses its oldest entry first, and the entry just stored is never the one removed.
What this does not defend
- The cache lives in one process. Bytes are measured as JSON length, so real memory use is higher: the limits are a guard, not an exact bound.
- A scope limit does not limit CPU use or call rate. Expired entries count against the limits until they are read or evicted. No independent security review has happened.
Verified (real output)
- GitHub CI: 55 of 55 checks passed on the PR head.
- VPS (Python 3.10.12, SQLite 3.37.2, ragleap-security 0.2.0): 217 tests passed. Sandbox: 217 on Python 3.12.3 and 3.10.20, also with ragleap-security 0.1.0 (the lowest allowed).
- Mutation check: 119 of 119 killed on Python 3.12.3 and 3.10.20.
- From PyPI: the wheel's 7 Python files are identical to the source at the tag; the two gaps behave as described above on the published 0.1.0 and 0.1.1 wheels; the 217 tests from the source archive pass against the installed wheel.
Not verified
- Several processes sharing a cache. Real traffic. Windows and macOS. The mutation run on the VPS.
Provenance
- Tag ragleap-optimizer-v0.1.1 on 4594027. Uploaded to PyPI 2026-11-16T09:29:59 UTC by the Release workflow (environment pypi).
- Wheel sha256 19a16f4ebe68023f2dffeb7cd2865a34d1e00d705548c7b0f77ec5d0997f9018
- Source archive sha256 7dabd10da411d5d5415523fbf14699bc3d0e69339888141ab1dd211c6322eda9
- The provenance records of the wheel and of the source archive were decoded: repository ragleap/ragleap-core, workflow release.yml, environment pypi, digests identical to the files.