{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://runpile.com/schemas/runpile-run-1.0.json",
  "title": "Runpile run manifest 1.0",
  "description": "One serving benchmark run with exact configuration, workload, measured results, and evidence declarations.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "kind",
    "client_run_id",
    "name",
    "visibility",
    "license",
    "outcome",
    "subject",
    "environment",
    "runtime",
    "workload",
    "measurement",
    "provenance"
  ],
  "properties": {
    "schema_version": {
      "const": "1.0"
    },
    "kind": {
      "const": "run"
    },
    "client_run_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 255
    },
    "notes": {
      "type": "string",
      "maxLength": 5000
    },
    "visibility": {
      "$ref": "#/$defs/visibility"
    },
    "license": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80
    },
    "outcome": {
      "enum": [
        "completed",
        "failed",
        "interrupted",
        "partial",
        "invalid"
      ]
    },
    "started_at": {
      "type": "string",
      "format": "date-time"
    },
    "ended_at": {
      "type": "string",
      "format": "date-time"
    },
    "supersedes_run_id": {
      "type": "string",
      "maxLength": 64
    },
    "subject": {
      "$ref": "#/$defs/subject"
    },
    "environment": {
      "$ref": "#/$defs/environment"
    },
    "runtime": {
      "$ref": "#/$defs/runtime"
    },
    "workload": {
      "$ref": "#/$defs/workload"
    },
    "measurement": {
      "$ref": "#/$defs/measurementMethod"
    },
    "results": {
      "$ref": "#/$defs/results"
    },
    "trials": {
      "type": "array",
      "maxItems": 1000,
      "items": {
        "$ref": "#/$defs/trial"
      }
    },
    "artifacts": {
      "type": "array",
      "maxItems": 25,
      "items": {
        "$ref": "#/$defs/artifact"
      }
    },
    "failure": {
      "$ref": "#/$defs/failure"
    },
    "provenance": {
      "$ref": "#/$defs/provenance"
    },
    "warnings": {
      "type": "array",
      "maxItems": 100,
      "items": {
        "type": "string",
        "maxLength": 1000
      }
    },
    "extensions": {
      "type": "object",
      "propertyNames": {
        "pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)+$"
      },
      "additionalProperties": true
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "outcome": {
            "const": "failed"
          }
        },
        "required": [
          "outcome"
        ]
      },
      "then": {
        "required": [
          "failure"
        ]
      }
    }
  ],
  "$defs": {
    "visibility": {
      "enum": [
        "public",
        "unlisted",
        "private"
      ]
    },
    "extensions": {
      "type": "object",
      "propertyNames": {
        "pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)+$"
      },
      "additionalProperties": true
    },
    "measurement": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "value",
        "measurement_status"
      ],
      "properties": {
        "value": {
          "type": "number"
        },
        "measurement_status": {
          "enum": [
            "measured",
            "derived",
            "inferred",
            "estimated"
          ]
        },
        "sample_count": {
          "type": "integer",
          "minimum": 0
        },
        "derivation": {
          "type": "string",
          "maxLength": 2000
        },
        "input_run_ids": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "maxLength": 64
          }
        },
        "unit": {
          "type": "string",
          "maxLength": 48
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "measurement_status": {
                "enum": [
                  "derived",
                  "inferred",
                  "estimated"
                ]
              }
            },
            "required": [
              "measurement_status"
            ]
          },
          "then": {
            "required": [
              "derivation"
            ]
          }
        }
      ]
    },
    "percentiles": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "measurement_status"
      ],
      "properties": {
        "measurement_status": {
          "enum": [
            "measured",
            "derived",
            "inferred",
            "estimated"
          ]
        },
        "mean": {
          "type": "number",
          "minimum": 0
        },
        "stddev": {
          "type": "number",
          "minimum": 0
        },
        "p50": {
          "type": "number",
          "minimum": 0
        },
        "p90": {
          "type": "number",
          "minimum": 0
        },
        "p95": {
          "type": "number",
          "minimum": 0
        },
        "p99": {
          "type": "number",
          "minimum": 0
        },
        "sample_count": {
          "type": "integer",
          "minimum": 0
        },
        "derivation": {
          "type": "string",
          "maxLength": 2000
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "measurement_status": {
                "enum": [
                  "derived",
                  "inferred",
                  "estimated"
                ]
              }
            },
            "required": [
              "measurement_status"
            ]
          },
          "then": {
            "required": [
              "derivation"
            ]
          }
        }
      ]
    },
    "tokenShape": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind"
      ],
      "properties": {
        "kind": {
          "enum": [
            "fixed",
            "distribution",
            "histogram",
            "artifact",
            "dataset_native"
          ]
        },
        "value": {
          "type": "integer",
          "minimum": 0
        },
        "mean": {
          "type": "number",
          "minimum": 0
        },
        "min": {
          "type": "integer",
          "minimum": 0
        },
        "max": {
          "type": "integer",
          "minimum": 0
        },
        "p50": {
          "type": "number",
          "minimum": 0
        },
        "p90": {
          "type": "number",
          "minimum": 0
        },
        "p95": {
          "type": "number",
          "minimum": 0
        },
        "p99": {
          "type": "number",
          "minimum": 0
        },
        "artifact_id": {
          "type": "string",
          "maxLength": 128
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "fixed"
              }
            },
            "required": [
              "kind"
            ]
          },
          "then": {
            "required": [
              "value"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "artifact"
              }
            },
            "required": [
              "kind"
            ]
          },
          "then": {
            "required": [
              "artifact_id"
            ]
          }
        }
      ]
    },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "client_artifact_id",
        "kind",
        "filename",
        "media_type",
        "size_bytes",
        "sha256"
      ],
      "properties": {
        "client_artifact_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$"
        },
        "kind": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "filename": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255,
          "pattern": "^[^/\\\\]+$"
        },
        "media_type": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "size_bytes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 26214400
        },
        "sha256": {
          "type": "string",
          "pattern": "^[a-fA-F0-9]{64}$"
        },
        "visibility": {
          "$ref": "#/$defs/visibility"
        },
        "raw_requests_included": {
          "type": "boolean"
        },
        "license": {
          "type": "string",
          "maxLength": 80
        },
        "extensions": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)+$"
          },
          "additionalProperties": true
        }
      }
    },
    "modelMaterialReference": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "role",
        "source",
        "identifier"
      ],
      "properties": {
        "role": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "source": {
          "enum": [
            "huggingface",
            "local",
            "api",
            "other"
          ]
        },
        "identifier": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "revision": {
          "type": "string",
          "maxLength": 255
        },
        "revision_kind": {
          "enum": [
            "commit",
            "tag",
            "version",
            "digest",
            "unknown"
          ]
        },
        "variant": {
          "type": "string",
          "maxLength": 255
        },
        "artifact_digest": {
          "type": "string",
          "maxLength": 255
        },
        "quantization": {
          "type": "object",
          "additionalProperties": true
        },
        "adapters": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "modifications": {
          "type": "array",
          "items": {
            "type": "string",
            "maxLength": 1000
          }
        },
        "extensions": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)+$"
          },
          "additionalProperties": true
        }
      }
    },
    "servingSetup": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind"
      ],
      "properties": {
        "kind": {
          "const": "speculative_decoding"
        },
        "method": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "draft_tokens": {
          "type": "integer",
          "minimum": 1
        },
        "auxiliary_models": {
          "type": "array",
          "maxItems": 32,
          "items": {
            "$ref": "#/$defs/modelMaterialReference"
          }
        },
        "extensions": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)+$"
          },
          "additionalProperties": true
        }
      }
    },
    "subject": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "source",
        "identifier"
      ],
      "properties": {
        "type": {
          "enum": [
            "model",
            "other"
          ]
        },
        "source": {
          "enum": [
            "huggingface",
            "local",
            "api",
            "other"
          ]
        },
        "identifier": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "revision": {
          "type": "string",
          "maxLength": 255
        },
        "revision_kind": {
          "enum": [
            "commit",
            "tag",
            "version",
            "digest",
            "unknown"
          ]
        },
        "architecture": {
          "type": "string",
          "maxLength": 255
        },
        "parameter_count_total": {
          "type": "number",
          "minimum": 0
        },
        "parameter_count_active": {
          "type": "number",
          "minimum": 0
        },
        "modalities": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "maxLength": 80
          }
        },
        "base_model": {
          "type": "string",
          "maxLength": 500
        },
        "variant": {
          "type": "string",
          "maxLength": 255
        },
        "artifact_digest": {
          "type": "string",
          "maxLength": 255
        },
        "quantization": {
          "type": "object",
          "additionalProperties": true
        },
        "adapters": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "modifications": {
          "type": "array",
          "items": {
            "type": "string",
            "maxLength": 1000
          }
        },
        "extensions": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)+$"
          },
          "additionalProperties": true
        }
      }
    },
    "accelerator": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "vendor",
        "model",
        "count"
      ],
      "properties": {
        "vendor": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "model": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "count": {
          "type": "integer",
          "minimum": 1,
          "maximum": 4096
        },
        "memory_bytes_per_device": {
          "type": "integer",
          "minimum": 0
        },
        "architecture": {
          "type": "string",
          "maxLength": 128
        },
        "interconnect": {
          "type": "string",
          "maxLength": 255
        },
        "driver": {
          "type": "string",
          "maxLength": 128
        },
        "extensions": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)+$"
          },
          "additionalProperties": true
        }
      }
    },
    "environment": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "accelerators"
      ],
      "properties": {
        "accelerators": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/accelerator"
          }
        },
        "host_architecture": {
          "type": "string",
          "maxLength": 64
        },
        "cpu": {
          "type": "object",
          "additionalProperties": true
        },
        "system_memory_bytes": {
          "type": "integer",
          "minimum": 0
        },
        "os": {
          "type": "string",
          "maxLength": 128
        },
        "kernel": {
          "type": "string",
          "maxLength": 255
        },
        "driver_versions": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "topology": {
          "type": "string",
          "maxLength": 4000
        },
        "extensions": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)+$"
          },
          "additionalProperties": true
        }
      }
    },
    "runtime": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "engine"
      ],
      "properties": {
        "engine": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "version": {
          "type": "string",
          "maxLength": 128
        },
        "source_revision": {
          "type": "string",
          "maxLength": 255
        },
        "build_identifier": {
          "type": "string",
          "maxLength": 255
        },
        "container": {
          "type": "object",
          "additionalProperties": true
        },
        "launch_command": {
          "type": "string",
          "maxLength": 12000
        },
        "parallelism": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "tensor": {
              "type": "integer",
              "minimum": 1
            },
            "pipeline": {
              "type": "integer",
              "minimum": 1
            },
            "data": {
              "type": "integer",
              "minimum": 1
            },
            "expert": {
              "type": "integer",
              "minimum": 1
            },
            "replicas": {
              "type": "integer",
              "minimum": 1
            }
          }
        },
        "parameters": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "serving": {
          "$ref": "#/$defs/servingSetup"
        },
        "safe_environment": {
          "type": "object",
          "additionalProperties": {
            "type": "string",
            "maxLength": 1000
          }
        },
        "extensions": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)+$"
          },
          "additionalProperties": true
        }
      }
    },
    "workload": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "task",
        "mode",
        "endpoint_type",
        "arrival_process",
        "streaming",
        "input_tokens",
        "output_tokens"
      ],
      "properties": {
        "task": {
          "const": "text_generation"
        },
        "mode": {
          "const": "online"
        },
        "endpoint_type": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "dataset": {
          "type": "object",
          "additionalProperties": true
        },
        "request_count": {
          "type": "integer",
          "minimum": 0
        },
        "warmup_request_count": {
          "type": "integer",
          "minimum": 0
        },
        "concurrency": {
          "type": "integer",
          "minimum": 1
        },
        "request_rate_per_second": {
          "type": [
            "number",
            "null"
          ],
          "exclusiveMinimum": 0
        },
        "arrival_process": {
          "enum": [
            "closed_loop",
            "poisson",
            "burst",
            "trace",
            "sequential",
            "custom"
          ]
        },
        "streaming": {
          "type": "boolean"
        },
        "input_tokens": {
          "$ref": "#/$defs/tokenShape"
        },
        "output_tokens": {
          "$ref": "#/$defs/tokenShape"
        },
        "sampling": {
          "type": "object",
          "additionalProperties": true
        },
        "stopping": {
          "type": "object",
          "additionalProperties": true
        },
        "prefix_behavior": {
          "type": "object",
          "additionalProperties": true
        },
        "tokenizer": {
          "type": "object",
          "additionalProperties": true
        },
        "client": {
          "type": "object",
          "additionalProperties": true
        },
        "random_seed": {
          "type": "integer"
        },
        "extensions": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)+$"
          },
          "additionalProperties": true
        }
      }
    },
    "measurementMethod": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "harness",
        "timing_scope",
        "client_overhead_included"
      ],
      "properties": {
        "harness": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "version": {
          "type": "string",
          "maxLength": 128
        },
        "revision": {
          "type": "string",
          "maxLength": 255
        },
        "benchmark_command": {
          "type": "string",
          "maxLength": 12000
        },
        "timing_scope": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1000
        },
        "client_overhead_included": {
          "type": "boolean"
        },
        "warmup": {
          "type": "string",
          "maxLength": 2000
        },
        "repetitions": {
          "type": "integer",
          "minimum": 1
        },
        "repetition_aggregation": {
          "enum": [
            "pooled_requests",
            "mean_of_trials",
            "median_of_trials",
            "harness_reported",
            "other"
          ]
        },
        "retry_failure_treatment": {
          "type": "string",
          "maxLength": 2000
        },
        "notes": {
          "type": "string",
          "maxLength": 5000
        },
        "extensions": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)+$"
          },
          "additionalProperties": true
        }
      }
    },
    "results": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "duration_seconds": {
          "type": "number",
          "minimum": 0
        },
        "successful_requests": {
          "type": "integer",
          "minimum": 0
        },
        "failed_requests": {
          "type": "integer",
          "minimum": 0
        },
        "total_input_tokens": {
          "type": "integer",
          "minimum": 0
        },
        "total_output_tokens": {
          "type": "integer",
          "minimum": 0
        },
        "throughput": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "requests_per_second": {
              "$ref": "#/$defs/measurement"
            },
            "input_tokens_per_second": {
              "$ref": "#/$defs/measurement"
            },
            "output_tokens_per_second": {
              "$ref": "#/$defs/measurement"
            },
            "total_tokens_per_second": {
              "$ref": "#/$defs/measurement"
            }
          }
        },
        "latency_ms": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "time_to_first_token": {
              "$ref": "#/$defs/percentiles"
            },
            "time_per_output_token": {
              "$ref": "#/$defs/percentiles"
            },
            "inter_token": {
              "$ref": "#/$defs/percentiles"
            },
            "end_to_end": {
              "$ref": "#/$defs/percentiles"
            }
          }
        },
        "additional_metrics": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "value",
              "measurement_status",
              "unit"
            ],
            "properties": {
              "value": {
                "type": "number"
              },
              "measurement_status": {
                "enum": [
                  "measured",
                  "derived",
                  "inferred",
                  "estimated"
                ]
              },
              "sample_count": {
                "type": "integer",
                "minimum": 0
              },
              "derivation": {
                "type": "string",
                "maxLength": 2000
              },
              "input_run_ids": {
                "type": "array",
                "uniqueItems": true,
                "items": {
                  "type": "string",
                  "maxLength": 64
                }
              },
              "unit": {
                "type": "string",
                "maxLength": 48
              }
            },
            "allOf": [
              {
                "if": {
                  "properties": {
                    "measurement_status": {
                      "enum": [
                        "derived",
                        "inferred",
                        "estimated"
                      ]
                    }
                  },
                  "required": [
                    "measurement_status"
                  ]
                },
                "then": {
                  "required": [
                    "derivation"
                  ]
                }
              }
            ]
          }
        }
      }
    },
    "trial": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "client_trial_id",
        "outcome"
      ],
      "properties": {
        "client_trial_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "outcome": {
          "enum": [
            "completed",
            "failed",
            "interrupted",
            "partial",
            "invalid"
          ]
        },
        "started_at": {
          "type": "string",
          "format": "date-time"
        },
        "ended_at": {
          "type": "string",
          "format": "date-time"
        },
        "duration_seconds": {
          "type": "number",
          "minimum": 0
        },
        "results": {
          "$ref": "#/$defs/results"
        },
        "notes": {
          "type": "string",
          "maxLength": 4000
        }
      }
    },
    "failure": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "stage",
        "category",
        "message_sanitized"
      ],
      "properties": {
        "stage": {
          "type": "string",
          "maxLength": 128
        },
        "category": {
          "type": "string",
          "maxLength": 128
        },
        "message_sanitized": {
          "type": "string",
          "maxLength": 4000
        },
        "exit_code": {
          "type": "integer"
        },
        "reproducible": {
          "type": "boolean"
        }
      }
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source"
      ],
      "properties": {
        "source": {
          "enum": [
            "agent",
            "cli",
            "api",
            "import",
            "other"
          ]
        },
        "tool": {
          "type": "string",
          "maxLength": 128
        },
        "tool_version": {
          "type": "string",
          "maxLength": 80
        },
        "generated_at": {
          "type": "string",
          "format": "date-time"
        },
        "notes": {
          "type": "string",
          "maxLength": 2000
        }
      }
    }
  }
}
