test(cognitive-load): pin cache eviction behavior for both in-memory caches#82
Open
tongshu2023 wants to merge 1 commit into
Open
test(cognitive-load): pin cache eviction behavior for both in-memory caches#82tongshu2023 wants to merge 1 commit into
tongshu2023 wants to merge 1 commit into
Conversation
…caches (zijinz456#30) The two caches named in zijinz456#30 already enforce hard bounds in the current code (the issue predates the fix): _analysis_cache caps at 500 and flushes the oldest half, _cache caps at 200 and evicts the least-active baseline. What was still missing from the acceptance criteria was a unit test verifying eviction, so a regression back to unbounded growth would fail loudly. tests/test_cognitive_load_cache_bounds.py (6 tests): - NLP cache never exceeds its cap under sustained distinct messages - crossing the cap drops the oldest entries and keeps the newest - cache hits return the cached object without re-analysis - calibrator cache never exceeds its cap - eviction removes exactly the least-active (lowest message_count) baseline and keeps the newcomer - same user always gets the same baseline instance Caps are monkeypatched small in the fixture (the eviction logic reads the module attribute at call time), keeping the suite at ~6s instead of ~3min with production-size caps. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
Addresses the remaining acceptance item on #30.
The two caches named in the issue already enforce hard bounds in the current code (the issue predates the fix):
cognitive_load_nlp._analysis_cachecaps at 500 and flushes the oldest half when full (under anasyncio.Lock), andcognitive_load_calibrator._cachecaps at 200 and evicts the least-active (lowestmessage_count) baseline. So of the acceptance criteria, the first two are already satisfied — what was missing was the unit test verifying eviction behavior, without which a regression back to unbounded growth would land silently.Changes
tests/test_cognitive_load_cache_bounds.py(6 tests):NLP analysis cache
Calibrator baseline cache
The fixture monkeypatches the caps small (the eviction logic reads the module attribute at call time), keeping the suite at ~6s instead of ~3min with production-size caps.
Tests
test_cognitive_load_cache_bounds.py + test_cognitive_load_calibrator.py: 23 passed locally.Acceptance criteria
🤖 Generated with Claude Code