opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Azure Model o4-mini error Invalid schema edit

Open blubbelgum opened this issue 1 year ago • 3 comments

Problem

i've got error schema when using model o4-mini, but for other model like GPT-4.1 has no issue so far.

Image

INFO  2025-06-21T13:10:18 +1ms service=bus type=storage.write publishing
INFO  2025-06-21T13:10:18 +0ms service=app name=config registering service
INFO  2025-06-21T13:10:18 +2ms service=config $schema=https://opencode.ai/config.json loaded
INFO  2025-06-21T13:10:18 +0ms service=bus type=session.updated publishing

█▀▀█ █▀▀█ █▀▀ █▀▀▄ █▀▀ █▀▀█ █▀▀▄ █▀▀
█░░█ █░░█ █▀▀ █░░█ █░░ █░░█ █░░█ █▀▀
▀▀▀▀ █▀▀▀ ▀▀▀ ▀  ▀ ▀▀▀ ▀▀▀▀ ▀▀▀  ▀▀▀

>  hi

INFO  2025-06-21T13:10:18 +1ms service=app name=provider registering service
INFO  2025-06-21T13:10:18 +1ms service=models.dev refreshing
INFO  2025-06-21T13:10:18 +1ms service=provider init
INFO  2025-06-21T13:10:18 +1ms service=provider providerID=azure found
INFO  2025-06-21T13:10:18 +0ms service=provider providerID=openai found
@  azure/o4-mini

INFO  2025-06-21T13:10:18 +1ms service=bus type=message.part.updated subscribing
INFO  2025-06-21T13:10:18 +3ms service=session session=ses_86d63855fffeyji3DPzRwtBZSt chatting
INFO  2025-06-21T13:10:18 +1ms service=provider providerID=azure modelID=o4-mini getModel
INFO  2025-06-21T13:10:18 +1ms service=provider status=started providerID=azure getSDK
INFO  2025-06-21T13:10:18 +24ms service=provider status=completed duration=24 providerID=azure getSDK
INFO  2025-06-21T13:10:18 +0ms service=provider providerID=azure modelID=o4-mini found
INFO  2025-06-21T13:10:18 +2ms service=session sessionID=ses_86d63855fffeyji3DPzRwtBZSt locking
INFO  2025-06-21T13:10:18 +7ms service=bus type=storage.write publishing
INFO  2025-06-21T13:10:18 +0ms service=bus type=message.updated publishing
INFO  2025-06-21T13:10:18 +3ms service=bus type=storage.write publishing
INFO  2025-06-21T13:10:18 +0ms service=bus type=message.updated publishing
INFO  2025-06-21T13:10:18 +0ms service=app name=mcp registering service
ERROR 2025-06-21T13:10:19 +1933ms service=session error=AI_APICallError: Invalid schema for function 'edit': In context=('properties', 'replaceAll'), schema must have a 'type' key. callback error
INFO  2025-06-21T13:10:19 +0ms service=bus type=session.error publishing
INFO  2025-06-21T13:10:19 +1ms service=session session=ses_86d63855fffeyji3DPzRwtBZSt type=error part
INFO  2025-06-21T13:10:19 +0ms service=session session=ses_86d63855fffeyji3DPzRwtBZSt type=error unhandled
INFO  2025-06-21T13:10:20 +1ms service=bus type=storage.write publishing
INFO  2025-06-21T13:10:20 +0ms service=bus type=message.updated publishing
INFO  2025-06-21T13:10:20 +0ms service=session sessionID=ses_86d63855fffeyji3DPzRwtBZSt unlocking
INFO  2025-06-21T13:10:20 +0ms service=app name=session shutdown
INFO  2025-06-21T13:10:20 +0ms service=app name=mcp shutdown

Hotfix

so, for now the solution i use is Modified the optionalToNullable function in packages/opencode/src/provider/provider.ts to completely remove optional fields from the schema when using Azure/OpenAI providers, rather than trying to make them nullable.

function optionalToNullable(schema: z.ZodTypeAny): z.ZodTypeAny {
  if (schema instanceof z.ZodObject) {
    const shape = schema.shape
    const newShape: Record<string, z.ZodTypeAny> = {}

    for (const [key, value] of Object.entries(shape)) {
      const zodValue = value as z.ZodTypeAny
      if (zodValue instanceof z.ZodOptional) {
        // For OpenAI/Azure compatibility, completely remove optional fields
        // from the schema to avoid validation errors about required arrays
        continue // <- This removes optional fields entirely
      } else {
        newShape[key] = optionalToNullable(zodValue)
      }
    }
    return z.object(newShape)
  }
  // ... rest of function
}

Image

blubbelgum avatar Jun 21 '25 13:06 blubbelgum

how do you see these logs?

divakaivan avatar Jun 21 '25 14:06 divakaivan

how do you see these logs?

opencode run "hello" --print-logs use --print-logs

blubbelgum avatar Jun 21 '25 15:06 blubbelgum

[automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!

rekram1-node avatar Dec 28 '25 01:12 rekram1-node