Repository navigation
Fix auto-title race condition: extract message before background task - #2599
Conversation
The AutoTitleSubscriber was spawning a background task that re-read events from the conversation state to find the first user message. Due to a race condition, the event that triggered the subscriber hadn't been persisted to the events list yet, causing 'No user messages found in conversation events' errors (33/33 failures). Fix: extract the message text directly from the event in the subscriber callback (which already has the event), then pass it to the title generation utils. This completely avoids the race. Co-authored-by: openhands <openhands@all-hands.dev>
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED |
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
||||||||||||||||||||||||||||||
all-hands-bot
left a comment
There was a problem hiding this comment.
🟡 Acceptable - Solves the race condition but introduces code duplication. Consider refactoring to reuse existing utilities.
|
@OpenHands fix all the code duplication mentioned in code review |
|
I'm on it! rbren can track my progress at all-hands.dev |
There was a problem hiding this comment.
I’m OpenHands-GPT-5.4, an AI assistant responding on behalf of the user.
Thanks for the targeted fix — this looks like it addresses a real race in the autotitle path.
My read is that the core issue is AutoTitleSubscriber firing before the first user event is guaranteed to be persisted, so extracting the text from the incoming MessageEvent before spawning the background task is a sound way to break that dependency on event-store timing.
I agree there is a bit of duplication with the existing title utilities, but I would treat that as follow-up cleanup rather than a blocker here. I would not contort the current event-based generate_conversation_title() API into also accepting raw message text just to deduplicate this patch; if we want cleanup, a dedicated helper like generate_title_from_message_text(...) or extract_text_from_message(...) would be a cleaner refactor.
From a maintainer perspective, I’d favor landing the race fix first and iterating on cleanup separately.
This review was created by OpenHands-GPT-5.4, an AI assistant, on behalf of the user.
|
@OpenHands Understand this PR, merge main into it, babysit it and review it, and if you think it's ready merge it. |
|
I'm on it! enyst can track my progress at all-hands.dev |
Refactor auto-title generation to reuse shared message/title helpers. Co-authored-by: openhands <openhands@all-hands.dev>
enyst
left a comment
There was a problem hiding this comment.
Reviewed latest commit fd7d126. Merging main resolved the conflict cleanly, and the follow-up refactor now centralizes message extraction/title generation in title_utils without widening the existing event-based API. I also verified locally with make build, uv run pytest tests/sdk/conversation/test_generate_title.py tests/agent_server/test_conversation_service.py, and uv run pre-commit run --files AGENTS.md openhands-sdk/openhands/sdk/conversation/title_utils.py openhands-agent-server/openhands/agent_server/conversation_service.py tests/agent_server/test_conversation_service.py. Looks ready pending green CI.
This review was created by an AI assistant (OpenHands) on behalf of the user.
|
Here’s the final summary of my work since the last summary:
Conciseness check:
Final state: |
…OpenHands#2599) Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Engel Nyst <engel.nyst@gmail.com>
…OpenHands#2599) Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Engel Nyst <engel.nyst@gmail.com>
Problem
Auto-title generation fails intermittently with
ValueError: No user messages found in conversation events.All 33 failures in the logs are this same error — a race condition in
AutoTitleSubscriber.Root Cause
The subscriber fires on a user
MessageEvent, then spawns a backgroundasyncio.create_taskthat callsgenerate_title(). That method re-readsself._state.eventsto find the first user message — but the event that triggered the subscriber hasn't been persisted to the events list yet when the background task runs.Fix
Extract the message text directly from the event in the subscriber callback (which already has it), then pass it to the title generation utils (
generate_title_with_llm/generate_fallback_title). This completely avoids the race since we no longer need to re-read from the events list.Changes
conversation_service.py: Added_extract_message_text()helper. RefactoredAutoTitleSubscriberto extract text upfront and added_generate_title_from_text()that calls title utils directly.test_conversation_service.py: UpdatedTestAutoTitletests to match new behavior. Added tests for empty messages and LLM fallback.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.13-nodejs22-slimgolang: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:d9cc307-pythonRun
All tags pushed for this build
About Multi-Architecture Support
d9cc307-python) is a multi-arch manifest supporting both amd64 and arm64d9cc307-python-amd64) are also available if needed