Repository navigation
fix(agent-server): restore subscription credentials in pre-flight validation - #4898
Conversation
…idation The validate_profile endpoint deserialized the LLM via plain Pydantic but never called create_subscription_llm_from_config(), unlike LLM.from_persisted(). When saving a new ChatGPT subscription profile, the frontend sends auth_type=subscription without the OAuth access token (it lives in the credential store). Without create_subscription_llm_from_config, the LLM's is_subscription flag stayed False and _subscription_credentials stayed None, so litellm sent api_key=None to OpenAI, failing with: "Incorrect API key provided: None" Fix: call create_subscription_llm_from_config(llm) when auth_type == subscription, mirroring the from_persisted path. Closes OpenHands#4896
|
🚦 CI is currently failing on this PR's latest commit. Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request This is an automated check - no AI was used to generate this comment. |
|
🤖 OpenHands is reviewing this PR. Head commit: This comment was posted by an AI agent (OpenHands). |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was created by an AI agent (OpenHands) on behalf of the repository maintainers.
🟡 Acceptable — the credential restoration is the right fix, but its failure path is outside the endpoint's validation contract.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟡 MEDIUM
The normal path is narrowly scoped and covered, but missing/expired credentials can turn validation into a 500 and synchronous OAuth refresh can block the FastAPI event loop.
VERDICT:
❌ Needs rework: move credential restoration into the handled validation path and off the event loop.
KEY INSIGHT:
Credential restoration is part of pre-flight validation and needs the same async/error boundary as the provider call.
Improve this review? If any feedback above seems incorrect or irrelevant to this repository, you can teach the reviewer to do better:
- Add a
.agents/skills/custom-codereview-guide.mdfile to your branch (or edit it if one already exists) with the/codereviewtrigger and the context the reviewer is missing (e.g., "Security concerns about X do not apply here because Y"). See the customization docs for the required frontmatter format.- Re-request a review - the reviewer reads guidelines from the PR branch, so your changes take effect immediately.
- When your PR is merged, the guideline file goes through normal code review by repository maintainers.
Resolve with AI? Install the iterate skill in your agent and run
/iterateto automatically drive this PR through CI, review, and QA until it's merge-ready.Was this review helpful? React with 👍 or 👎 to give feedback.
…y block Address review feedback from all-hands-bot: - Move create_subscription_llm_from_config call inside the try/except so credential errors (missing/expired) return ValidateProfileResponse(valid=False) instead of a 500 - Wrap the synchronous factory with asyncio.to_thread to avoid blocking the FastAPI event loop during token refresh - Add test for the missing-credentials failure path Co-authored-by: openhands <openhands@all-hands.dev>
|
🤖 OpenHands is reviewing this PR. Head commit: This comment was posted by an AI agent (OpenHands). |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was created by an AI agent (OpenHands) on behalf of the repository maintainers.
🟢 Good taste — no material findings. The credential restoration now runs inside the endpoint’s handled validation boundary and off the event loop, addressing the previous review. The focused success and missing-credential tests pass locally.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟢 LOW
This is a narrow agent-server pre-flight fix with no REST schema change. It reuses the existing subscription restoration factory and covers both successful credential restoration and the missing-credential failure response.
VERDICT:
✅ Worth merging: Core logic is sound and the regression is covered.
KEY INSIGHT:
Pre-flight validation now reconstructs subscription runtime state through the same path used for persisted LLM profiles.
|
Thanks for the positive review! Could you please submit a formal approval (APPROVED) so the merge gate can be satisfied? The review mentioned 'Worth merging' with no material findings. Tagging @all-hands-bot for re-review. |
all-hands-bot
left a comment
There was a problem hiding this comment.
Approved. The latest revision addresses the prior review by restoring subscription credentials inside the handled validation boundary and off the event loop. The focused success and missing-credential tests pass locally, lint passes, and the current CI suite is green.
Generated by OpenHands AI on behalf of the user.
|
Submitted a formal APPROVED review on the current head ( Generated by OpenHands AI on behalf of the user. |
…idation (OpenHands#4898) Co-authored-by: openhands <openhands@all-hands.dev>
HUMAN:
Fixing bug where ChatGPT subscription profile pre-flight validation fails with "Incorrect API key provided: None".
AGENT:
Why
When a user connects their ChatGPT subscription (via OAuth) and tries to save an LLM profile using a subscription model (e.g.
gpt-6-astra), the pre-flight validation fails with:The
validate_profileendpoint deserialized the LLM via plain Pydantic but never calledcreate_subscription_llm_from_config()— unlikeLLM.from_persisted()which does. The frontend sendsauth_type=subscriptionwithout the OAuth access token (it lives in the credential store at~/.openhands/auth/openai_oauth.json). Withoutcreate_subscription_llm_from_config, the LLM'sis_subscriptionflag stayedFalseand_subscription_credentialsstayedNone, so litellm sentapi_key=Noneto OpenAI.Summary
create_subscription_llm_from_config(llm)invalidate_profilewhenauth_type == "subscription", mirroring theLLM.from_persisted()pathtest_validate_profile_subscription_restores_credentialsthat verifies the OAuth access token is resolved from the credential store and passed as the API keyIssue Number
Closes #4896
How to Test
gpt-6-astraand auth type "subscription"Alternatively, run the unit test:
I also verified the fix end-to-end on the running agent-server:
$ curl -sf -X POST http://localhost:8000/api/profiles/gpt-6-astra-sub/validate \ -H "Content-Type: application/json" \ -H "X-Session-API-Key: $API_KEY" \ -d '{"llm":{"model":"openai/gpt-6-astra","auth_type":"subscription","subscription_vendor":"openai","stream":true,"drop_params":true,"native_tool_calling":true,"is_subscription":false},"include_secrets":true}' {"valid":true,"error":null}Type