Repository navigation
fix(agent-profiles): only seed a 'default' LLM profile for real config (#4031) - #4033
Conversation
The #3933 fix backfills a persisted LLM profile named `default` at seed time so the freshly-seeded AgentProfile's `llm_profile_ref` resolves. But it did so unconditionally — including on a fresh, never-configured account whose live `agent_settings.llm` is just bare SDK defaults (`model="gpt-5.5"`, no api_key). That left a keyless, non-functional "ghost" `default` profile in the LLM profiles list forever, which the user never created and nothing cleans up (#4031). Gate the backfill on `_llm_has_real_config`: persist only when the live LLM is real, pre-existing configuration (an API key, subscription auth, or a custom base_url) — exactly the legacy/cloud migration case the mechanism exists for. On bare defaults, skip the save and leave `llm_profile_ref="default"` as a soft/dangling ref: the canvas "LLM not configured" banner, the graceful materialize/dry-run `dangling_llm_profile_ref`, and the legible launch-time error already cover that state, and the ref resolves for real the moment the user saves an actual LLM profile. Fixes #4031 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED |
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Verified the agent-profile seeding behavior through real agent-server HTTP requests; the PR removes the fresh-account ghost LLM profile while preserving real-config backfill.
Does this PR achieve its stated goal?
Yes. On main, a fresh OH_PERSISTENCE_DIR created a persisted profiles/default.json and exposed default from GET /api/profiles even though llm_api_key_set=false, reproducing the ghost-profile problem. On this PR, the same fresh-account flow leaves /api/profiles empty and no profiles/default.json exists, while POST /api/agent-profiles/default/materialize returns a graceful unresolved profile result instead of persisting a keyless profile. I also verified the intended migration/backfill case still works when the live LLM has a custom base_url.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed; agent-server instances started with isolated temp OH_PERSISTENCE_DIR values |
| CI Status | 🟡 No failures observed; 27 checks passing, 3 still in progress when queried (qa-changes, two Build & Push jobs) |
| Functional Verification | ✅ Real HTTP API verification passed for fresh-account, real-config, and post-seed save flows |
Functional Verification
Test 1: Fresh account no longer gets a ghost default LLM profile
Step 1 — Reproduce / establish baseline without the fix:
Created a detached origin/main worktree (98f56248), started the real server with a fresh persistence dir, then ran:
OH_PERSISTENCE_DIR=/tmp/qa-base-fresh-persist \
uv run uvicorn openhands.agent_server.api:create_app --factory --host 127.0.0.1 --port 8770
curl http://127.0.0.1:8770/api/agent-profiles
curl http://127.0.0.1:8770/api/profiles
curl -X POST http://127.0.0.1:8770/api/agent-profiles/default/materialize
find "$OH_PERSISTENCE_DIR" -maxdepth 6 -type fObserved:
GET /api/agent-profiles -> {"agent_profiles":[{"name":"default","llm_profile_ref":"default"}]}
GET /api/profiles -> {"llm_profile_names":["default"],"active_profile":null}
POST /api/agent-profiles/default/materialize -> {"valid":true,"llm_profile_resolved":true,"llm_api_key_set":false,"errors":[]}
files -> <persist>/agent-profiles/default.json, <persist>/profiles/default.json, <persist>/settings.jsonThis reproduces the bug: a never-configured account still gets a persisted default LLM profile, but it has no API key and is not actually usable.
Step 2 — Apply the PR's changes:
Created a detached PR worktree at cf98b0c8b6c106f2535afd642476f3b329e3f9ce and used a new empty OH_PERSISTENCE_DIR.
Step 3 — Re-run with the fix in place:
Ran the same endpoint sequence against the PR server:
GET /api/agent-profiles -> {"agent_profiles":[{"name":"default","llm_profile_ref":"default"}]}
GET /api/profiles -> {"llm_profile_names":[],"active_profile":null}
POST /api/agent-profiles/default/materialize -> {"valid":false,"llm_profile_resolved":false,"llm_api_key_set":false,"errors":["LLM profile 'default' not found"]}
files -> <persist>/agent-profiles/default.json, <persist>/settings.json (no <persist>/profiles/default.json)This confirms the fix: the default agent profile is still seeded, but the keyless LLM ghost profile is not persisted and materialization reports the soft/dangling ref cleanly.
Test 2: Real-config backfill is preserved
Step 1 — Establish preserved baseline without the fix:
On main, I first set a real custom endpoint via the settings API, then triggered agent-profile seeding:
PATCH /api/settings -> {"llm":{"model":"gpt-5.5","base_url":"https://proxy.example/v1"}}
GET /api/profiles -> {"profiles":[{"name":"default","model":"gpt-5.5","base_url":"https://proxy.example/v1","api_key_set":false}],"active_profile":null}
POST /api/agent-profiles/default/materialize -> {"valid":true,"llm_profile_resolved":true,"llm_api_key_set":false,"errors":[],"resolved_base_url":"https://proxy.example/v1"}This is the behavior the PR claims to preserve for legacy/cloud settings with real config.
Step 2 — Apply the PR's changes:
Used the PR worktree at cf98b0c8b6c106f2535afd642476f3b329e3f9ce with a fresh persistence dir.
Step 3 — Re-run with the fix in place:
Ran the same custom-base_url flow:
PATCH /api/settings -> {"llm":{"model":"gpt-5.5","base_url":"https://proxy.example/v1"}}
GET /api/agent-profiles -> {"agent_profiles":[{"name":"default","llm_profile_ref":"default"}]}
GET /api/profiles -> {"profiles":[{"name":"default","model":"gpt-5.5","base_url":"https://proxy.example/v1","api_key_set":false}],"active_profile":null}
POST /api/agent-profiles/default/materialize -> {"valid":true,"llm_profile_resolved":true,"llm_api_key_set":false,"errors":[],"resolved_base_url":"https://proxy.example/v1"}
files -> <persist>/agent-profiles/default.json, <persist>/profiles/default.json, <persist>/settings.jsonThis confirms the narrowing did not break the intended real-config backfill path.
Test 3: Soft ref resolves after a user saves a real default LLM profile
After triggering the PR's fresh-account soft ref, I saved a real default LLM profile through the public profiles API:
GET /api/agent-profiles -> {"agent_profiles":[{"name":"default","llm_profile_ref":"default"}]}
POST /api/profiles/default -> {"name":"default","message":"Profile 'default' saved"}
POST /api/agent-profiles/default/materialize -> {"valid":true,"llm_profile_resolved":true,"errors":[],"resolved_base_url":"https://proxy.example/v1"}This confirms the dangling ref becomes resolvable once a real profile is explicitly saved.
Issues Found
None.
This QA review was generated by an AI agent (OpenHands) on behalf of the user.
Final verdict: PASS
HUMAN:
Ghost profiles are being created in agent-canvas with latest SDK. This is the fix.
AGENT:
Why
The #3933 fix (#3934) makes a freshly-seeded default
AgentProfile'sllm_profile_refresolve by backfilling a persisted LLM profile nameddefaultat seed time. But it did this unconditionally — including on a fresh, never-configured account whose liveagent_settings.llmis just bare SDK defaults (model="gpt-5.5", noapi_key).That leaves a keyless, non-functional
default"ghost" profile in the LLM profiles list forever: the user never created it, it can't be used (no credentials), nothing references it once a real profile is created, and nothing ever cleans it up. See #4031 for the full repro and analysis.Summary
_llm_has_real_config(llm)— true when the live LLM carries real, user-provided config (an API key, subscription auth, or a custombase_url)._seed_default_llm_profileon it: persist thedefaultLLM profile only for real, pre-existing config — exactly the legacy/cloudSaasSettingsStorebackfill case the mechanism exists for.llm_profile_ref="default"as a soft/dangling ref. The canvas "LLM not configured" banner (useLlmConfiguredchecks the referenced profile'sapi_key_set, not whether adefaultprofile exists), the graceful materialize/dry-rundangling_llm_profile_ref, and the legible launch-time error already cover that state — and the ref resolves for real the moment the user saves an actual LLM profile.This is the "gate on real config" option from the issue's refined recommendation: it fixes the ghost-profile problem for every new account while preserving the real cloud/legacy-account migration case. Unconditional AgentProfile seeding is unchanged.
Issue Number
Fixes #4031
How to Test
Unit tests (new + updated):
uv run pytest tests/agent_server/test_agent_profiles_router.py -q # 61 passedNew/updated coverage:
test_seed_skips_ghost_llm_profile_for_bare_defaults— fresh account: nodefault.jsonwritten, ref left as a softdefault, materialize reports dangling (not a 500).test_seed_backfills_default_llm_profile_when_real_config— real config (custombase_url): backfill still fires and resolves (Seeded default AgentProfile has dangling llm_profile_ref ("default") → conversation launch 404s #3933 regression preserved).test_seed_backfills_when_active_profile_is_empty_string— updated to carry real config so the falsy-trigger regression still exercises a real backfill.test_llm_has_real_config— parametrized unit test for the gate (api_key / blank key / base_url / subscription / bare defaults).End-to-end through the real FastAPI app + real on-disk stores (fresh temp
OH_PERSISTENCE_DIR, no mocks), drivingGET /api/agent-profiles(triggers the lazy seed) then inspecting the LLM profile store andPOST .../materialize:uv run pre-commit run(ruff format/lint, pycodestyle, pyright, import rules) passes on both changed files.Video/Screenshots
N/A — server-side seed logic; covered by unit tests + the e2e transcript above.
Type
Notes
defaultprofiles are still never clobbered (the pre-existingload()existence check runs first).ProfileNotFoundfrom 404 → 422 structured detail. Can follow up separately if wanted.defaultLLM profile.This PR was created by an AI agent (OpenHands) on behalf of the user.
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.13-nodejs22-slimgolang: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:cf98b0c-pythonRun
All tags pushed for this build
About Multi-Architecture Support
cf98b0c-python) is a multi-arch manifest supporting both amd64 and arm64cf98b0c-python-amd64) are also available if needed