Repository navigation
perf(presets): avoid redundant SDK imports during setup - #754
Conversation
Verify the three installed SDK distributions through package metadata. Leave module initialization to the preset entrypoint and preserve the existing nonzero setup failure when a required distribution is absent. Cover all three setup scripts with isolated runtime regression tests. Fixes #668
setup.py, setup.sh's Windows counterpart added on main after this branch started, still imported the SDK as its install check. Use the same importlib.metadata check, test it, and keep test_setup_py_mirrors_setup_sh in step. Add timing evidence for #668 under .pr/. Co-authored-by: openhands <openhands@all-hands.dev>
|
📁 PR Artifacts Notice This PR adds or changes temporary PR-specific documents under |
|
Warning Your comment is too long (maximum is 65536 characters), so the coverage report was not added. See the job log for how to reduce it. |
|
@all-hands-bot Please review the latest head 22671ea. All CI checks are green and the branch merges cleanly with main. Before/after evidence is in the PR description. This comment/PR was created by an AI agent (OpenHands) on behalf of Graham Neubig. |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Correction: this supersedes an empty APPROVED review (id 5902653534) posted a minute earlier whose body failed to attach. The verdict below is the complete one.
Scope
In scope: AGENTS.md assigns openhands/automation/presets/*/setup.sh to this repository, and issue #668's triage names it as the owning repo with the metadata check as its endorsed "Fix 1". Linked issue #668 carries ready-for-dev and no release-blocker labels; the changed scripts ship in the automation image built by this PR's CI.
Review
The change replaces the full cold SDK import in all three setup.sh variants and the Windows presets/setup.py with importlib.metadata.version() checks, plus tests. Verification against the workspace:
- Behavior parity. Missing distributions still print
[setup] ERROR: OpenHands SDK is not importable from .venvand exit non-zero, so failure visibility at setup is unchanged for the common case. The detection is intentionally weaker (metadata-only, no import), and the trade-off is sound:main.pyimportsopenhands.sdk,openhands.tools, andopenhands.workspaceimmediately after setup, so a metadata-present-but-broken install now fails the run once at the entrypoint with a real traceback instead of twice. This matchesAGENTS.md's split of duties (setup installs, entrypoint initializes). setup.py/setup.shparity. The Windows counterpart uses the identical metadata check, satisfying theAGENTS.mdrule that the two stay in step;test_setup_py_mirrors_setup_shnow enforces both the metadata-check needles and the absence ofimport openhandsin both scripts.- All three presets covered, including plugin_spec.
presets/plugin_spec/setup.shreceives the same change, and_load_plugin_spec_preset_files()reads it (withPRESETS_DIR / "setup.py") into generated plugin-spec tarballs.with_current_preset_runnerswaps the current runner into every preset tarball at dispatch, so existing automations pick this up without regeneration; the POSIX branch still dropssetup.pyas before. - Tests are real-path.
_fake_run_venvbuilds an actual venv with real dist-info metadata whoseopenhands.*modules raise on import, and asserts setup never triggers an SDK import while still failing correctly when a distribution's metadata is absent (12 bash cases; 4 forsetup.py). Thesetup.pytest only stubs the externaluvinstaller and the version API, not the metadata check itself. The 17 new/updated cases pass here, and the full focused suite (tests/test_preset_router.py+tests/test_plugin_specs.py) shows 279 passed with only the 27 fixture-collection errors that occur identically at base949c001in this Docker-less environment (verified by diffing error sets). - No unintended side effects. No changes to run-state, phases, callbacks, auth, or tarball contracts; the bench evidence in
.pr/issue-668/matches the PR body's numbers, and.pr/use follows the repository's artifact policy with release-time cleanup.
No material findings. CI on 22671ead08f5dbccf689f49b402cd0bad3bdd439 is green.
✅ APPROVED
|
🚀 Released in 1.33.0. |
Why
Fixes #668. Supersedes #719 by @claire-fang (fork PR whose CI could not run without approval and which conflicted with
main); her two commits are kept unchanged on this branch.Every preset run's
setup.shended withpython -c 'import openhands.sdk, openhands.tools, openhands.workspace'as an install check. That full cold import is the slowest part of setup, and the entrypoint (main.py) imports the same packages right after, so every run paid the import twice.Summary
presets/prompt/setup.sh,presets/plugin/setup.sh,presets/plugin_spec/setup.sh(from perf(presets): avoid redundant SDK imports during setup #719): verifyopenhands-sdk,openhands-tools,openhands-workspacewithimportlib.metadata.version(). Missing distributions still print[setup] ERROR: OpenHands SDK is not importable from .venvand exit non-zero.presets/setup.py(new here): the Windows counterpart ofsetup.sh, added onmainafter perf(presets): avoid redundant SDK imports during setup #719 was opened, had the same import check. It now uses the same metadata check, asAGENTS.mdrequires the two to stay in step.mainand resolved thetests/test_preset_router.pyconflict (kept main'sskipif(os.name == "nt")for bash tests).setup.shagainst a real venv whoseopenhands.*modules raise on import, with and without each distribution's metadata), 4 new runtime cases forsetup.py, andtest_setup_py_mirrors_setup_shnow asserts both use the metadata check and neither containsimport openhands.A broken install that has metadata but cannot import now fails in the entrypoint's own import, once, instead of in setup.
How to Test
358 passed locally. Pre-commit (ruff, pycodestyle, pyright) passes.
Timing (
.pr/issue-668/bench.sh): the prompt presetsetup.shfrom each revision in a fresh run directory, real PyPI install of SDK 1.62.0 with a warm uv cache, then the entrypoint's SDK import, 3 alternating runs each on Linux:Before / after
Notes
Out of scope, per the issue triage: prebuilt/hardlinked venvs,
UV_COMPILE_BYTECODE, a new progress phase, and making the SDK'slitellmimport lazy (SDK repo)..pr/holds review evidence only and is removed on release.This comment/PR was created by an AI agent (OpenHands) on behalf of Graham Neubig.