Skip to content

LLM credential problems are only discovered mid-conversation on some settings paths; expired credentials produce a generic failure with no re-authentication action #6050

Open

Description

@neubig

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_profile in openhands-agent-server/openhands/agent_server/profiles_router.py:316 performs a bounded one-token completion (_preflight_llm at line 288, PREFLIGHT_TIMEOUT_SECONDS at 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_profile in profiles_router.py:215 decrypts and persists the profile without any LLM call, so a bad credential is stored silently.
  • The settings path does not validate either. update_settings in openhands-agent-server/openhands/agent_server/settings_router.py:182 (applied via _apply_settings_update at 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.py raises CredentialNeedsReauthentication when the credential is missing/invalid (status handling at lines 151 and 159) and CredentialAuthorizationRejected for rejected authorization (line 163), but classify_error in openhands-sdk/openhands/sdk/event/error_classification.py:52 has no entry for these codes, so they fall through to FailureKind.UNKNOWN (line 192) with no user action. By contrast, a mapped LLMAuthenticationError classifies 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) to classify_error as 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.py and tests/agent_server/test_settings_router.py with 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.py for the status-to-exception mapping already present, and tests/sdk/event/test_error_classification.py to assert credential re-authentication/authorization codes classify as auth with a settings action.
  • Add a conversation-level test under tests/sdk/conversation/local/ (following tests/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.py and tests/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

  1. all-hands-bot commented on Oct 17, 2026

    @all-hands-bot
    Collaborator

    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) to classify_error in openhands-sdk/openhands/sdk/event/error_classification.py as auth failures with user_action="settings", so a mid-conversation credential failure is classified instead of falling through to FailureKind.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.

    1. 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}/validate is 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 to ProfileMutationResponse, ActivateProfileResponse, and SettingsResponse, which are public surfaces mirrored by clients/typescript?

    2. Which mutation paths are in scope: POST /api/profiles/{name} (save), POST /api/profiles/{name}/activate, and PATCH /api/settings (both active_profile and agent_settings_diff.llm)? Should the agent-profile and meta-profile routers be included or explicitly excluded?

    3. 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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions