Skip to content

feat: publish display labels for built-in event keys in capabilities - #713

Open
all-hands-bot wants to merge 1 commit into
mainfrom
feat/event-labels-in-capabilities
Open

all-hands-bot wants to merge 1 commit into
mainfrom
feat/event-labels-in-capabilities

Conversation

@all-hands-bot

@all-hands-bot all-hands-bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Why

The setup UI can only offer event keys as raw strings today (pull_request.*, pr:opened, jira:issue_created, …), so users configuring an event trigger have to guess, look up, or memorize the right key for their use case. The display names belong next to the catalogs that own the keys, and publishing them in the capabilities response lets any client render well-named options.

Context: OpenHands/OpenHands#19465 tracks the Canvas side (a proper dropdown for the event key field). This PR is the backend half: authoritative, human-readable names for every built-in catalog entry.

What

  • Each built-in event source module (GitHub, Jira DC, Bitbucket DC, Azure DevOps) now carries display labels for its event key patterns (EVENT_TYPE_LABELS / *_EVENT_TYPE_LABELS), alongside the keys they name.
  • openhands/automation/event_schemas/catalog.py gains event_labels(source), returning labels keyed exactly like supported_event_patterns(source) — a pattern missing a label raises, so the two lists cannot drift apart silently.
  • GET /v1/capabilities (the setup contract, camelCase) now returns eventLabelsBySource: Record<source, Record<pattern, label>> alongside eventTypesBySource. Backward compatible: the field defaults to {}, older clients ignore it, and newer clients against an older service fall back to showing raw keys.

GitHub's patterns are families (actions are free-form), so their labels name the family ("Pull request activity"); keyed sources name each key exactly ("Pull request opened").

How I tested it

$ python3 -m pytest tests/test_event_schemas.py -q
61 passed

$ python3 -c "from openhands.automation.schemas import CapabilitiesResponse; from openhands.automation.event_schemas.catalog import event_labels; r = CapabilitiesResponse(ready=True, max_automation_timeout_seconds=900, trigger_kinds=['cron','event'], event_sources=['github'], event_types=['push'], event_types_by_source={'github':['push']}, event_labels_by_source={'github': event_labels('github')}, triggers={}, features=[], repo_providers=[]); print(r.model_dump(by_alias=True)['eventLabelsBySource'])"
{'github': {'pull_request.*': 'Pull request activity', ...}}
  • New TestEventLabels in tests/test_event_schemas.py: every supported pattern has a non-empty label (drift guard for future catalog additions), labels are unique per source, spot checks per source, and a source without a catalog returns None.
  • tests/test_capabilities_router.py asserts eventLabelsBySource mirrors eventTypesBySource per source with the expected names.

Note: the full router test suite needs the Postgres testcontainer, which this environment cannot run (no Docker daemon); tests/test_event_schemas.py::TestEventLabels and the schema serialization check above cover the change end-to-end at the unit level, and CI runs the container suite.

Jev-Fast-Audit

⚡ Jev fast audit · estimates · 0.34s · commit 2e8cb16
Strongest signal: No primary concern selected.
Evidence: No primary concern to locate.
Coverage: complete supplied coverage; 14/14 hunks, 9/9 files.

All estimates and evidence
Estimate Likelihood / value Direct evidence
SQL injection 3.0% No direct hunk selected
Command injection 3.0% No direct hunk selected
Weakened authentication 3.0% No direct hunk selected
Weakened authorization 5.0% No direct hunk selected
Contract regression 11.0% No direct hunk selected
Data loss 3.0% No direct hunk selected
Sensitive data disclosure 3.0% No direct hunk selected
Unexpected data transfer 3.0% No direct hunk selected
Credential misuse 3.0% No direct hunk selected
Untrusted instruction authority 2.0% No direct hunk selected
Package source redirection 3.0% No direct hunk selected
Unverified remote execution 2.0% No direct hunk selected
Privileged environment access 2.0% No direct hunk selected
Security assessment bypass 3.0% No direct hunk selected
Prohibited workload 2.0% No direct hunk selected
Primary concern None selected; confidence 96.0% No primary concern to locate

A setup UI can only show event keys as raw strings today, so users have to
guess or memorize keys like 'pull_request.*' or 'pr:opened'. Give every
built-in catalog entry a human-readable display name and expose them in
GET /v1/capabilities as eventLabelsBySource, keyed exactly like
eventTypesBySource. Clients without labels keep showing the raw key.
@github-actions

github-actions Bot commented Nov 7, 2026

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.

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

Copy link
Copy Markdown
Contributor Author

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

In scope: this repository owns the automation service's event catalogs and the /v1/capabilities setup contract, and this PR publishes display labels from those catalogs through that endpoint. The Canvas-side dropdown is correctly tracked separately in OpenHands/OpenHands#19465. Design context in the PR description is adequate: intent, before/after contract shape, and compatibility all covered.

What I verified

  • Pattern/label alignment: event_labels(source) returns keys exactly matching supported_event_patterns(source) for all four catalog sources (checked locally). GitHub labels derive from the same GITHUB_PAYLOAD_CLASSES iteration that produces patterns, so that side cannot drift; the keyed sources raise KeyError on drift, matching the stated fail-loudly design.
  • Contract: _SetupContractModel camelCase aliasing applies to the new field (eventLabelsBySource verified via model_dump(by_alias=True)), default_factory=dict keeps older clients unaffected, and the not-ready path returns {} consistently.
  • Tests: tests/test_event_schemas.py — 61 passed locally, including the 5 new TestEventLabels tests. The router suite needs the Postgres testcontainer, which this environment cannot run (as the PR notes); CI's unit-tests job covers it and passes.

Blocking finding

The required backend check fails on this head (run 42330710895). The cause is this PR's own new test code: pyright (part of the backend pre-commit job) reports 8 errors in the new TestEventLabels class — event_labels() is typed dict[str, str] | None, and three of the five tests subscript or measure the result without narrowing the None branch. I reproduced all 8 errors locally with uv run pyright, at identical line numbers. The implementation files are pyright-clean (0 errors). This must be fixed before merge; the fix is small (assert the result is not None after each assignment, as the first test already does).

"""Two options with the same name would be indistinguishable."""
for source in catalog_sources():
labels = event_labels(source)
assert len(set(labels.values())) == len(labels)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pyright error on this head (CI backend check fails): event_labels(source) is typed dict[str, str] | None, so labels.values() and len(labels) here are flagged (reportOptionalMemberAccess / reportArgumentType). Add assert labels is not None after the assignment, as test_every_supported_pattern_has_a_label already does for its own variables.

"""GitHub actions are free-form, so a pattern's label names the family."""
labels = event_labels("github")

assert labels["pull_request.*"] == "Pull request activity"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pyright errors on this line and the next (CI backend check fails): labels is dict[str, str] | None and is subscripted without narrowing (reportOptionalSubscript). Add assert labels is not None after line 1191.

bitbucket = event_labels("bitbucket_data_center")
azure = event_labels("azure_devops")

assert jira["jira:issue_created"] == "Issue created"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pyright errors on lines 1202–1205 (CI backend check fails): jira, bitbucket, and azure are each dict[str, str] | None and are subscripted without narrowing (reportOptionalSubscript). Add assert ... is not None after each assignment on lines 1198–1200.

This branch has not been deployed

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

Labels

type: feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants