Repository navigation
fix(agent-server): preserve legacy conversations in Docker catalogs - #5128
Conversation
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
🤖 OpenHands is reviewing this PR. Head commit: This comment was posted by an AI agent (OpenHands). |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was created by an AI agent (OpenHands) on behalf of the repository maintainers.
Summary
The fix is well-targeted: load_optional cleanly distinguishes a genuinely-absent provisioning manifest (legacy host-local conversation -> fall back to the host cipher) from a present-but-corrupt one (-> raise, fail closed). That preserves per-conversation cipher isolation for real Docker identities and only degrades to the host key for conversations that were originally encrypted with it. The runtime_info distinction (legacy = missing/can_resume=false, stopped Docker = missing/can_resume=true) is consistent and the cipher-boundary tests cover both directions. The REST contract change (optional runtime_info on ConversationInfo) is additive and non-breaking.
One design concern worth confirming before merge (see inline), plus a minor type-safety note.
Risk Assessment: MEDIUM
The change touches the conversation catalog + event-read routing path in Docker mode. The cipher fallback is sound and fail-closed, but proxy_event_read will start a Docker container on a read-only history request for stopped Docker conversations, which has resource/surprise implications the author should confirm is intentional.
Verdict: COMMENT (requesting maintainer confirmation on the container-start-on-read behavior)
Inline finding (registry.py, proxy_event_read): A GET /events/{search,count,id} for a stopped Docker conversation calls get_or_create, which spins up the conversation container. runtime_info reports such conversations as missing + can_resume=true, so the UI presents them as not-running -- yet a read-only history browse will actually resume (start) the runtime. The persisted events live in conversation_dir (a host path the outer ConversationService can already decrypt via runtime_cipher_resolver), so the outer catalog could serve them without a container start. The add_execution_routes comment even states persisted history is "safe to read from the outer catalog." Worth confirming that proxying reads -- and therefore starting a container per history view -- is intended, vs. serving persisted reads from the outer catalog and only proxying when a live lease is actually held.
Minor -- type safety (event_router.py): The four return proxied # type: ignore[return-value] sites return a Response from handlers declared to return JSONResponse/int/Event/list. Widening those handler return types to Response (or JSONResponse | Response) would remove the ignores rather than silencing the checker.
|
Addressed both automated review findings in 2c1cb3d: stopped Docker history reads stay in persisted outer storage, and the event handlers now use accurate return types without ignores. The focused event/runtime/OpenAPI suite passes (82 tests). Ready for another look and explicit approval. |
|
🤖 OpenHands is reviewing this PR. Head commit: This comment was posted by an AI agent (OpenHands). |
|
The fresh automated review identified one more cipher-boundary issue before its GitHub token hit a secondary API limit while submitting: opening stopped Docker history constructed the outer |
|
Live Canvas validation exposed one more boundary: hydrating the full outer |
|
The matched live deployment now passes the full lifecycle: profile-selected |
|
🤖 OpenHands is reviewing this PR. Head commit: This comment was posted by an AI agent (OpenHands). |
|
@all-hands-bot the v1.49.2 release security scan found that the merged head changed after its prior approval. Please review the final merged head commit |
all-hands-bot
left a comment
There was a problem hiding this comment.
Security review — merged head 5bb12b2bc059e31031a6325fc5ef2389e77e641c
Reviewed the final merged head (commit 5bb12b2bc — "fix: read Docker history without hydrating runtimes") plus the full PR diff against main. No blocking findings; submitting APPROVE against this exact commit.
What the change does
Docker-mode read-only event routes (GET /events/{search,count,id,batch}) are now served from the outer catalog's persisted EventLog instead of proxying into (and therefore starting) the conversation container. Writes (POST /events, /respond_to_confirmation) and sockets still go to the runtime via the existing Docker proxy. Legacy host-local conversations (no provisioning identity) keep working because persisted history is cipher-agnostic on the read path.
Security-relevant checks
Cipher boundary (the prior finding) — resolved and fail-closed.
RuntimeProvisioningStore.load_optionalreturnsNoneonly for a genuinely-absent manifest; a present-but-corrupt manifest still raisesValueError(provisioning.py).resolve_persisted_cipherfalls back to the host key only when the identity is absent, so a corrupt/foreign identity never silently degrades to the host key. Covered bytest_present_invalid_identity_does_not_fall_back_to_host_cipher._start_event_serviceand_load_persisted_state_syncnow construct the cipher viaself._cipher_for(stored.id)rather than the bare hostself.cipher, so base-state hydration uses the correct per-runtime key.
No secret exposure on the persisted read path.
EventService.for_persisted_eventsopens only the append-onlyEventLogunderconversations_dir/<id.hex>/events. It never setscipher, never callsload_meta/save_meta, and never hydratesbase_state.jsonor/workspace. The prior "hydrate full outerEventService" path that touched the container-only workspace is removed entirely.- Event payloads are plaintext JSON and contain no
SecretStrfields;Event.model_validate_jsonis invoked without a cipher context, so any**********-redacted values inConversationStateUpdateEventsnapshots stay redacted. No plaintext secret material is reachable through this path.
Path traversal / injection — not present.
conversation_diris built fromstored.id.hex(UUID-derived).EventLogfilenames are validated byEVENT_NAME_RE(event-\d{5,}-[0-9a-fA-F-]{8,}.json) and_pathconstructs only{EVENTS_DIR}/{pattern}.LocalFileStore.get_full_pathsandboxes every read/write under the store root. No user-controlled path component reaches the filesystem.
Auth — preserved.
event_read_routeris mounted underapi_router, which carriescheck_session_api_key+require_initialized. Docker'sadd_execution_routesmounts onlyevent_read_router+docker_conversation_router(both under the same authenticatedapi_router). The write router (event_write_router) is not mounted in Docker mode, so the persisted-onlyEventService(which has no_conversation) can never receive asend_message/respond_to_confirmationcall — those still proxy to the live container.
Fail-closed 404.
get_event_servicenow raises 404 when the persisted record is absent rather than returningNonefor the proxy to interpret. Existence is already disclosed bysearch_conversations, so this leaks no new information and prevents aNoneservice from flowing into handlers.
Risk assessment: LOW
The change narrows the Docker read path to append-only, immutable, cipher-agnostic persisted files served through the existing authenticated router group, and removes the live-read proxy machinery that previously started containers. The cipher fallback is sound and fail-closed, and tests cover the mixed legacy/Docker cipher case through actual EventService hydration plus a persisted-read assertion.
Generated by OpenHands AI on behalf of the user.
|
@all-hands-bot Please review the requested final merged head |
all-hands-bot
left a comment
There was a problem hiding this comment.
Re-reviewing final merged head 5bb12b2bc059e31031a6325fc5ef2389e77e641c (the post-approval drift flagged by the release security scan).
Reviewed the delta since the prior approval (046fc8877 → 5bb12b2b):
event_service.py: addsfor_persisted_events()opening an append-onlyEventLogrooted atconversations_dir / stored.id.hex(UUID hex, no traversal) and_events_for_read()selecting the persisted log when present, falling back to the live conversation's event store. Read methods (get_event,search,count,batch_get) use it uniformly.conversation_registry.py/docker_runtime/registry.py: replaces the per-request HTTP proxy of event reads with aserves_persisted_event_readsproperty; Docker runtime serves read-only history from shared persisted storage without hydrating a runtime lease.dependencies.py/event_router.py: read routes now depend onget_event_service(no longer Optional) and route to persisted storage when the registry opts in; the proxy fallback path is removed.conversation_service.py:get_persisted_event_servicereconciles the catalog record and uses_cipher_for(stored.id)so present Docker identities retain their isolated cipher while absent ones fail closed.- PR-only
.pr/*.pngartifacts removed; tests updated.
No blocking findings: read-only access is confined to the conversation's own persisted event dir; no new untrusted-input-to-path mapping, no network egress, no secret exposure. The proxy-removal simplifies the read surface. Approving.
Generated by OpenHands AI on behalf of the user.
all-hands-bot
left a comment
There was a problem hiding this comment.
Security review - final merged head 5bb12b2bc059e31031a6325fc5ef2389e77e641c
Re-reviewed the final merged head (commit 5bb12b2bc - "fix: read Docker history without hydrating runtimes") against main (merge base 632894b7). No blocking findings; submitting APPROVE against this exact commit.
Scope reviewed
The full PR diff (632894b7..5bb12b2bc) across the agent-server: Docker provisioning/registry, EventService persisted-read path, the event_read_router/event_write_router split, the ConversationInfo.runtime_info addition, and the get_event_service persisted-vs-runtime dispatch in dependencies.py.
Security-relevant findings
Cipher boundary - sound and fail-closed.
RuntimeProvisioningStore.load_optionalreturnsNoneonly for a genuinely absent manifest; a present-but-corrupt manifest still raisesValueError(provisioning.py).DockerConversationRegistry.resolve_persisted_cipherfalls back to the host key only when the identity is absent, so a corrupt/foreign identity never silently degrades to the host cipher. Covered bytest_present_invalid_identity_does_not_fall_back_to_host_cipherandtest_optional_load_distinguishes_missing_from_invalid_identity._start_event_service/_load_persisted_state_syncnow build the cipher viaself._cipher_for(stored.id)rather than the bare hostself.cipher, so base-state hydration uses the correct per-runtime key.
No secret exposure on the persisted read path.
EventService.for_persisted_eventsopens only the append-onlyEventLogunderconversations_dir/<id.hex>/events. It never sets a cipher, never callsload_meta/save_meta, and never hydratesbase_state.jsonor the container-only/workspace. The previous "hydrate full outerEventService" path that touched the container workspace is removed entirely.- Event payloads are plaintext JSON with no
SecretStrfields;Event.model_validate_jsonis invoked without a cipher context, so any**********-redacted values inConversationStateUpdateEventsnapshots stay redacted. No plaintext secret material is reachable via this path.
Path traversal / injection - not present.
conversation_diris built fromstored.id.hex(UUID-derived).EventLogfilenames are validated byEVENT_NAME_RE(event-\d{5,}-[0-9a-fA-F-]{8,}.json) and_pathconstructs only{EVENTS_DIR}/{pattern}.LocalFileStore.get_full_pathsandboxes every read/write under the store root. No user-controlled path component reaches the filesystem.
Auth - preserved.
event_read_routeris mounted underapi_router, which carriescheck_session_api_key+require_initialized. In Docker modeadd_execution_routesmounts onlyevent_read_router+docker_conversation_router(both under the same authenticatedapi_router). The write router (event_write_router) is not mounted in Docker mode, so the persisted-onlyEventService(which has no_conversation) can never receive asend_message/respond_to_confirmationcall - those still proxy to the live container viaproxy_conversation.
Fail-closed 404.
get_event_serviceraises 404 when the persisted record is absent rather than returningNonefor a proxy to interpret. Existence is already disclosed bysearch_conversations, so this leaks no new information and prevents aNoneservice from flowing into handlers.
Test coverage
The added tests exercise the security-critical paths directly: persisted event history read with no container start (test_docker_event_history_reads_persistence_without_starting_a_container - asserts get_or_create is never awaited), the missing-vs-invalid identity distinction, and the mixed legacy/Docker cipher isolation through the catalog listing test.
Risk assessment: LOW
The change narrows the Docker read path to append-only, immutable, cipher-agnostic persisted files served through the existing authenticated router group, and removes the live-read proxy machinery that previously started containers on history views. The cipher fallback is sound and fail-closed, and tests cover the mixed legacy/Docker case. Approving.
Generated by OpenHands AI on behalf of the user.
HUMAN:
I tested this on my own canvas and it is working properly.
AGENT:
Why
Switching an existing installation to Docker runtime mode made every historical local conversation disappear: catalog loading requested a Docker identity cipher for each directory, and legacy local conversations have no provisioning manifest.
Summary
ConversationInfo.runtime_infoto catalog search, detail, and batch responses. Historical local entries reportmissingandcan_resume=false; stopped provisioned Docker conversations remainmissingand resumable.REST API contract changes
Compared with base OpenAPI
632894b716effor public/api/**paths.Issue Number
Closes #5127.
How to Test
uv run pytest -q tests/agent_server/docker_runtime/test_provisioning.py tests/agent_server/docker_runtime/test_registry.py tests/agent_server/docker_runtime/test_routes.py tests/agent_server/test_conversation_router.py(112 passed locally).uv run pytest -q tests/agent_server/test_api.py tests/agent_server/test_models.py tests/agent_server/test_openapi_discriminator.py tests/agent_server/test_conversation_service.py(171 passed locally).uv run pre-commit run --files <changed files>andnpm run format:check && npm run buildinclients/typescript.GET /api/conversations/search. The local record remains present withruntime_info={"runtime_status":"missing","can_resume":false,"runtime_error":null}; a provisioned stopped Docker record reportsmissingwithcan_resume=true.GET /api/conversations/{id}/events/searchreturns 200 from persisted storage, no runtime WebSocket is opened, and the read-only history renders with the archived banner.Video/Screenshots
With SDK
main, Docker mode omits the historical host-local conversation from the catalog:With this branch and Canvas #17500, the same persisted conversation is visible as read-only history:
Design Doc
The API reuses the existing generic
ConversationRuntimeInfomodel. Canvas can map onlyruntime_status === "missing" && can_resume === falseto its archived/MISSING presentation without adding Docker-specific UI fields.Type
Notes
The local REST compatibility check reported no breaking changes.
oasdiffwas unavailable locally, so CI remains authoritative for its comparison.🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang: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:5bb12b2-pythonRun
All tags pushed for this build
About Multi-Architecture Support
5bb12b2-python) is a multi-arch manifest supporting both amd64 and arm645bb12b2-python-amd64) are also available if needed