Fix base_url handling for openhands/ provider with explicit None value #1341
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.
Problem
The
openhands/provider was failing whenbase_urlwas explicitly set toNone, which broke the new user setup flow in the CLI. This occurs when CLI saves settings to JSON withbase_url=nulland then reloads them.Related issues:
Root Cause
PR #1273 changed the
openhands/provider conversion logic inllm.py:The Issue: Python's
dict.get(key, default)only returns the default when the key is missing, not when it exists with valueNone. When CLI serializes config to JSON withbase_url: nulland deserializes it, the dictionary contains{"base_url": None}, causingdict.get()to returnNoneinstead of the default.The Workaround in 1.4.0: Commit 54d93bc changed the test workflow to bypass the
openhands/provider entirely by usinglitellm_proxy/directly with a hardcoded URL.Solution
llm.py: Changed to used.get("base_url") or defaultpattern to handle explicitNonevalues correctly.github/workflows/run-examples.ymlback to usingopenhands/provider as intendedCode Changes
This correctly handles:
d.get("base_url")→None→orreturns defaultNone:d.get("base_url")→None→orreturns defaultd.get("base_url")→ value →orshort-circuitsTesting
Added comprehensive test cases in
test_llm.py:test_base_url_for_openhands_provider- Existing test for missing base_urltest_base_url_for_openhands_provider_with_explicit_none- New: Reproduces CLI bug with explicitNonetest_base_url_for_openhands_provider_with_custom_url- New: Ensures custom URLs still workAll tests pass:
Impact
Before Fix
openhands/provider (settings saved withbase_url=null)litellm_proxy/directlyAfter Fix
openhands/provider seamlesslyChecklist
@xingyaoww can click here to continue refining the PR
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.12-nodejs22golang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:7d075e5-pythonRun
All tags pushed for this build
About Multi-Architecture Support
7d075e5-python) is a multi-arch manifest supporting both amd64 and arm647d075e5-python-amd64) are also available if needed