Skip to content

harness: surface provider error when schema output file is missing #217

@santoshkumarradha

Description

@santoshkumarradha

Problem

When Agent.harness(..., schema=...) is used and the provider fails before writing .agentfield_output.json (for example opencode run returning Session not found), the SDK currently returns a generic schema error:

Schema validation failed after parse and cosmetic repair attempts.

This hides the real provider failure and makes debugging look like a schema problem.

Reproduction

  • Provider: opencode
  • Schema mode enabled (schema=...)
  • CWD: /tmp/dvga
  • Provider exits with Session not found
  • No .agentfield_output.json is created

Observed result:

  • is_error=True
  • parsed=None
  • error_message="Schema validation failed after parse and cosmetic repair attempts."

Expected result:

  • Preserve provider error (e.g. Session not found) and include missing output-file context.

Root Cause

HarnessRunner._handle_schema_output() always returns the generic schema-validation error when parse_and_validate() returns None, even if raw.is_error=True from the provider and the output file was never created.

Proposed Fix

In _handle_schema_output():

  • If raw.is_error and schema parsing failed, return provider error details.
  • If output file is missing, append context like:
    • Output file was not created at {path}

This keeps the schema path for normal validation failures while preserving root-cause visibility for provider/runtime failures.

Metadata

Metadata

Assignees

No one assigned

    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