mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-09 23:08:04 -05:00
fix: make local runtime use host-writable paths and local cache defaults (#12015)
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Tim O'Farrell <tofarr@gmail.com>
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
import atexit
|
import atexit
|
||||||
import json
|
import json
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import browsergym.core # noqa F401 (we register the openended task as a gym environment)
|
import browsergym.core # noqa F401 (we register the openended task as a gym environment)
|
||||||
import gymnasium as gym
|
import gymnasium as gym
|
||||||
@@ -67,6 +69,16 @@ class BrowserEnv:
|
|||||||
raise BrowserInitException('Failed to start browser environment.')
|
raise BrowserInitException('Failed to start browser environment.')
|
||||||
|
|
||||||
def browser_process(self) -> None:
|
def browser_process(self) -> None:
|
||||||
|
def _is_local_runtime() -> bool:
|
||||||
|
runtime_flag = os.getenv('RUNTIME', '').lower()
|
||||||
|
return runtime_flag == 'local'
|
||||||
|
|
||||||
|
# Default Playwright cache for local runs only; do not override in docker
|
||||||
|
if _is_local_runtime() and 'PLAYWRIGHT_BROWSERS_PATH' not in os.environ:
|
||||||
|
os.environ['PLAYWRIGHT_BROWSERS_PATH'] = str(
|
||||||
|
Path.home() / '.cache' / 'playwright'
|
||||||
|
)
|
||||||
|
|
||||||
if self.eval_mode:
|
if self.eval_mode:
|
||||||
assert self.browsergym_eval_env is not None
|
assert self.browsergym_eval_env is not None
|
||||||
logger.info('Initializing browser env for web browsing evaluation.')
|
logger.info('Initializing browser env for web browsing evaluation.')
|
||||||
@@ -87,6 +99,11 @@ class BrowserEnv:
|
|||||||
)
|
)
|
||||||
env = gym.make(self.browsergym_eval_env, tags_to_mark='all', timeout=100000)
|
env = gym.make(self.browsergym_eval_env, tags_to_mark='all', timeout=100000)
|
||||||
else:
|
else:
|
||||||
|
downloads_path = os.getenv('BROWSERGYM_DOWNLOAD_DIR')
|
||||||
|
if not downloads_path and _is_local_runtime():
|
||||||
|
downloads_path = str(Path.home() / '.cache' / 'browsergym-downloads')
|
||||||
|
if not downloads_path:
|
||||||
|
downloads_path = '/workspace/.downloads/'
|
||||||
env = gym.make(
|
env = gym.make(
|
||||||
'browsergym/openended',
|
'browsergym/openended',
|
||||||
task_kwargs={'start_url': 'about:blank', 'goal': 'PLACEHOLDER_GOAL'},
|
task_kwargs={'start_url': 'about:blank', 'goal': 'PLACEHOLDER_GOAL'},
|
||||||
@@ -96,7 +113,7 @@ class BrowserEnv:
|
|||||||
tags_to_mark='all',
|
tags_to_mark='all',
|
||||||
timeout=100000,
|
timeout=100000,
|
||||||
pw_context_kwargs={'accept_downloads': True},
|
pw_context_kwargs={'accept_downloads': True},
|
||||||
pw_chromium_kwargs={'downloads_path': '/workspace/.downloads/'},
|
pw_chromium_kwargs={'downloads_path': downloads_path},
|
||||||
)
|
)
|
||||||
obs, info = env.reset()
|
obs, info = env.reset()
|
||||||
|
|
||||||
|
|||||||
@@ -249,7 +249,22 @@ class LocalRuntime(ActionExecutionClient):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Set up workspace directory
|
# Set up workspace directory
|
||||||
|
# For local runtime, prefer a stable host path over /workspace defaults.
|
||||||
|
if (
|
||||||
|
self.config.workspace_base is None
|
||||||
|
and self.config.runtime
|
||||||
|
and self.config.runtime.lower() == 'local'
|
||||||
|
):
|
||||||
|
env_base = os.getenv('LOCAL_WORKSPACE_BASE')
|
||||||
|
if env_base:
|
||||||
|
self.config.workspace_base = os.path.abspath(env_base)
|
||||||
|
else:
|
||||||
|
self.config.workspace_base = os.path.abspath(
|
||||||
|
os.path.join(os.getcwd(), 'workspace', 'local')
|
||||||
|
)
|
||||||
|
|
||||||
if self.config.workspace_base is not None:
|
if self.config.workspace_base is not None:
|
||||||
|
os.makedirs(self.config.workspace_base, exist_ok=True)
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f'Workspace base path is set to {self.config.workspace_base}. '
|
f'Workspace base path is set to {self.config.workspace_base}. '
|
||||||
'It will be used as the path for the agent to run in. '
|
'It will be used as the path for the agent to run in. '
|
||||||
|
|||||||
Reference in New Issue
Block a user