Repository navigation
fix: events search API blocks during agent step (FIFOLock contention) - #2296
Conversation
… step search_events blocks for the entire duration of agent.step() because the read path and the run loop contend on the same FIFOLock inside ConversationState. Co-authored-by: openhands <openhands@all-hands.dev>
API breakage checks (Griffe)Result: Failed Log excerpt (first 1000 characters) |
Agent server REST API breakage checks (OpenAPI)Result: Passed |
all-hands-bot
left a comment
There was a problem hiding this comment.
Taste Rating: 🟡 Acceptable - Excellent problem documentation, but CI impact needs addressing
[CRITICAL ISSUES]
The test will fail and break CI. Either mark it @pytest.mark.xfail(reason="reproduces lock contention - fix pending") or include the fix in this PR.
[IMPROVEMENT OPPORTUNITIES]
The mock setup works but is fragile. Consider if there's a cleaner way to test lock contention.
VERDICT:
KEY INSIGHT: Failing tests that document bugs are valuable, but must be marked as expected-to-fail to avoid breaking the build for other developers.
Coverage Report •
|
||||||||||||||||||||
tofarr
left a comment
There was a problem hiding this comment.
Append only nature means locking should not be required
|
I'm going to merge to prevent this from going stale. |
…OpenHands#2296) Co-authored-by: openhands <openhands@all-hands.dev>
…OpenHands#2296) Co-authored-by: openhands <openhands@all-hands.dev>
🧑🦱 Human description: the events search endpoint hangs while running a command. Minimal repro is to ask the agent to
sleep 30, then refresh the pageProblem
GET /api/conversations/{id}/events/searchblocks for the entire duration of an agent step (LLM call + tool execution) because the read path and the run loop contend on the sameFIFOLockinsideConversationState.When the agent runs a long command (e.g.
sleep 30), the search API is unresponsive for 30+ seconds.Root Cause
LocalConversation.run()holdsself._state(aFIFOLock) for each iteration:EventService._search_events_sync()acquires the same lock to iterate events:Both run in thread executors (
run_in_executor), so they contend on the sameFIFOLock. The search thread blocks inFIFOLock.acquire()untilagent.step()finishes and releases the lock.Also affects
_count_events_sync,_get_event_sync, and any other code path that acquiresConversationStateas a context manager.Affected Endpoints
GET .../events/searchGET .../events/countGET .../events/{event_id}GET .../events(batch get)Reproduction
The new test
TestSearchEventsBlockedByRunLoop::test_search_events_not_blocked_by_state_lockreproduces this directly:EventServicewith a conversation whose_stateuses a realFIFOLockrun()→agent.step())search_events()concurrentlyThe test currently fails —
search_eventstakes the full 2s because it's blocked by the lock:Changes
tests/agent_server/test_event_service.pythat reproduces the lock contention.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:102f1dc-pythonRun
All tags pushed for this build
About Multi-Architecture Support
102f1dc-python) is a multi-arch manifest supporting both amd64 and arm64102f1dc-python-amd64) are also available if needed