{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dist.ota.run/spec/json-schemas/latest/proof-runtime.json",
  "title": "ota proof runtime --json",
  "oneOf": [
    {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "ok",
        "execution_id",
        "proof_verdict",
        "path",
        "mode",
        "phase",
        "stage_family",
        "proof_scope",
        "summary"
      ],
      "properties": {
        "ok": {
          "type": "boolean",
          "description": "Execution/readiness success only. Consumers must use proof_verdict together with not_proved to interpret proof breadth."
        },
        "execution_id": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" },
        "proof_verdict": {
          "type": "string",
          "enum": ["passed", "passed_with_unproven_boundaries", "failed"]
        },
        "path": { "type": "string" },
        "mode": { "const": "runtime-proof" },
        "workflow": { "type": "string" },
        "phase": { "type": "string" },
        "stage_family": { "const": "proof" },
        "proof_scope": { "$ref": "#/$defs/proofScope" },
        "crossing_evidence": { "$ref": "#/$defs/crossingEvidence" },
        "execution_boundary": { "$ref": "#/$defs/executionBoundary" },
        "dependency_evidence": {
          "type": "array",
          "items": { "$ref": "#/$defs/dependencyEvidence" }
        },
        "seam_observations": {
          "type": "array",
          "items": { "$ref": "#/$defs/seamObservation" }
        },
        "negative_control": { "$ref": "#/$defs/negativeControl" },
        "not_proved": {
          "type": "array",
          "items": { "$ref": "#/$defs/proofNotProved" }
        },
        "summary": { "$ref": "./doctor.json#/properties/summary" },
        "artifact_routing": {
          "type": "array",
          "items": { "$ref": "./shared.json#/$defs/artifactRoute" }
        },
        "workflow_env_artifacts": {
          "type": "array",
          "items": { "$ref": "#/$defs/workflowEnvArtifact" }
        },
        "artifacts": {
          "type": "object",
          "additionalProperties": false,
          "required": ["topology", "doctor", "up_log"],
          "properties": {
            "topology": { "type": "string" },
            "doctor": { "type": "string" },
            "up_log": { "type": "string" }
          }
        },
        "failure_class": { "type": "string" },
        "error": { "type": "string" },
        "cleanup_failure": { "$ref": "#/$defs/cleanupFailure" },
        "likely_cause": { "type": "string" },
        "likely_cause_evidence": { "$ref": "#/$defs/likelyCauseEvidence" },
        "next": { "type": "string" }
      }
    },
    {
      "type": "object",
      "additionalProperties": false,
      "required": ["ok", "path"],
      "properties": {
        "ok": { "const": false },
        "path": { "type": "string" },
        "code": { "type": "string" },
        "execution_started": { "const": false },
        "preflight": {
          "$ref": "./run-preview.json#/$defs/replayInputIdentityFailure/properties/preflight"
        },
        "replay_input_policy": {
          "$ref": "./doctor.json#/$defs/replayInputPolicy"
        },
        "crossing_grant_admission": {
          "$ref": "./tasks.json#/$defs/governanceRefusalRecord"
        },
        "summary": {
          "type": ["object", "null"]
        },
        "errors": {
          "type": "array",
          "items": { "type": "string" }
        },
        "error": { "type": "string" },
        "warnings": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    }
  ],
  "$defs": {
    "crossingEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "transaction_id",
        "scope_identity"
      ],
      "properties": {
        "receipt_archive_identity": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" },
        "receipt_archive_path": { "type": "string" },
        "transaction_id": { "type": "string" },
        "proof_execution_id": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" },
        "scope_identity": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" },
        "authority": {
          "$ref": "./receipt.json#/oneOf/0/properties/receipt/properties/crossing/properties/authority"
        }
      },
      "oneOf": [
        {
          "required": ["receipt_archive_identity", "receipt_archive_path"],
          "not": { "required": ["authority"] }
        },
        {
          "required": ["authority", "proof_execution_id"],
          "properties": {
            "authority": { "required": ["transaction"] }
          },
          "not": {
            "anyOf": [
              { "required": ["receipt_archive_identity"] },
              { "required": ["receipt_archive_path"] }
            ]
          }
        }
      ]
    },
    "proofScope": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "proof_class"],
      "properties": {
        "kind": {
          "type": "string",
          "enum": ["runtime_path"]
        },
        "proof_class": {
          "type": "string",
          "enum": ["slice_proof"]
        },
        "workflow": { "type": ["string", "null"] },
        "task": { "type": ["string", "null"] },
        "intent": { "type": ["string", "null"] }
      }
    },
    "executionBoundary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schema_version",
        "identity",
        "asserted_target_closure",
        "derivation_input_closure",
        "prerequisites",
        "edges",
        "target_freshness",
        "derivation_posture"
      ],
      "properties": {
        "schema_version": { "const": 1 },
        "identity": { "type": "string", "pattern": "^sha256:" },
        "asserted_target_closure": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string" }
        },
        "derivation_input_closure": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string" }
        },
        "prerequisites": {
          "type": "array",
          "items": { "$ref": "#/$defs/boundaryPrerequisite" }
        },
        "edges": {
          "type": "array",
          "items": { "$ref": "#/$defs/boundaryEdge" }
        },
        "target_freshness": {
          "type": "string",
          "enum": ["cold_start_verified", "persistent_state_reused", "unknown"]
        },
        "derivation_posture": {
          "type": "object",
          "additionalProperties": false,
          "required": ["materialization", "immutable_inputs"],
          "properties": {
            "materialization": {
              "type": "string",
              "enum": ["fully_derived", "cache_assisted", "unknown"]
            },
            "immutable_inputs": {
              "type": "string",
              "enum": ["none", "inherited_immutable", "unknown"]
            }
          }
        }
      }
    },
    "boundaryPrerequisite": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "class", "precondition", "state"],
      "properties": {
        "id": { "type": "string" },
        "class": {
          "type": "string",
          "enum": ["filesystem", "dependency_cache", "service", "volume", "environment", "image_runtime"]
        },
        "declared_artifacts": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string" }
        },
        "declared_producers": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string" }
        },
        "precondition": { "type": "string", "enum": ["absent", "present", "cleared", "unknown"] },
        "precondition_identity": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
        "state": { "type": "string", "enum": ["created_this_run", "declared_immutable_input", "verified_reused", "unknown"] },
        "materializations": { "type": "array", "items": { "$ref": "#/$defs/boundaryMaterialization" } },
        "assertions": { "type": "array", "items": { "$ref": "#/$defs/boundaryAssertion" } },
        "terminal_established_by_edge_id": { "type": "string" },
        "ambient_boundary": { "type": "string" }
      }
    },
    "boundaryMaterialization": {
      "type": "object",
      "additionalProperties": false,
      "required": ["edge_id", "producer_execution", "identity", "evidence_class", "sequence"],
      "properties": {
        "edge_id": { "type": "string" },
        "producer_execution": { "type": "string" },
        "identity": { "type": "string" },
        "evidence_class": { "type": "string", "enum": ["derived", "attested"] },
        "sequence": { "type": "integer", "minimum": 0 }
      }
    },
    "boundaryAssertion": {
      "type": "object",
      "additionalProperties": false,
      "required": ["edge_id", "consumer_execution", "identity", "evidence_class", "sequence", "established_by_edge_id"],
      "properties": {
        "edge_id": { "type": "string" },
        "consumer_execution": { "type": "string" },
        "identity": { "type": "string" },
        "evidence_class": { "type": "string", "enum": ["derived", "attested"] },
        "sequence": { "type": "integer", "minimum": 0 },
        "established_by_edge_id": { "type": "string" }
      }
    },
    "boundaryEdge": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "kind", "prerequisite_id", "execution_id", "boundary_id", "scope", "identity", "evidence_class", "sequence"],
      "properties": {
        "id": { "type": "string" },
        "kind": { "type": "string", "enum": ["produced", "asserted_at", "consumed", "derived_from", "reused_from", "cleared_before"] },
        "prerequisite_id": { "type": "string" },
        "execution_id": { "type": "string" },
        "boundary_id": { "type": "string" },
        "scope": { "type": "string" },
        "identity": { "type": "string" },
        "evidence_class": { "type": "string", "enum": ["derived", "attested"] },
        "sequence": { "type": "integer", "minimum": 0 }
      }
    },
    "proofNotProved": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "relative_to", "source"],
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "functional_runtime_not_proved",
            "dependency_exercise_not_proved",
            "dependency_causality_not_proved",
            "dependency_output_shaping_not_proved",
            "external_network_path_not_proved",
            "broader_repo_completion_not_proved"
          ]
        },
        "relative_to": {
          "type": "string",
          "enum": ["runtime_path"]
        },
        "source": {
          "type": "string",
          "enum": ["contract_lane", "proof_scope"]
        },
        "dependency_id": { "type": "string" },
        "declared_by_tasks": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string" }
        },
        "declared_by_workflows": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string" }
        },
        "proof_obligation_id": { "type": "string" },
        "reason": { "type": "string" }
      }
    },
    "dependencyEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["dependency_id", "observation"],
      "properties": {
        "dependency_id": { "type": "string" },
        "proof_obligation_id": { "type": "string" },
        "level": {
          "type": "string",
          "enum": ["reachable", "exercised", "fault_tested"]
        },
        "interaction_attempted": { "const": true },
        "observation": { "$ref": "#/$defs/dependencyObservation" },
        "declared_by_tasks": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string" }
        },
        "declared_by_workflows": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string" }
        },
        "negative_control": { "$ref": "#/$defs/dependencyNegativeControl" }
      },
      "allOf": [
        {
          "if": {
            "properties": { "level": { "const": "fault_tested" } },
            "required": ["level"]
          },
          "then": {
            "properties": {
              "negative_control": {
                "properties": { "status": { "const": "validated" } },
                "required": ["status"]
              }
            },
            "required": ["negative_control"]
          }
        },
        {
          "if": {
            "properties": {
              "negative_control": {
                "properties": { "status": { "const": "validated" } },
                "required": ["status"]
              }
            },
            "required": ["negative_control"]
          },
          "then": {
            "properties": { "level": { "const": "fault_tested" } },
            "required": ["level"]
          }
        }
      ]
    },
    "dependencyObservation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["origin", "evidence_class"],
      "properties": {
        "origin": {
          "type": "string",
          "enum": ["caller_side", "dependency_side", "round_trip_effect"]
        },
        "evidence_class": {
          "type": "string",
          "enum": ["derived", "attested"]
        }
      }
    },
    "dependencyNegativeControl": {
      "type": "object",
      "additionalProperties": false,
      "required": ["evidence_class", "status", "same_obligation"],
      "properties": {
        "evidence_class": {
          "const": "derived",
          "description": "Runner-derived projection of the canonical top-level negative_control record."
        },
        "status": { "type": "string", "enum": ["unrun", "invalid", "validated"] },
        "same_obligation": { "type": "boolean" },
        "negative_control_id": { "type": "string" },
        "failure_mode": { "$ref": "#/$defs/negativeControlFailureMode" },
        "failure_attestation_digest": { "type": "string" }
      },
      "allOf": [
        {
          "if": {
            "properties": { "status": { "const": "validated" } },
            "required": ["status"]
          },
          "then": {
            "properties": {
              "same_obligation": { "const": true },
              "failure_mode": { "const": "expected_missing_effect" }
            },
            "required": [
              "negative_control_id",
              "failure_mode",
              "failure_attestation_digest"
            ]
          },
          "else": {
            "properties": { "same_obligation": { "const": false } },
            "not": {
              "anyOf": [
                { "required": ["negative_control_id"] },
                { "required": ["failure_attestation_digest"] }
              ]
            }
          }
        }
      ]
    },
    "seamObservation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "dependency_id",
        "producer_task",
        "transaction_id",
        "observer_task",
        "marker_env",
        "outcome",
        "proof_scope_ref",
        "evidence_class"
      ],
      "properties": {
        "id": { "type": "string" },
        "dependency_id": { "type": "string" },
        "producer_task": { "type": "string" },
        "transaction_id": { "type": "string" },
        "observer_task": { "type": "string" },
        "marker_env": { "type": "string" },
        "outcome": {
          "type": "string",
          "enum": ["observed", "observation_failed", "observation_could_not_run"]
        },
        "proof_scope_ref": { "type": "string" },
        "evidence_class": { "type": "string", "enum": ["derived", "attested"] },
        "attestation_digest": { "type": "string" },
        "exit_code": { "type": "integer" },
        "detail": { "type": "string" }
      }
    },
    "negativeControl": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "dependency_id",
        "obligation_id",
        "control_task",
        "intervention",
        "expected_failure",
        "outcome",
        "status",
        "proof_scope_ref",
        "evidence_class"
      ],
      "properties": {
        "id": { "type": "string" },
        "dependency_id": { "type": "string" },
        "obligation_id": { "type": "string" },
        "transaction_id": { "type": "string" },
        "control_task": { "type": "string" },
        "intervention": { "$ref": "#/$defs/negativeControlIntervention" },
        "expected_failure": { "type": "string" },
        "outcome": {
          "type": "string",
          "enum": [
            "expected_obligation_failed",
            "nonzero_exit_observed",
            "unexpected_success",
            "control_could_not_run"
          ]
        },
        "status": { "type": "string", "enum": ["unrun", "invalid", "validated"] },
        "failure_mode": { "$ref": "#/$defs/negativeControlFailureMode" },
        "proof_scope_ref": { "type": "string" },
        "evidence_class": { "type": "string", "enum": ["derived", "attested"] },
        "failure_attestation_digest": { "type": "string" },
        "exit_code": { "type": "integer" },
        "detail": { "type": "string" }
      },
      "allOf": [
        {
          "if": {
            "properties": { "status": { "const": "validated" } },
            "required": ["status"]
          },
          "then": {
            "properties": {
              "outcome": { "const": "expected_obligation_failed" },
              "failure_mode": { "const": "expected_missing_effect" },
              "evidence_class": { "const": "attested" }
            },
            "required": ["failure_mode", "failure_attestation_digest"]
          }
        }
      ]
    },
    "negativeControlIntervention": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "id"],
      "properties": {
        "kind": { "type": "string" },
        "id": { "type": "string" }
      }
    },
    "negativeControlFailureMode": {
      "type": "string",
      "enum": [
        "expected_missing_effect",
        "setup_failure",
        "timeout",
        "crash",
        "transport_failure",
        "wrong_assertion",
        "unclassified_nonzero"
      ]
    },
    "cleanupFailure": {
      "type": "object",
      "additionalProperties": false,
      "required": ["summary", "error", "why", "next"],
      "properties": {
        "summary": { "type": "string" },
        "error": { "type": "string" },
        "why": { "type": "string" },
        "next": {
          "type": "array",
          "items": { "type": "string" }
        },
        "reason": {
          "type": "string",
          "enum": ["engine_unavailable", "other", "active_execution_conflict"]
        },
        "engine": { "type": "string" },
        "action": { "type": "string" },
        "resource_kind": {
          "type": "string",
          "enum": [
            "host_service",
            "persistent_container",
            "dependency_isolation_volume",
            "stale_containers"
          ]
        },
        "resource_name": { "type": ["string", "null"] },
        "details": { "type": "string" },
        "registry_path": { "type": "string" },
        "reasons": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "active_execution_present",
              "host_service",
              "compose_project",
              "persistent_backend_family",
              "env_materialization_path",
              "write_path",
              "runtime_listener",
              "service_task"
            ]
          }
        },
        "active_execution_count": { "type": "integer", "minimum": 0 },
        "owners": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "task",
              "execution_mode",
              "host_services",
              "compose_projects",
              "persistent_backend_families",
              "env_materialization_paths",
              "pid",
              "started_at"
            ],
            "properties": {
              "task": { "type": "string" },
              "requested_mode": { "type": ["string", "null"] },
              "execution_mode": { "type": "string" },
              "lifecycle": { "type": ["string", "null"] },
              "host_services": {
                "type": "array",
                "items": { "type": "string" }
              },
              "compose_projects": {
                "type": "array",
                "items": { "type": "string" }
              },
              "persistent_backend_families": {
                "type": "array",
                "items": { "type": "string" }
              },
              "env_materialization_paths": {
                "type": "array",
                "items": { "type": "string" }
              },
              "write_paths": {
                "type": "array",
                "items": { "type": "string" }
              },
              "write_owners": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["path", "namespace"],
                  "properties": {
                    "path": { "type": "string" },
                    "namespace": { "type": "string" }
                  }
                }
              },
              "runtime_owners": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["task", "namespace", "allocation"],
                  "properties": {
                    "task": { "type": "string" },
                    "listener": { "type": ["string", "null"] },
                    "namespace": { "type": "string" },
                    "protocol": { "type": ["string", "null"] },
                    "address": { "type": ["string", "null"] },
                    "port": { "type": ["integer", "null"], "minimum": 1, "maximum": 65535 },
                    "allocation": { "enum": ["fixed", "managed_dynamic", "isolated", "unresolved"] }
                  }
                }
              },
              "service_task": { "type": "boolean" },
              "pid": { "type": "integer", "minimum": 0 },
              "started_at": { "type": "string" }
            }
          }
        }
      }
    },
    "likelyCauseEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "artifact"],
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "auth_credential_failure",
            "dns_service_name_resolution_failure",
            "readiness_target_mismatch",
            "loopback_service_drift",
            "missing_env",
            "install_or_toolchain_failure",
            "detached_run_output",
            "bind_conflict"
          ]
        },
        "artifact": { "type": "string" },
        "signal": { "type": ["string", "null"] },
        "listener": { "type": ["string", "null"] },
        "variable": { "type": ["string", "null"] },
        "service": { "type": ["string", "null"] },
        "host": { "type": ["string", "null"] },
        "port": { "type": ["integer", "null"], "minimum": 0 },
        "declared_target": { "type": ["string", "null"] },
        "observed_target": { "type": ["string", "null"] }
      }
    },
    "workflowEnvArtifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "kind", "exists"],
      "properties": {
        "path": { "type": "string" },
        "kind": { "type": "string" },
        "includes": {
          "type": "array",
          "items": { "type": "string" }
        },
        "exists": { "type": "boolean" },
        "profile": { "type": ["string", "null"] },
        "consumers": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    }
  }
}
