I'm noticing the agent-server's `/search` endpoint...
# proj-agent
w
I'm noticing the agent-server's
/search
endpoint has a strong tendency to hang, even if I just set it to 10 events
@nutritious-balloon-65098 diagnose why this endpoint can be slow and offer 3-5 suggestions for how to make it more performant
n
I'm on it! Robert Brennan can track my progress here.
## Summary:
/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.
w
@nutritious-balloon-65098 implement early exit, reduce the lock scope, and use parallel IO
n
I'm on it! Robert Brennan can continue tracking my progress here.