Skip to content

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

Closed

Description

@bendecastro

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.

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Dec 1, 2025
  2. github-actions commented on Dec 1, 2025

    @github-actions
    Contributor

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

    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.

  3. self-assigned this
    on Dec 1, 2025
  4. added
    bugSomething isn't working
    and removed
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Dec 1, 2025
  5. rekram1-node commented on Dec 1, 2025

    @rekram1-node
    Contributor

    What is this imagen_generate tool?

  6. bendecastro commented on Dec 1, 2025

    @bendecastro
    Author

    google's image generation tool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions