perf: bound L1 cache access-history retention - #1299
Conversation
InMemoryCacheLayer.access_patterns appended one float per cache hit and never trimmed, and _evict_if_needed() removed the cache entry without releasing the matching history. delete() already released it, so eviction was the sole path that orphaned a history with no resident key left to ever trigger its cleanup. The retained bytes are invisible to stats.total_size_bytes, so the max_size_bytes LRU budget could neither see nor reclaim them. Under a 200-entry cache serving 200k reads across 5k churn keys the layer reports 2,200 bytes while actually holding 7.1 MiB of timestamps. Bound each key's history to ACCESS_HISTORY_WINDOW=64 via a deque and pop it on eviction. _calculate_adaptive_ttl() reads only accesses[0], accesses[-1] and len(accesses), all O(1) on a deque, so it needs no change. Retained history drops 7,461,354 -> 587,664 bytes with hit rate, total_size_bytes, resident entry count and wall time all unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned FilesNone |
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository YAML (base), Repository UI (inherited), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Agent Completion Truth Gate: BLOCKEDReasons: Machine-readable verdict{
"details": {
"invalid_fields": [
"issue.number",
"policy.agent_login",
"policy.run_id"
]
},
"reasons": [
"invalid_payload"
],
"verdict": "blocked"
} |
|
|
Closing this as a duplicate of #1295, which the owner deliberately closed and split. I opened this PR carrying commit Two independent reasons this should not stay open:
No work is lost — the bug fix is in #1298 and the windowing change follows on #1294. The unrelated Generated by Claude Code |
Canonical issue
No pre-existing tracking issue. This surfaces a focused memory-hygiene commit that
was sitting unmerged/unpushed on the assigned branch; opened as a draft for review.
Outcome
InMemoryCacheLayer.access_patternsappended one timestamp per cache hit and nevertrimmed it, and
_evict_if_needed()dropped the cache entry without releasing thematching history — so eviction orphaned a per-key history that no resident key could
ever clean up. Those bytes are invisible to
stats.total_size_bytes, so themax_size_bytesLRU budget could neither see nor reclaim them.Under a 200-entry cache serving 200k reads across 5k churn keys, the layer reported
2,200 bytes while actually holding ~7.1 MiB of timestamps. After the fix, retained
history drops 7,461,354 → 587,664 bytes with hit rate,
total_size_bytes, residententry count and wall time all unchanged.
Scope
src/youtube_extension/backend/services/intelligent_cache.py(bound eachkey's history to
ACCESS_HISTORY_WINDOW=64viadeque(maxlen=...); pop it oneviction),
tests/unit/test_intelligent_cache.py(regression coverage)._calculate_adaptive_ttl()— it reads onlyaccesses[0],accesses[-1]andlen(accesses), all O(1) on a deque.Risk
estimator needs; behaviour and reported stats are unchanged. Additive to a bounded
collection.
Verification
Against head
0f2612b:(The repo-wide 88% coverage gate is expected-red when running a single file in
isolation; every test in the touched file passes.)
Production evidence
Not applicable — this changes an in-memory L1 cache internal only. No runtime request
path, response shape, or deployed surface is touched.
Agent handoff
main🤖 Generated with Claude Code
https://claude.ai/code/session_01CJQeUmsAzh2TKbRW1kBNJf
Generated by Claude Code