Skip to content

AI_JSONParseError during SSE streaming is not retried (falls to NamedError.Unknown) #13579

Closed

Description

@konard

Description

When SSE streams from providers return malformed JSON (e.g., corrupted chunks from Kimi K2.5 via Kilo Gateway), the Vercel AI SDK throws AI_JSONParseError. In the current message-v2.ts:fromError() error classification chain, this error:

  1. Is NOT an APICallError (skips that branch)
  2. Is NOT a LoadAPIKeyError or DOMException (skips those branches)
  3. Falls through to case e instanceof Error: → becomes NamedError.Unknown

Since NamedError.Unknown is not recognized as retryable by retry.ts:retryable(), the session terminates immediately instead of retrying.

Evidence

This was observed in production:

{
  "name": "AI_JSONParseError",
  "text": "{\"id\":\"chatcmpl-jQugNdata:{\"id\":\"chatcmpl-iU6vkr3fItZ0Y4rTCmIyAnXO\",...}"
}

The error is classified as UnknownError and the session stops:

{
  "type": "error",
  "error": {
    "name": "UnknownError",
    "data": {
      "message": "AI_JSONParseError: JSON parsing failed: ..."
    }
  }
}

How Other CLI Agents Handle This

OpenAI Codex CLI: Skips unparseable SSE events and continues. CodexErr::Json is retryable with up to 5 stream retries.

Qwen Code: SDK's parseJsonLineSafe() silently skips failed lines.

Proposed Fix

In message-v2.ts:fromError(), add detection before the generic instanceof Error fallback:

case e instanceof Error: {
  const message = e.message || e.toString();
  const isStreamParseError =
    e.name === 'AI_JSONParseError' ||
    message.includes('AI_JSONParseError') ||
    message.includes('JSON parsing failed');
  if (isStreamParseError) {
    return new MessageV2.StreamParseError(
      { message, isRetryable: true, text: (e as any).text },
      { cause: e }
    ).toObject();
  }
  // ... existing socket/timeout checks
}

Related Issues

See: link-assistant/agent#169

Activity

  1. github-actions commented on Apr 16, 2026

    @github-actions
    Contributor

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

  2. added a commit that references this issue on Jul 21, 2026
    186a688
  3. added a commit that references this issue on Jul 27, 2026
    8af076e
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