{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "ChronoLens diagnostic report v1",
  "description": "Core JSON diagnostic export. Error details use documented code-specific fields. JSON Schema does not verify graph mathematics, reference integrity, or the Int64 numeric range of strings.",
  "type": "object",
  "properties": {
    "schema_version": {
      "const": "chronolens.diagnostic.v1"
    },
    "producer": {
      "type": "object",
      "properties": {
        "module": {
          "const": "Mitsuha11zz/chronolens"
        },
        "version": {
          "type": "string"
        }
      },
      "required": [
        "module",
        "version"
      ],
      "additionalProperties": false
    },
    "time_unit": {
      "const": "us"
    },
    "int64_encoding": {
      "const": "decimal_string"
    },
    "status": {
      "enum": [
        "not_analyzed",
        "input_invalid",
        "input_limited",
        "pipeline_failed",
        "feasible",
        "infeasible",
        "analysis_incomplete",
        "no_constraints"
      ]
    },
    "input": {
      "anyOf": [
        {
          "$ref": "#/$defs/input"
        },
        {
          "type": "null"
        }
      ]
    },
    "coverage": {
      "anyOf": [
        {
          "$ref": "#/$defs/coverage"
        },
        {
          "type": "null"
        }
      ]
    },
    "model": {
      "anyOf": [
        {
          "$ref": "#/$defs/model"
        },
        {
          "type": "null"
        }
      ]
    },
    "summary": {
      "anyOf": [
        {
          "$ref": "#/$defs/summary"
        },
        {
          "type": "null"
        }
      ]
    },
    "has_conflicts": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ]
    },
    "events": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/event"
      }
    },
    "messages": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/message"
      }
    },
    "unresolved_groups": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/unresolved"
      }
    },
    "constraints": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/constraint"
      }
    },
    "components": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/component"
      }
    },
    "failure": {
      "anyOf": [
        {
          "$ref": "#/$defs/failure"
        },
        {
          "type": "null"
        }
      ]
    },
    "assumptions": {
      "type": "array",
      "items": {
        "enum": [
          "fixed_offsets_within_analysis_window",
          "only_explicit_unique_message_pairs_create_message_constraints",
          "relation_tolerance_and_priors_are_assumptions",
          "representative_offsets_are_not_utc",
          "components_have_independent_coordinates",
          "interval_endpoints_are_marginal",
          "negative_cycles_do_not_determine_root_cause"
        ]
      }
    }
  },
  "required": [
    "schema_version",
    "producer",
    "time_unit",
    "int64_encoding",
    "status",
    "input",
    "coverage",
    "model",
    "summary",
    "has_conflicts",
    "events",
    "messages",
    "unresolved_groups",
    "constraints",
    "components",
    "failure",
    "assumptions"
  ],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "status": {
            "enum": [
              "not_analyzed",
              "input_invalid",
              "input_limited",
              "pipeline_failed"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "coverage": {
            "type": "null"
          },
          "model": {
            "type": "null"
          },
          "summary": {
            "type": "null"
          },
          "has_conflicts": {
            "type": "null"
          },
          "messages": {
            "maxItems": 0
          },
          "unresolved_groups": {
            "maxItems": 0
          },
          "constraints": {
            "maxItems": 0
          },
          "components": {
            "maxItems": 0
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "status": {
            "enum": [
              "feasible",
              "infeasible",
              "analysis_incomplete",
              "no_constraints"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "coverage": {
            "$ref": "#/$defs/coverage"
          },
          "model": {
            "$ref": "#/$defs/model"
          },
          "summary": {
            "$ref": "#/$defs/summary"
          },
          "failure": {
            "type": "null"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "status": {
            "const": "infeasible"
          }
        }
      },
      "then": {
        "properties": {
          "has_conflicts": {
            "const": true
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "status": {
            "enum": [
              "feasible",
              "no_constraints"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "has_conflicts": {
            "const": false
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "status": {
            "const": "analysis_incomplete"
          }
        }
      },
      "then": {
        "properties": {
          "has_conflicts": {
            "enum": [
              true,
              null
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "status": {
            "const": "pipeline_failed"
          }
        }
      },
      "then": {
        "properties": {
          "failure": {
            "$ref": "#/$defs/failure"
          }
        }
      }
    }
  ],
  "$defs": {
    "i64": {
      "type": "string",
      "pattern": "^(0|-?[1-9][0-9]*)$",
      "maxLength": 20,
      "description": "Canonical signed Int64 decimal. Numeric range is enforced by producer types; this schema checks string shape."
    },
    "key": {
      "type": "object",
      "properties": {
        "trace_id": {
          "type": "string"
        },
        "message_id": {
          "type": "string"
        },
        "attempt": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        }
      },
      "required": [
        "trace_id",
        "message_id",
        "attempt"
      ],
      "additionalProperties": false
    },
    "source": {
      "type": "object",
      "properties": {
        "path": {
          "type": "string"
        },
        "line": {
          "type": "integer",
          "minimum": 1,
          "maximum": 2147483647
        }
      },
      "required": [
        "path",
        "line"
      ],
      "additionalProperties": false
    },
    "event": {
      "type": "object",
      "properties": {
        "event_id": {
          "type": "string"
        },
        "clock_id": {
          "type": "string"
        },
        "trace_id": {
          "type": "string"
        },
        "message_id": {
          "type": "string"
        },
        "attempt": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "kind": {
          "enum": [
            "send",
            "receive"
          ]
        },
        "ts_us": {
          "$ref": "#/$defs/i64"
        },
        "source": {
          "anyOf": [
            {
              "$ref": "#/$defs/source"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "event_id",
        "clock_id",
        "trace_id",
        "message_id",
        "attempt",
        "kind",
        "ts_us",
        "source"
      ],
      "additionalProperties": false
    },
    "origin": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "message"
            },
            "send_event_id": {
              "type": "string"
            },
            "receive_event_id": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "send_event_id",
            "receive_event_id"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "prior"
            },
            "label": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "label"
          ],
          "additionalProperties": false
        }
      ]
    },
    "issue": {
      "type": "object",
      "properties": {
        "code": {
          "enum": [
            "invalid_json",
            "expected_object",
            "empty_input",
            "missing_field",
            "wrong_type",
            "unknown_field",
            "duplicate_field",
            "invalid_value",
            "duplicate_event_id",
            "limit_exceeded"
          ]
        },
        "line": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 1
            },
            {
              "type": "null"
            }
          ]
        },
        "details": {
          "type": "object"
        }
      },
      "required": [
        "code",
        "line",
        "details"
      ],
      "additionalProperties": false
    },
    "input": {
      "type": "object",
      "properties": {
        "validation": {
          "enum": [
            "valid",
            "invalid"
          ]
        },
        "scan_status": {
          "enum": [
            "complete",
            "limited"
          ]
        },
        "limited_by": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "records_seen": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "accepted_event_count": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "events_are_preview": {
          "type": "boolean"
        },
        "issues": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/issue"
          }
        }
      },
      "required": [
        "validation",
        "scan_status",
        "limited_by",
        "records_seen",
        "accepted_event_count",
        "events_are_preview",
        "issues"
      ],
      "additionalProperties": false
    },
    "coverage": {
      "type": "object",
      "properties": {
        "total_events": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "group_count": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "paired_groups": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "unresolved_groups": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "missing_groups": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "ambiguous_groups": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "pairing_status": {
          "enum": [
            "no_events",
            "fully_paired",
            "has_unresolved_groups"
          ]
        },
        "log_completeness": {
          "const": "unknown"
        }
      },
      "required": [
        "total_events",
        "group_count",
        "paired_groups",
        "unresolved_groups",
        "missing_groups",
        "ambiguous_groups",
        "pairing_status",
        "log_completeness"
      ],
      "additionalProperties": false
    },
    "prior": {
      "type": "object",
      "properties": {
        "label": {
          "type": "string"
        },
        "clock_id": {
          "type": "string"
        },
        "reference_clock": {
          "type": "string"
        },
        "lower_us": {
          "anyOf": [
            {
              "$ref": "#/$defs/i64"
            },
            {
              "type": "null"
            }
          ]
        },
        "upper_us": {
          "anyOf": [
            {
              "$ref": "#/$defs/i64"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "label",
        "clock_id",
        "reference_clock",
        "lower_us",
        "upper_us"
      ],
      "additionalProperties": false,
      "anyOf": [
        {
          "properties": {
            "lower_us": {
              "$ref": "#/$defs/i64"
            }
          }
        },
        {
          "properties": {
            "upper_us": {
              "$ref": "#/$defs/i64"
            }
          }
        }
      ]
    },
    "model": {
      "type": "object",
      "properties": {
        "clock_model": {
          "const": "fixed_offset_per_clock_id"
        },
        "time_definition": {
          "const": "observed_timestamp_us + offset_us"
        },
        "constraint_definition": {
          "const": "offset(left) - offset(right) <= upper_bound_us"
        },
        "reference_scope": {
          "const": "weak_component"
        },
        "relation_tolerance_us": {
          "$ref": "#/$defs/i64"
        },
        "priors": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/prior"
          }
        },
        "resource_limits": {
          "type": "null"
        },
        "resource_limits_recording": {
          "const": "not_available_in_source_reports"
        }
      },
      "required": [
        "clock_model",
        "time_definition",
        "constraint_definition",
        "reference_scope",
        "relation_tolerance_us",
        "priors",
        "resource_limits",
        "resource_limits_recording"
      ],
      "additionalProperties": false
    },
    "message": {
      "type": "object",
      "properties": {
        "key": {
          "$ref": "#/$defs/key"
        },
        "send_event_id": {
          "type": "string"
        },
        "receive_event_id": {
          "type": "string"
        }
      },
      "required": [
        "key",
        "send_event_id",
        "receive_event_id"
      ],
      "additionalProperties": false
    },
    "unresolved": {
      "type": "object",
      "properties": {
        "key": {
          "$ref": "#/$defs/key"
        },
        "send_event_ids": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "receive_event_ids": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "issues": {
          "type": "array",
          "items": {
            "enum": [
              "missing_send",
              "missing_receive",
              "ambiguous"
            ]
          },
          "minItems": 1
        }
      },
      "required": [
        "key",
        "send_event_ids",
        "receive_event_ids",
        "issues"
      ],
      "additionalProperties": false
    },
    "evidence": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "message"
            },
            "key": {
              "$ref": "#/$defs/key"
            },
            "send_event_id": {
              "type": "string"
            },
            "receive_event_id": {
              "type": "string"
            },
            "relation_tolerance_us": {
              "$ref": "#/$defs/i64"
            }
          },
          "required": [
            "kind",
            "key",
            "send_event_id",
            "receive_event_id",
            "relation_tolerance_us"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "prior"
            },
            "prior_label": {
              "type": "string"
            },
            "bound": {
              "enum": [
                "lower",
                "upper"
              ]
            }
          },
          "required": [
            "kind",
            "prior_label",
            "bound"
          ],
          "additionalProperties": false
        }
      ]
    },
    "constraint": {
      "type": "object",
      "properties": {
        "index": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "left_clock": {
          "type": "string"
        },
        "right_clock": {
          "type": "string"
        },
        "upper_bound_us": {
          "$ref": "#/$defs/i64"
        },
        "edge_from": {
          "type": "string"
        },
        "edge_to": {
          "type": "string"
        },
        "origin": {
          "$ref": "#/$defs/origin"
        },
        "evidence": {
          "$ref": "#/$defs/evidence"
        }
      },
      "required": [
        "index",
        "left_clock",
        "right_clock",
        "upper_bound_us",
        "edge_from",
        "edge_to",
        "origin",
        "evidence"
      ],
      "additionalProperties": false
    },
    "stats": {
      "type": "object",
      "properties": {
        "clock_count": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "constraint_count": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "passes": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "edge_visits": {
          "$ref": "#/$defs/i64"
        }
      },
      "required": [
        "clock_count",
        "constraint_count",
        "passes",
        "edge_visits"
      ],
      "additionalProperties": false
    },
    "bound": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "finite"
            },
            "value_us": {
              "$ref": "#/$defs/i64"
            }
          },
          "required": [
            "kind",
            "value_us"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "unbounded"
            }
          },
          "required": [
            "kind"
          ],
          "additionalProperties": false
        }
      ]
    },
    "offset": {
      "type": "object",
      "properties": {
        "clock_id": {
          "type": "string"
        },
        "offset_us": {
          "$ref": "#/$defs/i64"
        }
      },
      "required": [
        "clock_id",
        "offset_us"
      ],
      "additionalProperties": false
    },
    "interval": {
      "type": "object",
      "properties": {
        "clock_id": {
          "type": "string"
        },
        "lower": {
          "$ref": "#/$defs/bound"
        },
        "upper": {
          "$ref": "#/$defs/bound"
        }
      },
      "required": [
        "clock_id",
        "lower",
        "upper"
      ],
      "additionalProperties": false
    },
    "cycle": {
      "type": "object",
      "properties": {
        "constraint_indices": {
          "type": "array",
          "items": {
            "type": "integer",
            "minimum": 0,
            "maximum": 2147483647
          },
          "minItems": 1
        },
        "total_weight_us": {
          "allOf": [
            {
              "$ref": "#/$defs/i64"
            },
            {
              "pattern": "^-[1-9][0-9]*$"
            }
          ]
        },
        "minimum_conflict_guaranteed": {
          "const": false
        }
      },
      "required": [
        "constraint_indices",
        "total_weight_us",
        "minimum_conflict_guaranteed"
      ],
      "additionalProperties": false
    },
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "enum": [
            "invalid_limit",
            "clock_limit_exceeded",
            "constraint_limit_exceeded",
            "empty_clock_id",
            "unknown_reference_clock",
            "offset_overflow",
            "bound_overflow",
            "edge_visit_limit_exceeded",
            "arithmetic_overflow",
            "invalid_witness",
            "invalid_input",
            "invalid_event_limit",
            "event_limit_exceeded",
            "duplicate_event_id",
            "invalid_tolerance",
            "invalid_prior_field",
            "empty_prior_bounds",
            "inverted_prior_range",
            "duplicate_prior_label",
            "invalid_constraint_limit",
            "invalid_source_path"
          ]
        },
        "details": {
          "type": "object"
        }
      },
      "required": [
        "code",
        "details"
      ],
      "additionalProperties": false
    },
    "failure": {
      "type": "object",
      "properties": {
        "stage": {
          "enum": [
            "input_configuration",
            "correlation",
            "constraint_build",
            "solver"
          ]
        },
        "error": {
          "$ref": "#/$defs/error"
        }
      },
      "required": [
        "stage",
        "error"
      ],
      "additionalProperties": false
    },
    "component": {
      "type": "object",
      "properties": {
        "component_id": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "clock_ids": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1
        },
        "reference_clock": {
          "type": "string"
        },
        "constraint_indices": {
          "type": "array",
          "items": {
            "type": "integer",
            "minimum": 0,
            "maximum": 2147483647
          }
        },
        "status": {
          "enum": [
            "feasible",
            "infeasible",
            "failed"
          ]
        },
        "stats": {
          "$ref": "#/$defs/stats"
        },
        "offsets": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "$ref": "#/$defs/offset"
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "intervals": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "$ref": "#/$defs/interval"
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "cycle": {
          "anyOf": [
            {
              "$ref": "#/$defs/cycle"
            },
            {
              "type": "null"
            }
          ]
        },
        "error": {
          "anyOf": [
            {
              "$ref": "#/$defs/error"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "component_id",
        "clock_ids",
        "reference_clock",
        "constraint_indices",
        "status",
        "stats",
        "offsets",
        "intervals",
        "cycle",
        "error"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "status": {
                "const": "feasible"
              }
            }
          },
          "then": {
            "properties": {
              "offsets": {
                "type": "array",
                "items": {
                  "$ref": "#/$defs/offset"
                }
              },
              "intervals": {
                "type": "array",
                "items": {
                  "$ref": "#/$defs/interval"
                }
              },
              "cycle": {
                "type": "null"
              },
              "error": {
                "type": "null"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "status": {
                "const": "infeasible"
              }
            }
          },
          "then": {
            "properties": {
              "offsets": {
                "type": "null"
              },
              "intervals": {
                "type": "null"
              },
              "cycle": {
                "$ref": "#/$defs/cycle"
              },
              "error": {
                "type": "null"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "status": {
                "const": "failed"
              }
            }
          },
          "then": {
            "properties": {
              "offsets": {
                "type": "null"
              },
              "intervals": {
                "type": "null"
              },
              "cycle": {
                "type": "null"
              },
              "error": {
                "$ref": "#/$defs/error"
              }
            }
          }
        }
      ]
    },
    "summary": {
      "type": "object",
      "properties": {
        "component_count": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "feasible_components": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "infeasible_components": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "failed_components": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "unbounded_clock_count": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "stats": {
          "$ref": "#/$defs/stats"
        }
      },
      "required": [
        "component_count",
        "feasible_components",
        "infeasible_components",
        "failed_components",
        "unbounded_clock_count",
        "stats"
      ],
      "additionalProperties": false
    }
  }
}
