Skip to content

[Bug]: DELETE /api/profiles/{name}.json deletes an LLM profile that an agent profile still cites (plain name answers 409) #5861

Closed

Description

@enyst

I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.

Is there an existing issue for the same bug?

  • I have searched existing issues and this is not a duplicate.

Bug Description

The LLM-profile store treats foo and foo.json as the same profile (GET /api/profiles/foo.json reads foo), but the agent-profile FK guard and the active_profile pointer compare the raw name. So DELETE /api/profiles/qa-alias.json answers 200 and deletes qa-alias while an agent profile still cites it through llm_profile_ref, although DELETE /api/profiles/qa-alias correctly answers 409. The same mismatch leaves active_profile naming a deleted profile after an alias delete, and an alias rename (POST /api/profiles/qa-alias.json/rename) moves the file without moving active_profile or the agent profiles' llm_profile_ref.

Expected Behavior

DELETE /api/profiles/qa-alias.json answers 409 with LLM profile is referenced by 1 agent profile(s): qa-f20-alias-agent, like the plain name, and qa-alias survives. Deleting or renaming through the alias clears / moves active_profile and cascades llm_profile_ref exactly as the plain name does.

Actual Behavior

200 {"name": "qa-alias.json", "message": "Profile 'qa-alias.json' deleted"}; afterwards GET /api/profiles/qa-alias is 404 Profile 'qa-alias' not found while qa-f20-alias-agent still has llm_profile_ref: "qa-alias".

Steps to Reproduce

  1. In a checkout of main: uv sync, then SESSION_API_KEY=dev-key uv run python -m openhands.agent_server --host 127.0.0.1 --port 8000.
  2. With H='X-Session-API-Key: dev-key' and B=http://127.0.0.1:8000/api:
curl -s -H "$H" -H 'Content-Type: application/json' -X POST $B/profiles/qa-alias -d '{"llm": {"model": "openai/qa-alias"}}'
curl -s -H "$H" -H 'Content-Type: application/json' -X POST $B/agent-profiles/qa-f20-alias-agent -d '{"llm_profile_ref": "qa-alias"}'
curl -s -H "$H" -X DELETE $B/profiles/qa-alias        # 409, referenced by qa-f20-alias-agent (control)
curl -s -H "$H" -X DELETE $B/profiles/qa-alias.json   # 200 "Profile 'qa-alias.json' deleted"
curl -s -H "$H" $B/profiles/qa-alias                  # 404

With the verify-agent-server skill (#5621): control-agent-server map run --file F20 --only F20.json-alias-guard --fresh reports the known-bug bullet as an expected failure while the bug lasts.

Acceptance Criteria

  • DELETE /api/profiles/<name>.json answers 409 naming the referrers whenever DELETE /api/profiles/<name> would, and the profile survives.
  • Deleting through the alias clears active_profile when it names that profile; renaming through the alias moves active_profile and cascades llm_profile_ref like the plain name.
  • A unit test covers the alias in the FK guard (openhands-sdk/openhands/sdk/profiles/profile_refs.py) and the router.
  • The map bullet F20.json-alias-guard passes with its # bug marker removed.

Installation Method

uv sync in a checkout of main

Version

main at 6e7a853

Additional Context

Root cause:

  • LLMProfileStore._get_profile_path strips a trailing .json (openhands-sdk/openhands/sdk/llm/llm_profile_store.py:166), so qa-alias.json addresses the file qa-alias.json of profile qa-alias.
  • _scan_referrers compares llm_profile_ref with the raw name (openhands-sdk/openhands/sdk/profiles/profile_refs.py:66); it is used by delete_llm_profile and by the rename cascade (_rewrite_refs).
  • _set_active_profile_if_matches compares active_profile with the raw name (openhands-agent-server/openhands/agent_server/profiles_router.py:136), called from delete and rename.

Related: the agent-profile store has the same suffix mismatch for its own identity (map ID F21.json-suffix-identity), which is a separate fix.

Found by the first full agentic run of verify-agent-server; tracked in #5653.

Activity

  1. added
    bug
    ready-for-dev
    on Oct 14, 2026
  2. enyst commented on Oct 14, 2026

    @enyst
    MemberAuthor

    I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.

    A fix is on branch claude/umbrella-bug-fixes-tgz9ai-json-alias-guard (PR follows). It adds canonical_profile_name() next to _get_profile_path in llm_profile_store.py. The FK scan and rename cascade in profile_refs.py and the active_profile pointer in profiles_router.py (delete, rename, activate) now compare and store that key. So foo.json acts exactly like foo, and active_profile / llm_profile_ref always record the plain name.

    Decision needed (maintainer): I kept the .json alias and made every path honour it. Two things follow from that choice:

    1. profile_refs.py is meant to work with any store, and it now applies the file store's rule (foo.json is foo) whatever LLM store sits behind it. The regex accepts names like foo.json, so a non-file store that treats them as separate profiles would also see the guard treat them as one. No such store exists in this repo today.
    2. The other option is to reject a trailing .json with 422 at the API (and in _get_profile_path), so the alias does not exist at all. That is a stricter API change: existing GET /api/profiles/foo.json calls would start failing. The F21 sibling (F21.json-suffix-identity) lists the same 422 option for agent profiles, so the two stores could be made to match later either way.

    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugready-for-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions