Repository navigation
Description
Problem
Users can save or activate LLM settings through paths that never actually test the credentials, so an expired, revoked or mistyped credential is only discovered after a conversation has started — at which point the conversation fails with a generic error and no clear "sign in again / fix your key" action. The same underlying problem can therefore look like an unexplained conversation failure instead of a simple settings fix. This issue is scoped to the SDK / agent-server side: validation coverage and the structured action metadata attached to credential failures. (Any frontend prompt is a separate client concern.)
Current behavior (with code references)
Verified against origin/main:
- A real pre-flight check exists but is opt-in.
validate_profileinopenhands-agent-server/openhands/agent_server/profiles_router.py:316performs a bounded one-token completion (_preflight_llmat line 288,PREFLIGHT_TIMEOUT_SECONDSat line 285) and reports invalid keys/model problems before saving — but only when a client explicitly calls that endpoint. - Saving a profile does not validate.
save_profileinprofiles_router.py:215decrypts and persists the profile without any LLM call, so a bad credential is stored silently. - The settings path does not validate either.
update_settingsinopenhands-agent-server/openhands/agent_server/settings_router.py:182(applied via_apply_settings_updateat line 292) performs schema/pydantic validation only and returns a generic "Settings validation failed" (line 345) for payload problems; activating a profile or patching LLM settings through this path never exercises the credential against the provider. The first real test is then the conversation's first LLM call. - Credential-source failures carry no actionable classification.
openhands-sdk/openhands/sdk/credential.pyraisesCredentialNeedsReauthenticationwhen the credential is missing/invalid (status handling at lines 151 and 159) andCredentialAuthorizationRejectedfor rejected authorization (line 163), butclassify_errorinopenhands-sdk/openhands/sdk/event/error_classification.py:52has no entry for these codes, so they fall through toFailureKind.UNKNOWN(line 192) with no user action. By contrast, a mappedLLMAuthenticationErrorclassifies as auth with a settings action (line 65) and gets a dedicated friendly branch in the conversation (openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py:2086).
Expected behavior
- Saving or activating LLM settings through any agent-server settings/profile mutation path should either validate the credential (reusing the existing pre-flight) or explicitly surface that validation was skipped/not possible, rather than silently persisting an untested credential.
- When a credential problem is nevertheless discovered mid-conversation — including credential-source re-authentication failures — the resulting conversation error should carry structured metadata identifying it as an authentication problem with a settings/re-authentication user action, not a generic unknown failure.
- Transient validation failures (rate limit, timeout, provider temporarily unavailable) must not block saving settings, consistent with the existing validate endpoint's policy.
- Validation must never log or return credential values; error messages remain redacted as in the existing pre-flight.
Possible approaches (not prescriptive)
- Invoke the existing pre-flight validation from the profile-save and settings-activation paths (possibly async/non-blocking with an explicit "unvalidated" result state where a synchronous check is inappropriate).
- Add
CredentialNeedsReauthentication/CredentialAuthorizationRejected(and any related credential-binding codes) toclassify_erroras auth failures with a settings/re-authentication action, and ensure conversation error construction preserves that classification. - Return the validation outcome as structured data from settings/profile mutations so clients can prompt immediately, instead of relying on the first conversation failure.
- Cache/coalesce validation results briefly to avoid a provider call on every settings keystroke-level update.
Testing strategy
- Extend
tests/agent_server/test_profiles_router.pyandtests/agent_server/test_settings_router.pywith stubbed/monkeypatched LLM completion calls (no network): saving/activating with a credential the stub rejects must surface a validation failure (or explicit unvalidated state), while transient stub failures must not block, mirroring the existing validate-endpoint tests. - Extend
tests/sdk/test_credential.pyfor the status-to-exception mapping already present, andtests/sdk/event/test_error_classification.pyto assert credential re-authentication/authorization codes classify as auth with a settings action. - Add a conversation-level test under
tests/sdk/conversation/local/(followingtests/sdk/conversation/local/test_auth_error_friendly_message.py) raising a credential re-authentication error mid-run and asserting the emitted error event carries the auth classification/action rather than unknown. - No-regression check: existing
tests/agent_server/test_profiles_router.py,tests/agent_server/test_settings_router.py,tests/sdk/test_credential.pyandtests/sdk/event/suites pass; secrets remain redacted in all new responses/logs (assert via existing redaction test patterns where present).
Acceptance criteria
- Persisting or activating LLM settings with a provider-rejected credential produces immediate, structured feedback on that path (or an explicit, client-visible "not validated" state), instead of failing first inside a conversation.
- Transient provider problems during validation do not block saving/activating settings.
- Mid-conversation credential failures (including credential-source re-authentication errors) emit an error event classified as an authentication problem with a settings/re-authentication user action — never as generic unknown.
- No credential value appears in any new API response, event field or log line (covered by tests).
- Existing profile/settings/credential test suites pass without modification to their current expectations, except where they assert the old generic-failure behavior.
This issue was drafted by an AI agent (OpenHands) on behalf of the reporter, from a review of the public codebase. Code references were checked against main at the time of writing.
Activity
all-hands-bot commentedon Oct 17, 2026
The following comments were added by the OpenHands AI agent.
Decision needed
The issue bundles two changes. One is ready: adding
CredentialNeedsReauthentication/CredentialAuthorizationRejected(and any related credential-binding codes) toclassify_errorinopenhands-sdk/openhands/sdk/event/error_classification.pyas auth failures withuser_action="settings", so a mid-conversation credential failure is classified instead of falling through toFailureKind.UNKNOWN. The other half cannot be scoped without a product decision, because the issue lists two mutually exclusive approaches and its own acceptance criterion accepts either.For the settings/profile mutation paths, should a provider-rejected credential (a) fail the mutation immediately, (b) still persist but return an explicit machine-readable "not validated" outcome, or (c) leave mutations unvalidated and only fix the mid-conversation classification? Note the current design:
POST /api/profiles/{name}/validateis a separate opt-in route that never reads or writes the store, and Agent Canvas calls it on a draft before saving. If (b), what is the response shape, and should it be added toProfileMutationResponse,ActivateProfileResponse, andSettingsResponse, which are public surfaces mirrored byclients/typescript?Which mutation paths are in scope:
POST /api/profiles/{name}(save),POST /api/profiles/{name}/activate, andPATCH /api/settings(bothactive_profileandagent_settings_diff.llm)? Should the agent-profile and meta-profile routers be included or explicitly excluded?If validation runs inline on a save/activate request, is the added provider call and latency acceptable, and must it reuse the validate endpoint's existing policy exactly (rate limit and timeout non-blocking; provider 503 blocking)? A related open PR (fix(agent-server): refuse activating or re-saving a profile under a changed cipher key #5775) already changes save/activate behavior under a rotated cipher key, so ordering matters.