openhands-agent-server 1.61.0__tar.gz → 1.62.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 (114) hide show
  1. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/PKG-INFO +4 -4
  2. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/api.py +8 -2
  3. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/conversation_router.py +33 -0
  4. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/conversation_service.py +16 -1
  5. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/docker_runtime/proxy.py +0 -4
  6. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/event_service.py +22 -2
  7. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/file_router.py +61 -5
  8. openhands_agent_server-1.62.0/openhands/agent_server/git_provider_service.py +419 -0
  9. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/git_router.py +57 -0
  10. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/llm_router.py +31 -2
  11. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/models.py +18 -1
  12. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/session_socket.py +60 -9
  13. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands_agent_server.egg-info/PKG-INFO +4 -4
  14. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands_agent_server.egg-info/requires.txt +3 -3
  15. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/pyproject.toml +4 -4
  16. openhands_agent_server-1.61.0/openhands/agent_server/git_provider_service.py +0 -228
  17. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/__init__.py +0 -0
  18. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/__main__.py +0 -0
  19. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/_secret_redaction.py +0 -0
  20. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/_secrets_exposure.py +0 -0
  21. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/acp_router.py +0 -0
  22. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/agent_profiles_router.py +0 -0
  23. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/auth_router.py +0 -0
  24. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/bash_router.py +0 -0
  25. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/bash_service.py +0 -0
  26. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/canvas_extensions/__init__.py +0 -0
  27. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/canvas_extensions/backend.py +0 -0
  28. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/canvas_extensions/bridge.py +0 -0
  29. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/canvas_extensions/installed.py +0 -0
  30. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/canvas_extensions/manifest.py +0 -0
  31. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/canvas_extensions_bridge_router.py +0 -0
  32. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/canvas_extensions_router.py +0 -0
  33. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/code_server_proxy.cjs +0 -0
  34. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/config.py +0 -0
  35. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/conversation_lease.py +0 -0
  36. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/conversation_registry.py +0 -0
  37. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/credential_binding.py +0 -0
  38. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/dependencies.py +0 -0
  39. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/docker/Dockerfile +0 -0
  40. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/docker/build.py +0 -0
  41. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/docker_runtime/__init__.py +0 -0
  42. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/docker_runtime/hybrid.py +0 -0
  43. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/docker_runtime/mediation.py +0 -0
  44. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/docker_runtime/provisioning.py +0 -0
  45. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/docker_runtime/registry.py +0 -0
  46. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/docker_runtime/routers.py +0 -0
  47. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/docker_runtime/storage.py +0 -0
  48. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/env_parser.py +0 -0
  49. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/event_router.py +0 -0
  50. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/hooks_router.py +0 -0
  51. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/hooks_service.py +0 -0
  52. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/init_router.py +0 -0
  53. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/launch.py +0 -0
  54. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/local_secret_resolver.py +0 -0
  55. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/local_storage.py +0 -0
  56. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/logging_config.py +0 -0
  57. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/managed_llm_key.py +0 -0
  58. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/mcp_oauth_store.py +0 -0
  59. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/mcp_router.py +0 -0
  60. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/meta_profiles_router.py +0 -0
  61. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/middleware.py +0 -0
  62. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/openai/__init__.py +0 -0
  63. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/openai/models.py +0 -0
  64. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/openai/router.py +0 -0
  65. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/openai/service.py +0 -0
  66. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/openai/usage.py +0 -0
  67. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/openapi.py +0 -0
  68. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/persistence/__init__.py +0 -0
  69. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/persistence/models.py +0 -0
  70. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/persistence/store.py +0 -0
  71. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/plugins_router.py +0 -0
  72. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/plugins_service.py +0 -0
  73. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/profiles_router.py +0 -0
  74. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/provider_connections_router.py +0 -0
  75. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/pub_sub.py +0 -0
  76. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/py.typed +0 -0
  77. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/runtime_router.py +0 -0
  78. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/server_details_router.py +0 -0
  79. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/session_protocol.py +0 -0
  80. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/settings_router.py +0 -0
  81. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/skills_router.py +0 -0
  82. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/skills_service.py +0 -0
  83. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/sockets.py +0 -0
  84. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/storage/__init__.py +0 -0
  85. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/storage/model.py +0 -0
  86. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/storage/reclaimer.py +0 -0
  87. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/storage/selectors.py +0 -0
  88. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/storage/trash.py +0 -0
  89. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/sub_agents_router.py +0 -0
  90. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/telemetry/__init__.py +0 -0
  91. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/telemetry/factory.py +0 -0
  92. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/telemetry/http_exporter.py +0 -0
  93. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/telemetry/models.py +0 -0
  94. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/telemetry/policy.py +0 -0
  95. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/telemetry/posthog_exporter.py +0 -0
  96. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/telemetry/sanitizer.py +0 -0
  97. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/telemetry/service.py +0 -0
  98. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/telemetry/sink.py +0 -0
  99. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/telemetry/subscriber.py +0 -0
  100. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/telemetry_types.py +0 -0
  101. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/tool_preload_service.py +0 -0
  102. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/tool_router.py +0 -0
  103. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/utils.py +0 -0
  104. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/vscode_extensions/openhands-settings/extension.js +0 -0
  105. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/vscode_extensions/openhands-settings/package.json +0 -0
  106. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/vscode_router.py +0 -0
  107. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/vscode_service.py +0 -0
  108. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/workspace_router.py +0 -0
  109. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands/agent_server/workspaces_router.py +0 -0
  110. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands_agent_server.egg-info/SOURCES.txt +0 -0
  111. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands_agent_server.egg-info/dependency_links.txt +0 -0
  112. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands_agent_server.egg-info/entry_points.txt +0 -0
  113. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/openhands_agent_server.egg-info/top_level.txt +0 -0
  114. {openhands_agent_server-1.61.0 → openhands_agent_server-1.62.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openhands-agent-server
3
- Version: 1.61.0
3
+ Version: 1.62.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
@@ -16,9 +16,9 @@ Requires-Dist: openhands-sdk
16
16
  Requires-Dist: openhands-tools
17
17
  Requires-Dist: openai<3,>=2.33.0
18
18
  Requires-Dist: pydantic>=2.13.5
19
- Requires-Dist: sqlalchemy>=2.1.5
19
+ Requires-Dist: sqlalchemy>=2.1.6
20
20
  Requires-Dist: uvicorn>=0.54.0
21
21
  Requires-Dist: websockets>=12
22
- Requires-Dist: wsproto>=1.2.0
22
+ Requires-Dist: wsproto>=1.3.2
23
23
  Provides-Extra: posthog
24
- Requires-Dist: posthog<8,>=7.75.11; extra == "posthog"
24
+ Requires-Dist: posthog<8,>=7.82.2; extra == "posthog"
@@ -927,10 +927,16 @@ def _add_exception_handlers(api: FastAPI) -> None:
927
927
  return JSONResponse(
928
928
  status_code=exc.status_code,
929
929
  content=content,
930
+ headers=exc.headers,
930
931
  )
931
932
 
932
- # Return clean JSON response for all non-5xx HTTP exceptions
933
- return JSONResponse(status_code=exc.status_code, content={"detail": exc.detail})
933
+ # Return clean JSON response for all non-5xx HTTP exceptions. Keep the
934
+ # exception's headers (e.g. Retry-After, WWW-Authenticate).
935
+ return JSONResponse(
936
+ status_code=exc.status_code,
937
+ content={"detail": exc.detail},
938
+ headers=exc.headers,
939
+ )
934
940
 
935
941
 
936
942
  def create_app(config: Config | None = None) -> FastAPI:
@@ -746,6 +746,39 @@ async def switch_conversation_acp_model(
746
746
  return Success()
747
747
 
748
748
 
749
+ @conversation_router.post(
750
+ "/{conversation_id}/switch_acp_effort",
751
+ responses={
752
+ 400: {"description": "Agent is not ACP, or the model doesn't offer it"},
753
+ 404: {"description": "Conversation not found"},
754
+ 504: {"description": "ACP server did not answer the switch in time"},
755
+ },
756
+ )
757
+ async def switch_conversation_acp_effort(
758
+ conversation_id: UUID,
759
+ effort: str = Body(..., embed=True),
760
+ conversation_service: ConversationService = Depends(get_conversation_service),
761
+ ) -> Success:
762
+ """Switch the reasoning effort of an ACP conversation.
763
+
764
+ For a conversation that has already started, sets the session's reasoning
765
+ effort option so subsequent turns use it without losing context. For one
766
+ created but not yet run, the value is persisted and applied when the first
767
+ session starts (returns ``200`` either way). ``effort`` must be one of the
768
+ conversation's ``available_efforts`` when the session reports them.
769
+ """
770
+ event_service = await conversation_service.get_event_service(conversation_id)
771
+ if event_service is None:
772
+ raise HTTPException(status.HTTP_404_NOT_FOUND)
773
+ try:
774
+ await event_service.switch_acp_effort(effort)
775
+ except ValueError as e:
776
+ raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
777
+ except TimeoutError as e:
778
+ raise HTTPException(status_code=status.HTTP_504_GATEWAY_TIMEOUT, detail=str(e))
779
+ return Success()
780
+
781
+
749
782
  @conversation_router.patch(
750
783
  "/{conversation_id}", responses={404: {"description": "Item not found"}}
751
784
  )
@@ -379,7 +379,20 @@ def _compose_conversation_info(
379
379
  or agent_state.get("acp_available_models")
380
380
  or []
381
381
  )
382
- # Static provider capability. Unlike the two fields above it has no
382
+ # Effort: live → persisted hint → the configured ``acp_effort`` before any
383
+ # session wrote a hint. A stored ``None`` hint means the model offers none.
384
+ current_effort = getattr(agent, "current_effort", None)
385
+ if current_effort is None:
386
+ if "acp_current_effort" in agent_state:
387
+ current_effort = agent_state["acp_current_effort"]
388
+ elif not agent_initialized:
389
+ current_effort = getattr(agent, "acp_effort", None)
390
+ available_efforts = (
391
+ getattr(agent, "available_efforts", None)
392
+ or agent_state.get("acp_available_efforts")
393
+ or []
394
+ )
395
+ # Static provider capability. Unlike the fields above it has no
383
396
  # meaningful live-vs-persisted distinction — it's derived from the stable
384
397
  # provider identity and written once at session init — so we read the
385
398
  # persisted value directly. Defaults False for non-ACP agents and
@@ -399,6 +412,8 @@ def _compose_conversation_info(
399
412
  sub_conversation_ids=sub_conversation_ids or [],
400
413
  current_model_id=current_model_id,
401
414
  available_models=available_models,
415
+ current_effort=current_effort,
416
+ available_efforts=available_efforts,
402
417
  supports_runtime_model_switch=supports_runtime_model_switch,
403
418
  client_tools=stored.client_tools,
404
419
  tool_module_qualnames=dict(stored.tool_module_qualnames),
@@ -58,10 +58,6 @@ _HOP_BY_HOP_HEADERS = frozenset(
58
58
  # without de-duplicating, so copying the upstream's would send two of each.
59
59
  _RESPONSE_DROP_HEADERS = frozenset({"date", "server"})
60
60
 
61
- # Stream chunk size for request/response bodies. Set it explicitly so proxy
62
- # behavior does not depend on an httpx implementation default.
63
- _CHUNK_SIZE = 64 * 1024
64
-
65
61
 
66
62
  def _filter_headers(headers) -> dict[str, str]:
67
63
  return {k: v for k, v in headers.items() if k.lower() not in _HOP_BY_HOP_HEADERS}
@@ -37,7 +37,10 @@ from openhands.sdk.agent.acp_file_credentials import (
37
37
  )
38
38
  from openhands.sdk.agent.stream_context import StreamProgress
39
39
  from openhands.sdk.conversation.base import BaseConversation
40
- from openhands.sdk.conversation.event_store import EventLog
40
+ from openhands.sdk.conversation.event_store import (
41
+ UNREADABLE_EVENT_FILE_CODE,
42
+ EventLog,
43
+ )
41
44
  from openhands.sdk.conversation.events_list_base import EventsListBase
42
45
  from openhands.sdk.conversation.exceptions import ConversationRunError
43
46
  from openhands.sdk.conversation.goal import (
@@ -603,7 +606,7 @@ class EventService:
603
606
 
604
607
  def _get_searchable_event(self, events: EventsListBase, index: int) -> Event | None:
605
608
  try:
606
- return events[index]
609
+ event = events[index]
607
610
  except (FileNotFoundError, UnicodeDecodeError, ValidationError) as exc:
608
611
  logger.warning(
609
612
  "Skipping unreadable event at index %d for conversation %s (%s)",
@@ -612,6 +615,12 @@ class EventService:
612
615
  type(exc).__name__,
613
616
  )
614
617
  return None
618
+ if (
619
+ isinstance(event, ConversationErrorEvent)
620
+ and event.code == UNREADABLE_EVENT_FILE_CODE
621
+ ):
622
+ return None # the log's stand-in for a damaged file
623
+ return event
615
624
 
616
625
  def _search_events_sync(
617
626
  self,
@@ -2253,6 +2262,17 @@ class EventService:
2253
2262
  loop = asyncio.get_running_loop()
2254
2263
  await loop.run_in_executor(None, self._conversation.switch_acp_model, model)
2255
2264
 
2265
+ async def switch_acp_effort(self, effort: str) -> None:
2266
+ """Switch the reasoning effort on an ACP conversation.
2267
+
2268
+ Same lifecycle as :meth:`switch_acp_model`: a live switch runs in a
2269
+ worker thread, a not-yet-run conversation only persists the value.
2270
+ """
2271
+ if self._conversation is None:
2272
+ raise ValueError("inactive_service")
2273
+ loop = asyncio.get_running_loop()
2274
+ await loop.run_in_executor(None, self._conversation.switch_acp_effort, effort)
2275
+
2256
2276
  async def close(self):
2257
2277
  if self.bash_event_service is not None:
2258
2278
  await self.bash_event_service.close()
@@ -4,11 +4,14 @@ import fnmatch
4
4
  import io
5
5
  import json
6
6
  import os
7
+ import re
7
8
  import stat
8
9
  import subprocess
9
10
  import tarfile
10
11
  import tempfile
12
+ import time
11
13
  import zipfile
14
+ from concurrent.futures import ThreadPoolExecutor
12
15
  from pathlib import Path, PurePosixPath
13
16
  from typing import IO, Annotated, Any, Literal
14
17
  from urllib.parse import quote
@@ -26,6 +29,7 @@ from fastapi import (
26
29
  from fastapi.responses import FileResponse
27
30
  from pydantic import BaseModel
28
31
  from starlette.background import BackgroundTask
32
+ from starlette.types import Receive, Scope, Send
29
33
 
30
34
  from openhands.agent_server._secret_redaction import (
31
35
  redacted_json_bytes,
@@ -174,6 +178,27 @@ async def _download_file(path: str) -> FileResponse:
174
178
 
175
179
 
176
180
  _TRAJECTORY_EXCLUDED_TOP_DIRS = frozenset({"acp"})
181
+ _TRAJECTORY_TEMP_ZIP_NAME = re.compile(r"\.[0-9a-f]{32}-\w+\.zip")
182
+ _TRAJECTORY_TEMP_ZIP_MAX_AGE_SECONDS = 60 * 60
183
+ _TRAJECTORY_ZIP_EXECUTOR = ThreadPoolExecutor(
184
+ max_workers=2, thread_name_prefix="trajectory-zip"
185
+ )
186
+
187
+
188
+ def _remove_stale_trajectory_temp_zips(conversations_path: Path) -> None:
189
+ """Remove temp zips left behind when a server died during a download.
190
+
191
+ A younger zip may belong to a live download, possibly in another server
192
+ process sharing this directory, so only old ones are removed.
193
+ """
194
+ cutoff = time.time() - _TRAJECTORY_TEMP_ZIP_MAX_AGE_SECONDS
195
+ with contextlib.suppress(OSError):
196
+ for path in conversations_path.iterdir():
197
+ if not _TRAJECTORY_TEMP_ZIP_NAME.fullmatch(path.name):
198
+ continue
199
+ with contextlib.suppress(OSError):
200
+ if path.stat().st_mtime < cutoff:
201
+ path.unlink(missing_ok=True)
177
202
 
178
203
 
179
204
  def _create_zip_from_directory(source_dir: Path, output_path: Path) -> None:
@@ -222,6 +247,14 @@ def _create_zip_from_directory(source_dir: Path, output_path: Path) -> None:
222
247
  raise
223
248
 
224
249
 
250
+ class _TemporaryFileResponse(FileResponse):
251
+ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
252
+ try:
253
+ await super().__call__(scope, receive, send)
254
+ finally:
255
+ Path(self.path).unlink(missing_ok=True)
256
+
257
+
225
258
  ArchiveFormat = Literal["git-delta", "tar.gz"]
226
259
 
227
260
  _ARCHIVE_SUFFIX: dict[str, str] = {
@@ -945,7 +978,6 @@ async def download_trajectory(
945
978
  ) -> FileResponse:
946
979
  """Download a zip archive of a conversation trajectory."""
947
980
  config: Config = request.app.state.config
948
- temp_file = config.conversations_path / f"{conversation_id.hex}.zip"
949
981
  conversation_dir = config.conversations_path / conversation_id.hex
950
982
 
951
983
  if not conversation_dir.is_dir():
@@ -954,12 +986,36 @@ async def download_trajectory(
954
986
  detail="Conversation not found",
955
987
  )
956
988
 
957
- await asyncio.to_thread(_create_zip_from_directory, conversation_dir, temp_file)
958
- return FileResponse(
989
+ await asyncio.to_thread(
990
+ _remove_stale_trajectory_temp_zips, config.conversations_path
991
+ )
992
+
993
+ # Each request gets its own temp zip: a shared path would let one
994
+ # response's cleanup, or another request's rewrite, break a download of
995
+ # the same trajectory that is still being built or streamed.
996
+ fd, tmp_name = tempfile.mkstemp(
997
+ prefix=f".{conversation_id.hex}-", suffix=".zip", dir=config.conversations_path
998
+ )
999
+ os.close(fd)
1000
+ temp_file = Path(tmp_name)
1001
+ zip_task = asyncio.get_running_loop().run_in_executor(
1002
+ _TRAJECTORY_ZIP_EXECUTOR,
1003
+ _create_zip_from_directory,
1004
+ conversation_dir,
1005
+ temp_file,
1006
+ )
1007
+ try:
1008
+ await asyncio.shield(zip_task)
1009
+ except BaseException:
1010
+ try:
1011
+ await zip_task
1012
+ finally:
1013
+ temp_file.unlink(missing_ok=True)
1014
+ raise
1015
+ return _TemporaryFileResponse(
959
1016
  path=temp_file,
960
- filename=temp_file.name,
1017
+ filename=f"{conversation_id.hex}.zip",
961
1018
  media_type="application/octet-stream",
962
- background=BackgroundTask(temp_file.unlink),
963
1019
  )
964
1020
 
965
1021