Skip to content

[SDK] HarnessRunner with retry & schema orchestration for .harness() #201

@santoshkumarradha

Description

@santoshkumarradha

Overview

Implement the HarnessRunner that orchestrates provider execution with retry logic, schema output handling (4-layer recovery), temp file lifecycle, cost tracking, and JSONL event logging.

Branch: feat/harness-v2
Design doc: docs/design/harness-v2-design.md (Sections 3.2, 5.4, 9)

Scope

Python (sdk/python/agentfield/harness/)

  • _runner.pyHarnessRunner class:
    • async run(prompt, schema, options) → orchestrates full execution
    • Config resolution: merge HarnessConfig defaults + per-call overrides
    • Provider dispatch via factory
    • Retry with exponential backoff + jitter for transient errors
    • Schema orchestration: inject prompt suffix → execute → 4-layer recovery
    • Layer 1: Read output file → parse → validate
    • Layer 2: Cosmetic repair → re-validate
    • Layer 3: Follow-up prompt in same session (cap 2 attempts)
    • Layer 4: Full retry (limit 1)
    • Temp file cleanup (always, even on failure)
    • Cost/metrics tracking
  • Tests: retry behavior, schema orchestration layers, config resolution, error categories, transient error detection

TypeScript (sdk/typescript/src/harness/)

  • runner.tsHarnessRunner class (mirrors Python)
  • Tests: mirror Python coverage

Key Design Decisions

  • Transient errors: rate limits, timeouts, 5xx, connection errors → retry
  • Non-transient errors: auth, billing, invalid request → fail immediately
  • Schema follow-up uses same session (cheap, agent has context)
  • No separate schema budget — uses overall max_budget_usd
  • Always clean up temp files, even on error paths

Acceptance Criteria

  • Retry correctly backs off with jitter
  • All 4 schema recovery layers work in sequence
  • Follow-up prompt capped at 2 attempts
  • Full retry capped at 1 attempt
  • Transient vs non-transient error classification correct
  • Temp files always cleaned up
  • All tests pass

Dependencies

Metadata

Metadata

Labels

ai-friendlyWell-documented task suitable for AI-assisted developmentarea:harnessCoding agent harness integrationenhancementNew feature or requestsdk:pythonPython SDK relatedsdk:typescriptTypeScript SDK related

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions