Bug Report: OpenCode Validation Fails on AI SDK V3 Stream Parts #10667
Description
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
- Use any AI SDK V3-compliant provider (e.g.,
@acedergren/opencode-oci-genai) - Send a chat message through OpenCode
- 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
- Provider declares V3 compliance: The OCI GenAI provider correctly declares
specificationVersion = 'v3'and all 726 tests pass - Structure matches official providers: The finish event structure matches Vercel's official providers (OpenAI, Anthropic, xAI)
- Conforms to type definitions: Output matches
@ai-sdk/provider@3.0.5type definitions exactly - 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:
- Use discriminated unions based on the
typefield - Accept V3 finish format with
finishReasonas object:const FinishStreamPartSchema = z.object({ type: z.literal('finish'), finishReason: z.object({ unified: z.string(), raw: z.string().optional() }), usage: UsageInfoSchema });
- Validate based on
specificationVersionto 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
Operating System
MacOS 26.2
Terminal
Apple terminal Version 2.15 (466)
Activity
[-]# Bug Report: OpenCode Validation Fails on AI SDK V3 Stream Parts[/-][+]Bug Report: OpenCode Validation Fails on AI SDK V3 Stream Parts[/+]github-actions commentedon Jan 26, 2026
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
acedergren commentedon Feb 2, 2026
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
rekram1-node commentedon Feb 2, 2026
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.
acedergren commentedon Feb 2, 2026
Yes. I'm happy to help when it time . I've adapted my provider to v5 for now.
rekram1-node commentedon Mar 27, 2026
Our next release will be using ai sdk v6:
c33d999
acedergren commentedon Mar 27, 2026
Great work!