Repository navigation
feat(dispatcher): skip runs the install's license does not allow (OHE-4179) - #763
Conversation
…-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.
|
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
left a comment
There was a problem hiding this comment.
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.
LicenseLimitReachedErroris raised inside_create_sandboxbeforeraise_for_status(), and none of the three retry layers catch it: the tenacity_retryretries only 429HTTPStatusErrors,_with_auth_retryonly 401/403, and_acquire_execution_contextretries onlySandboxProvisioningError. 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_terminalkeeps its only-if-RUNNING guard, andSKIPPEDis already in the watchdog's terminal set, so a skipped run can't double-transition. - Other 402s unchanged.
_quota_limit_detail's newstatus_codeparameter defaults to 429, so both existing callers keep their behavior; a 402 without theLICENSE_LIMIT_REACHEDcode still falls through toraise_for_status()and fails the run as before. The conversation-start path is genuinely untouched:_lacks_conversation_startonly treats 404/405/422 as "no contract", so a 402 there raisesConversationStartErrorwith the API's reason in the message, as the PR notes claim. - Contract surface.
status_detailisdict[str, Any]in the API schema andkinda plain string, so the newlicense_limitkind andskip_reasontelemetry 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
…-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.
|
🚀 Released in 1.34.0. |
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 whosedetailis{"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_sandboxraisesLicenseLimitReachedErrorfor a 402 withLICENSE_LIMIT_REACHED, carrying the reason from the API. It is not retried.SKIPPED, withstatus_detail.kind = "license_limit",transient: falseand the reason asdetail, and emitsautomation_run_skippedwithskip_reason: "license_limit". The automation stays enabled, so its runs work again once the install has a license._quota_limit_detailtakes 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.tests/test_backends.py: a 402 with the license code raisesLicenseLimitReachedErrorwith the API's reason after a single request, and another 402 stays anhttpx.HTTPStatusError.test_quota_limit_marks_skipped_and_keeps_enabledintests/test_dispatcher.pyhas a third case for the license limit.backends/cloud.pyanddispatcher.pyfrommain, the first new backend test and the new dispatcher case fail.ruff check,ruff format --check,pycodestyleandpyrightare clean on the changed files.Notes
status_detail.detail, andkindis a plain string there.OpenHands API refused to start the conversation (HTTP 402): …, which includes the reason. That path is unchanged.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