Skip to content

fix: read session/message lists from OpenAI-list data shape - #20

Open
coolswood wants to merge 1 commit into
JPeetz:mainfrom
coolswood:fix/list-sessions-openai-data-format
Open

fix: read session/message lists from OpenAI-list data shape#20
coolswood wants to merge 1 commit into
JPeetz:mainfrom
coolswood:fix/list-sessions-openai-data-format

Conversation

@coolswood

Copy link
Copy Markdown

Summary

Fixes #18.

listSessions() and getMessages() in src/server/hermes-api.ts read resp.items, but the Hermes gateway (v0.18/0.20) returns the OpenAI-list shape:

GET /api/sessions?limit=50&offset=0
→ 200 {"object":"list","data":[{"id":"...","source":"api_server","message_count":2,...}]}

GET /api/sessions/{id}/messages
→ 200 {"object":"list","session_id":"...","data":[{"id":70,"role":"user",...}]}

So resp.items was undefined, the session history rendered empty on page reload, and message history never loaded — even though the data stayed intact in the gateway database. The same .items assumption in src/routes/api/context-usage.ts (~lines 95 and 161) zeroed out the context-usage estimate for sessions without cache_read_tokens.

This is the same class of bug as the closed issue #5 (closed without a fix landing in main).

Changes

Adds a small extractList() helper that returns the first array it finds across items | data | messages | results (and the payload itself when it is already an array), then uses it in listSessions() and getMessages(). context-usage.ts does the same resilient lookup inline in its two spots. This mirrors what fetchHermesModels in src/routes/api/models.ts already does (payload.data ?? payload.models) and stays compatible if the gateway ever changes the list key again.

  • src/server/hermes-api.tsextractList() helper + listSessions/getMessages use it
  • src/routes/api/context-usage.ts — resilient list lookup (2 spots)

Note

getSession/createSession/updateSession read resp.session, and the gateway does return { session: {...} } for those single-resource endpoints — so only the list endpoints are affected. The single-object shape is correct and left untouched.

Verification

Against Hermes Agent v0.20.0 with a populated session DB:

Endpoint (via Studio proxy) Before After
GET /api/sessions { source: "gateway", sessions: [] } (0) { source: "gateway", sessions: [...] } (8)
Session message history empty loads
Context-usage indicator stuck at 0% reflects conversation size
  • npx tsc --noEmit: no new errors (the 4 pre-existing errors on main are unrelated — the missing remark-math/rehype-katex deps and two untouched files)
  • npx vitest run: 190/190 tests pass (including operations-aggregator.test, which mocks listSessions — the call signature is unchanged)
  • prettier --check: passes on both changed files

Related: #19 (separate bug — proxy routes missing Authorization).

)

listSessions() and getMessages() in src/server/hermes-api.ts read
resp.items, but the Hermes gateway (v0.18/0.20) returns the OpenAI-list
shape { object: "list", data: [...] } for sessions and
{ object: "list", session_id, data: [...] } for messages. So resp.items
was undefined and the session history rendered empty on page reload while
the data stayed intact in the gateway database. The same .items assumption
in src/routes/api/context-usage.ts zeroed out the context-usage estimate
for sessions without cache_read_tokens.

Adds a small extractList() helper that returns the first array it finds
across items | data | messages | results (and the payload itself when it is
already an array), mirroring what fetchHermesModels in src/routes/api/models.ts
already does (payload.data ?? payload.models). This stays compatible if the
gateway ever changes the list key again.

Note: getSession/createSession/updateSession read resp.session and the gateway
does return { session: {...} } for those single-resource endpoints, so only the
list endpoints are affected.

Closes JPeetz#18
@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

@coolswood is attempting to deploy a commit to the Joerg Peetz's projects Team on Vercel.

A member of the Team first needs to authorize it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

listSessions()/getMessages() read .items but gateway returns .data (OpenAI list format) → empty session/message history

1 participant