Skip to content

fix(server): accept OpenAI-style list shape for gateway sessions/messages#577

Open
morganjppeach wants to merge 1 commit into
outsourc-e:mainfrom
morganjppeach:fix/gateway-session-list-shape
Open

fix(server): accept OpenAI-style list shape for gateway sessions/messages#577
morganjppeach wants to merge 1 commit into
outsourc-e:mainfrom
morganjppeach:fix/gateway-session-list-shape

Conversation

@morganjppeach
Copy link
Copy Markdown

Problem

When the Hermes Agent gateway runs without the dashboard (enhanced-fork mode), listSessions() and getMessages() call the gateway's /api/sessions and /api/sessions/:id/messages endpoints. Those return an OpenAI-style list{ object: "list", data: [...] } — not the { items: [...] } shape the code assumed.

So resp.items was undefined, and:

  • /api/sessions did undefined.map(...)HTTP 500 Cannot read properties of undefined (reading 'map')
  • /api/history did undefined.lengthHTTP 500 Cannot read properties of undefined (reading 'length')

In the UI this surfaced as a persistent "Connection error — Try refreshing or check Settings → Advanced → Hermes" banner, even though chat itself worked fine (it doesn't depend on the session list).

Fix

In src/server/claude-api.ts, both functions now accept either response shape and never return undefined:

return resp.items ?? resp.data ?? []

Testing

Against a live gateway in enhanced-fork mode (no dashboard):

  • GET /api/sessions → was 500, now 200 with the session list
  • GET /api/history?... → was 500, now 200 with mapped messages
  • /api/ping, /api/models, /api/session-status, /api/sessions/:id/status, /api/sessions/:id/active-run → unaffected (still 200)

These were the only two resp.items sites in the file.

🤖 Generated with Claude Code

…ages

When the Hermes Agent gateway runs without the dashboard (enhanced-fork
mode), `listSessions()` and `getMessages()` call the gateway's
`/api/sessions` and `/api/sessions/:id/messages` endpoints, which return
an OpenAI-style list `{ object: "list", data: [...] }` — not the
`{ items: [...] }` shape the code assumed.

`resp.items` was therefore `undefined`, so `/api/sessions` (`.map`) and
`/api/history` (`.length`) crashed with HTTP 500 ("Cannot read properties
of undefined"), surfacing as a "Connection error" banner in the chat UI
even though chat itself worked.

Accept either shape (`items` or `data`) and never return undefined.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants