Skip to content

fix(agent-server): stop rescanning Docker conversations - #5137

Merged
neubig merged 1 commit into
mainfrom
fix/docker-catalog-reconciliation-cache
Sep 17, 2026
Merged

neubig merged 1 commit into
mainfrom
fix/docker-catalog-reconciliation-cache

Conversation

@neubig

@neubig neubig commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

On the OSS Agent Canvas, loading the conversations appears to stall.


AGENT:

Why

ConversationService already loads its persisted catalog once at startup and serves search and count from that in-memory index. Docker runtime mode added sync_external_catalog, which instead rescanned and decrypted all persisted metadata before every search and count request. With 2,335 conversations on the OSS Agent Canvas, a 20-row sidebar request took 13–36 seconds.

Docker containers are external writers to the same persisted catalog, but they do not require a second query mechanism. This change removes sync_external_catalog. Docker create, mutation, release, deletion, and socket-close lifecycle boundaries now refresh only the conversation record they changed. Search and count use the existing catalog again.

Summary

  • Remove full external-catalog reconciliation from conversation search and count.
  • Refresh one persisted catalog record after Docker lifecycle changes.
  • Preserve existing startup loading, live-record precedence, deletion, and per-conversation cipher behavior.

Issue Number

Closes #5136.

How to Test

  • uv run pytest -q tests/agent_server/test_conversation_service.py (117 passed)
  • uv run pytest -q tests/agent_server/docker_runtime tests/agent_server/test_conversation_router.py (123 passed)
  • uv run pre-commit run --files openhands-agent-server/openhands/agent_server/conversation_service.py openhands-agent-server/openhands/agent_server/docker_runtime/registry.py openhands-agent-server/openhands/agent_server/docker_runtime/routers.py tests/agent_server/docker_runtime/test_routes.py tests/agent_server/test_conversation_service.py
  • Live OSS Agent Canvas validation against commit 060f102e2:
    • first 20-row search after restart: 3.11s; repeated searches: 0.031s and 0.030s (previously 13–36s)
    • created a Docker conversation and confirmed it appeared in the existing catalog
    • updated its persisted title inside the container, released the runtime, and confirmed the targeted refresh exposed the new title in a 0.20s search
    • deleted it and confirmed it disappeared in a 0.10s search

Video/Screenshots

No visual UI change. The live backend timings and create/update/delete lifecycle results are recorded above.

Design Doc

Not needed for this focused removal of the per-request catalog scan.

Type

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

Notes

The startup catalog load remains unchanged. No REST or WebSocket contract changes.

@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@neubig
neubig force-pushed the fix/docker-catalog-reconciliation-cache branch from ff23ea3 to 872c9bc Compare September 17, 2026 16:08
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   conversation_service.py125413289%202–203, 212, 239–240, 244–245, 250, 396–397, 400–401, 417–418, 432, 599–600, 661, 764, 771–772, 873, 959, 1010–1011, 1018, 1050–1051, 1067, 1098, 1102, 1114, 1134, 1146–1149, 1155–1156, 1165, 1167, 1233, 1243, 1268, 1274–1275, 1279–1280, 1288, 1315, 1321, 1415, 1421, 1426, 1432, 1440–1441, 1450–1453, 1462, 1474, 1482, 1528, 1534–1535, 1538–1540, 1567, 1619, 1668–1669, 1673, 1763–1764, 1835, 1890–1892, 1894–1895, 1898–1899, 1936, 2010–2011, 2043, 2046, 2053–2055, 2058–2059, 2063–2065, 2068–2069, 2073–2075, 2078–2079, 2108, 2117, 2160, 2170–2172, 2232, 2235, 2262, 2272, 2277–2280, 2294, 2305, 2317–2318, 2350, 2445, 2502, 2560, 2575–2576, 2954, 3007, 3010
openhands-agent-server/openhands/agent_server/docker_runtime
   registry.py1994677%53, 58, 61, 157, 171–172, 175, 183, 198–202, 208, 211–212, 218–228, 260, 318, 325, 333–335, 338–346, 355–358
   routers.py1829249%46, 53–59, 77–82, 84–85, 89–91, 93–94, 97–100, 102–112, 118–121, 125–129, 132–135, 137–140, 142, 145, 156, 165, 175, 181–183, 193–195, 204, 229, 245, 251–252, 274, 295–297, 316, 318–332, 338, 349, 358
TOTAL439551816059% 

@neubig
neubig force-pushed the fix/docker-catalog-reconciliation-cache branch from 872c9bc to 060f102 Compare September 17, 2026 16:24
@neubig neubig changed the title fix(agent-server): reuse unchanged external catalog records fix(agent-server): stop rescanning Docker conversations Sep 17, 2026
@all-hands-bot

Copy link
Copy Markdown
Collaborator

🚦 CI is currently failing on this PR's latest commit.

Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request @all-hands-bot as a reviewer to have it reviewed regardless of CI status.)

This is an automated check - no AI was used to generate this comment.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

🤖 OpenHands is reviewing this PR.

Head commit: 060f102e25b099e31538e1858a50f7fdc8da29ff
View the conversation: https://oss-agent-canvas.ngrok.dev/conversations/f48a8119-c31e-47f8-a844-87249a486b96

This comment was posted by an AI agent (OpenHands).

@neubig
neubig requested review from all-hands-bot and removed request for all-hands-bot September 17, 2026 18:25
@neubig

neubig commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

@all-hands-bot The earlier review run has not completed. Please review the current green head and submit an approval if there are no material findings.

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the green head commit 060f102e2.

Verification

  • CI: all checks pass on this head (no failures).
  • Locally ran the two test suites cited in the PR description:
    • tests/agent_server/test_conversation_service.py — 117 passed
    • tests/agent_server/docker_runtime + tests/agent_server/test_conversation_router.py — 123 passed

Findings

No material findings. Approving.

The change cleanly removes the per-request full-catalog rescan (sync_external_catalog) from Docker-mode get/search/count paths and replaces it with targeted refresh_persisted_conversation(conversation_id) calls at Docker lifecycle boundaries (start, release, delete, mutating proxy, socket close).

  • refresh_persisted_conversation mirrors the old per-record reconcile semantics exactly: setdefault into _conversation_records, only update stored and invalidate cached_info when stored actually differs, and live (open) event services still win. The "not on disk → pop unless live" branch preserves deletion behavior, so no semantic regression versus the prior _reconcile_active_records.
  • Refresh decrypts only the single conversation's meta.json (via _load_catalog_sync(conversation_id)), which is the whole point of the perf fix; the hot GET/search/count paths no longer touch disk at all.
  • Refresh is only invoked on mutations (status < 400) and lifecycle boundaries, never on reads. The socket-close refresh is correctly scoped in a finally around bridge_websocket (after auth/container resolution).
  • Tests assert the refresh is awaited on release/delete/secret-update and cover add/remove, metadata-update-without-state-change, live-preservation, and single-record decryption.

Two non-blocking observations:

  • refresh_persisted_conversation raises ValueError("inactive_service") if _event_services is None; in a post-mutation path this could turn a successful op into a 500, but that state is only reachable during shutdown when requests aren't being processed.
  • Per-mutation refresh re-reads meta.json even for mutations that don't change persisted metadata; it's cheap (one record) and only clears the cache when stored actually changed.

Generated by OpenHands AI on behalf of the user.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

Reviewing the green head commit 060f102e2 as requested.

Verification

  • CI: all checks pass on this head (no failures).
  • Local tests (ran the two suites cited in the PR description):
    • tests/agent_server/test_conversation_service.py — 117 passed
    • tests/agent_server/docker_runtime + tests/agent_server/test_conversation_router.py — 123 passed

Findings

No material findings — approval submitted.

The change cleanly removes the per-request full-catalog rescan (sync_external_catalog) from Docker-mode get / search / count paths and replaces it with targeted refresh_persisted_conversation(conversation_id) calls at Docker lifecycle boundaries (start, release, delete, mutating proxy, socket close).

  • refresh_persisted_conversation mirrors the old per-record reconcile semantics exactly: setdefault into _conversation_records, only update stored and invalidate cached_info when stored actually differs, and live (open) event services still win. The "not on disk → pop unless live" branch preserves deletion behavior, so no semantic regression versus the prior _reconcile_active_records.
  • Refresh decrypts only the single conversation's meta.json (via _load_catalog_sync(conversation_id)), which is the whole point of the perf fix; the hot GET / search / count paths no longer touch disk at all.
  • Refresh is only invoked on mutations (status < 400) and lifecycle boundaries, never on reads. The socket-close refresh is correctly scoped in a finally around bridge_websocket (after auth/container resolution).
  • Tests assert the refresh is awaited on release/delete/secret-update and cover add/remove, metadata-update-without-state-change, live-preservation, and single-record decryption.

Two non-blocking observations:

  • refresh_persisted_conversation raises ValueError("inactive_service") if _event_services is None; in a post-mutation path this could turn a successful op into a 500, but that state is only reachable during shutdown when requests aren't being processed.
  • Per-mutation refresh re-reads meta.json even for mutations that don't change persisted metadata; it's cheap (one record) and only clears the cache when stored actually changed.

Generated by OpenHands AI on behalf of the user.

@neubig
neubig merged commit c00f26a into main Sep 17, 2026
59 of 63 checks passed
@neubig
neubig deleted the fix/docker-catalog-reconciliation-cache branch September 17, 2026 18:39
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.

Avoid full catalog rescans in Docker runtime mode

3 participants