Skip to content

Bug Report: OpenCode Validation Fails on AI SDK V3 Stream Parts #10667

Closed

Description

@acedergren

Description

OpenCode's Zod validation incorrectly rejects valid AI SDK V3 stream parts from compliant providers, causing validation errors when providers emit finish events according to the official V3 specification.

Error Message

ZodError: [
  {
    "expected": "string",
    "code": "invalid_type",
    "path": ["finish"],
    "message": "Invalid input: expected string, received object"
  }
]

Steps to Reproduce

  1. Use any AI SDK V3-compliant provider (e.g., @acedergren/opencode-oci-genai)
  2. Send a chat message through OpenCode
  3. Observe Zod validation error when provider emits finish event

Expected Behavior

OpenCode should accept AI SDK V3 finish events with the structure:

{
  type: 'finish',
  finishReason: {
    unified: 'stop',  // or 'length', 'content-filter', 'tool-calls', etc.
    raw?: string
  },
  usage: {
    inputTokens: number,
    outputTokens: number
  }
}

Actual Behavior

OpenCode validation expects finish field to be a string, but receives an object containing finishReason (which is correctly an object in V3).

Root Cause

OpenCode's Zod validation schemas appear to be based on AI SDK V2 specification, where finishReason was a simple string. In V3, this was changed to an object with {unified, raw} structure for better standardization across providers.

V2 vs V3 Comparison

AI SDK V2 (legacy):

interface FinishStreamPart {
  type: 'finish';
  finishReason: string;  // Simple string
  usage: UsageInfo;
}

AI SDK V3 (current):

interface FinishStreamPart {
  type: 'finish';
  finishReason: {        // Object with unified format
    unified: string;
    raw?: string;
  };
  usage: UsageInfo;
}

Evidence

  1. Provider declares V3 compliance: The OCI GenAI provider correctly declares specificationVersion = 'v3' and all 726 tests pass
  2. Structure matches official providers: The finish event structure matches Vercel's official providers (OpenAI, Anthropic, xAI)
  3. Conforms to type definitions: Output matches @ai-sdk/provider@3.0.5 type definitions exactly
  4. No "finish" field exists: Code search confirms no "finish" property is emitted - only the correct V3 structure

Impact

  • Users see validation errors in logs when using V3-compliant providers
  • May cause confusion about whether providers are working correctly
  • Blocks adoption of properly implemented V3 providers

Suggested Fix

Update OpenCode's stream part validation schemas to:

  1. Use discriminated unions based on the type field
  2. Accept V3 finish format with finishReason as object:
    const FinishStreamPartSchema = z.object({
      type: z.literal('finish'),
      finishReason: z.object({
        unified: z.string(),
        raw: z.string().optional()
      }),
      usage: UsageInfoSchema
    });
  3. Validate based on specificationVersion to support both V2 and V3 providers during transition period

Workaround

The validation error is cosmetic - V3 providers ARE working correctly despite the error. Users can safely ignore this validation error until OpenCode's schemas are updated.

Environment

  • OpenCode version: 1.1.36
  • AI SDK version: @ai-sdk/provider@3.0.5
  • Provider: @acedergren/opencode-oci-genai@0.1.0

Additional Context

The AI SDK V3 migration guide explicitly documents this breaking change from string to object format for finishReason. OpenCode's validation needs to be updated to reflect the current V3 specification.

References:

  • AI SDK V3 Provider Types: @ai-sdk/provider@3.0.5/dist/index.d.ts
  • Official Vercel AI SDK providers (all use V3 object format)

Plugins

None

OpenCode version

1.1.36

Steps to reproduce

Ask to be invited to my private OCI GenAI Provider repo (will be public soon)

Screenshot and/or share link

Image

Operating System

MacOS 26.2

Terminal

Apple terminal Version 2.15 (466)

Activity

  1. changed the title [-]# Bug Report: OpenCode Validation Fails on AI SDK V3 Stream Parts[/-] [+]Bug Report: OpenCode Validation Fails on AI SDK V3 Stream Parts[/+] on Jan 26, 2026
  2. github-actions commented on Jan 26, 2026

    @github-actions
    Contributor

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

    Feel free to ignore if none of these address your specific case.

  3. acedergren commented on Feb 2, 2026

    @acedergren
    Author

    After further troubleshooting over concluded its due to lagging support of the ai sdk v6 and language provider v3. Happy to help upgrade the codebase

  4. rekram1-node commented on Feb 2, 2026

    @rekram1-node
    Contributor

    As you noticed this is because we are on v5 of the sdk, so not a bug this would be expected if u are using non compliant version.

    We will probably do an upgrade soon but it's not just an easy flip there are a lot of third party packages we need to make sure all are v6 compliant too.

  5. acedergren commented on Feb 2, 2026

    @acedergren
    Author

    Yes. I'm happy to help when it time . I've adapted my provider to v5 for now.

  6. rekram1-node commented on Mar 27, 2026

    @rekram1-node
    Contributor

    Our next release will be using ai sdk v6:
    c33d999

  7. acedergren commented on Mar 27, 2026

    @acedergren
    Author

    Great work!

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