openhands-agent-server 1.56.0__tar.gz → 1.57.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/PKG-INFO +1 -1
  2. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/api.py +8 -0
  3. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/config.py +42 -6
  4. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/conversation_registry.py +7 -2
  5. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/conversation_router.py +5 -0
  6. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/conversation_service.py +55 -15
  7. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/dependencies.py +3 -4
  8. openhands_agent_server-1.57.0/openhands/agent_server/docker_runtime/hybrid.py +170 -0
  9. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/docker_runtime/provisioning.py +2 -0
  10. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/docker_runtime/registry.py +16 -7
  11. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/docker_runtime/routers.py +24 -5
  12. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/event_service.py +26 -2
  13. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/init_router.py +13 -0
  14. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/persistence/__init__.py +2 -0
  15. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/persistence/store.py +128 -17
  16. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/profiles_router.py +5 -1
  17. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/server_details_router.py +14 -0
  18. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/settings_router.py +15 -3
  19. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/skills_router.py +39 -0
  20. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/sockets.py +2 -2
  21. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands_agent_server.egg-info/PKG-INFO +1 -1
  22. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands_agent_server.egg-info/SOURCES.txt +2 -0
  23. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/pyproject.toml +1 -1
  24. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/__init__.py +0 -0
  25. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/__main__.py +0 -0
  26. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/_secret_redaction.py +0 -0
  27. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/_secrets_exposure.py +0 -0
  28. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/acp_router.py +0 -0
  29. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/agent_profiles_router.py +0 -0
  30. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/auth_router.py +0 -0
  31. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/bash_router.py +0 -0
  32. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/bash_service.py +0 -0
  33. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/canvas_extensions/__init__.py +0 -0
  34. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/canvas_extensions/backend.py +0 -0
  35. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/canvas_extensions/bridge.py +0 -0
  36. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/canvas_extensions/installed.py +0 -0
  37. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/canvas_extensions/manifest.py +0 -0
  38. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/canvas_extensions_bridge_router.py +0 -0
  39. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/canvas_extensions_router.py +0 -0
  40. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/conversation_lease.py +0 -0
  41. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/credential_binding.py +0 -0
  42. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/docker/Dockerfile +0 -0
  43. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/docker/build.py +0 -0
  44. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/docker_runtime/__init__.py +0 -0
  45. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/docker_runtime/mediation.py +0 -0
  46. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/docker_runtime/proxy.py +0 -0
  47. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/docker_runtime/storage.py +0 -0
  48. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/env_parser.py +0 -0
  49. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/event_router.py +0 -0
  50. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/file_router.py +0 -0
  51. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/git_provider_service.py +0 -0
  52. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/git_router.py +0 -0
  53. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/hooks_router.py +0 -0
  54. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/hooks_service.py +0 -0
  55. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/launch.py +0 -0
  56. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/llm_router.py +0 -0
  57. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/local_secret_resolver.py +0 -0
  58. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/local_storage.py +0 -0
  59. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/logging_config.py +0 -0
  60. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/managed_llm_key.py +0 -0
  61. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/mcp_oauth_store.py +0 -0
  62. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/mcp_router.py +0 -0
  63. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/meta_profiles_router.py +0 -0
  64. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/middleware.py +0 -0
  65. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/models.py +0 -0
  66. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/openai/__init__.py +0 -0
  67. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/openai/models.py +0 -0
  68. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/openai/router.py +0 -0
  69. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/openai/service.py +0 -0
  70. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/openapi.py +0 -0
  71. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/persistence/models.py +0 -0
  72. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/plugins_router.py +0 -0
  73. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/plugins_service.py +0 -0
  74. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/provider_connections_router.py +0 -0
  75. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/pub_sub.py +0 -0
  76. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/py.typed +0 -0
  77. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/runtime_router.py +0 -0
  78. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/session_protocol.py +0 -0
  79. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/session_socket.py +0 -0
  80. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/skills_service.py +0 -0
  81. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/storage/__init__.py +0 -0
  82. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/storage/model.py +0 -0
  83. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/storage/reclaimer.py +0 -0
  84. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/storage/selectors.py +0 -0
  85. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/storage/trash.py +0 -0
  86. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/sub_agents_router.py +0 -0
  87. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/telemetry/__init__.py +0 -0
  88. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/telemetry/factory.py +0 -0
  89. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/telemetry/http_exporter.py +0 -0
  90. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/telemetry/models.py +0 -0
  91. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/telemetry/policy.py +0 -0
  92. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/telemetry/posthog_exporter.py +0 -0
  93. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/telemetry/sanitizer.py +0 -0
  94. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/telemetry/service.py +0 -0
  95. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/telemetry/sink.py +0 -0
  96. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/telemetry/subscriber.py +0 -0
  97. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/telemetry_types.py +0 -0
  98. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/tool_preload_service.py +0 -0
  99. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/tool_router.py +0 -0
  100. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/utils.py +0 -0
  101. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/vscode_extensions/openhands-settings/extension.js +0 -0
  102. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/vscode_extensions/openhands-settings/package.json +0 -0
  103. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/vscode_router.py +0 -0
  104. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/vscode_service.py +0 -0
  105. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/workspace_router.py +0 -0
  106. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands/agent_server/workspaces_router.py +0 -0
  107. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands_agent_server.egg-info/dependency_links.txt +0 -0
  108. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands_agent_server.egg-info/entry_points.txt +0 -0
  109. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands_agent_server.egg-info/requires.txt +0 -0
  110. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/openhands_agent_server.egg-info/top_level.txt +0 -0
  111. {openhands_agent_server-1.56.0 → openhands_agent_server-1.57.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openhands-agent-server
3
- Version: 1.56.0
3
+ Version: 1.57.0
4
4
  Summary: OpenHands Agent Server - REST/WebSocket interface for OpenHands AI Agent
5
5
  Project-URL: Source, https://github.com/OpenHands/software-agent-sdk
6
6
  Project-URL: Homepage, https://github.com/OpenHands/software-agent-sdk
@@ -78,6 +78,7 @@ from openhands.agent_server.openai.router import (
78
78
  check_openai_api_key,
79
79
  openai_router,
80
80
  )
81
+ from openhands.agent_server.persistence import reencrypt_stale_stores
81
82
  from openhands.agent_server.plugins_router import plugins_router
82
83
  from openhands.agent_server.profiles_router import profiles_router
83
84
  from openhands.agent_server.provider_connections_router import (
@@ -375,6 +376,7 @@ async def api_lifespan(api: FastAPI) -> AsyncIterator[None]:
375
376
 
376
377
  # Non-deferred (legacy) path: build and enter the conversation
377
378
  # service as part of the lifespan, exactly as before.
379
+ await asyncio.to_thread(reencrypt_stale_stores, config)
378
380
  #
379
381
  # A key that came from the config file is visible only in ``config``;
380
382
  # in-process callers of this server read it from the environment.
@@ -890,6 +892,12 @@ def create_app(config: Config | None = None) -> FastAPI:
890
892
 
891
893
  _add_api_routes(app)
892
894
  _setup_static_files(app, config)
895
+ if config.conversation_runtime_selectable:
896
+ from openhands.agent_server.docker_runtime.hybrid import (
897
+ RuntimeDispatchMiddleware,
898
+ )
899
+
900
+ app.add_middleware(RuntimeDispatchMiddleware)
893
901
  app.add_middleware(
894
902
  CORSDispatcher,
895
903
  allow_origins=config.allow_cors_origins,
@@ -362,6 +362,21 @@ class Config(BaseModel):
362
362
  "be restored between restarts."
363
363
  ),
364
364
  )
365
+ previous_secret_keys: list[SecretStr] = Field(
366
+ default_factory=list,
367
+ description=(
368
+ "Earlier values of secret_key, used only to decrypt. Values saved "
369
+ "under one of them stay readable and are re-encrypted under "
370
+ "secret_key when next saved (the settings and secrets stores are "
371
+ "re-encrypted at startup). To rotate, set the new key as "
372
+ "secret_key and put the old one here. Prefer setting OH_SECRET_KEY "
373
+ "explicitly: while secret_key falls back to the first session API "
374
+ "key, rotating that session key also rotates the encryption key, "
375
+ "so the old session key must go here. Set with "
376
+ "OH_PREVIOUS_SECRET_KEYS as a JSON list, or "
377
+ "OH_PREVIOUS_SECRET_KEYS_0, OH_PREVIOUS_SECRET_KEYS_1, ..."
378
+ ),
379
+ )
365
380
  web_url: str | None = Field(
366
381
  default_factory=_default_web_url,
367
382
  description=(
@@ -386,6 +401,16 @@ class Config(BaseModel):
386
401
  ),
387
402
  )
388
403
  conversation_runtime: Literal["local", "docker"] = "local"
404
+ conversation_runtime_selectable: bool = Field(
405
+ default=False,
406
+ description=(
407
+ "Serve both the local and the docker runtime and let each start "
408
+ "request pick one with `conversation_runtime`; requests that leave "
409
+ "it unset use this server's `conversation_runtime`. Requires a "
410
+ "Docker daemon and "
411
+ "`OH_SECRET_KEY`."
412
+ ),
413
+ )
389
414
  conversation_image: str = DEFAULT_CONVERSATION_IMAGE
390
415
  conversation_image_has_browser: bool | None = Field(
391
416
  default=None,
@@ -538,17 +563,28 @@ class Config(BaseModel):
538
563
 
539
564
  @property
540
565
  def cipher(self) -> Cipher | None:
541
- cipher = getattr(self, "_cipher", None)
542
- if cipher is None:
543
- if self.secret_key is None:
566
+ if self.secret_key is None:
567
+ if getattr(self, "_cipher", None) is not False:
544
568
  _logger.warning(
545
569
  "⚠️ OH_SECRET_KEY was not defined. Secrets will not "
546
570
  "be persisted between restarts."
547
571
  )
548
- cipher = None
549
- else:
550
- cipher = Cipher(self.secret_key.get_secret_value())
572
+ setattr(self, "_cipher", False)
573
+ return None
574
+ keys = (
575
+ self.secret_key.get_secret_value(),
576
+ tuple(key.get_secret_value() for key in self.previous_secret_keys),
577
+ )
578
+ cipher = getattr(self, "_cipher", None)
579
+ # ``model_copy`` carries the cached cipher over, so rebuild it when the
580
+ # copy was given other keys (e.g. by ``POST /api/init``).
581
+ if (
582
+ not isinstance(cipher, Cipher)
583
+ or getattr(self, "_cipher_keys", None) != keys
584
+ ):
585
+ cipher = Cipher(keys[0], previous_keys=keys[1])
551
586
  setattr(self, "_cipher", cipher)
587
+ setattr(self, "_cipher_keys", keys)
552
588
  return cipher
553
589
 
554
590
 
@@ -34,8 +34,7 @@ class ConversationRegistry:
34
34
  can_resume=True,
35
35
  )
36
36
 
37
- @property
38
- def serves_persisted_event_reads(self) -> bool:
37
+ def serves_persisted_event_reads(self, _conversation_id: UUID) -> bool:
39
38
  """Whether read-only event routes should use shared persisted storage."""
40
39
  return False
41
40
 
@@ -82,6 +81,12 @@ class ConversationRegistry:
82
81
 
83
82
 
84
83
  def create_conversation_registry(config: Config) -> ConversationRegistry:
84
+ if config.conversation_runtime_selectable:
85
+ from openhands.agent_server.docker_runtime.hybrid import (
86
+ HybridConversationRegistry,
87
+ )
88
+
89
+ return HybridConversationRegistry(config)
85
90
  if config.conversation_runtime == "docker":
86
91
  from openhands.agent_server.docker_runtime.registry import (
87
92
  DockerConversationRegistry,
@@ -332,6 +332,11 @@ async def start_conversation(
332
332
  conversation_service: ConversationService = Depends(get_conversation_service),
333
333
  ) -> ConversationInfo:
334
334
  """Start a conversation in the local environment."""
335
+ if request.conversation_runtime not in (None, "local"):
336
+ raise HTTPException(
337
+ status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
338
+ detail="This server only runs local conversations",
339
+ )
335
340
  request = _request_with_observability_headers(
336
341
  request,
337
342
  span_name=x_openhands_observability_span_name,
@@ -65,6 +65,7 @@ from openhands.sdk.agent.acp_file_credentials import CODEX_AUTH_SECRET_NAME
65
65
  from openhands.sdk.agent.base import AgentBase
66
66
  from openhands.sdk.conversation.impl.local_conversation import LocalConversation
67
67
  from openhands.sdk.conversation.persistence_const import BASE_STATE
68
+ from openhands.sdk.conversation.request import ConversationWorktreeOptions
68
69
  from openhands.sdk.conversation.state import (
69
70
  ConversationExecutionStatus,
70
71
  ConversationState,
@@ -109,7 +110,12 @@ def _build_worktree_guidance(
109
110
  worktree_root: Path,
110
111
  workspace_dir: Path,
111
112
  branch: str,
113
+ options: ConversationWorktreeOptions,
112
114
  ) -> str:
115
+ base_ref = {
116
+ "head": "the original workspace's current HEAD",
117
+ "ref": f"`{options.ref}`",
118
+ }.get(options.base, "the main/master branch")
113
119
  return (
114
120
  "This conversation uses a dedicated git worktree.\n"
115
121
  f"- Original workspace: {source_workspace}\n"
@@ -117,7 +123,7 @@ def _build_worktree_guidance(
117
123
  f"- Active workspace: {workspace_dir}\n"
118
124
  f"- Branch: {branch}\n"
119
125
  "Do all file and git work inside this worktree. Do your work on a new, "
120
- "appropriately-named branch, based off the main/master branch, "
126
+ f"appropriately-named branch, based off {base_ref}, "
121
127
  "and do not switch back to the original workspace."
122
128
  )
123
129
 
@@ -141,6 +147,20 @@ def _local_branch_exists(repo_root: Path, branch: str) -> bool:
141
147
  return True
142
148
 
143
149
 
150
+ def _fetch_origin(repo_root: Path) -> None:
151
+ """Refresh ``origin``'s refs for a worktree start point; keep cached ones on
152
+ failure."""
153
+ try:
154
+ run_git_command(["git", "fetch", "origin"], repo_root, timeout=60)
155
+ except GitCommandError as exc:
156
+ logger.warning(
157
+ "git fetch origin failed while choosing worktree start point "
158
+ "for %s; using cached refs. Error: %s",
159
+ repo_root,
160
+ exc,
161
+ )
162
+
163
+
144
164
  def _get_worktree_start_point(repo_root: Path) -> str:
145
165
  """Resolve the base ref a new conversation worktree should be created from.
146
166
 
@@ -157,15 +177,7 @@ def _get_worktree_start_point(repo_root: Path) -> str:
157
177
  creation still succeeds on freshly initialized repos.
158
178
  """
159
179
  if _has_git_remote(repo_root):
160
- try:
161
- run_git_command(["git", "fetch", "origin"], repo_root, timeout=60)
162
- except GitCommandError as exc:
163
- logger.warning(
164
- "git fetch origin failed while choosing worktree start point "
165
- "for %s; using cached refs. Error: %s",
166
- repo_root,
167
- exc,
168
- )
180
+ _fetch_origin(repo_root)
169
181
  try:
170
182
  ref = run_git_command(
171
183
  ["git", "symbolic-ref", "refs/remotes/origin/HEAD"],
@@ -191,6 +203,7 @@ class _WorktreePlan:
191
203
  worktree_root: Path
192
204
  workspace_dir: Path
193
205
  branch: str
206
+ options: ConversationWorktreeOptions
194
207
 
195
208
  @property
196
209
  def guidance(self) -> str:
@@ -199,6 +212,7 @@ class _WorktreePlan:
199
212
  worktree_root=self.worktree_root,
200
213
  workspace_dir=self.workspace_dir,
201
214
  branch=self.branch,
215
+ options=self.options,
202
216
  )
203
217
 
204
218
 
@@ -206,7 +220,9 @@ def _plan_conversation_worktree(
206
220
  workspace: LocalWorkspace,
207
221
  conversation_id: UUID,
208
222
  conversation_worktree_root: Path,
223
+ options: ConversationWorktreeOptions | None,
209
224
  ) -> _WorktreePlan | None:
225
+ options = options or ConversationWorktreeOptions()
210
226
  source_workspace = Path(workspace.working_dir).resolve()
211
227
  try:
212
228
  validate_git_repository(source_workspace)
@@ -225,10 +241,21 @@ def _plan_conversation_worktree(
225
241
  source_workspace=source_workspace,
226
242
  worktree_root=worktree_root,
227
243
  workspace_dir=worktree_root / source_workspace.relative_to(repo_root),
228
- branch=f"openhands/{conversation_id}",
244
+ branch=f"{options.branch_prefix}{conversation_id}",
245
+ options=options,
229
246
  )
230
247
 
231
248
 
249
+ def _worktree_start_point(plan: _WorktreePlan) -> str:
250
+ if plan.options.base == "head":
251
+ return "HEAD"
252
+ if plan.options.base == "ref" and plan.options.ref:
253
+ if _has_git_remote(plan.repo_root):
254
+ _fetch_origin(plan.repo_root)
255
+ return plan.options.ref
256
+ return _get_worktree_start_point(plan.repo_root)
257
+
258
+
232
259
  def _create_conversation_worktree(plan: _WorktreePlan) -> LocalWorkspace:
233
260
  repo_root = plan.repo_root
234
261
  plan.worktree_root.parent.mkdir(parents=True, exist_ok=True)
@@ -255,7 +282,7 @@ def _create_conversation_worktree(plan: _WorktreePlan) -> LocalWorkspace:
255
282
  "-b",
256
283
  plan.branch,
257
284
  str(plan.worktree_root),
258
- _get_worktree_start_point(repo_root),
285
+ _worktree_start_point(plan),
259
286
  ],
260
287
  repo_root,
261
288
  )
@@ -1566,7 +1593,10 @@ class ConversationService:
1566
1593
 
1567
1594
  worktree = (
1568
1595
  _plan_conversation_worktree(
1569
- request.workspace, conversation_id, self.conversation_worktree_root
1596
+ request.workspace,
1597
+ conversation_id,
1598
+ self.conversation_worktree_root,
1599
+ request.worktree_options,
1570
1600
  )
1571
1601
  if request.worktree
1572
1602
  else None
@@ -2086,7 +2116,10 @@ class ConversationService:
2086
2116
  # shares it.
2087
2117
  worktree = (
2088
2118
  _plan_conversation_worktree(
2089
- parent_stored.workspace, child_id, self.conversation_worktree_root
2119
+ parent_stored.workspace,
2120
+ child_id,
2121
+ self.conversation_worktree_root,
2122
+ None,
2090
2123
  )
2091
2124
  if request.isolation == "worktree"
2092
2125
  else None
@@ -2619,12 +2652,18 @@ def _generate_title_traced(
2619
2652
  llm: LLM | None,
2620
2653
  max_length: int,
2621
2654
  on_error: Callable[[Exception], None] | None = None,
2655
+ prompt: str | None = None,
2622
2656
  ) -> str:
2623
2657
  call_context = (
2624
2658
  conversation.get_llm_call_context() if conversation else LLMCallContext()
2625
2659
  )
2626
2660
  return generate_title_from_message(
2627
- message, llm, max_length, call_context=call_context, on_error=on_error
2661
+ message,
2662
+ llm,
2663
+ max_length,
2664
+ call_context=call_context,
2665
+ on_error=on_error,
2666
+ prompt=prompt,
2628
2667
  )
2629
2668
 
2630
2669
 
@@ -2671,6 +2710,7 @@ class AutoTitleSubscriber(Subscriber):
2671
2710
  title_llm,
2672
2711
  50,
2673
2712
  _on_title_error,
2713
+ self.service.stored.prompt,
2674
2714
  )
2675
2715
  if title and self.service.stored.title is None:
2676
2716
  await self.service.save_meta(
@@ -117,10 +117,9 @@ async def get_event_service(
117
117
  conversation_service: ConversationService = Depends(get_conversation_service),
118
118
  ) -> EventService:
119
119
  registry = getattr(request.app.state, "conversation_registry", None)
120
- if (
121
- isinstance(registry, ConversationRegistry)
122
- and registry.serves_persisted_event_reads
123
- ):
120
+ if isinstance(
121
+ registry, ConversationRegistry
122
+ ) and registry.serves_persisted_event_reads(conversation_id):
124
123
  event_service = await conversation_service.get_persisted_event_service(
125
124
  conversation_id
126
125
  )
@@ -0,0 +1,170 @@
1
+ """Serve host-local and Docker conversations from one server.
2
+
3
+ Local routes keep their public paths. Docker routes are mounted again under
4
+ ``DOCKER_ROUTE_PREFIX`` and :class:`RuntimeDispatchMiddleware` rewrites a
5
+ request onto them when its conversation has a Docker provisioning manifest, or
6
+ when a start request selects ``conversation_runtime="docker"``.
7
+ """
8
+
9
+ import json
10
+ import re
11
+ from typing import Any, Final
12
+ from uuid import UUID
13
+
14
+ from fastapi import APIRouter
15
+ from starlette.types import ASGIApp, Message, Receive, Scope, Send
16
+
17
+ from openhands.agent_server.conversation_registry import ConversationRegistry
18
+ from openhands.agent_server.docker_runtime.registry import DockerConversationRegistry
19
+ from openhands.agent_server.models import ConversationRuntimeInfo
20
+
21
+
22
+ DOCKER_ROUTE_PREFIX: Final[str] = "/_docker"
23
+
24
+ _CONVERSATION_PATH = re.compile(r"^/api/conversations/([^/]+)(/.*)?$")
25
+ _SOCKET_PATH = re.compile(r"^/sockets/(?:events|session)/([^/]+)$")
26
+
27
+
28
+ class HybridConversationRegistry(DockerConversationRegistry):
29
+ """Registry for a server that runs both local and Docker conversations.
30
+
31
+ A conversation with a Docker provisioning manifest is a Docker one; any other
32
+ is local. Local routes keep their paths, and the Docker ones are mounted
33
+ again under ``DOCKER_ROUTE_PREFIX``.
34
+ """
35
+
36
+ def is_docker(self, conversation_id: UUID) -> bool:
37
+ return self.provisioning.manifest_path(conversation_id).is_file()
38
+
39
+ def runtime_info(self, conversation_id: UUID) -> ConversationRuntimeInfo:
40
+ if self.is_docker(conversation_id):
41
+ return super().runtime_info(conversation_id)
42
+ return ConversationRegistry.runtime_info(self, conversation_id)
43
+
44
+ def serves_persisted_event_reads(self, conversation_id: UUID) -> bool:
45
+ return self.is_docker(conversation_id)
46
+
47
+ def add_execution_routes(self, router: APIRouter) -> None:
48
+ ConversationRegistry.add_execution_routes(self, router)
49
+ docker = APIRouter(prefix=DOCKER_ROUTE_PREFIX, include_in_schema=False)
50
+ super().add_execution_routes(docker)
51
+ router.include_router(docker)
52
+
53
+ @property
54
+ def workspace_router(self) -> APIRouter:
55
+ from openhands.agent_server.workspace_router import workspace_router
56
+
57
+ router = APIRouter()
58
+ router.include_router(workspace_router)
59
+ router.include_router(
60
+ super().workspace_router,
61
+ prefix=DOCKER_ROUTE_PREFIX,
62
+ include_in_schema=False,
63
+ )
64
+ return router
65
+
66
+ @property
67
+ def sockets_router(self) -> APIRouter:
68
+ from openhands.agent_server.docker_runtime.routers import (
69
+ docker_session_sockets_router,
70
+ docker_sockets_router,
71
+ )
72
+ from openhands.agent_server.session_socket import session_router
73
+ from openhands.agent_server.sockets import (
74
+ bash_sockets_router,
75
+ conversation_sockets_router,
76
+ )
77
+
78
+ router = APIRouter()
79
+ router.include_router(conversation_sockets_router)
80
+ router.include_router(session_router)
81
+ router.include_router(bash_sockets_router)
82
+ for docker in (docker_sockets_router, docker_session_sockets_router):
83
+ router.include_router(
84
+ docker, prefix=DOCKER_ROUTE_PREFIX, include_in_schema=False
85
+ )
86
+ return router
87
+
88
+
89
+ class RuntimeDispatchMiddleware:
90
+ """Route each conversation's requests to the runtime that owns it."""
91
+
92
+ def __init__(self, app: ASGIApp) -> None:
93
+ self.app = app
94
+
95
+ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
96
+ registry = scope["app"].state.conversation_registry if "app" in scope else None
97
+ if scope["type"] not in ("http", "websocket") or not isinstance(
98
+ registry, HybridConversationRegistry
99
+ ):
100
+ await self.app(scope, receive, send)
101
+ return
102
+
103
+ root_path = scope.get("root_path", "")
104
+ path = scope["path"].removeprefix(root_path)
105
+ method = scope.get("method")
106
+ to_docker = False
107
+ if scope["type"] == "websocket":
108
+ match = _SOCKET_PATH.match(path)
109
+ conversation_id = _conversation_id(match[1]) if match is not None else None
110
+ to_docker = conversation_id is not None and registry.is_docker(
111
+ conversation_id
112
+ )
113
+ elif path == "/api/conversations" and method == "POST":
114
+ receive, body = await _buffer_body(receive)
115
+ request = _json_object(body)
116
+ # A start for an existing Docker conversation resumes it in Docker.
117
+ existing = _conversation_id(request.get("conversation_id"))
118
+ to_docker = (existing is not None and registry.is_docker(existing)) or (
119
+ request.get("conversation_runtime")
120
+ or registry.config.conversation_runtime
121
+ ) == "docker"
122
+ elif match := _CONVERSATION_PATH.match(path):
123
+ # GET of the conversation itself is the shared catalog record.
124
+ catalog_read = match[2] is None and method in ("GET", "HEAD")
125
+ conversation_id = _conversation_id(match[1])
126
+ to_docker = (
127
+ conversation_id is not None
128
+ and not catalog_read
129
+ and registry.is_docker(conversation_id)
130
+ )
131
+
132
+ if to_docker:
133
+ prefix = "/api" if path.startswith("/api/") else ""
134
+ rewritten = prefix + DOCKER_ROUTE_PREFIX + path[len(prefix) :]
135
+ full = root_path + rewritten
136
+ scope = {**scope, "path": full, "raw_path": full.encode()}
137
+ await self.app(scope, receive, send)
138
+
139
+
140
+ async def _buffer_body(receive: Receive) -> tuple[Receive, bytes]:
141
+ messages: list[Message] = []
142
+ body = b""
143
+ while True:
144
+ message = await receive()
145
+ messages.append(message)
146
+ if message["type"] != "http.request":
147
+ break
148
+ body += message.get("body", b"")
149
+ if not message.get("more_body"):
150
+ break
151
+
152
+ async def replay() -> Message:
153
+ return messages.pop(0) if messages else await receive()
154
+
155
+ return replay, body
156
+
157
+
158
+ def _json_object(body: bytes) -> dict[str, Any]:
159
+ try:
160
+ data = json.loads(body)
161
+ except (json.JSONDecodeError, UnicodeDecodeError):
162
+ return {}
163
+ return data if isinstance(data, dict) else {}
164
+
165
+
166
+ def _conversation_id(value: Any) -> UUID | None:
167
+ try:
168
+ return UUID(value) if isinstance(value, str) else None
169
+ except ValueError:
170
+ return None
@@ -14,6 +14,7 @@ from pydantic import BaseModel, ConfigDict, SecretStr, field_serializer, field_v
14
14
 
15
15
  from openhands.agent_server.config import Config
16
16
  from openhands.agent_server.persistence.store import _get_persistence_dir
17
+ from openhands.sdk.conversation.request import ConversationContainerOptions
17
18
  from openhands.sdk.profiles.agent_profile import LaunchedAgentProfile
18
19
  from openhands.sdk.utils.cipher import Cipher
19
20
  from openhands.sdk.utils.pydantic_secrets import serialize_secret, validate_secret
@@ -27,6 +28,7 @@ class RuntimeIdentity(BaseModel):
27
28
  encryption_key: SecretStr
28
29
  workspace_path: Path
29
30
  launched_agent_profile: LaunchedAgentProfile | None = None
31
+ container: ConversationContainerOptions | None = None
30
32
 
31
33
  @field_serializer("api_key", "encryption_key")
32
34
  def serialize_key(self, value, info):
@@ -27,6 +27,7 @@ from openhands.agent_server.models import (
27
27
  )
28
28
  from openhands.agent_server.persistence.store import _get_persistence_dir
29
29
  from openhands.agent_server.storage import Reclaimer
30
+ from openhands.sdk.conversation.request import ConversationContainerOptions
30
31
  from openhands.sdk.conversation.state import ConversationExecutionStatus
31
32
  from openhands.sdk.logger import get_logger
32
33
  from openhands.sdk.utils.cipher import Cipher
@@ -139,8 +140,7 @@ class DockerConversationRegistry(ConversationRegistry):
139
140
  can_resume=True,
140
141
  )
141
142
 
142
- @property
143
- def serves_persisted_event_reads(self) -> bool:
143
+ def serves_persisted_event_reads(self, _conversation_id: UUID) -> bool:
144
144
  return True
145
145
 
146
146
  async def start(self) -> None:
@@ -401,6 +401,7 @@ class DockerConversationRegistry(ConversationRegistry):
401
401
 
402
402
  def _build_container(self, conversation_id: UUID) -> ConversationContainer:
403
403
  identity = self.provisioning.load(conversation_id)
404
+ options = identity.container or ConversationContainerOptions()
404
405
  runtime_dir = self.provisioning.runtime_dir(conversation_id)
405
406
  persistence_dir = self.provisioning.direct_child(runtime_dir, "persistence")
406
407
  conversation_dir = self.conversation_dir(conversation_id)
@@ -416,7 +417,9 @@ class DockerConversationRegistry(ConversationRegistry):
416
417
  "OH_PERSISTENCE_DIR": _PERSISTENCE_DIR,
417
418
  "OH_CONVERSATION_RUNTIME": "local",
418
419
  "OH_ENABLE_BROWSER": (
419
- "1" if container_browser_enabled(self.config) else "0"
420
+ "1"
421
+ if container_browser_enabled(self.config) and options.browser
422
+ else "0"
420
423
  ),
421
424
  "OH_SECRET_KEY": identity.encryption_key.get_secret_value(),
422
425
  V1_SESSION_API_KEY_ENV: identity.api_key.get_secret_value(),
@@ -450,10 +453,16 @@ class DockerConversationRegistry(ConversationRegistry):
450
453
  (workspace_dir, _WORKSPACE_DIR),
451
454
  ):
452
455
  flags.extend(("-v", f"{host}:{target}"))
453
- if self.config.conversation_container_memory:
454
- flags.extend(("--memory", self.config.conversation_container_memory))
455
- if self.config.conversation_container_cpus is not None:
456
- flags.extend(("--cpus", str(self.config.conversation_container_cpus)))
456
+ memory = options.memory or self.config.conversation_container_memory
457
+ if memory:
458
+ flags.extend(("--memory", memory))
459
+ cpus = (
460
+ options.cpus
461
+ if options.cpus is not None
462
+ else self.config.conversation_container_cpus
463
+ )
464
+ if cpus is not None:
465
+ flags.extend(("--cpus", str(cpus)))
457
466
  if self.config.conversation_container_pids_limit is not None:
458
467
  flags.extend(
459
468
  ("--pids-limit", str(self.config.conversation_container_pids_limit))
@@ -40,6 +40,7 @@ from openhands.agent_server.models import (
40
40
  )
41
41
  from openhands.agent_server.persistence import PersistedSettings, get_settings_store
42
42
  from openhands.agent_server.utils import safe_rmtree
43
+ from openhands.sdk.conversation.request import ConversationContainerOptions
43
44
  from openhands.sdk.launch import AgentLaunchError, LaunchStoreError, ResolvedLaunch
44
45
  from openhands.sdk.logger import get_logger
45
46
  from openhands.sdk.profiles.agent_profile import LaunchedAgentProfile
@@ -127,6 +128,8 @@ async def start_conversation(
127
128
  raise HTTPException(400, "Invalid JSON body") from exc
128
129
  if not isinstance(body, dict):
129
130
  raise HTTPException(422, "Expected a JSON object")
131
+ if body.pop("conversation_runtime", None) not in (None, "docker"):
132
+ raise HTTPException(422, "This server only runs docker conversations")
130
133
 
131
134
  workspace = body.get("workspace")
132
135
  if workspace is not None and (
@@ -156,10 +159,19 @@ async def start_conversation(
156
159
  except ValueError as exc:
157
160
  raise HTTPException(422, str(exc)) from exc
158
161
  try:
159
- payload, launched = await _prepare_forward(body, registry, existing=existing)
162
+ payload, launched, options = await _prepare_forward(
163
+ body, registry, existing=existing
164
+ )
160
165
  identity = registry.provisioning.create(conversation_id, host_workspace)
166
+ updates: dict[str, Any] = {}
161
167
  if launched is not None and identity.launched_agent_profile is None:
162
- identity = identity.model_copy(update={"launched_agent_profile": launched})
168
+ updates["launched_agent_profile"] = launched
169
+ # Fixed once the container accepted the conversation; until then a
170
+ # retried start may change them.
171
+ if not existing and identity.container != options:
172
+ updates["container"] = options
173
+ if updates:
174
+ identity = identity.model_copy(update=updates)
163
175
  registry.provisioning.save(identity)
164
176
  container = await registry.get_or_create(conversation_id)
165
177
  async with httpx.AsyncClient(timeout=60) as client:
@@ -199,7 +211,11 @@ async def start_conversation(
199
211
 
200
212
  async def _prepare_forward(
201
213
  body: dict[str, Any], registry: DockerConversationRegistry, *, existing: bool
202
- ) -> tuple[Callable[[Cipher], dict[str, Any]], LaunchedAgentProfile | None]:
214
+ ) -> tuple[
215
+ Callable[[Cipher], dict[str, Any]],
216
+ LaunchedAgentProfile | None,
217
+ ConversationContainerOptions | None,
218
+ ]:
203
219
  """Resolve the start request with this host's stores; the container finalizes.
204
220
 
205
221
  The profile of a conversation that already exists is not resolved again:
@@ -235,7 +251,7 @@ async def _prepare_forward(
235
251
  )
236
252
 
237
253
  launched = source.profile if isinstance(source, ResolvedLaunch) else None
238
- return payload, launched
254
+ return payload, launched, start.container
239
255
 
240
256
 
241
257
  @docker_conversation_router.get(
@@ -345,7 +361,10 @@ async def proxy_conversation(
345
361
  raise HTTPException(501, "This operation is unavailable in Docker runtime mode")
346
362
  registry = get_registry(request)
347
363
  container = await _container(registry, conversation_id)
348
- upstream_path = _upstream_path(request, request.url.path)
364
+ upstream_path = _upstream_path(
365
+ request,
366
+ f"/api/conversations/{conversation_id}" + (f"/{tail}" if tail else ""),
367
+ )
349
368
  if tail == "secrets" and request.method == "POST":
350
369
  try:
351
370
  update = UpdateSecretsRequest.model_validate_json(await request.body())