Skip to content

feat: add template provenance, idempotent enablement, and first-run outcome to presets - #322

Merged
neubig merged 2 commits into
mainfrom
hieptl/oss-6318
Aug 11, 2026
Merged

neubig merged 2 commits into
mainfrom
hieptl/oss-6318

Conversation

@hieptl

@hieptl hieptl commented Aug 10, 2026

Copy link
Copy Markdown
Contributor
  • A human has tested these changes.

Why

Issue #76 asks for default/preset automations with version identity and user-level enablement, re-scoped so that the automation service does not own a template registry: template definitions and configurable fields live in OpenHands/extensions; this service stores opaque provenance and implements safe lifecycle behavior. Its dependency #56 asks to persist an opaque extension template identifier, version, and non-secret submitted configuration (superseding stale PR #89, which targeted the old repo layout and had migration-number collisions).

Today the preset endpoints record nothing about which template an automation came from, cannot create a disabled automation (clients work around it with create-then-PATCH), enabling the same template twice silently duplicates it, and nothing reports whether an enabled preset actually worked on its first run.

Summary

  • preset_metadata JSON column (migration 013, generic sa.JSON, SQLite + PostgreSQL) populated by both preset endpoints and returned on AutomationResponse; the prompt key is re-synced on PATCH.
  • Both preset create requests accept optional template: {id, version, config} (stored verbatim, never catalog-validated, config ≤ 16 KB) and explicit enabled (default true).
  • Idempotent enablement: a create carrying a template id that matches a live automation for the same user+org returns it unchanged with 200 (201 when created). Lookup uses cross-database JSON extraction following the get_event_automations precedent; the small concurrent-create race is documented and accepted (no cross-database unique index on a JSON path).
  • One-time first-run outcome recorded under preset_metadata["first_run"] (status, failure_stage, template_version, recorded_at) — absence of the key is the once-guard, SELECT … FOR UPDATE on PostgreSQL — plus one automation_template_first_run telemetry event. Recording never raises, and each hook site is placed so a recording failure cannot affect the run transition.

Issue Number

Resolves #76

How to Test

uv run pytest tests/ -v --ignore=tests/integration   # 1101 passed
uv run pyright                                        # clean
uv run pre-commit run --files openhands/automation/preset_router.py \
  openhands/automation/utils/run.py openhands/automation/watchdog.py \
  openhands/automation/router.py                      # all hooks pass

New tests (14) live beside the behavior they pin:

  • tests/test_preset_router.py — provenance storage on both endpoints, explicit enabled, 200-idempotency (including cross-endpoint), 16 KB config cap (422), soft-delete does not block re-enabling.
  • tests/test_router.py::TestCompleteRun — first-run success/failure via the completion callback (stage execution), record shape carries nothing sensitive, once-only, no record without template provenance.
  • tests/test_dispatcher.py — dispatcher failure records stage dispatch; SKIPPED does not consume the slot.
  • tests/test_watchdog.py — watchdog failure records stage watchdog.

Manual check: POST /v1/preset/prompt twice with the same template.id — second response is 200 with the first automation's id; GET /v1 shows total: 1 and preset_metadata.template populated.

Video/Screenshots

N/A — backend-only change; behavior is pinned by the API-level tests above.

@hieptl hieptl self-assigned this Aug 10, 2026
@github-actions github-actions Bot added the type: feat A new feature label Aug 10, 2026
@github-actions

github-actions Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

@neubig neubig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, thank you!

@neubig
neubig enabled auto-merge (squash) August 11, 2026 00:01
@neubig
neubig merged commit b476d29 into main Aug 11, 2026
7 checks passed
@openhands-release-bot openhands-release-bot Bot added the released: 1.7.0 Shipped in 1.7.0 label Aug 11, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.7.0.

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

Labels

released: 1.7.0 Shipped in 1.7.0 type: feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support default/preset automations with versioning and user-level toggles

2 participants