fix: prevent invalid proxy tokens after managed profile changes - #209
Open
saurya wants to merge 2 commits into
Open
fix: prevent invalid proxy tokens after managed profile changes#209saurya wants to merge 2 commits into
saurya wants to merge 2 commits into
Conversation
Co-authored-by: openhands <openhands@all-hands.dev>
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
saurya
marked this pull request as ready for review
August 19, 2026 22:35
OHE-3109 [Bug] Switching an active conversation to Gemini ProPreview causes invalid proxy token error
Environment
Steps to reproduce
Actual resultThe conversation fails with a 401: invalid proxy server token; the token is missing from the LiteLLM cache or Expected resultThe conversation continues with the newly selected profile without an authentication failure. ContextRelated to OHE-2678, but this is a distinct reproduction after changing an active conversation profile. OHE-2678 is Done, so this is tracked separately as a regression. This issue was created by an AI agent (OpenHands) on behalf of Saurya. |
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.
Summary
Root cause
Switching an active conversation from Kimi K3 to an OpenHands-managed Gemini profile sent
api_key: \"\". The backend interpreted that blank value as a key deletion/regeneration request, while active-profile synchronization could retain a raw key that no longer matched the current managed credential.Verification
PYTHONPATH=\"$PWD/enterprise:$PWD\" poetry -C enterprise run pytest -q tests/unit/test_saas_settings_store.py tests/unit/test_org_profiles.py— 67 passedcd frontend && npm run test -- --run __tests__/routes/llm-settings.test.tsx— 81 passedcd frontend && npm run build— passedThe new regressions were confirmed failing before the fix for blank managed-key reuse, raw managed-profile persistence, and stale BYOK leakage into the managed Gemini payload.
Why key regeneration is preserved
The fix changes an empty managed-provider payload from an unconditional rotation signal into a request to reuse the member's stored managed key when that key is still valid. Regeneration continues in both required cases:
_ensure_api_key()follows its existing missing-key path, deletes any key under the deterministic alias, and generates a replacement.LiteLlmManager.verify_existing_key()returnsfalse, so the existing invalid-key path deletes the alias and generates a replacement.Existing transition behavior is also preserved:
has_custom_llm_api_key=true, so the custom key is never selected as the managed fallback and the managed-key generation path still runs.Regression coverage asserts valid stored-key reuse without rotation, invalid fallback rotation, custom-key-to-managed generation, and unchanged explicit managed-key behavior.
Related
This pull request was created by an AI agent (OpenHands) on behalf of Saurya Velagapudi.
Enterprise server image for this PR: