Skip to content

bug: SSE parser fails on custom event types from OpenAI-compatible API servers #8280

@FedeCuci

Description

@FedeCuci

Describe the bug

JAN Chat's SSE (Server-Sent Events) parser fails when an OpenAI-compatible API server uses custom event: types in the SSE stream. The parser appears to read ALL data: lines regardless of the event: type and tries to parse them as standard chat.completion.chunk format (expecting a choices[] array). This causes a "Generation failed / Type validation failed" error and the chat breaks.

To Reproduce

  1. Set up an OpenAI-compatible API server that emits custom SSE events (e.g. tool progress events with event: hermes.tool.progress)
  2. In JAN Chat, add a provider pointing to this server:
    • Type: OpenAI Compatible
    • API URL: http://<server>:8642/v1
    • API Key: (any valid key)
  3. Select the model and send a message
  4. The server sends back SSE events like:
event: hermes.tool.progress
data: {"tool":"terminal","emoji":"💻","label":"ls -la ~","toolCallId":"call_xxx","status":"running"}

data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":...,"model":"hermes-agent","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}

data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":...,"model":"hermes-agent","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
  1. JAN Chat shows: "Generation failed / Type validation failed" with an error similar to:
Type validation failed: Value: {"tool":"terminal","emoji":"💻","label":"ls -la ~","toolCallId":"call_d695aa830a5147b29e95cbc5","status":"running"}. Error message: [ { "code": "invalid_union", "errors": [ [ { "expected": "array", "code": "invalid_type", "path": [ "choices" ], "message": "Invalid input" } ], [ { "expected": "object", "code": "invalid_type", "path": [ "error" ], "message": "Invalid input" } ] ], "path": [], "message": "Invalid input" } ]

Expected behavior

JAN Chat's SSE parser should filter data: lines by their event: type. Only the default "message" event (plain data: lines with no preceding event: header) should be parsed as OpenAI chat.completion.chunk chunks. Custom event types like hermes.tool.progress should be silently ignored when the client doesn't have a handler for them, or at minimum should not cause a fatal validation error.

A compliant SSE implementation handles unknown event types by skipping them — this is standard SSE behaviour as defined by the W3C spec.

Actual behavior

The client's SSE parser treats ALL data: lines as OpenAI stream chunks regardless of the event: type. When a custom event type payload doesn't match the chat.completion.chunk schema (which requires choices[] or error), the parser raises a "Type validation failed" error, which halts the entire stream and shows "Generation failed" to the user. No response content is displayed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions