fix(server): accept OpenAI-style list shape for gateway sessions/messages#577
Open
morganjppeach wants to merge 1 commit into
Open
fix(server): accept OpenAI-style list shape for gateway sessions/messages#577morganjppeach wants to merge 1 commit into
morganjppeach wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the Hermes Agent gateway runs without the dashboard (enhanced-fork mode),
listSessions()andgetMessages()call the gateway's/api/sessionsand/api/sessions/:id/messagesendpoints. Those return an OpenAI-style list —{ object: "list", data: [...] }— not the{ items: [...] }shape the code assumed.So
resp.itemswasundefined, and:/api/sessionsdidundefined.map(...)→ HTTP 500Cannot read properties of undefined (reading 'map')/api/historydidundefined.length→ HTTP 500Cannot 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 returnundefined:Testing
Against a live gateway in enhanced-fork mode (no dashboard):
GET /api/sessions→ was 500, now 200 with the session listGET /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.itemssites in the file.🤖 Generated with Claude Code