Skip to content

[Bug]: "Unexpected token 'D'" crash with OpenAI-compatible providers sending double spaces in data: [DONE] #614

Description

@akramcodez

Description

Nanocoder crashes with an Unexpected token 'D', " [DONE]" is not valid JSON error when using certain OpenAI-compatible APIs (like Atlas Cloud). This happens because these providers send data: [DONE] (with two spaces) instead of the standard data: [DONE]. The strict @ai-sdk/openai-compatible parser strips only one space, leaving " [DONE]", which fails strict string comparison and falls through to JSON.parse().

Environment

  • OS: Linux
  • Node version: (insert your node version here)
  • Nanocoder version: 1.28.0
  • Provider: OpenAI-compatible API (Atlas Cloud)
  • Model: deepseek-ai/deepseek-r1-0528

Steps to Reproduce

  1. Configure an OpenAI-compatible provider in agents.config.json that sends data: [DONE] at the end of SSE streams (e.g., Atlas Cloud).
  2. Start a chat session using this provider and any model.
  3. Wait for the model to finish generating the response.

Expected Behavior

The stream should complete successfully and the response should be processed.

Actual Behavior

Nanocoder crashes at the end of the stream with the error Unexpected token 'D', " [DONE]" is not valid JSON and silently attempts to retry the request 4 times before failing.

Logs/Screenshots

Image

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions