Skip to content

fix(watchdog): keep a run RUNNING when the verification key mint fails transiently - #802

Draft
neubig wants to merge 2 commits into
mainfrom
fix/797-watchdog-transient-key-mint
Draft

neubig wants to merge 2 commits into
mainfrom
fix/797-watchdog-transient-key-mint

Conversation

@neubig

@neubig neubig commented Nov 24, 2026

Copy link
Copy Markdown
Member

This PR was created by an AI agent (OpenHands) on behalf of @neubig.

Why

The watchdog checks runs that did not send their completion callback. In cloud mode, CloudSandboxBackend.verify_run first mints a new per-user API key. Then it reads the sandbox's bash history.

If the key mint failed once with a network error or a 5xx, verify_run raised APIKeyError. _verify_and_mark_run treats any exception as terminal. So it marked the run FAILED ("Timed out: verification failed: ...") with transient: false, then cleaned up the sandbox. This happened even when the run's command had already exited with code 0.

The other transient verification errors already leave the run RUNNING for the next scan: the sandbox-API 429/5xx and the agent-server errors. Only the key mint was missing this behavior.

Summary of the change

  • The new _verify_run wraps backend.verify_run. It turns a transient error into a VerificationResult with outcome TRANSIENT_ERROR, using classify_httpx_transient_error. A transient error here is a timeout, a transport error, or an HTTP 408, 429 or 5xx.
  • For an APIKeyError, the code classifies the httpx error it was raised from (its __cause__). The status_detail then names openhands_api / create_api_key.
  • That result goes through the existing TRANSIENT_ERROR branch. The run stays RUNNING, gets a transient status_detail and keeps its sandbox. The next watchdog scan checks it again.
  • Permanent failures still fail the run as before:
    • a 401/403/404 from the mint
    • an APIKeyError that no httpx error caused, such as a bad response body
    • any other exception

Notes:

  • This adds no new time limit for transient verification. It matches the current handling of transient sandbox-API and agent-server errors, which also wait for the next scan. Issue Watchdog marks a run FAILED when the API-key mint for verification fails once #797 suggested a limit. If maintainers want one, it should apply to the whole TRANSIENT_ERROR branch, in a separate change.
  • This PR does not reuse the dispatcher's key mint. A transient retry already removes the false terminal result. Reusing the dispatcher's key would be a larger change.

Fixes #797

How to Test

uv sync --frozen
uv run python -m pytest tests/test_watchdog.py -k 'TransientKeyMint or VerificationFailed or transient' -v

Result on this branch: 7 passed.

The new tests run the real mark_stale_runs, _verify_and_mark_run, CloudSandboxBackend.verify_run and verify_run_status against the PostgreSQL test fixture. These external boundaries are stubbed: the key mint (get_api_key_for_automation_run), the sandbox-API lookup, the agent-server bash read, and the sandbox delete call.

  • test_one_failed_key_mint_does_not_fail_a_finished_run: the first mint raises an APIKeyError caused by httpx.ConnectError, and the command exited with code 0. After the first scan, the run is RUNNING with a transient transport status. After the second scan, it is COMPLETED.
  • test_permanent_key_mint_failure_still_fails_the_run: a 403 mint failure, or an APIKeyError with no httpx cause, still marks the run FAILED with transient: false.

I also ran tests/test_watchdog.py, tests/test_backends.py, tests/test_verification_result.py and tests/test_workspace_purge.py: 151 passed, 7 skipped. Pre-commit (ruff, pycodestyle, pyright) is clean on the changed files.

Video/Screenshots

Before: on main, one failed key mint marks a run FAILED ("Timed out: verification failed: Request failed: connection reset"), although its command exited with code 0.

Before: regression test fails on main

After: on this branch, the run stays RUNNING and completes on the next scan. The existing verification-failure tests still pass.

After: regression tests pass on the fix branch

…s transiently

Fixes #797

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 24, 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.

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: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Watchdog marks a run FAILED when the API-key mint for verification fails once

2 participants