Skip to content

[Bug]: AI SDK ignores SSE event: field — custom server events crash Chat Completions stream with TypeValidationError #38106

Closed as not planned

Description

@SozinovD

Description

Тело:

Description

Summary

When a custom OpenAI-compatible provider emits named SSE events (using the
standard event: field from the SSE spec) inside a /v1/chat/completions
stream, OpenCode's AI SDK parser attempts to validate every data: line as a
chat.completion.chunk and throws a TypeValidationError, terminating the
agent turn.

Environment

  • OpenCode version: opencode --version → 1.x.x
  • Provider: custom OpenAI-compatible endpoint (Hermes Agent API server,
    @ai-sdk/openai-compatible)
  • Model: any
  • Runtime: ai-sdk

Reproducing

1. Provider config (opencode.json)json

{
"$schema": "https://opencode.ai/config.json",
"provider": {
"hermes": {
"npm": "@ai-sdk/openai-compatible",
"name": "Hermes Agent",
"options": {
"baseURL": "https://hermes-endpoint/v1"
},
"models": {
"glm-5": {
"name": "GLM-5",
"limit": { "context": 131072, "output": 8192 }
}
}
}
}
}

2. Trigger a tool call

Any prompt that causes the agent to call a tool, e.g.:bash
opencode run "search for X" --model hermes/glm-5

3. ErrorType validation failed: Value: {"tool":"web_search","emoji":"🔍","label":"...","toolCallId":"call_9e19...","status":"running"}.

Error message: [
{
"code": "invalid_union",
"errors": [
[
{
"expected": "array",
"code": "invalid_type",
"path": ["choices"],
"message": "Invalid input: expected array, received undefined"
}
],
[
{
"expected": "object",
"code": "invalid_type",
"path": ["error"],
"message": "Invalid input: expected object, received undefined"
}
]
],
"path": [],
"message": "Invalid input"
}
]

4. Root cause confirmed via curl

The Hermes API server emits named SSE events for tool-progress UX:bash
curl -N -s "https://hermes-endpoint/v1/chat/completions"
-H "Authorization: Bearer ***"
-H "Content-Type: application/json"
-d '{"model":"glm-5","messages":[{"role":"user","content":"search"}],"stream":true}'
The stream contains:data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}

event: hermes.tool.progress
data: {"tool":"web_search","emoji":"🔍","label":"...","toolCallId":"call_...","status":"running"}

data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Here"},"finish_reason":null}]} (1/2)

The event: hermes.tool.progress block is a named SSE event per the
SSE specification:
data lines following an event: field must only be dispatched to listeners
registered for that event type, not to the default message handler.

The AI SDK's @ai-sdk/openai-compatible SSE parser ignores the event: field
entirely and passes every data: line to the Chat Completions chunk validator.
The tool-progress payload has no choices array and no error object, so the
Zod union fails → TypeValidationError.

5. Expected behavior

Per the SSE spec, data: lines preceded by event: foo should be:

  • Ignored by consumers that only handle the default (unnamed) message event,
    OR
  • Filtered out at the transport layer so they never reach the Chat
    Completions / Responses schema validator.

The fix should be in the AI SDK's SSE parser: respect the event: field
(event: without a matching listener → drop the frame), so custom provider
events don't crash the stream.

This is the same class of bug as #30916 (closed PR #30919 introduced a
configurable filterSseFrame option, but the PR was auto-closed by the cleanup
bot and never merged). A general fix — honoring the SSE event: field — would
resolve both that case and this one without requiring per-provider config.

6. Related

Operating System

Any

OpenCode version

Latest

Plugins

No response

OpenCode version

latest

Steps to reproduce

use hermes api integration

Screenshot and/or share link

No response

Operating System

macos 26

Terminal

opencode desktop, not terminal version

Activity

  1. github-actions commented on Jul 21, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. github-actions commented on Sep 20, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions