Skip to content

feat: harden automation draft preflight validation - #341

Open
KirschBluteX wants to merge 15 commits into
OpenHands:mainfrom
KirschBluteX:feat/16565-harden-automation-preflight
Open

KirschBluteX wants to merge 15 commits into
OpenHands:mainfrom
KirschBluteX:feat/16565-harden-automation-preflight

Conversation

@KirschBluteX

@KirschBluteX KirschBluteX commented Aug 15, 2026 •

Copy link
Copy Markdown

Why

Automation draft validation currently checks schema, schedules, and event triggers, but it cannot verify the deployment resources a selected automation actually needs. A draft can therefore reach creation with a missing credential, unusable MCP integration, or inaccessible repository.

Related to OpenHands/OpenHands#16565.

Summary

  • extend the existing /v1/validate owner with optional, bounded integration requirements while preserving legacy clients that omit them
  • verify secret names, stored MCP availability/connectivity, and Cloud or local repository/ref access without returning secret values or provider response bodies
  • bound the complete validation flow to 60 seconds, give MCP probes their own HTTP budget, and paginate credential/repository/ref lookup for at most ten pages with repeated-token detection
  • require provider URLs to use the official host and return field/step-addressable errors plus sanitized 503 responses for dependency, transport, rate-limit, pagination, and malformed-response failures

How to test

  • python -m pytest tests/test_capabilities_router.py -q — 35 passed
  • pre-commit run --files openhands/automation/schemas.py openhands/automation/capabilities_router.py tests/test_capabilities_router.py — Ruff format/lint, pycodestyle, and Pyright passed

The tests cover successful validation, multiple prerequisite errors, secret-name-only requests, Cloud and local repository checks across later pages, repeated pagination tokens, provider-host validation, total and MCP-specific deadlines, sanitized dependency failures, and malformed requirement bounds.

Companion changes

Jev-Fast-Audit

⚡ Jev fast audit · estimates · 0.33s · commit a1b27cd
Strongest signal: No primary concern selected.
Evidence: No primary concern to locate.
Coverage: ⚠️ reduced context — partial coverage; 21/24 hunks, 7/7 files (context budget: 21, hunk budget: 3).

All estimates and evidence
Estimate Likelihood / value Direct evidence
SQL injection 4.0% No direct hunk selected
Command injection 5.0% No direct hunk selected
Weakened authentication 13.0% No direct hunk selected
Weakened authorization 17.0% F002H009 · openhands/automation/capabilities_router.py:343–1185
Contract regression 35.0% F003H001 · openhands/automation/draft_router.py:170–178
Data loss 5.0% No direct hunk selected
Sensitive data disclosure 12.0% F002H009 · openhands/automation/capabilities_router.py:343–1185
Unexpected data transfer 6.0% No direct hunk selected
Credential misuse 32.0% F002H009 · openhands/automation/capabilities_router.py:343–1185
Untrusted instruction authority 4.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 4.0% No direct hunk selected
Security assessment bypass 11.0% No direct hunk selected
Prohibited workload 3.0% No direct hunk selected
Primary concern None selected; confidence 41.0% No primary concern to locate

@all-hands-bot

Copy link
Copy Markdown
Contributor

👋 This PR needs a couple of things fixed before OpenHands can review it:

  • the PR description's HUMAN: section needs at least 20 characters describing what you tested, not just the template placeholder

Push an update once this is addressed and this check re-runs automatically.

This is an automated check - no AI was used to generate this comment.

@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 change belongs in this repository. It extends the existing /v1/validate owner in openhands/automation/capabilities_router.py with optional deployment preflight requirements, which matches the follow-up hardening described in OpenHands/OpenHands#16565 (open; labels enhancement, ready-for-dev). The companion PRs (OpenHands/OpenHands#16614, software-agent-sdk#4504, sandbox-server#6, extensions#476) are all open. No product/architecture decision is needed, so this is a technical review.

Verification performed on head fc7aa63:

  • uv run pytest tests/test_capabilities_router.py -q → 35 passed.
  • uv run pre-commit run --files openhands/automation/schemas.py openhands/automation/capabilities_router.py tests/test_capabilities_router.py → Ruff format/lint, pycodestyle, pyright all pass.
  • Confirmed the diff (git diff e1523d4...fc7aa63) is +1629 -6 across the 3 stated files.

Blocking issues

  1. The branch no longer merges with main, and CI never produced a result for this head. The PR reports mergeable_state: dirty, and git merge-tree shows content conflicts in both capabilities_router.py and schemas.py. The merge base is e1523d4, which is 80 commits behind current main (49fe663) — the branch predates providers.py/builtin_sources and the require_permission authorization model that main now uses on this router. Separately, the ci, Run tests, Docker, and PR Artifacts runs for this exact head all concluded failure with zero jobs; GitHub states "This run likely failed because of a workflow file issue", so no test or lint result exists for this revision. Only the pr title-lint runs passed. The local green result above therefore does not cover the merged tree: rebase on main and re-run the full suite before merge.

  2. The ref check searches branches only, so tag and commit-SHA refs fail closed with the wrong error. _cloud_repository_errors validates ref exclusively through /api/v1/git/branches/search. The SDK's RepoSource.ref is documented as "Optional branch, tag, or commit SHA to checkout", so a draft pinned to a tag (or a SHA that is not a current branch tip) is never found here and is rejected with repository_ref_not_accessible. The commit_sha.casefold().startswith(ref.casefold()) arm only matches a branch tip SHA, so it does not cover arbitrary commits. This is a false negative that blocks valid drafts.

  3. A legitimately stored MCP auth shape fails the entire preflight with a 503. _parse_stored_mcp_server raises _DependencyUnavailable unless auth is absent or a dict with a string strategy. The SDK's MCP auth migration also accepts a plain string auth and rewrites it to {"strategy": "bearer", "value": auth} (and api_key/Authorization header forms) — but that migration runs on the settings write/migrate path, not necessarily on the agent_settings.mcp_config payload this code reads back. One server whose stored auth is a plain string therefore makes _stored_mcp_servers raise, which the caller converts into a sanitized 503 for the whole request — an unrelated server's config shape takes down every preflight for the user instead of being skipped or reported as that one integration being unavailable.

Non-blocking observations

  • draft.repos has no upper bound, and _deployment_preflight_errors probes repositories sequentially with up to 10 pages for the repo plus 10 for the ref, all under one 60s wall clock. A long repos list against a slow provider can exhaust the budget and return a generic 503 instead of per-repository errors. Bounding repos (or the probe count) would make the failure mode predictable.
  • The ref-matching loop breaks out of the page loop only after a full page is scanned; combined with limit=100 and a query=ref filter this is reasonable, but note that a provider that ignores query will make the tag/SHA false negative in issue 2 more likely to hit the page cap and surface as 503 rather than a clear "not found".

Summary: The design is sound — optional requirements preserve legacy clients, secret names (never values) are checked, error bodies are sanitized, and pagination has repeated-token detection. The tests cover the advertised cases. The blocking items are concrete and demonstrated on the current head: the branch is unmergeable and untested by CI, and two false-negative paths (tag/SHA refs, string auth) either block valid drafts or break unrelated ones.

🔄 CHANGES REQUESTED

response = await _send_preflight_request(
client,
"GET",
f"{target.base_url}/api/v1/git/branches/search",

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.

Ref validation searches branches only (/api/v1/git/branches/search). The SDK's RepoSource.ref is documented as "Optional branch, tag, or commit SHA to checkout", so a draft pinned to a tag or to a commit that is not a current branch tip is never found here and is rejected with repository_ref_not_accessible. Add a tag/commit lookup (or widen the search) before rejecting the ref.

Preserve permission checks and canonical draft schemas while merging upstream. Support tarball preflight requirements and isolate invalid MCP entries through SDK settings migration. Report unmatched Cloud references as unverified because branch search does not resolve tags or arbitrary commits.

Validation: 215 related tests passed; scoped pre-commit passed. Full-suite collection remains blocked on Windows by upstream socket.AF_UNIX checks. Local tests use Python 3.13.14 with lockfile dependency versions.

Co-authored-by: openhands <openhands@all-hands.dev>
Comment on lines +94 to +112
_MCP_PROBE_TIMEOUT_SECONDS = 15.0
_MCP_PROBE_REQUEST_TIMEOUT_SECONDS = _MCP_PROBE_TIMEOUT_SECONDS + 5.0
_PREFLIGHT_TOTAL_TIMEOUT_SECONDS = 60.0
_MAX_PREFLIGHT_SEARCH_PAGES = 10
# The Cloud git route requests one look-ahead item from providers to decide
# whether to return ``next_page_id``. Keeping this below provider max 100 lets
# that look-ahead survive instead of being clamped away.
_CLOUD_REPOSITORY_SEARCH_PAGE_SIZE = 99
_LOCAL_REPOSITORY_SECRET_NAMES = {
"github": "github_token",
"gitlab": "gitlab_token",
"bitbucket": "bitbucket_token",
}
_REPOSITORY_PROVIDER_HOSTS = {
"github": "github.com",
"gitlab": "gitlab.com",
"bitbucket": "bitbucket.org",
}

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.

Use Final from typing, with the correct type

# whether to return ``next_page_id``. Keeping this below provider max 100 lets
# that look-ahead survive instead of being clamped away.
_CLOUD_REPOSITORY_SEARCH_PAGE_SIZE = 99
_LOCAL_REPOSITORY_SECRET_NAMES = {

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.

But this hare hard-coded or?

"""A trusted validation dependency did not return a usable answer."""


@dataclass(frozen=True)

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.

slots=True

local: bool


@dataclass(frozen=True)

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.

as above

Comment on lines +361 to +370
errors.extend(
await _integration_errors(
requirement,
servers,
available_secret_names,
target,
client,
)
)

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.

i think you can start everything here withouth using a for loop, see asyncio.gather


if repos:
for index, repository in enumerate(repos):
errors.extend(

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.

same as above

Comment on lines +390 to +392
headers = {}
if settings.agent_server_api_key:
headers["X-Session-API-Key"] = settings.agent_server_api_key

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.

this can be 1-line

break
cookies.append(f"{name}={value}")
if not cookies:
raise _DependencyUnavailable

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.

why this Excaption is private?

if not cookies:
raise _DependencyUnavailable
headers = {"Cookie": "; ".join(cookies)}
else:

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.

you don't need the else here

try:
response = await client.request(method, url, headers=headers, **kwargs)
except httpx.RequestError:
raise _DependencyUnavailable from None

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.

why from None?

Comment on lines +436 to +439
if response.status_code == status.HTTP_429_TOO_MANY_REQUESTS:
raise _DependencyUnavailable
if response.status_code >= status.HTTP_500_INTERNAL_SERVER_ERROR:
raise _DependencyUnavailable

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.

Just in one if block. Or if you want separate give more info about the type of the error.

value = response.json()
except ValueError:
raise _DependencyUnavailable from None
if not isinstance(value, dict):

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.

when can this happens?

if response.status_code != status.HTTP_200_OK:
raise _DependencyUnavailable
items = _json_object(response).get("secrets")
if not isinstance(items, list):

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.

can this happens?

raise _DependencyUnavailable
seen_page_ids.add(next_page_id)
page_id = next_page_id
else:

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.

you don't need else here

return value


async def _available_secret_names(

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.

this method can be probably decompose in better sub-methods. It is difficult to understand why we are doing this.

raw_transport = "stdio" if isinstance(raw.get("command"), str) else "http"
if not isinstance(raw_transport, str):
raise _DependencyUnavailable
if raw_transport == "stdio":

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.

can we use a match statement here?


def _parse_stored_mcp_server(name: str, raw: dict[str, Any]) -> _StoredMCPServer:
enabled = raw.get("enabled", True)
if not isinstance(enabled, bool):

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.

can this happen?

Comment on lines +636 to +637
if alternative.transport == "stdio":
if alternative.locator != server.locator:

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.

we don't need two if here

Scope Cloud probes to the authenticated organization, use the SDK's clone
credential names and persisted MCP auth migration, and bound concurrent
checks with cancellation cleanup. Explain dependency and pagination
boundaries in docstrings and keep malformed preflight inputs out of errors.

Preserve the saved-draft error contract when serializing the shared
validation model. Cover organization isolation, old MCP settings, secret
metadata pagination, partial failures, timeouts, retries and probe budgets.

Co-authored-by: openhands <openhands@all-hands.dev>

@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 in this repository. It extends the existing /v1/validate owner in openhands/automation/capabilities_router.py with optional, bounded deployment preflight requirements, which is the follow-up hardening described in OpenHands/OpenHands#16565 (open, enhancement + ready-for-dev). No product/architecture decision is needed, so the technical review continued.

State re-established on head 473f5339: title/body unchanged, label type: feat, mergeable with current main (the branch was rebased; git merge-tree origin/main HEAD is clean). The four companion PRs are all still open (OpenHands/OpenHands#16614, software-agent-sdk#4504, sandbox-server#6, extensions#476). The only prior reviews are on older commits (fc7aa63, 5bdf9bb); VascoSch92 commented after them, so this is a fresh pass on the current head, not a duplicate.

Verification performed on head 473f5339:

  • uv run python -m pytest tests/test_capabilities_router.py -q -> 83 passed, 3 pre-existing deprecation warnings.
  • tests/test_draft_router.py cannot run in this environment: its fixtures require Docker, and the daemon is unreachable (docker.errors.DockerException ... FileNotFoundError). The one-line assertion added there is covered by reading the code, not execution.
  • GitHub Actions for this exact head: ci, Run tests, and Docker all concluded action_required with no jobs, so repository CI gave no signal; only the title-lint / PR-description / artifacts workflows passed. The focused suite above is the local evidence.

The boundaries introduced here are sound: the 60s total asyncio.timeout, the separate MCP probe budget, the 10-page pagination cap with repeated-token detection, the official-host requirement for provider URLs, the bounded requirements envelope (extra="forbid", per-alternative secret-name cap, 16-integration and 32-distinct-name caps, _MAX_PREFLIGHT_REPOSITORIES), the fail-closed handling of a truncated search, and the sanitized 503 mapping for dependency/transport/rate-limit/malformed-response failures. Secret names only (never values) cross the public API, and provider bodies are not returned.

Two material findings are inline. Both were checked against the SDK pinned by this repo (openhands-sdk==1.50.0) and against the companion PRs' contracts.

Non-blocking coordination note (unchanged in kind from the earlier pass): the Cloud MCP probe (POST /api/v1/settings/mcp/{name}/test) is added by sandbox-server#6, which is not on that repository's main yet, and the local repository probe (POST /api/git/validate-repository) is added by software-agent-sdk#4504, which is not on the pinned agent-server (openhands-agent-server==1.50.0 exposes only /api/git/changes, /diff, /commits, /commits/{sha}/changes). Both companion PRs are still open. A 404 here is handled as _DependencyUnavailable, so if this merges before them, any draft that actually sends requirements.integrations (or local repos) fails closed with a 503 rather than validating. Legacy clients that omit requirements are unaffected. Worth confirming merge order.

🔄 CHANGES REQUESTED

Use the existing 501 advisory outcome when Cloud cannot resolve a tag or
historical commit, but only after other checks have succeeded. Keep real
validation errors and dependency failures blocking, and stop treating a
branch-tip SHA prefix as proof that an arbitrary ref is valid.

Trace the local preset's canonical credential lookup in English and test
it against the pinned SDK for all providers, including anonymous public
access and environment or MCP aliases. Cover mixed failures, pagination,
provider outages, and unchanged exact-branch validation.

Co-authored-by: openhands <openhands@all-hands.dev>
@all-hands-bot

all-hands-bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

⏳ Review waiting on checks

The current head 292d106152aa still has checks that have not finished, so no review conversation was started:

  • Docker
  • Run tests
  • ci

No action is needed. The scheduled scan retries once every check on the head reports a conclusion.

This is an automated check - no AI was used to generate this comment.

@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 in this repository. It extends the existing /v1/validate owner (openhands/automation/capabilities_router.py) with optional, bounded deployment preflight requirements, which is the preflight/capability ownership AGENTS.md assigns here. No maintainer decision is needed.

State re-established on head 7fba11e5: title and body unchanged, label type: feat, mergeable with current main. Companion PRs still open: OpenHands/OpenHands#16614 (clean), software-agent-sdk#4504 (blocked), sandbox-server#6 (clean), extensions#476 (dirty). Existing reviews are on older commits (fc7aa63, 5bdf9bb) plus my earlier pass on 473f5339; this is a fresh review of the new head, not a duplicate.

Verification performed on this head:

  • uv run python -m pytest tests/test_capabilities_router.py -q -> 112 passed.
  • GitHub Actions for this exact head: ci, Run tests, and Docker all concluded action_required with no jobs, so repository CI gave no signal; only the title/description/artifacts workflows ran. The focused suite above is the local evidence.

Prior findings — both resolved on this head:

  1. Local repository credential name (previously line 951). The docstring and the new test_local_repository_credentials_match_real_sdk_clone_lookup now trace the pinned SDK path (RemoteWorkspace._get_secret_value -> PROVIDER_TOKEN_NAMES[provider] -> GET /api/settings/secrets/{name}) and confirm the canonical lowercase name (github_token/gitlab_token/bitbucket_token) is exactly what the clone path reads — across all three providers, anonymous public access, and OPENHANDS_*_TOKEN/MCP aliases. Gating credential_names on that name is now justified rather than a false-negative source.
  2. Cloud ref handling (previously line 1144). _cloud_ref_errors now proves exact branch names only and reports tags/arbitrary commits as advisory. The hex-prefix false pass is gone (the is_commit_sha/commit_sha.startswith(ref) arm was removed), and new tests confirm an unverified ref cannot mask a denied repository, a missing credential, or an invalid trigger.

The remaining boundaries hold up: the 60s total timeout, separate MCP probe budget, 10-page pagination cap with repeated-token detection, official-host requirement, bounded requirements envelope (extra="forbid"), fail-closed truncated-search handling, and sanitized 503 mapping. Secret names only cross the public API, and the new RequestValidationError handler strips rejected input so a mistaken secret value is not echoed in a 422.

Non-blocking note: the new advisory path at line 342 is a contract addition — when the only finding is an unverifiable ref, the endpoint now returns 501 with a bare detail instead of the field-addressable ValidateDraftResponse envelope. This matches the Canvas companion (OpenHands/OpenHands#16614 maps 404/501 to an unsupported advisory), so the behavior is intended; the PR description's Summary simply doesn't mention it yet and could be updated.

✅ APPROVED

@KirschBluteX

KirschBluteX commented Sep 30, 2026 •

Copy link
Copy Markdown
Author

Hi Vasco, thank you for reviewing this and for pointing out that the preflight flow was difficult to follow.
I revisited the implementation with your readability feedback in mind. The current code adds focused docstrings and comments around the parts that were hardest to understand: Cloud authentication and organization scoping, repository credential ownership, legacy MCP authentication, pagination and cancellation cleanup, and sanitized dependency failures.
The local repository check now also documents and tests the exact SDK path it mirrors:
RemoteWorkspace.clone_repos()
→ canonical provider credential name
→ agent-server secret store
This makes clear why the canonical names are used and why MCP or environment-variable aliases are not substituted.
During the same review, I corrected Cloud reference handling. Exact branch names can be verified; tags and historical commits now produce an explicit advisory only when no other validation error exists. Repository access, credentials, trigger configuration, and dependency failures remain blocking.
The current head is 7fba11e. The focused preflight suite passes with 112 tests, and pre-commit checks and package builds also pass.
Could you please take another look when convenient and let me know whether the flow is clearer now or whether any further explanation would help?

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

I'm an AI agent (Claude, based on Opus 5.5) helping Engel Nyst (@enyst) with project work.

Requesting changes: since the last approval, this branch has started conflicting with main, and the test module quietly moves the existing tests off PostgreSQL.

  1. Conflict with #541 (agent profiles in cloud mode, merged 2026-10-02). There are four conflict regions in capabilities_router.py, covering get_capabilities features and validate_draft. Main's validate_draft now takes request and calls ensure_agent_profile_exists(), an outbound call made before the other checks and reported last. The rebase has to bring that into _validated_draft_response and its 60s/503 handling. agentProfiles is also now advertised unconditionally.
  2. tests/test_capabilities_router.py:127-134 overrides async_engine with in-memory SQLite for the whole module. async_client depends on that fixture, so the 23 existing capabilities tests stop running on the PostgreSQL fixture in CI too. Please limit the override to the new tests or drop it.

On the scoping questions:

  • Not superseded. Main's POST /v1/validate still checks only schema, model and agent profile, cron floor, event source and types, and sample events. Nothing on main checks credentials, MCP integrations, or repository access.
  • The bot's merge-order note still applies. SDK 1.51.0, main's pin since #549, still has no /api/git/validate-repository. OpenHands/software-agent-sdk#4504 and OpenHands/sandbox-server#6 are still open. Until they ship, a client that sends requirements gets a 503 for local drafts with repos and for Cloud drafts whose integrations reach the MCP probe.
  • Size. capabilities_router.py grows from 350 lines on main to about 1,255 here, most of it defensive client code for the Cloud and agent-server endpoints it calls. The tests add about 1,600 lines for 26 new cases. They contain 27 hand-written outbound mock handlers that repeat the same upstream responses, for example /api/v1/git/branches/search and /api/v1/settings 11 times each. Moving preflight into its own module and building the tests on one shared fake upstream would shrink both and address @VascoSch92's readability feedback. This is not blocking on its own.

Comment thread tests/test_capabilities_router.py Resolved
@KirschBluteX
KirschBluteX requested a review from enyst October 8, 2026 11:57

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

I'm an AI agent (Claude, based on Opus 5.5) helping Engel Nyst (@enyst) with project work.

Both items from my last review are fixed: the branch now builds on #541, and the module-wide SQLite engine override is gone.

15884fd introduces one new issue. A failed agent-profile lookup now returns 503 for every request (capabilities_router.py:278), including legacy clients that send no requirements. On main, #541 deliberately leaves the profile unjudged and still returns the other verdicts. This PR rewrites #541's test for that case to expect 503: test_keeps_its_other_verdicts_when_profiles_cannot_be_checked is now test_profile_dependency_failure_is_not_reported_as_a_valid_draft. Please keep #541's behavior when requirements is absent and return 503 only to clients that opt in, or agree the change with #541's author.

Status of the dependencies: OpenHands/software-agent-sdk#4504 and OpenHands/sandbox-server#6 are both still open.

@KirschBluteX
KirschBluteX requested a review from enyst October 9, 2026 05:59
@neubig
neubig requested a review from all-hands-bot October 16, 2026 10:20

@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 in this repository — it extends the existing /v1/validate owner (openhands/automation/capabilities_router.py), which is the preflight/capability ownership AGENTS.md assigns here. No maintainer decision is needed.

State re-established on head e8530ea: title and body unchanged, label type: feat, open and mergeable (GitHub reports behind). Head is now a merge of main (7cda26a, 1.19.3) into the feature branch (11 commits, 7 files, +2763/-19). The prior reviewer's two requests are addressed: the branch is rebased onto #541 (agent profiles in cloud mode), the module-wide in-memory SQLite async_engine override is gone, and commit 9cd66f8 restores legacy behavior so an unavailable agent-profile lookup now returns 503 only to clients that send requirements (capabilities_router.py:275-289). Existing reviews are on older commits; there is no review on e8530ea, so this is not a duplicate.

Blocking finding — the module no longer imports

openhands/automation/capabilities_router.py:28 still imports SESSION_COOKIE_NAME from openhands.automation.auth, but the merge with main brought in #568 (fb3f3cb), which replaced that symbol with SESSION_COOKIE_NAMES = ("openhands_auth", "keycloak_auth") plus _extract_session_cookie(). SESSION_COOKIE_NAME is not defined, re-exported, or aliased anywhere in the tree at this head (verified against the raw GitHub content for the head SHA). Importing the router therefore raises ImportError: cannot import name 'SESSION_COOKIE_NAME' from 'openhands.automation.auth', which fails at openhands.automation.app import time. Confirmed locally: uv run python -m pytest tests/test_capabilities_router.py -q aborts during conftest collection with that exact error, so none of the 1657 added test lines run.

The stale symbol is used at line 506 to reconstruct the cookie header:

cookies.append(f"{name}={value}")

Beyond the hard failure, this reconstruction is also semantically wrong on current main: #568 deliberately forwards the cookie under its original name (the openhands_auth JWT cookie is preferred over the legacy keycloak_auth), and _extract_session_cookie() returns that name. Hard-coding keycloak_auth here would send the credential back under the wrong cookie name even after the ImportError is resolved. The fix should obtain both the name and the value from _extract_session_cookie(request) (or the SESSION_COOKIE_NAMES loop with the matched name), matching the reader main now uses.

Note this cannot be caught by the checks that ran on this head: Docker, Run tests, and ci all concluded action_required with no jobs, so only the title/description/artifact workflows reported. python -m pytest tests/test_capabilities_router.py -q reproduces the failure immediately after installing dependencies.

The remainder of the head is consistent with the previously approved design (bounded requirements envelope, 60s budget, paginated credential/repo lookup with repeated-token detection, official-host requirement, sanitized 503 mapping, and the fail-closed-only-when-requirements-present profile handling). Clarifying the HUMAN: section would also let the automated description check pass, but that is not the blocker.

🔄 CHANGES REQUESTED

@neubig
neubig requested review from all-hands-bot and removed request for all-hands-bot October 19, 2026 21:42

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

Review of 292d106152aaa2241c4174a8831600a5a0d7cfc0

Scope gate: in scope. This is the automation service's own /v1/validate owner plus app.py/schemas.py, which AGENTS.md places here. No repository move or product decision needed.

I re-read the current state: head is still 292d106152aa, title/labels unchanged (type: feat only), the linked issue OpenHands/OpenHands#16565 is open with enhancement + ready-for-dev, and the head's checks (pr-title, Validate PR description, check-pr-artifacts) are green. No review by this account exists on this head, so this is not a duplicate.

The implementation itself is careful: bounded concurrency and deadlines, field-addressable errors, sanitized 503s, secret-name-only requests, and the _errors_to_json(exclude_unset=True) change that keeps saved-draft responses byte-compatible. The previously reported SESSION_COOKIE_NAME breakage is fixed at this head (_extract_session_cookie is imported and SESSION_COOKIE_NAME no longer appears).

However, the new preflight calls two endpoints that do not exist in the versions this repo actually pins, so the feature fails closed on the deployments it targets:

  1. Local repository preflight posts to POST {agent_server}/api/git/validate-repository. The released agent server (openhands-agent-server 1.55.1 and the newest 1.56.0, which is what openhands-workspace==1.55.1 pulls in) exposes only /git/repositories/search, /git/changes, /git/diff, /git/commits, /git/commits/{sha}/changes. The route is added only by the still-open OpenHands/software-agent-sdk#4504. Against the pinned dependency the 404 becomes _DependencyUnavailable and the whole validation returns 503, so any local-mode draft with a repos entry now fails outright instead of validating.
  2. Cloud MCP preflight posts to POST {cloud}/api/v1/settings/mcp/{name}/test. OpenHands/sandbox-server main has no /settings/mcp/... route (its settings_router exposes only '', /agent-schema, /conversation-schema, and /profiles*); the route is added only by the still-open OpenHands/sandbox-server#6. So any Cloud-mode integration requirement returns 503.

This PR does not bump the SDK/agent-server pins (pyproject.toml is untouched) and carries no needs-sdk-release label, even though AGENTS.md and the review guide require tracing new endpoints to their real producer and labeling work that cannot finish until an upstream release ships. Merging as-is would land a validation path that hard-fails with 503 on the current released stack.

Requested: either land the upstream endpoints and bump the pinned openhands-sdk/openhands-workspace (and Cloud server) so these routes exist, or add the needs-sdk-release label and hold until those releases ship. Note also that the Cloud ref check only proves branch names: a draft pinned to a tag or commit returns 501 via repository_ref_unverified, which is a deliberate, documented limitation rather than a defect, so it is not blocking here.

🔄 CHANGES REQUESTED

@malhotra5
malhotra5 removed their request for review October 22, 2026 16:37

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.

4 participants