openhands-agent-server 1.58.2__tar.gz → 1.59.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.58.2 → openhands_agent_server-1.59.0}/PKG-INFO +1 -1
  2. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/agent_profiles_router.py +8 -7
  3. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/api.py +10 -0
  4. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/config.py +2 -1
  5. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/conversation_service.py +51 -16
  6. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/event_service.py +18 -0
  7. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/mcp_router.py +233 -19
  8. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/meta_profiles_router.py +5 -5
  9. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/models.py +19 -1
  10. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/openai/service.py +1 -1
  11. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/profiles_router.py +6 -10
  12. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/provider_connections_router.py +4 -4
  13. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/session_protocol.py +3 -2
  14. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/session_socket.py +8 -7
  15. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/settings_router.py +2 -2
  16. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands_agent_server.egg-info/PKG-INFO +1 -1
  17. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/pyproject.toml +1 -1
  18. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/__init__.py +0 -0
  19. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/__main__.py +0 -0
  20. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/_secret_redaction.py +0 -0
  21. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/_secrets_exposure.py +0 -0
  22. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/acp_router.py +0 -0
  23. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/auth_router.py +0 -0
  24. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/bash_router.py +0 -0
  25. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/bash_service.py +0 -0
  26. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/canvas_extensions/__init__.py +0 -0
  27. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/canvas_extensions/backend.py +0 -0
  28. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/canvas_extensions/bridge.py +0 -0
  29. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/canvas_extensions/installed.py +0 -0
  30. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/canvas_extensions/manifest.py +0 -0
  31. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/canvas_extensions_bridge_router.py +0 -0
  32. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/canvas_extensions_router.py +0 -0
  33. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/conversation_lease.py +0 -0
  34. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/conversation_registry.py +0 -0
  35. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/conversation_router.py +0 -0
  36. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/credential_binding.py +0 -0
  37. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/dependencies.py +0 -0
  38. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/docker/Dockerfile +0 -0
  39. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/docker/build.py +0 -0
  40. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/docker_runtime/__init__.py +0 -0
  41. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/docker_runtime/hybrid.py +0 -0
  42. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/docker_runtime/mediation.py +0 -0
  43. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/docker_runtime/provisioning.py +0 -0
  44. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/docker_runtime/proxy.py +0 -0
  45. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/docker_runtime/registry.py +0 -0
  46. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/docker_runtime/routers.py +0 -0
  47. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/docker_runtime/storage.py +0 -0
  48. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/env_parser.py +0 -0
  49. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/event_router.py +0 -0
  50. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/file_router.py +0 -0
  51. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/git_provider_service.py +0 -0
  52. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/git_router.py +0 -0
  53. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/hooks_router.py +0 -0
  54. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/hooks_service.py +0 -0
  55. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/init_router.py +0 -0
  56. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/launch.py +0 -0
  57. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/llm_router.py +0 -0
  58. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/local_secret_resolver.py +0 -0
  59. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/local_storage.py +0 -0
  60. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/logging_config.py +0 -0
  61. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/managed_llm_key.py +0 -0
  62. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/mcp_oauth_store.py +0 -0
  63. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/middleware.py +0 -0
  64. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/openai/__init__.py +0 -0
  65. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/openai/models.py +0 -0
  66. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/openai/router.py +0 -0
  67. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/openapi.py +0 -0
  68. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/persistence/__init__.py +0 -0
  69. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/persistence/models.py +0 -0
  70. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/persistence/store.py +0 -0
  71. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/plugins_router.py +0 -0
  72. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/plugins_service.py +0 -0
  73. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/pub_sub.py +0 -0
  74. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/py.typed +0 -0
  75. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/runtime_router.py +0 -0
  76. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/server_details_router.py +0 -0
  77. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/skills_router.py +0 -0
  78. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/skills_service.py +0 -0
  79. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/sockets.py +0 -0
  80. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/storage/__init__.py +0 -0
  81. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/storage/model.py +0 -0
  82. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/storage/reclaimer.py +0 -0
  83. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/storage/selectors.py +0 -0
  84. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/storage/trash.py +0 -0
  85. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/sub_agents_router.py +0 -0
  86. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/telemetry/__init__.py +0 -0
  87. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/telemetry/factory.py +0 -0
  88. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/telemetry/http_exporter.py +0 -0
  89. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/telemetry/models.py +0 -0
  90. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/telemetry/policy.py +0 -0
  91. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/telemetry/posthog_exporter.py +0 -0
  92. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/telemetry/sanitizer.py +0 -0
  93. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/telemetry/service.py +0 -0
  94. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/telemetry/sink.py +0 -0
  95. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/telemetry/subscriber.py +0 -0
  96. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/telemetry_types.py +0 -0
  97. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/tool_preload_service.py +0 -0
  98. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/tool_router.py +0 -0
  99. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/utils.py +0 -0
  100. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/vscode_extensions/openhands-settings/extension.js +0 -0
  101. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/vscode_extensions/openhands-settings/package.json +0 -0
  102. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/vscode_router.py +0 -0
  103. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/vscode_service.py +0 -0
  104. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/workspace_router.py +0 -0
  105. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands/agent_server/workspaces_router.py +0 -0
  106. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands_agent_server.egg-info/SOURCES.txt +0 -0
  107. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands_agent_server.egg-info/dependency_links.txt +0 -0
  108. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands_agent_server.egg-info/entry_points.txt +0 -0
  109. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands_agent_server.egg-info/requires.txt +0 -0
  110. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/openhands_agent_server.egg-info/top_level.txt +0 -0
  111. {openhands_agent_server-1.58.2 → openhands_agent_server-1.59.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openhands-agent-server
3
- Version: 1.58.2
3
+ Version: 1.59.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
@@ -334,7 +334,7 @@ def _summary_id_for_name(store: AgentProfileStore, name: str) -> str | None:
334
334
 
335
335
 
336
336
  @agent_profiles_router.get("", response_model=AgentProfileListResponse)
337
- async def list_agent_profiles(request: Request) -> AgentProfileListResponse:
337
+ def list_agent_profiles(request: Request) -> AgentProfileListResponse:
338
338
  """List all stored agent profiles and the active pointer.
339
339
 
340
340
  Some profile is always active: with no valid pointer, ``default`` is
@@ -358,7 +358,7 @@ async def list_agent_profiles(request: Request) -> AgentProfileListResponse:
358
358
 
359
359
 
360
360
  @agent_profiles_router.get("/{name}", response_model=AgentProfileDetailResponse)
361
- async def get_agent_profile(name: ProfileName) -> AgentProfileDetailResponse:
361
+ def get_agent_profile(name: ProfileName) -> AgentProfileDetailResponse:
362
362
  """Get a stored profile.
363
363
 
364
364
  A profile is secret-free at rest (#4017), so there is nothing to mask or
@@ -407,7 +407,7 @@ def _validate_profile_payload(
407
407
  response_model=AgentProfileMutationResponse,
408
408
  status_code=status.HTTP_201_CREATED,
409
409
  )
410
- async def save_agent_profile(
410
+ def save_agent_profile(
411
411
  name: ProfileName, body: dict[str, Any]
412
412
  ) -> AgentProfileMutationResponse:
413
413
  """Save an ``AgentProfile`` under ``name`` (overwriting a namesake).
@@ -446,7 +446,7 @@ async def save_agent_profile(
446
446
 
447
447
 
448
448
  @agent_profiles_router.delete("/{name}", response_model=AgentProfileMutationResponse)
449
- async def delete_agent_profile(
449
+ def delete_agent_profile(
450
450
  request: Request, name: ProfileName
451
451
  ) -> AgentProfileMutationResponse:
452
452
  """Delete a stored profile (idempotent).
@@ -503,7 +503,7 @@ async def delete_agent_profile(
503
503
  @agent_profiles_router.post(
504
504
  "/{name}/rename", response_model=AgentProfileMutationResponse
505
505
  )
506
- async def rename_agent_profile(
506
+ def rename_agent_profile(
507
507
  name: ProfileName, body: RenameAgentProfileRequest
508
508
  ) -> AgentProfileMutationResponse:
509
509
  """Rename a stored profile atomically.
@@ -538,7 +538,7 @@ async def rename_agent_profile(
538
538
  @agent_profiles_router.post(
539
539
  "/{profile_id}/activate", response_model=ActivateAgentProfileResponse
540
540
  )
541
- async def activate_agent_profile(
541
+ def activate_agent_profile(
542
542
  request: Request, profile_id: ProfileId
543
543
  ) -> ActivateAgentProfileResponse:
544
544
  """Activate a profile by its stable ``id`` — pointer only.
@@ -610,7 +610,8 @@ async def materialize_agent_profile(
610
610
  store = get_agent_profile_store()
611
611
  try:
612
612
  with store_errors():
613
- profile = store.load(name)
613
+ # Off the event loop: the store lock wait blocks (up to 30 s).
614
+ profile = await asyncio.to_thread(store.load, name)
614
615
  except FileNotFoundError:
615
616
  raise HTTPException(
616
617
  status_code=status.HTTP_404_NOT_FOUND,
@@ -121,6 +121,7 @@ from openhands.tools.terminal.constants import (
121
121
  TMUX_SOCKET_NAME,
122
122
  TMUX_SOCKET_OWNER_OPTION,
123
123
  )
124
+ from openhands.tools.terminal.env import UTF8_FALLBACK_LOCALE, ensure_utf8_locale
124
125
  from openhands.tools.terminal.terminal.tmux_terminal import _socket_creation_lock
125
126
 
126
127
 
@@ -268,6 +269,8 @@ async def api_lifespan(api: FastAPI) -> AsyncIterator[None]:
268
269
  tmux_tmpdir, tmux_tmpdir_was_defaulted, tmux_tmpdir_was_created = (
269
270
  _ensure_server_tmux_tmpdir()
270
271
  )
272
+ # Stale-session cleanup below queries tmux before any terminal exists.
273
+ locale_override = ensure_utf8_locale() if os.name == "posix" else None
271
274
  secret_resolution: local_secret_resolution | None = None
272
275
  try:
273
276
  # Clean up stale tmux sessions from previous server runs
@@ -442,6 +445,13 @@ async def api_lifespan(api: FastAPI) -> AsyncIterator[None]:
442
445
  os.environ.pop("TMUX_TMPDIR", None)
443
446
  else:
444
447
  os.environ["TMUX_TMPDIR"] = original_tmux_tmpdir
448
+ if locale_override is not None:
449
+ locale_name, original_locale = locale_override
450
+ if os.environ.get(locale_name) == UTF8_FALLBACK_LOCALE:
451
+ if original_locale is None:
452
+ os.environ.pop(locale_name, None)
453
+ else:
454
+ os.environ[locale_name] = original_locale
445
455
  if os.environ.get(V1_SESSION_API_KEY_ENV) != original_session_api_key:
446
456
  if original_session_api_key is None:
447
457
  os.environ.pop(V1_SESSION_API_KEY_ENV, None)
@@ -472,7 +472,8 @@ class Config(BaseModel):
472
472
  "container runtimes, where that host configuration is absent): also "
473
473
  "inject the user/org/public/marketplace skills the server "
474
474
  "discovers. Project/repository skills are never injected either way "
475
- "— the CLI reads AGENTS.md itself (#4019). Set explicitly per "
475
+ "— the CLI reads AGENTS.md itself (#4019). Skills a client supplies "
476
+ "at launch are kept in both modes. Set explicitly per "
476
477
  "deployment; the agent-server image sets 'openhands_managed'."
477
478
  ),
478
479
  )
@@ -173,8 +173,8 @@ def _get_worktree_start_point(repo_root: Path) -> str:
173
173
  exists locally.
174
174
  3. Local ``master`` if neither remote default nor local ``main`` is
175
175
  available.
176
- 4. Fall back to ``HEAD`` only when none of the above applies, so worktree
177
- creation still succeeds on freshly initialized repos.
176
+ 4. Fall back to ``HEAD`` only when none of the above applies. The planner
177
+ checks whether the selected ref resolves to a commit.
178
178
  """
179
179
  if _has_git_remote(repo_root):
180
180
  _fetch_origin(repo_root)
@@ -204,6 +204,7 @@ class _WorktreePlan:
204
204
  workspace_dir: Path
205
205
  branch: str
206
206
  options: ConversationWorktreeOptions
207
+ start_point: str
207
208
 
208
209
  @property
209
210
  def guidance(self) -> str:
@@ -235,6 +236,18 @@ def _plan_conversation_worktree(
235
236
  except (GitCommandError, GitRepositoryError):
236
237
  return None
237
238
 
239
+ start_ref = _worktree_start_point(repo_root, options)
240
+ try:
241
+ run_git_command(
242
+ ["git", "rev-parse", "--verify", "--quiet", f"{start_ref}^{{commit}}"],
243
+ repo_root,
244
+ expected_failure=True,
245
+ )
246
+ except GitCommandError as exc:
247
+ if exc.exit_code == 1 and options.base != "ref":
248
+ return None
249
+ raise
250
+
238
251
  worktree_root = conversation_worktree_root / str(conversation_id) / repo_root.name
239
252
  return _WorktreePlan(
240
253
  repo_root=repo_root,
@@ -243,17 +256,19 @@ def _plan_conversation_worktree(
243
256
  workspace_dir=worktree_root / source_workspace.relative_to(repo_root),
244
257
  branch=f"{options.branch_prefix}{conversation_id}",
245
258
  options=options,
259
+ # Keep the ref so Git preserves remote branch tracking configuration.
260
+ start_point=start_ref,
246
261
  )
247
262
 
248
263
 
249
- def _worktree_start_point(plan: _WorktreePlan) -> str:
250
- if plan.options.base == "head":
264
+ def _worktree_start_point(repo_root: Path, options: ConversationWorktreeOptions) -> str:
265
+ if options.base == "head":
251
266
  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)
267
+ if options.base == "ref" and options.ref:
268
+ if _has_git_remote(repo_root):
269
+ _fetch_origin(repo_root)
270
+ return options.ref
271
+ return _get_worktree_start_point(repo_root)
257
272
 
258
273
 
259
274
  def _create_conversation_worktree(plan: _WorktreePlan) -> LocalWorkspace:
@@ -282,7 +297,7 @@ def _create_conversation_worktree(plan: _WorktreePlan) -> LocalWorkspace:
282
297
  "-b",
283
298
  plan.branch,
284
299
  str(plan.worktree_root),
285
- _worktree_start_point(plan),
300
+ plan.start_point,
286
301
  ],
287
302
  repo_root,
288
303
  )
@@ -1681,6 +1696,7 @@ class ConversationService:
1681
1696
  "agent_settings",
1682
1697
  "agent_profile_id",
1683
1698
  "agent_launch_additions",
1699
+ "max_budget_per_run",
1684
1700
  },
1685
1701
  )
1686
1702
  launched_agent_profile = launched.profile or runtime_launched_profile
@@ -1714,6 +1730,7 @@ class ConversationService:
1714
1730
  else None
1715
1731
  ),
1716
1732
  reuse_request=request,
1733
+ max_budget_per_run=request.max_budget_per_run,
1717
1734
  )
1718
1735
 
1719
1736
  async def _launch_prepared_conversation(
@@ -1724,6 +1741,7 @@ class ConversationService:
1724
1741
  run_slot: RunSlot,
1725
1742
  initial_message: Message | None,
1726
1743
  reuse_request: StartConversationRequest | None = None,
1744
+ max_budget_per_run: float | None = None,
1727
1745
  ) -> tuple[ConversationInfo, bool]:
1728
1746
  """Persist a prepared conversation, deliver its first message and notify.
1729
1747
 
@@ -1753,7 +1771,10 @@ class ConversationService:
1753
1771
  # New conversation: the agent is written to base_state.json (its
1754
1772
  # single source of truth), not to meta.json. Pass it explicitly.
1755
1773
  event_service = await self._start_event_service(
1756
- stored, is_new_conversation=True, launched=launched
1774
+ stored,
1775
+ is_new_conversation=True,
1776
+ launched=launched,
1777
+ max_budget_per_run=max_budget_per_run,
1757
1778
  )
1758
1779
  if initial_message is not None:
1759
1780
  await event_service.send_message(initial_message, False)
@@ -1895,6 +1916,8 @@ class ConversationService:
1895
1916
  update["title"] = request.title.strip()
1896
1917
  if request.tags is not None:
1897
1918
  update["tags"] = request.tags
1919
+ # Membership, not None: an explicit null removes the budget limit.
1920
+ budget_updated = "max_budget_per_run" in request.model_fields_set
1898
1921
  # Persist first: a refused write (e.g. lost lease ownership) must leave
1899
1922
  # the in-memory metadata and state untouched.
1900
1923
  await event_service.save_meta(event_service.stored.model_copy(update=update))
@@ -1904,6 +1927,10 @@ class ConversationService:
1904
1927
  state = await loop.run_in_executor(
1905
1928
  None, _update_state_tags_sync, state, request.tags
1906
1929
  )
1930
+ if budget_updated:
1931
+ # base_state.json owns the budget; the event service is loaded
1932
+ # above, so this writes the live state under its lock.
1933
+ await event_service.set_max_budget_per_run(request.max_budget_per_run)
1907
1934
  record = self._conversation_records.get(conversation_id)
1908
1935
  if record is not None:
1909
1936
  record.stored = event_service.stored
@@ -1922,6 +1949,8 @@ class ConversationService:
1922
1949
  updated_fields.append("title")
1923
1950
  if request.tags is not None:
1924
1951
  updated_fields.append("tags")
1952
+ if budget_updated:
1953
+ updated_fields.append("max_budget_per_run")
1925
1954
  logger.info(
1926
1955
  "Successfully updated conversation %s (%s)",
1927
1956
  conversation_id,
@@ -2091,9 +2120,10 @@ class ConversationService:
2091
2120
  resolved agent, but it starts with a fresh event history: ``task`` is
2092
2121
  delivered as the child's first user message. With
2093
2122
  ``isolation="worktree"`` the child runs in a git worktree carved from
2094
- the parent's workspace when that workspace is a git repository;
2095
- otherwise (or with ``isolation="shared"``) it shares the parent's
2096
- directory. The link is recorded via ``parent_conversation_id``.
2123
+ the parent's workspace when that workspace is a git repository with
2124
+ a usable base commit; otherwise (or with ``isolation="shared"``) it
2125
+ shares the parent's directory. The link is recorded via
2126
+ ``parent_conversation_id``.
2097
2127
 
2098
2128
  Returns ``None`` when *parent_id* does not exist.
2099
2129
 
@@ -2113,12 +2143,14 @@ class ConversationService:
2113
2143
  with await RunSlot.acquire(self._run_semaphore) as run_slot:
2114
2144
  parent_stored = parent_service.stored
2115
2145
  parent_agent = cast(AgentBase, parent_service.get_conversation().agent)
2146
+ # A child spends under the same cap as its parent.
2147
+ max_budget_per_run = parent_service.get_conversation().max_budget_per_run
2116
2148
  child_id = uuid4()
2117
2149
 
2118
2150
  # Reuse the worktree machinery of a regular start: a worktree is
2119
2151
  # planned (and its guidance appended to the child's agent) only when
2120
- # the parent workspace is a git repository; otherwise the child
2121
- # shares it.
2152
+ # the parent workspace has a usable git base commit; otherwise
2153
+ # the child shares it.
2122
2154
  worktree = (
2123
2155
  _plan_conversation_worktree(
2124
2156
  parent_stored.workspace,
@@ -2162,6 +2194,7 @@ class ConversationService:
2162
2194
  child_stored,
2163
2195
  launched,
2164
2196
  run_slot=run_slot,
2197
+ max_budget_per_run=max_budget_per_run,
2165
2198
  initial_message=Message(
2166
2199
  role="user", content=[TextContent(text=request.task)]
2167
2200
  ),
@@ -2442,6 +2475,7 @@ class ConversationService:
2442
2475
  is_new_conversation: bool = False,
2443
2476
  launched: LaunchedAgent | None = None,
2444
2477
  persisted_agent: AgentBase | None = None,
2478
+ max_budget_per_run: float | None = None,
2445
2479
  ) -> EventService:
2446
2480
  event_services = self._event_services
2447
2481
  if event_services is None:
@@ -2458,6 +2492,7 @@ class ConversationService:
2458
2492
  stored=stored,
2459
2493
  conversations_dir=self.conversations_dir,
2460
2494
  agent=launched.agent if launched is not None else None,
2495
+ initial_max_budget_per_run=max_budget_per_run,
2461
2496
  cipher=self._cipher_for(stored.id),
2462
2497
  mcp_tool_provider=self.mcp_tool_provider,
2463
2498
  credential_bindings=credential_bindings,
@@ -230,6 +230,8 @@ class EventService:
230
230
  # caller passes it here. On resume this is ``None`` and the agent is loaded
231
231
  # from base_state.json.
232
232
  agent: AgentBase | None = None
233
+ # Budget for a new conversation; base_state.json owns it from then on.
234
+ initial_max_budget_per_run: float | None = field(default=None, kw_only=True)
233
235
  cipher: Cipher | None = None
234
236
  mcp_tool_provider: MCPToolProvider | None = None
235
237
  credential_bindings: dict[str, VersionedCredentialBinding] = field(
@@ -1358,6 +1360,7 @@ class EventService:
1358
1360
  token_callbacks=([_token_streaming_callback] if streaming_enabled else []),
1359
1361
  stream_callbacks=[_publish_stream_progress],
1360
1362
  max_iteration_per_run=self.stored.max_iterations,
1363
+ max_budget_per_run=self.initial_max_budget_per_run,
1361
1364
  stuck_detection=self.stored.stuck_detection,
1362
1365
  visualizer=None,
1363
1366
  secrets=self.stored.secrets,
@@ -2166,6 +2169,21 @@ class EventService:
2166
2169
  None, self._conversation.set_confirmation_policy, policy
2167
2170
  )
2168
2171
 
2172
+ async def set_max_budget_per_run(self, max_budget_per_run: float | None) -> None:
2173
+ """Set the conversation's cost ceiling, taking effect from its next step.
2174
+
2175
+ The value lives in the conversation state (base_state.json). Writing it
2176
+ takes the state lock, hence the executor; connected clients receive it
2177
+ as a state update.
2178
+ """
2179
+ conversation = self._conversation
2180
+ if conversation is None:
2181
+ raise ValueError("inactive_service")
2182
+ loop = asyncio.get_running_loop()
2183
+ await loop.run_in_executor(
2184
+ None, setattr, conversation, "max_budget_per_run", max_budget_per_run
2185
+ )
2186
+
2169
2187
  async def set_security_analyzer(
2170
2188
  self, security_analyzer: SecurityAnalyzerBase | None
2171
2189
  ):