wooden-umbrella-84098
02/22/2026, 3:03 AM/search endpoint has a strong tendency to hang, even if I just set it to 10 eventswooden-umbrella-84098
02/22/2026, 3:07 AMnutritious-balloon-65098
02/22/2026, 3:08 AMnutritious-balloon-65098
02/22/2026, 3:10 AM/search Endpoint Performance Diagnosis
I analyzed the agent-server's /search endpoint and identified why it tends to hang, even with small limits like 10 events.
### Root Cause
The endpoint reads ALL event files from disk and deserializes them with Pydantic, regardless of the limit parameter. Each search request with 1000 events means 1000 disk reads + 1000 JSON parses, even if you only need 10 results.
Additionally, the search holds a FIFOLock on the conversation state for the entire duration, blocking concurrent operations like agent runs.
### Performance Bottlenecks Identified
1. Full iteration with disk I/O - EventLog.__iter__ reads every event file serially
2. Lock contention - FIFOLock held during entire search blocks agent operations
3. No indexing - Filters require deserializing every event
4. No caching - Events are re-read and re-parsed on every request
5. Serial I/O - No parallelism in file reads
### 5 Recommendations for Improvement
| # | Suggestion | Impact | Effort |
|---|------------|--------|--------|
| 1 | Early exit - Stop iterating after finding limit matches (for ascending timestamp sort) | High | Low |
| 2 | LRU event cache - Cache deserialized events since they're immutable | High | Low |
| 3 | Reduce lock scope - Release lock after getting event count, read files outside lock | Medium | Medium |
| 4 | Metadata index - Store lightweight index (id, kind, source, timestamp) for filtering without full deserialization | High | High |
| 5 | Parallel I/O - Use ThreadPoolExecutor to read multiple event files concurrently | Medium | Medium |
The quickest wins are #1 (early exit) and #2 (caching), which would dramatically improve the common case of fetching recent events with a small limit.
---
No code changes were made - this was a diagnostic analysis only.wooden-umbrella-84098
02/22/2026, 3:11 AMnutritious-balloon-65098
02/22/2026, 3:11 AM