Skip to content

[Bug]: GET /api/conversations/{id}/events/{event_id} with an unknown id returns 500 instead of 404, and batch get fails whole on one missing id #5806

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

GET /api/conversations/{conversation_id}/events/{event_id} documents 404 for a missing event, and the batch route GET /api/conversations/{conversation_id}/events (JSON array of ids as the body) documents "returning null for any missing item". Both answer 500 Internal Server Error instead when an id is not in the log, and a single missing id fails the whole batch. The TypeScript client relies on the documented contract: RemoteEventsList.getEventById should reject with a 404 HttpError, and getEventsById maps that 404 to null (clients/typescript/src/events/remote-events-list.ts:110), so today getEventsById rejects as soon as one id is missing.

Expected Behavior

  • GET .../events/<unknown id> returns 404.
  • GET .../events with body ["<known id>", "qa-missing-event"] returns 200 with [<event>, null].
  • TS: getEventById(<unknown>) rejects with a 404 HttpError; getEventsById([<known>, <unknown>]) resolves to [<event>, null].

Actual Behavior

Both server calls return 500 with {"detail": "Internal Server Error", "exception": "'Unknown event_id: ...'"}. Both TS calls reject with a 500 HttpError.

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. Create a conversation and send it one message (any LLM config; the event is persisted before the run), note its id $CID and one event id $E from GET /api/conversations/$CID/events/search.
  3. curl -s -H 'X-Session-API-Key: dev-key' http://127.0.0.1:8000/api/conversations/$CID/events/00000000-0000-4000-8000-0000000000e6 returns 500.
  4. curl -s -X GET -H 'X-Session-API-Key: dev-key' -H 'Content-Type: application/json' -d "[\"$E\", \"qa-missing-event\"]" http://127.0.0.1:8000/api/conversations/$CID/events returns 500.

With the verify-agent-server skill: control-agent-server map run --file F06 --only F06.unknown-event --fresh and control-agent-server map run --file F34 --only F34.events-unknown-id --fresh report the known-bug bullets as expected failures while the bug lasts.

Acceptance Criteria

  • GET .../events/{event_id} with an unknown id returns 404.
  • Batch get returns null in the slot of each missing id and the found events in request order, with 200.
  • A unit test in tests/agent_server/ covers both cases.
  • The map bullets F06.unknown-event and F34.events-unknown-id pass with their # bug markers removed.

Installation Method

uv sync in a checkout of main

Version

main at 6a298a4

Additional Context

Root cause: EventService._get_event_sync (openhands-agent-server/openhands/agent_server/event_service.py:529-538) calls EventLog.get_index (openhands-sdk/openhands/sdk/conversation/event_store.py:69-74), which raises KeyError('Unknown event_id: ...') for an unknown id. The method is typed -> Event | None, but the KeyError escapes before the router's if event is None: raise HTTPException(404) check (openhands-agent-server/openhands/agent_server/event_router.py:196-198), and the catch-all handler turns it into a 500. batch_get_events (event_service.py:835-840) gathers get_event for every id with asyncio.gather, so one KeyError fails the whole batch.

Suggested fix: catch KeyError in _get_event_sync and return None, which makes both routes match their documented contract; no TS change is needed.

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

Confirmed against the repository at the referenced revision. EventService._get_event_sync is annotated -> Event | None, but EventLog.get_index raises KeyError for an id that is not in the log, so the lookup escapes before the router's existing event is None -> 404 branch and the catch-all handler converts it to 500. EventService.batch_get_events awaits get_event for every id with asyncio.gather, so a single KeyError rejects the whole batch instead of leaving a null slot. This breaks two documented contracts: the get-one route's responses={404: ...} and the batch route's "returning null for any missing item". The TypeScript RemoteEventsList.getEventsById already maps that 404 to null, so no client change is required.

Scope: make an unknown id resolve through the existing not-found path for both routes, so get-one returns 404 and batch-get returns the found events with null in each missing slot, in request order. Reuse the existing not-found handling rather than introducing a new error path or response shape.

Non-goals: no TypeScript client change (it already maps 404 to null); no change to EventLog.get_index semantics for other callers; no change to search, paging, count, or auth behavior, including the unknown-conversation 404; no new endpoints or response fields.

Acceptance Criteria

  • GET /api/conversations/{conversation_id}/events/{event_id} with an id that is not in the event log returns 404; with an id that is present it still returns 200 and the same event body as before.
  • GET /api/conversations/{conversation_id}/events with a JSON array body returns 200 and a list of the same length as the request: each id present in the log yields its event in request position, and each id absent from the log yields null in its slot, including when some, or all, of the ids are missing.
  • Known-id behavior is unchanged: a batch whose ids are all present returns the same events in the same request order as before, and no existing route changes its status code for a known id or for an unknown conversation.
  • A test under tests/agent_server/ exercises both paths and asserts the observable results: the single-get 404 for an unknown id and the batch-get 200 body with null in each missing slot and the found events in order.
  • The verify-agent-server feature-map bullets F06.unknown-event and F34.events-unknown-id pass against a running agent-server with their # bug markers removed.

Activity

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