Skip to content

[Bug]: POST /api/conversations/{id}/ask_agent returns 500 for an unknown conversation instead of the documented 404 #5813

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

POST /api/conversations/{conversation_id}/ask_agent with a conversation id the server does not know answers 500 {"detail": "Internal Server Error", "exception": "500: Internal Server Error"}. The route's OpenAPI entry documents 404 for this case, and the sibling routes POST /condense and POST /navigate answer 404 for the same unknown id. A client therefore cannot tell "no such conversation" from a server failure (for example an unreachable model, which is also a 500).

Expected Behavior

404 with {"detail": "Conversation not found"} (the same shape condense uses).

Actual Behavior

500 {"detail": "Internal Server Error", "exception": "500: Internal Server Error"}.

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. curl -s -o /dev/null -w '%{http_code}\n' -H 'X-Session-API-Key: dev-key' -H 'Content-Type: application/json' -d '{"question": "hi"}' http://127.0.0.1:8000/api/conversations/$(python -c 'import uuid; print(uuid.uuid4())')/ask_agent prints 500.
  3. Control: the same id on POST .../condense prints 404.

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

Acceptance Criteria

  • POST /api/conversations/{id}/ask_agent with an unknown id returns 404 ({"detail": "Conversation not found"}), matching condense and navigate.
  • A known conversation still answers 200 {"response": ...}; an unreachable model is still a 500 with an error_id.
  • A unit test in tests/agent_server/test_conversation_router.py covers the unknown-id case.
  • The map bullet F10.ask-agent-unknown passes with its # bug marker removed.

Installation Method

uv sync in a checkout of main

Version

main at 6a298a4

Additional Context

Root cause:

  • ConversationService.ask_agent (openhands-agent-server/openhands/agent_server/conversation_service.py:1869-1873) returns None when _get_or_load_event_service finds no conversation. EventService.ask_agent returns str, so None only ever means "not found".
  • The route (openhands-agent-server/openhands/agent_server/conversation_router.py:760-762) maps None to a bare HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR), although it declares responses={404: ...} (line 752). condense_conversation (line 773-775) raises 404 "Conversation not found" for the same case.

Suggested fix: raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Conversation not found") there. RemoteConversation.ask_agent and the TypeScript client's askAgent just surface the HTTP error, so they need no change.

Related: #5800 (unknown ids on pause/interrupt/DELETE/PATCH).

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


OpenHands AI triage

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

Triage

The agent-server REST API is owned by this repository, and the reported behavior is confirmed in the current tree: ask_agent (openhands-agent-server/openhands/agent_server/conversation_router.py) declares responses={404: ...} but maps a None service result to a bare HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR), while the sibling condense_conversation raises HTTPException(status.HTTP_404_NOT_FOUND, detail="Conversation not found") for the same unknown-id case. ConversationService.ask_agent returns None only for "not found" because EventService.ask_agent returns str, so None is unambiguous.

Scope: make the unknown-conversation-id path of POST /api/conversations/{id}/ask_agent return 404 {"detail": "Conversation not found"}, matching condense and navigate, and cover it with a router test. Non-goals: the sibling unknown-id statuses tracked separately in #5800 (/pause, /interrupt, DELETE, PATCH); TypeScript client changes (RemoteConversation.ask_agent and askAgent only surface the HTTP status); and the other verify-agent-server bullets.

Acceptance Criteria

  • POST /api/conversations/{id}/ask_agent with an unknown conversation id returns HTTP 404 with body {"detail": "Conversation not found"}, matching POST /condense and POST /navigate.
  • POST /api/conversations/{id}/ask_agent for an existing conversation with a valid {"question": "..."} still returns 200 with {"response": "<string>"} and leaves the conversation's recorded events and status unchanged.
  • An unreachable model during ask_agent still returns 500 with an error_id, and a missing question still returns 422; neither is turned into a 404.
  • A router test in tests/agent_server/test_conversation_router.py asserts the unknown-id response is 404, following the existing missing-conversation test pattern (service ask_agent returns None).
  • The F10.ask-agent-unknown bullet in .agents/skills/verify-agent-server/references/feature-map/F10-fork-navigate-condense-ask.md passes against a live server once its # bug: marker is removed.

Activity

  1. added
    bug
    ready-for-dev
    on Oct 13, 2026
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