fix: treat empty llm api_key as no change when saving settings - #17809
Draft
all-hands-bot wants to merge 1 commit into
Draft
all-hands-bot wants to merge 1 commit into
all-hands-bot wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HUMAN:
AGENT:
Why
When a user changes only the LLM model/provider via the settings UI without re-typing the API key, the saved LLM profile is persisted with an empty
api_key. Switching to that profile mid-conversation then fails with anLLMAuthenticationError("You must provide an API key"), because the old key was overwritten with""on save. The root cause:the API-key input only shows a<hidden>placeholder, so an untouched key field submits as an empty string.saveSettingsMutationFninsrc/hooks/mutation/use-save-settings.tstrimmed and forwarded that""verbatim;the backenddeep_mergetreats onlyNoneas "preserve", so""overwrites the stored key.Summary
In
use-save-settings.ts, an empty( all-whitespace)llm.api_keyis now dropped from the save diff instead of forwarded as"", so "no change" no longer wipes the stored key。If the key was the only changed field in the llm diff, the empty
llmobject is also dropped so the backend never sees allm: {}no-op patch。A real (non-empty) key is still trimmed and forwarded as before。
Issue Number
Fixes #17806
How to Test
npm cinpx vitest run __tests__/hooks/mutation/use-save-settings.test.ts— all 7 tests pass, including 3 new ones covering:d dropping an emptyapi_keyfrom the payload,d dropping the wholellmdiff when the key was the only field,and keeping a non-empty key( trimmed。npx vitest run __tests__/api/settings-service.test.tsplus__tests__/routes/llm-settings.test.tsx— 39 tests pass( no regressions in the settings save flow.Video/Screenshots
The change is a pure outgoing request-payload transform. The three new unit tests in
__tests__/hooks/mutation/use-save-settings.test.tsexercise the behavior end-to-end for this data path:a spy onSettingsService.saveSettingsasserts the exact forwarded payload when the API key is empty, whitespace-only, or real.Type
Notes
The complementary backend hardening( treating
api_key == ""as "no change" indeep_merge/Settings.update) was intentionally scoped out per the issue — this fixes the frontend source of the bad payload. The behavior is consistent with the empty-base_urlspecial-casing already present inresolve_llm_base_url.AGENT Note: This PR description was created by an AI agent (OpenHands)on behalf of the repository contributor.
@all-hands-bot can click here to continue refining the PR
🐳 Docker images for this PR
• GHCR package: https://github.com/OpenHands/OpenHands/pkgs/container/agent-canvas
ghcr.io/openhands/agent-canvasghcr.io/openhands/agent-server:1.49.6-pythonopenhands-automation==1.15.11e94f71466e5f44be579d9324f032d24039c6f97Pull (multi-arch manifest)
# Multi-arch manifest — Docker automatically pulls the correct architecture docker pull ghcr.io/openhands/agent-canvas:sha-1e94f71Run
All tags pushed for this build
About Multi-Architecture Support
sha-1e94f71) is a multi-arch manifest supporting both amd64 and arm64sha-1e94f71-amd64) are also available if needed