fix(presets): pin SDK install to the run venv so UV_PYTHON cannot redirect it - #392
Closed
santhiprakash wants to merge 1 commit into
Closed
fix(presets): pin SDK install to the run venv so UV_PYTHON cannot redirect it#392santhiprakash wants to merge 1 commit into
santhiprakash wants to merge 1 commit into
Conversation
…irect it - Problem: an ambient UV_PYTHON (e.g. inherited from the agent-server's own uv/uvx launcher) takes precedence over the .venv in the CWD for 'uv pip install', so preset setup.sh silently installs the SDK into a different environment: setup prints Done, the run venv stays empty, and main.py fails with ModuleNotFoundError (OpenHands#338). - Fix: unset UV_PYTHON before the install in all three copies of the script (prompt/plugin presets + scripts/test_tarball), and verify the SDK imports from the run venv before handing off, covering both POSIX and Windows venv layouts so a misdirected install fails loudly at the setup step. - Verification: reproduced the redirect with uv 0.11.7 (UV_PYTHON pointing at a 3.13 env while the CWD .venv is 3.12: install lands in the 3.13 env, .venv empty) and confirmed the fixed fragment installs into .venv and the import check fails loudly on an empty venv; uv run pytest tests/ -q --ignore=tests/integration -> 1463 passed (8 new regression tests); pre-commit (ruff/pycodestyle/pyright) clean; bash -n clean on all copies.
Author
|
Closing for now to respect review bandwidth — we already have a few PRs queued in this repo. The branch stays up and the fix is complete; happy to reopen once the others land. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Preset
setup.shcreates a per-run venv and then installs the OpenHands SDK with a bareuv pip install.uvhonours an ambientUV_PYTHONahead of the.venvin the CWD, so when the agent-server's environment carriesUV_PYTHON(e.g. it was launched viauvx/uv run), the install is silently redirected into a different environment:setup.shprints[setup] Doneand exits 0, the run venv stays empty, and the entrypoint fails with a confusing traceback that points atmain.py:Reproduced locally with uv 0.11.7: with a 3.12
.venvin the CWD andUV_PYTHONpointing at a 3.13 environment,uv pip install sixreportsUsing Python 3.13.13 environment at: fake-server-env—sixlands in the 3.13 env,.venv/bin/python -c "import six"fails. Exactly the mechanism in #338 (which also documents the second-order damage: when the SDK version differs, the run overwrites the live agent-server's environment).Closes #338.
Triage / Root cause
openhands/automation/presets/prompt/setup.sh:43(and the byte-identicalpresets/plugin/setup.sh+scripts/test_tarball/setup.sh):Fix
unset UV_PYTHONbefore theuv pip installin all three copies of the script, so no ambient value can redirect the install away from the run venv..venv/bin/pythonand Windows.venv/Scripts/python.exelayouts — the entrypoint already supports both via_get_preset_entrypoint), so a misdirected install surfaces as[setup] ERROR: ...instead of aModuleNotFoundErrorinsidemain.py.I used
unset UV_PYTHONrather than the--python .venv/bin/pythonvariant sketched in the issue because hardcoding the POSIX venv path would break Windows sandboxes; withUV_PYTHONcleared,uv pip installresolves to the.venvin the CWD (whichexecution.pyguarantees is the run's work dir) portably.The secondary
--python '>=3.12'free-threaded-interpreter issue from #338 is not addressed here (needs an interpreter-request policy decision) — happy to follow up separately.Verification
.venv; the import check fails loudly on an empty venv) — sequence quoted in the issue monitor notes.bash -nclean on all three copies.uv run pytest tests/ -q --ignore=tests/integration→ 1463 passed, including 8 new regression tests asserting both preset copies (and the test-tarball copy) clearUV_PYTHONand verify the SDK import, and that the verification handles both venv layouts.uv run pre-commit run --files <changed>→ ruff format/lint, pycodestyle, pyright all pass.Notes / Risks
VIRTUAL_ENVfor the same failure class (uvalso honoursVIRTUAL_ENV); the two changes compose cleanly. If fix(presets): clear inherited VIRTUAL_ENV before building the run venv #349 merges first this applies on top with at most a trivial rebase.test_*_setup_sh_fetches_sdk_version_from_api,test_test_tarball_setup_fetches_service_sdk_version) pass unchanged.HUMAN: Prepared by Santhi Prakash with AI assistance (code, verification, PR description); reviewed and submitted by Santhi Prakash.