Skip to content

feat(dispatcher): skip runs the install's license does not allow (OHE-4179) - #763

Merged
hieptl merged 2 commits into
mainfrom
hiep/ohe-4179-license-enforcement-unlicensed-mode
Nov 18, 2026
Merged

hieptl merged 2 commits into
mainfrom
hiep/ohe-4179-license-enforcement-unlicensed-mode

Conversation

@hieptl

@hieptl hieptl commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Why

An OpenHands Enterprise install without a valid license is getting limits on conversations: 50 in its lifetime, started only by its first Super Admin. The OpenHands server enforces them where a conversation starts and at POST /api/v1/sandboxes, the first call every cloud run makes. It answers a refused request with a 402 whose detail is {"error": "LICENSE_LIMIT_REACHED", "message": "<reason>"} (OpenHands/enterprise#1406).

The automation service does not know that response. A run that meets it fails with Failed to get execution context, and the reason never reaches the user.

Ticket: https://linear.app/all-hands-ai/issue/OHE-4179/license-enforcement-unlicensed-mode-restrictions

Summary

  • CloudSandboxBackend._create_sandbox raises LicenseLimitReachedError for a 402 with LICENSE_LIMIT_REACHED, carrying the reason from the API. It is not retried.
  • The dispatcher marks that run SKIPPED, with status_detail.kind = "license_limit", transient: false and the reason as detail, and emits automation_run_skipped with skip_reason: "license_limit". The automation stays enabled, so its runs work again once the install has a license.
  • Any other 402 fails the run as before.
  • _quota_limit_detail takes the status code to match (429 by default), so the license check reuses it.

Testing

  • uv run pytest tests/test_backends.py tests/test_dispatcher.py tests/test_daily_sandbox_limit.py tests/test_run_status_detail.py: 141 passed.
  • New in tests/test_backends.py: a 402 with the license code raises LicenseLimitReachedError with the API's reason after a single request, and another 402 stays an httpx.HTTPStatusError.
  • test_quota_limit_marks_skipped_and_keeps_enabled in tests/test_dispatcher.py has a third case for the license limit.
  • With backends/cloud.py and dispatcher.py from main, the first new backend test and the new dispatcher case fail.
  • ruff check, ruff format --check, pycodestyle and pyright are clean on the changed files.
  • The full suite was not run, and nothing was exercised against a live deployment.

Notes

  • Nothing changes until an OpenHands server sends the new response. SaaS, and an install with a valid license or with license enforcement off, never does.
  • Canvas needs no change. The run details already show status_detail.detail, and kind is a plain string there.
  • If the sandbox is created and the conversation start is then refused, because the limit was reached between the two calls, the run fails with OpenHands API refused to start the conversation (HTTP 402): …, which includes the reason. That path is unchanged.
  • This can merge before or after the enterprise change. Until it is in the automation image an install runs, a refused run there fails with the generic message.

Jev-Fast-Audit

⚡ Jev fast audit · estimates · 0.32s · commit 0ebb8ab
Strongest signal: No primary concern selected.
Evidence: No primary concern to locate.
Coverage: complete supplied coverage; 13/13 hunks, 6/6 files.

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

…-4179)

An OpenHands Enterprise install without a valid license limits who can
start conversations and how many. It refuses the run's sandbox with a
402 whose detail carries the error LICENSE_LIMIT_REACHED and the reason.

Until now that response failed the run with "Failed to get execution
context", so the reason never reached the user.

- The cloud backend raises LicenseLimitReachedError for that response,
  with the reason from the API, and does not retry it.
- The dispatcher marks the run SKIPPED with the kind license_limit and
  that reason, and leaves the automation enabled. Its runs work again
  once the install has a license.
- Any other 402 fails the run as before.
@github-actions

github-actions Bot commented Nov 14, 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

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 license enforcement itself lives in the OpenHands server (enterprise#1406); this PR only teaches the automation service's dispatcher to recognize the new 402 response, which is dispatch/run-state handling this repository owns. The PR description states the intent, before/after behavior, and compatibility ordering with the enterprise change, which is adequate design context for this risk level.

What I verified against the workspace code:

  • No retry, no leak. LicenseLimitReachedError is raised inside _create_sandbox before raise_for_status(), and none of the three retry layers catch it: the tenacity _retry retries only 429 HTTPStatusErrors, _with_auth_retry only 401/403, and _acquire_execution_context retries only SandboxProvisioningError. The refusal reaches the dispatcher on the first attempt, and since the 402 happens on the create request itself, no sandbox exists to clean up.
  • Handler consistency. The dispatcher's skip mirrors the existing concurrency and daily-sandbox handlers, differing only in transient: false — correct, since the condition persists until the install has a license rather than expiring at midnight or when a slot frees. mark_run_terminal keeps its only-if-RUNNING guard, and SKIPPED is already in the watchdog's terminal set, so a skipped run can't double-transition.
  • Other 402s unchanged. _quota_limit_detail's new status_code parameter defaults to 429, so both existing callers keep their behavior; a 402 without the LICENSE_LIMIT_REACHED code still falls through to raise_for_status() and fails the run as before. The conversation-start path is genuinely untouched: _lacks_conversation_start only treats 404/405/422 as "no contract", so a 402 there raises ConversationStartError with the API's reason in the message, as the PR notes claim.
  • Contract surface. status_detail is dict[str, Any] in the API schema and kind a plain string, so the new license_limit kind and skip_reason telemetry value are additive for consumers.

Tests and checks: The GitHub Actions unit-tests and windows-tests runs for this exact head both passed, covering the Docker-dependent dispatcher case. Locally (no Docker available for the PostgreSQL testcontainer), the new backend tests and tests/test_backends.py (56), test_daily_sandbox_limit.py (6), and test_run_status_detail.py (6) all pass, and ruff check, ruff format --check, and pyright are clean on the changed files. The new tests exercise the single-request raise with the API's reason carried through, and the parametrized dispatcher case asserts the persisted status_detail and that the automation stays enabled.

No material findings.

✅ APPROVED

@tofarr tofarr 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.

🍰

…-enforcement-unlicensed-mode

main (#756) now defers runs blocked by the concurrency and daily sandbox
limits instead of skipping them. A license limit is not transient, so it is
still skipped at once.

- run_status_detail.py: keep both DEFER_EXPIRED and LICENSE_LIMIT.
- test_dispatcher.py: keep main's test_quota_limit_defers_run_and_keeps_enabled
  as is, and cover the license limit in its own test, which also checks the
  run is not deferred.
@hieptl
hieptl enabled auto-merge (squash) November 18, 2026 12:00
@hieptl
hieptl merged commit 3d97228 into main Nov 18, 2026
10 checks passed
@openhands-release-bot openhands-release-bot Bot added the released: 1.34.0 Shipped in 1.34.0 label Nov 19, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.34.0.

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants