Repository navigation
Description
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
- In a checkout of main:
uv sync, thenSESSION_API_KEY=dev-key uv run python -m openhands.agent_server --host 127.0.0.1 --port 8000. 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_agentprints500.- Control: the same id on
POST .../condenseprints404.
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_agentwith an unknown id returns404({"detail": "Conversation not found"}), matchingcondenseandnavigate. - A known conversation still answers
200 {"response": ...}; an unreachable model is still a500with anerror_id. - A unit test in
tests/agent_server/test_conversation_router.pycovers the unknown-id case. - The map bullet
F10.ask-agent-unknownpasses with its# bugmarker 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) returnsNonewhen_get_or_load_event_servicefinds no conversation.EventService.ask_agentreturnsstr, soNoneonly ever means "not found".- The route (
openhands-agent-server/openhands/agent_server/conversation_router.py:760-762) mapsNoneto a bareHTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR), although it declaresresponses={404: ...}(line 752).condense_conversation(line 773-775) raises404 "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_agentwith an unknown conversation id returns HTTP404with body{"detail": "Conversation not found"}, matchingPOST /condenseandPOST /navigate. -
POST /api/conversations/{id}/ask_agentfor an existing conversation with a valid{"question": "..."}still returns200with{"response": "<string>"}and leaves the conversation's recorded events and status unchanged. - An unreachable model during
ask_agentstill returns500with anerror_id, and a missingquestionstill returns422; neither is turned into a404. - A router test in
tests/agent_server/test_conversation_router.pyasserts the unknown-id response is404, following the existing missing-conversation test pattern (serviceask_agentreturnsNone). - The
F10.ask-agent-unknownbullet in.agents/skills/verify-agent-server/references/feature-map/F10-fork-navigate-condense-ask.mdpasses against a live server once its# bug:marker is removed.
Activity