opencode icon indicating copy to clipboard operation
opencode copied to clipboard

imagen_generate tool crashes with validation error: expected string, received object

Open bendecastro opened this issue 1 month ago • 3 comments

Environment

  • OpenCode Version: 1.0.125
  • Platform: macOS (Darwin)
  • Installation Method: Homebrew

Bug Description

The imagen_generate tool consistently crashes with a validation error whenever it is invoked, making image generation functionality completely unusable.

Error Message

Tool execution aborted
[
  {
    "code": "invalid_union",
    "errors": [
      [
        {
          "expected": "string",
          "code": "invalid_type",
          "path": ["state", "output"],
          "message": "Invalid input: expected string, received object"
        }
      ],
      [
        {
          "expected": "object",
          "code": "invalid_type",
          "path": ["part"],
          "message": "Invalid input: expected object, received undefined"
        },
        {
          "expected": "string",
          "code": "invalid_type",
          "path": ["delta"],
          "message": "Invalid input: expected string, received undefined"
        }
      ]
    ],
    "path": [],
    "message": "Invalid input"
  }
]

Steps to Reproduce

  1. Call the imagen_generate tool with any parameters
  2. Example: imagen_generate [prompt=A simple red apple on a white background, quality=flash, num_images=1, auto_preview=false]
  3. Observe the validation error and OpenCode crash

Root Cause

The imagen_generate tool is returning a structured object (containing image metadata, cost tracking, etc.) when OpenCode's tool validation layer expects a simple string message in the state.output field.

Evidence That Generation Works

Despite the error, images ARE successfully generated and saved to:

  • ~/.config/opencode/nano-banana/images/YYYY-MM-DD/
  • Cost tracking is functional and updates config.json
  • Image files (PNG/JPG) are created correctly

This indicates the underlying nano-banana functionality works correctly, but the tool wrapper's output format is incompatible with OpenCode's validation schema.

Attempted Workarounds (All Failed)

  1. Removed all config files
  2. Created minimal/empty config
  3. Disabled auto_preview
  4. Disabled confirm_before_generate
  5. Disabled show_cost_in_summary
  6. Disabled save_json_sidecar
  7. Set terminal_protocol to "none"
  8. Separated cost tracking to external file
  9. Made config read-only
  10. Removed entire nano-banana directory

None of these configuration changes resolved the issue.

Expected Behavior

The imagen_generate tool should return a simple string message (e.g., "Image generated successfully at /path/to/image.png") instead of a structured object.

Actual Behavior

The tool returns a complex object structure that fails OpenCode's output validation, causing the entire tool execution to abort.

Impact

  • The imagen_generate tool is completely unusable in OpenCode v1.0.125
  • Users cannot generate images through the OpenCode interface
  • This breaks the nano-banana subagent functionality

Suggested Fix

The imagen_generate tool wrapper should either:

  1. Convert its output to a simple string message before returning
  2. Update OpenCode's tool validation schema to accept object outputs
  3. Separate the metadata/tracking from the user-facing output message

Additional Context

The config file at ~/.config/opencode/nano-banana/config.json gets auto-generated and updated with cost tracking data, suggesting the tool is executing but failing at the output validation stage.

bendecastro avatar Dec 01 '25 20:12 bendecastro

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

  • #4357: Tool argument descriptions lost in schema conversion (related to tool schema issues)

Additionally, this appears to be a unique issue specific to the imagen_generate tool wrapper and its output format validation. If you haven't already, please check:

  1. The nano-banana tool's output format compliance with OpenCode's validation schema
  2. Whether other custom tools with structured outputs experience similar validation errors

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

github-actions[bot] avatar Dec 01 '25 20:12 github-actions[bot]

What is this imagen_generate tool?

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

google's image generation tool

bendecastro avatar Dec 01 '25 20:12 bendecastro