Skip to content

fix: run the automation's stored setup_script_path instead of a hardcoded setup.sh - #759

Merged
neubig merged 3 commits into
mainfrom
fix/honour-setup-script-path-343
Nov 14, 2026
Merged

neubig merged 3 commits into
mainfrom
fix/honour-setup-script-path-343

Conversation

@neubig

@neubig neubig commented Nov 14, 2026

Copy link
Copy Markdown
Member

Why

Fixes #343. setup_script_path is validated, stored and echoed by the API, but no executor reads it. Both run paths execute a hardcoded ([ ! -f setup.sh ] || bash setup.sh). A custom tarball that names its setup script anything else skips setup silently, and the run then fails in the entrypoint with nothing pointing at setup. This takes the "honour the field" option from the issue. It supersedes #390, which was closed as stale.

Summary

  • execution._setup_step(setup_script_path) builds the setup fragment:
    • None / "setup.sh": unchanged, ([ ! -f setup.sh ] || bash setup.sh) (presets and existing tarballs behave as before).
    • any other path: ([ -f 'p' ] || { echo 'setup script not found in the tarball: p' >&2; exit 1; }) && bash 'p'. A path the automation names explicitly must exist, so a typo fails the run before the entrypoint with a clear message instead of being skipped silently. The path is shell-quoted even though the request validator already rejects metacharacters.
  • execute_in_context and run_automation take setup_script_path. The dispatcher passes automation.setup_script_path.
  • Plugin-spec automations are excluded on purpose. /plugin-spec stores the manifest's entrypoint.setup_script, which is relative to the fetched plugin, not the runtime bundle. The bundle already contains a root setup.sh wrapper that runs $AUTOMATION_PLUGIN_ROOT/<setup_script>. Passing the stored value through would look for the script in the wrong directory, so the dispatcher passes None for them.
  • The Windows path (windows_runner.py, which runs setup.py) is unchanged and documented as such.
  • The setup_script_path API description and AGENTS.md describe the behaviour.

How to Test

uv run python -m pytest tests/test_execution.py tests/test_dispatcher.py tests/test_dispatcher_private_plugins.py tests/test_router.py -n 4

454 passed (plus the run_automation wiring test added after). New tests:

  • TestSetupStep runs the generated fragment in real bash in a temp dir. It covers: default setup.sh present or absent; a custom path runs instead of a root setup.sh; a missing custom path exits 1 before the entrypoint with the message; a failing setup stops the run; and quoting with ' and spaces.
  • Wiring tests for execute_in_context, run_automation and the dispatcher (stored path passed through; None for plugin specs).

pre-commit (ruff, pyright, …) passes on the changed files.

Live check: I ran the service from each checkout in local mode with a local agent-server (openhands-agent-server 1.62.0). I uploaded a tarball containing main.py and scripts/install.sh, created a custom automation with "setup_script_path": "scripts/install.sh", and dispatched it. Script and bundle: .pr/repro343.sh, .pr/343-bundle.

Before (main 949c001) After (this PR, c0f0ae9)
before after

Notes

  • Behaviour change: an automation that stored a non-default setup_script_path that is not in its tarball used to have it ignored. Now its runs fail with setup script not found in the tarball: <path>. That is the silent-skip case the issue asks to remove. The presets and the Canvas UI (fix(automations): make the setup script optional for new custom automations OpenHands#18653) send setup.sh, which is unaffected.
  • Follow-up outside this repo: the custom-automation.md reference in OpenHands/extensions can now document setup_script_path as working.
  • .pr/ holds temporary review evidence only.

This PR was created by an AI agent (OpenHands) on behalf of Graham Neubig.

…oded setup.sh

Fixes #343

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

Copy link
Copy Markdown
Contributor

📁 PR Artifacts Notice

This PR adds or changes temporary PR-specific documents under .pr/. They stay on this branch for review. After this PR merges, the next release PR removes them from main.

@github-actions github-actions Bot added the type: fix A bug fix label Nov 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage

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.

@neubig
neubig requested review from all-hands-bot and removed request for all-hands-bot November 14, 2026 01:04

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was posted by an AI agent (OpenHands).

Scope: This belongs here — the automation service owns dispatch and sandbox lifecycle orchestration, and #343 targets this repo's execution.py. The "honour the field" direction was already stated in the issue, so no product decision is needed.

Assessment: No material correctness, security, or compatibility findings. The fix does exactly what #343 asks: both former hardcoded ([ ! -f setup.sh ] || bash setup.sh) sites (execute_in_context, run_automation) now run _setup_step(setup_script_path).

Verified against the workspace code:

  • Backward compatibility: None/"setup.sh" produces the byte-identical previous fragment, so presets, catalog bundles, and existing tarballs behave as before. run_automation's new kwarg defaults to None, leaving existing callers unaffected.
  • Plugin-spec exclusion is correct and necessary: /plugin-spec stores the manifest's script path relative to the fetched plugin (router.py:576 via setup_script_for_manifest), while the runtime bundle only carries the root setup.sh wrapper that runs $AUTOMATION_PLUGIN_ROOT/<script> (plugin_specs.py:1352-1360, AUTOMATION_PLUGIN_ROOT exported at dispatcher.py:1162). Passing the stored value would look in the wrong directory; passing None reproduces the old fragment exactly, and the new test in test_dispatcher_private_plugins.py locks this in with a stored non-default path.
  • Security: validate_command_string is enforced at create, PATCH, and git-sync import (loop.py:542); _setup_step additionally single-quotes both the path and the error message (verified by the quoting test with ' and spaces). No new injection surface.
  • Git sync round-trips the field (serializer exports it, import revalidates), so synced automations keep the behavior.
  • Windows: windows_runner.py is deliberately unchanged and the limitation is documented in the docstring and AGENTS.md step 7 — a pre-existing platform limitation, not a regression.
  • Behavior change (a stored non-default path missing from the tarball now fails fast before the entrypoint instead of being skipped silently) is the fix's stated intent and is disclosed in the Notes.

Tests: Ran tests/test_execution.py (68/68 passed, including the 12 new real-bash TestSetupStep/wiring tests) plus the non-Docker portions of the dispatcher/plugin tests locally. Docker-backed fixtures could not run in this workspace (no Docker daemon), but the head's GitHub Actions unit-tests, backend, and windows-tests checks are all green on d1f5fcc. The .pr/ evidence follows the repo's documented PR-artifact convention and check-pr-artifacts passed.

Design context (intent, before/after, compatibility risk, SHA-pinned links, live before/after evidence) meets the repository's review-guide bar.

✅ APPROVED

@neubig
neubig merged commit 64e1295 into main Nov 14, 2026
10 checks passed
@openhands-release-bot openhands-release-bot Bot added the released: 1.33.0 Shipped in 1.33.0 label Nov 17, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.33.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released: 1.33.0 Shipped in 1.33.0 type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setup_script_path is validated, stored and tested — but never read; only a root setup.sh ever runs

3 participants