-
Notifications
You must be signed in to change notification settings - Fork 340
fix: validate an OpenHands setup before using it #2387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1716,6 +1716,45 @@ def _openhands_setup_target(self, commit: str) -> Path: | |
| return legacy_dir | ||
| return self.setup_root / "swe_openhands_setup" / _repo_slug(self.config.agent_framework_repo) / commit | ||
|
|
||
| def _probe_openhands_venv(self, openhands_dir: Path) -> Optional[str]: | ||
| """Probe an existing OpenHands venv's deps; return None if healthy, else the failure.""" | ||
| venv_python = openhands_dir / ".venv" / "bin" / "python" | ||
| probe = subprocess_run( | ||
| [ | ||
| str(venv_python), | ||
| "-c", | ||
| ( | ||
| "from importlib.metadata import version; " | ||
| "from packaging.version import Version; " | ||
| "assert Version(version('jinja2')) >= Version('3.1.3'); " | ||
| "assert Version(version('pyjwt')) >= Version('2.9'); " | ||
| "assert Version(version('sqlalchemy')) >= Version('2.0.40'); " | ||
| "assert Version(version('flask')) >= Version('2.2'); " | ||
| "import datasets, wandb" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NOTE: the probe's version floors ( |
||
| ), | ||
| ], | ||
| capture_output=True, | ||
| text=True, | ||
| env={**os.environ, "PYTHONNOUSERSITE": "1"}, | ||
| ) | ||
| if probe.returncode == 0: | ||
| return None | ||
| return " ".join(probe.stderr.strip().splitlines()[-1:]) or f"exit code {probe.returncode}" | ||
|
|
||
| def _existing_setup_is_reusable(self, openhands_dir: Path) -> bool: | ||
| """Whether a pre-existing OpenHands checkout can be reused as-is.""" | ||
| if not (openhands_dir.exists() and Path(openhands_dir / ".venv" / "bin" / "python").exists()): | ||
| return False | ||
| probe_failure = self._probe_openhands_venv(openhands_dir) | ||
| if probe_failure is not None: | ||
| print( | ||
| f"OpenHands venv at {openhands_dir} failed its runtime probe ({probe_failure}); " | ||
| "rebuilding the setup instead of reusing it", | ||
| flush=True, | ||
| ) | ||
| return False | ||
| return True | ||
|
|
||
| def setup(self) -> Path: | ||
| repo = self.config.agent_framework_repo | ||
| ref = self.config.agent_framework_commit | ||
|
|
@@ -1739,7 +1778,7 @@ def setup(self) -> Path: | |
| openhands_dir = setup_dir / "OpenHands" | ||
| miniforge_dir = setup_dir / "miniforge3" | ||
|
|
||
| if self._openhands_tree_valid(setup_dir): | ||
| if self._existing_setup_is_reusable(openhands_dir): | ||
| print(f"OpenHands already set up at {setup_dir}", flush=True) | ||
| self._sync_openhands_to_commit(openhands_dir, commit) | ||
| return setup_dir | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: the probe's version floors (
jinja2>=3.1.3,pyjwt>=2.9,sqlalchemy>=2.0.40,flask>=2.2) are decoupled from what a rebuild actually installs.openhands.shnever pins these — they come from whatever OpenHands' poetry lock resolves. If the lockfile ever resolves any of them below a floor,_existing_setup_is_reusablereturns False on every server startup, so the reuse fast-path is silently disabled and each process pays a full rebuild (which resolves the same sub-floor versions and would fail the probe again next time). No infinite loop (setup() doesn't re-probe after rebuild) and no data corruption — the cost is a permanent, silent loss of the reuse optimization. If these floors encode a known-bad OpenHands version, consider pinning them inopenhands.shalongside thewandb/datasetsinstall so the rebuild actually satisfies what the probe demands.