Skip to content

fix(agent-profiles): only seed a 'default' LLM profile for real config (#4031) - #4033

Merged
simonrosenberg merged 2 commits into
mainfrom
fix-seed-ghost-llm-profile
Jul 8, 2026
Merged

simonrosenberg merged 2 commits into
mainfrom
fix-seed-ghost-llm-profile

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Jul 8, 2026 •

Copy link
Copy Markdown
Member

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's llm_profile_ref resolve by backfilling a persisted LLM profile named default at seed time. But it did this 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 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

  • Add _llm_has_real_config(llm) — true when the live LLM carries real, user-provided config (an API key, subscription auth, or a custom base_url).
  • Gate _seed_default_llm_profile on it: persist the default LLM profile only for real, pre-existing config — exactly the legacy/cloud SaasSettingsStore backfill 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 (useLlmConfigured checks the referenced profile's api_key_set, not whether a default profile exists), 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.

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 passed

New/updated coverage:

  • test_seed_skips_ghost_llm_profile_for_bare_defaults — fresh account: no default.json written, ref left as a soft default, materialize reports dangling (not a 500).
  • test_seed_backfills_default_llm_profile_when_real_config — real config (custom base_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), driving GET /api/agent-profiles (triggers the lazy seed) then inspecting the LLM profile store and POST .../materialize:

=== FRESH account (bare gpt-5.5 defaults) ===
  agent profile llm_profile_ref : 'default'
  LLM profile files on disk      : []          # <- no ghost profile (was ['default.json'])
  /api/profiles names            : []
  materialize valid / resolved   : False / False   # <- graceful dangling ref

=== REAL config (base_url set) ===
  agent profile llm_profile_ref : 'default'
  LLM profile files on disk      : ['default.json']   # <- backfill preserved
  /api/profiles names            : ['default']
  materialize valid / resolved   : True / True

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

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • Additive and safe: only narrows when a profile is persisted; a fresh account simply gets no ghost profile instead of a broken one. No migration needed; existing real default profiles are still never clobbered (the pre-existing load() existence check runs first).
  • Left out of scope (issue's "optional polish"): recoding the launch-time ProfileNotFound from 404 → 422 structured detail. Can follow up separately if wanted.
  • Downstream (canvas): no change required — the banner already keys off the referenced profile, not the presence of a default LLM 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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:cf98b0c-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-cf98b0c-python \
  ghcr.io/openhands/agent-server:cf98b0c-python

All tags pushed for this build

ghcr.io/openhands/agent-server:cf98b0c-golang-amd64
ghcr.io/openhands/agent-server:cf98b0c8b6c106f2535afd642476f3b329e3f9ce-golang-amd64
ghcr.io/openhands/agent-server:fix-seed-ghost-llm-profile-golang-amd64
ghcr.io/openhands/agent-server:cf98b0c-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:cf98b0c-golang-arm64
ghcr.io/openhands/agent-server:cf98b0c8b6c106f2535afd642476f3b329e3f9ce-golang-arm64
ghcr.io/openhands/agent-server:fix-seed-ghost-llm-profile-golang-arm64
ghcr.io/openhands/agent-server:cf98b0c-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:cf98b0c-java-amd64
ghcr.io/openhands/agent-server:cf98b0c8b6c106f2535afd642476f3b329e3f9ce-java-amd64
ghcr.io/openhands/agent-server:fix-seed-ghost-llm-profile-java-amd64
ghcr.io/openhands/agent-server:cf98b0c-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:cf98b0c-java-arm64
ghcr.io/openhands/agent-server:cf98b0c8b6c106f2535afd642476f3b329e3f9ce-java-arm64
ghcr.io/openhands/agent-server:fix-seed-ghost-llm-profile-java-arm64
ghcr.io/openhands/agent-server:cf98b0c-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:cf98b0c-python-amd64
ghcr.io/openhands/agent-server:cf98b0c8b6c106f2535afd642476f3b329e3f9ce-python-amd64
ghcr.io/openhands/agent-server:fix-seed-ghost-llm-profile-python-amd64
ghcr.io/openhands/agent-server:cf98b0c-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:cf98b0c-python-arm64
ghcr.io/openhands/agent-server:cf98b0c8b6c106f2535afd642476f3b329e3f9ce-python-arm64
ghcr.io/openhands/agent-server:fix-seed-ghost-llm-profile-python-arm64
ghcr.io/openhands/agent-server:cf98b0c-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:cf98b0c-golang
ghcr.io/openhands/agent-server:cf98b0c8b6c106f2535afd642476f3b329e3f9ce-golang
ghcr.io/openhands/agent-server:fix-seed-ghost-llm-profile-golang
ghcr.io/openhands/agent-server:cf98b0c-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:cf98b0c-java
ghcr.io/openhands/agent-server:cf98b0c8b6c106f2535afd642476f3b329e3f9ce-java
ghcr.io/openhands/agent-server:fix-seed-ghost-llm-profile-java
ghcr.io/openhands/agent-server:cf98b0c-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:cf98b0c-python
ghcr.io/openhands/agent-server:cf98b0c8b6c106f2535afd642476f3b329e3f9ce-python
ghcr.io/openhands/agent-server:fix-seed-ghost-llm-profile-python
ghcr.io/openhands/agent-server:cf98b0c-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., cf98b0c-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., cf98b0c-python-amd64) are also available if needed

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>
@github-actions

github-actions Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   agent_profiles_router.py2251892%182, 186, 190, 209, 212, 235, 348, 352, 445, 485–486, 543–546, 557–559
TOTAL353941507557% 

@simonrosenberg
simonrosenberg marked this pull request as ready for review July 8, 2026 16:58
@simonrosenberg simonrosenberg self-assigned this Jul 8, 2026

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 f

Observed:

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.json

This 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.json

This 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

@simonrosenberg
simonrosenberg merged commit 378660c into main Jul 8, 2026
41 checks passed
@simonrosenberg
simonrosenberg deleted the fix-seed-ghost-llm-profile branch July 8, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Seeded default AgentProfile permanently persists an orphaned, keyless 'default' LLM profile (gpt-5.5)

3 participants