Skip to content

[Bug]: Sub-agent file naming a missing skill makes the first message return 500 instead of being skipped #5630

Closed

Description

@enyst

I'm an AI agent based on Opus 5.5, 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

A file-based sub-agent whose frontmatter skills names a skill that does not exist breaks every conversation that loads it. POST /api/sub-agents lists the agent as valid, but the conversation's first message returns 500, and so does every later one. The same file in ~/.agents/agents breaks new conversations in every workspace on the server.

Expected Behavior

Only that sub-agent is lost: it is skipped with a warning naming the file and the missing skill (as invalid frontmatter already is), and the message is accepted (200). A 4xx naming the agent and skill would also do. POST /api/conversations with initial_message does not return 500.

Actual Behavior

  • POST /api/conversations/{id}/events returns 500, logging ValueError: Skill 'qa-f27-missing-skill' not found but was given to agent 'qa-bad-skill'. Later messages fail the same way.
  • With initial_message, POST /api/conversations returns 500, yet the conversation is stored and listed as idle.
  • POST /api/sub-agents for that project_dir returns 200 and lists qa-bad-skill without a warning.

Steps to Reproduce

  1. Start a server from a checkout: uv run python -m openhands.agent_server --port 8000.
  2. Create a workspace with the agent file:
    W=$(mktemp -d); mkdir -p "$W/.agents/agents"
    printf -- '---\nname: qa-bad-skill\ndescription: Bad skill\nskills: qa-f27-missing-skill\n---\nBody\n' > "$W/.agents/agents/qa-bad-skill.md"
    
  3. Create a conversation there and send a message (run: false, so no model call):
    CID=$(curl -s localhost:8000/api/conversations -H 'content-type: application/json' \
      -d '{"agent": {"kind": "Agent", "llm": {"model": "test"}, "tools": []}, "workspace": {"working_dir": "'"$W"'"}}' | jq -r .id)
    curl -s -o /dev/null -w '%{http_code}\n' localhost:8000/api/conversations/$CID/events -H 'content-type: application/json' \
      -d '{"role": "user", "content": [{"type": "text", "text": "hi"}], "run": false}'
    
    Prints 500; a workspace without .agents/agents gives 200.
  4. Repeat the create with "initial_message": {"role": "user", "content": [{"type": "text", "text": "hi"}]}: it returns 500, and GET /api/conversations/search lists the conversation as idle.

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

Acceptance Criteria

  • An agent file naming a missing skill no longer makes the message POST, or a create with initial_message, return 500.
  • The bad agent is skipped with a warning naming its file and skill (or the request is a 4xx naming them); other valid agents are still registered.
  • A unit test covers register_file_agents with a definition naming a missing skill.
  • The map bullet F27.subagents-bad-skill passes and its # bug marker is removed.

Installation Method

uv sync in a checkout of main

Version

main at 2804c12

Additional Context

  • LocalConversation.send_message initializes the agent on the first message (openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py:1822-1823); _ensure_agent_ready (:1569) reaches register_file_agents(self.workspace.working_dir) (:1533).
  • register_file_agents (openhands-sdk/openhands/sdk/subagent/registry.py:288-333) builds a factory for every project and user definition (:319-320) without error handling, and agent_definition_to_factory raises ValueError for an unknown skill (:198-203).
  • event_router.py:227 does not catch it, so the route answers 500. _agent_ready is set only at the end (local_conversation.py:1598), so each later message fails again.
  • conversation_service.py stores the conversation (:1663) before sending the initial message (:1671), hence the leftover idle conversation.
  • The catalog (sub_agents_router.py:117-140) validates frontmatter only; the loader skips invalid files with a warning (subagent/load.py:213-220).

Suggested fix: in register_file_agents, catch the error per definition, log a warning with the agent name, its source and the message, and continue. register_plugin_agents (registry.py:356-357) has the same pattern.


OpenHands AI triage

The following comments and acceptance criteria were added by the OpenHands AI agent.

Triage

Confirmed bug in this repository (SDK + Agent Server). register_file_agents (openhands-sdk/openhands/sdk/subagent/registry.py) builds a factory for every deduplicated definition without per-definition error handling, and agent_definition_to_factory raises ValueError for an unknown skill (skills in frontmatter). That error escapes LocalConversation._ensure_agent_ready and the message route answers 500; _agent_ready is only set at the end, so later messages fail too, and a create with initial_message stores the conversation before it fails, leaving an idle conversation. The catalog endpoint (POST /api/sub-agents) validates frontmatter only, so it lists the agent without a warning — that is a separate, expected gap, not the defect.

Scope: make per-definition registration resilient for file-based agents so an individual bad definition is skipped with a warning naming the file/source and the offending skill, while other valid agents still register and the request succeeds. Apply the same treatment to register_plugin_agents, which shares the pattern.

Non-goals: changing POST /api/sub-agents catalog validation or adding a new 4xx API contract (a 4xx is an acceptable alternative for the fix, not a required deliverable); changing skill-resolution semantics; conversation create/rollback ordering beyond the secondary initial_message symptom; requiring the verify-agent-server map bullet (F27), which lives on the unmerged PR #5621 and is not on main.

Acceptance Criteria

  • With a workspace whose .agents/agents/ contains a definition naming a nonexistent skill, POST /api/conversations/{id}/events with run: false returns 200, and subsequent messages on the same conversation also return 200. (A 4xx naming the agent and skill is also acceptable for the first request.)
  • POST /api/conversations with initial_message in that workspace does not return 500 and does not leave a conversation stored as idle solely because of the skill error.
  • The offending definition is not registered, and a warning is logged that names its file/source and the missing skill; other valid agents in the same directory and in other scanned directories are still registered and usable.
  • The same resilience covers a plugin-provided definition naming a missing skill (register_plugin_agents).
  • A definition naming a registered skill still resolves and registers unchanged (no regression to valid skill resolution).
  • A unit test under tests/sdk/subagent/ exercises register_file_agents with a definition naming a missing skill and asserts the bad agent is absent from the registry while valid agents are present.
  • If the non-fatal contract for registration is treated as an invariant, openhands-sdk/openhands/sdk/subagent/AGENTS.md (and the linked user docs) state that a definition failing registration — e.g. naming an unknown skill — is skipped with a warning while other agents register.
  • Validation: the reproduction steps in the issue return 200 on the fixed revision (a live run against a checkout, or the F27.subagents-bad-skill map bullet once PR Add verify-agent-server: an executable feature map and control CLI for the Agent Server API #5621 lands).

Activity

  1. added
    bug
    on Oct 9, 2026
  2. added theissue type on Oct 9, 2026
  3. added
    ready-for-dev
    on Oct 9, 2026
  4. enyst commented on Oct 13, 2026

    @enyst
    MemberAuthor

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

    PR #5754 addresses this issue. Below, each point of the triage block in the issue body is answered (there were no separate comments).

    Acceptance criteria

    • Message POST with run: false returns 200, later messages too: done. The bad definition is skipped, so _ensure_agent_ready completes. In a live run, both messages returned 200; on main the first one returned 500.
    • initial_message create does not return 500 or leave an idle conversation: done. The create returned 500 on main and 201 on the branch. Nothing fails after the conversation is stored, so no conversation is left behind.
    • Bad definition not registered, warning names its file/source and the skill, other agents still register: done. The warning reads Skipping file-based agent 'qa-bad-skill' from <path>: Skill 'qa-f27-missing-skill' not found but was given to agent 'qa-bad-skill'. A test registers a valid agent with a real skill next to the bad one and checks that the valid one resolves.
    • Plugin-provided definitions (register_plugin_agents): done. Both functions now go through one helper, _register_definition, and a separate test covers the plugin case.
    • Valid skill resolution unchanged: the existing agent_definition_to_factory skill tests still pass. Only the caller catches the ValueError.
    • Unit test under tests/sdk/subagent/: two tests were added in test_subagent_registry.py. They fail on main and pass on the PR.
    • Invariant in subagent/AGENTS.md: done ("Registration failures must be non-fatal"). The user docs in OpenHands/docs are not updated in this PR.
    • Validation: PR Add verify-agent-server: an executable feature map and control CLI for the Agent Server API #5621 has since merged, so the F27.subagents-bad-skill map bullet exists on main. It reported xfail twice on main (dfd8fe8) and xpass twice on the PR. The PR removes its # bug marker, and the bullet now passes.

    Non-goals respected: the POST /api/sub-agents catalog still validates only frontmatter. The skip was chosen over a 4xx, which the issue accepts. Skill resolution and create ordering are unchanged.

    Maintainer decision needed: how this issue relates to #5718. The triage comment on #5718 asks whether #5718 absorbs this issue or stays a separate umbrella.


    Generated by Claude Code

  5. enyst commented on Oct 13, 2026

    @enyst
    MemberAuthor

    Agreed, this isn't much of a choice TBH since nobody doubted it. 😅

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions