Repository navigation
Conversation
Replace long-held locks in search_events and count_events with snapshot-based approach that minimizes lock hold time. This prevents selfish coroutines from blocking the main runloop during event iteration. Key changes: - Extract filtering logic into _event_matches_filters helper method - Take snapshot of event count before iteration - Acquire lock briefly for each individual event access - Apply filters outside the lock to minimize critical section - Handle race conditions gracefully with try/catch This resolves global server stalls caused by event search operations holding the conversation state lock for extended periods while iterating through large event collections. Co-authored-by: openhands <openhands@all-hands.dev>
This was referenced May 8, 2026
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.
Problem
The
search_eventsandcount_eventsmethods inEventServicewere causing global server stalls by holding the conversation state lock for extended periods while iterating through all events. This created "selfish coroutines" that blocked the main runloop, especially problematic for conversations with large event histories.Root Cause
Both methods used this pattern:
For conversations with thousands of events or slow running events, this could hold the lock for significant time, blocking:
Solution
Implemented a lock-free snapshot approach that minimizes lock hold time:
Key Changes
_event_matches_filtershelper methodNew Pattern
Benefits
Testing
Risk Assessment
Low Risk:
This change resolves a critical performance issue while maintaining all existing functionality and improving overall system responsiveness.
@tofarr can click here to continue refining the PR
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.12-nodejs22golang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:601c0be-pythonRun
All tags pushed for this build
About Multi-Architecture Support
601c0be-python) is a multi-arch manifest supporting both amd64 and arm64601c0be-python-amd64) are also available if needed