Skip to content

fix: wrap L1 caches in bounded LRU to prevent unbounded memory growth (PILOT-106)#7

Merged
TeoSlayer merged 1 commit into
mainfrom
openclaw/pilot-106-20260528-071400
May 28, 2026
Merged

fix: wrap L1 caches in bounded LRU to prevent unbounded memory growth (PILOT-106)#7
TeoSlayer merged 1 commit into
mainfrom
openclaw/pilot-106-20260528-071400

Conversation

@matthew-pilot
Copy link
Copy Markdown
Collaborator

What

Replaces the unbounded map[string]... L1 caches in both the paraphraser and hydePassager with a generic, thread-safe lruCache that enforces a hard 10,000-entry cap.

Why (PILOT-106)

The paraphraser cache (http.go) and HyDE passage cache (hyde.go) had no eviction, TTL, or size cap. Unique query strings kept adding entries forever, causing monotonic memory growth until OOM. An attacker could accelerate this by sending randomized queries.

Changes

File Change
internal/server/lru.go New. Generic lruCache[V] with internal mutex, LRU eviction, and optional per-entry TTL support.
internal/server/http.go paraphraser: map[string][]stringlruCache[[]string], cap 10k. Removed sync.Mutex (LRU handles its own). Removed unused sync import.
internal/server/hyde.go hydePassager: map[string]stringlruCache[string], cap 10k. Removed sync.Mutex + unused sync import.

Testing

  • go build ./...
  • go test ./... ✅ (9/9 packages pass)
  • Existing hyde and paraphraser tests pass unchanged (they exercise the public API, not the internal map).

… (PILOT-106)

Replace unbounded map[string]... caches in paraphraser and hydePassager
with a generic, thread-safe lruCache that enforces a hard 10,000-entry cap.
LRU eviction prevents monotonic memory growth from unique queries.

- New file: internal/server/lru.go — generic LRU with optional TTL
- paraphraser: map[string][]string → lruCache[[]string], cap 10k
- hydePassager: map[string]string → lruCache[string], cap 10k
- Removes sync.Mutex from both structs (LRU handles its own locking)

Fixes PILOT-106.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

❌ Patch coverage is 53.57143% with 26 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/server/lru.go 45.83% 21 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

@TeoSlayer TeoSlayer merged commit cd254f9 into main May 28, 2026
2 of 3 checks passed
@TeoSlayer TeoSlayer deleted the openclaw/pilot-106-20260528-071400 branch May 28, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants