Skip to content

Optimize conversation search and count - #3905

Closed
enyst wants to merge 2 commits into
mainfrom
openhands/conversation-search-index
Closed

enyst wants to merge 2 commits into
mainfrom
openhands/conversation-search-index

Conversation

@enyst

@enyst enyst commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

HUMAN:


AGENT:
This PR was created by an AI agent (OpenHands) on behalf of the user.

Why

Fixes #3142. The issue is still real on the current codebase: _search_conversations was still iterating every EventService, calling get_state() on each one, sorting the full list, then paginating. _count_conversations similarly loaded every conversation state.

Summary

  • Add an incremental in-memory conversation metadata index keyed by created time, updated time, and execution status.
  • Use the index for search pagination and count APIs, loading full conversation state only for returned page items.
  • Keep the index updated on start/resume, state status updates, activity timestamp changes, metadata updates, auto-title updates, and deletion.
  • Add a regression test proving search/count do not call get_state() for off-page conversations once the index is populated.

Issue Number

Fixes #3142

How to Test

Commands run successfully:

uv run ruff format openhands-agent-server/openhands/agent_server/conversation_service.py tests/agent_server/test_conversation_service.py
uv run pytest tests/agent_server/test_conversation_service.py::TestConversationServiceSearchConversations::test_search_and_count_use_metadata_index -vv
uv run pytest tests/agent_server/test_conversation_service.py
uv run pre-commit run --files openhands-agent-server/openhands/agent_server/conversation_service.py tests/agent_server/test_conversation_service.py

Observed results:

  • New regression test: 1 passed
  • Full conversation service test file: 78 passed
  • Pre-commit: Ruff format, Ruff lint, pycodestyle, pyright, import dependency rules, and tool registration checks all passed.

Reproduction/evidence note: the new regression seeds five conversations in the metadata index, requests a two-item first page, and asserts that only those two page items call get_state(); it also asserts indexed count calls do not add any get_state() calls.

Video/Screenshots

Not applicable; this is an agent-server backend performance fix with automated test coverage.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

The search path still reconciles missing metadata if private test/setup code mutates _event_services directly, but the normal service lifecycle maintains the index incrementally.

@enyst 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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:3175bb4-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-3175bb4-python \
  ghcr.io/openhands/agent-server:3175bb4-python

All tags pushed for this build

ghcr.io/openhands/agent-server:3175bb4-golang-amd64
ghcr.io/openhands/agent-server:3175bb4c7404a44871039df540f7dc7792ccd640-golang-amd64
ghcr.io/openhands/agent-server:openhands-conversation-search-index-golang-amd64
ghcr.io/openhands/agent-server:3175bb4-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:3175bb4-golang-arm64
ghcr.io/openhands/agent-server:3175bb4c7404a44871039df540f7dc7792ccd640-golang-arm64
ghcr.io/openhands/agent-server:openhands-conversation-search-index-golang-arm64
ghcr.io/openhands/agent-server:3175bb4-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:3175bb4-java-amd64
ghcr.io/openhands/agent-server:3175bb4c7404a44871039df540f7dc7792ccd640-java-amd64
ghcr.io/openhands/agent-server:openhands-conversation-search-index-java-amd64
ghcr.io/openhands/agent-server:3175bb4-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:3175bb4-java-arm64
ghcr.io/openhands/agent-server:3175bb4c7404a44871039df540f7dc7792ccd640-java-arm64
ghcr.io/openhands/agent-server:openhands-conversation-search-index-java-arm64
ghcr.io/openhands/agent-server:3175bb4-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:3175bb4-python-amd64
ghcr.io/openhands/agent-server:3175bb4c7404a44871039df540f7dc7792ccd640-python-amd64
ghcr.io/openhands/agent-server:openhands-conversation-search-index-python-amd64
ghcr.io/openhands/agent-server:3175bb4-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:3175bb4-python-arm64
ghcr.io/openhands/agent-server:3175bb4c7404a44871039df540f7dc7792ccd640-python-arm64
ghcr.io/openhands/agent-server:openhands-conversation-search-index-python-arm64
ghcr.io/openhands/agent-server:3175bb4-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:3175bb4-golang
ghcr.io/openhands/agent-server:3175bb4c7404a44871039df540f7dc7792ccd640-golang
ghcr.io/openhands/agent-server:openhands-conversation-search-index-golang
ghcr.io/openhands/agent-server:3175bb4-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:3175bb4-java
ghcr.io/openhands/agent-server:3175bb4c7404a44871039df540f7dc7792ccd640-java
ghcr.io/openhands/agent-server:openhands-conversation-search-index-java
ghcr.io/openhands/agent-server:3175bb4-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:3175bb4-python
ghcr.io/openhands/agent-server:3175bb4c7404a44871039df540f7dc7792ccd640-python
ghcr.io/openhands/agent-server:openhands-conversation-search-index-python
ghcr.io/openhands/agent-server:3175bb4-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., 3175bb4-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 3175bb4-python-amd64) are also available if needed

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

github-actions Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   conversation_service.py79111585%159–160, 169, 195–196, 200–201, 206, 291–292, 295–296, 308–309, 323, 463, 512–513, 558, 561, 571–577, 580, 653, 658, 733, 739, 760, 771–772, 781, 809, 815, 820, 826, 834–835, 844–847, 856, 868, 876, 921–922, 983, 1024–1028, 1030–1031, 1034–1035, 1045, 1057–1062, 1164, 1171–1175, 1178–1179, 1183–1187, 1190–1191, 1195–1199, 1202–1203, 1232, 1237, 1241, 1281, 1288–1290, 1309, 1331, 1341, 1345, 1347–1348, 1353–1354, 1360–1361, 1371, 1389–1390, 1420, 1435, 1474, 1806, 1809
TOTAL362071555757% 

@neubig
neubig self-requested a review July 13, 2026 04:42
@neubig

neubig commented Jul 13, 2026

Copy link
Copy Markdown
Member

I'd like to help get this merged, since it's solving a significant problem as conversation count gets higher.

One other potential solution is to actually create an sqlite database for instance.

@neubig

neubig commented Jul 14, 2026

Copy link
Copy Markdown
Member

Actually, with lazy loading I'm less convinced that this is the bottleneck, so I might remove myself as a reviewer.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @enyst, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

This comment was created by an AI agent (OpenHands) on behalf of the user.

@VascoSch92

Copy link
Copy Markdown
Member

Closing as superseded.

Issue #3142 was closed as completed by #4201 ("perf(agent-server): index conversation execution status for search/count", merged 2026-07-23), alongside #3197. main now has _read_execution_status_sync and the cached execution-status index in conversation_service.py.

@VascoSch92 VascoSch92 closed this Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: O(N) full scan for conversation search and count

4 participants