{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aiwg.io/schemas/decision/RulesetResult.v1alpha2.schema.json",
  "$defs": {
    "acceptanceEvidence": {
      "type": "object",
      "properties": {
        "policyVersion": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" },
        "uncertaintyProfile": { "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }] },
        "disposition": { "enum": ["act", "review", "reject", "fallback"] },
        "matchedRule": { "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }] },
        "fallbackTarget": { "type": "string", "minLength": 1 },
        "reason": { "enum": ["matched", "default", "missing-evidence", "invalid-evidence", "tie", "calibration-required"] },
        "values": {
          "type": "object",
          "propertyNames": { "enum": ["yes-probability", "selected-probability", "native-confidence", "top-two-margin", "entropy", "concentration", "expected-score", "dispersion", "calibrated-risk"] },
          "additionalProperties": {
            "type": "object",
            "properties": {
              "value": { "type": "number" },
              "normalizedBps": { "type": "number", "minimum": 0, "maximum": 10000 },
              "provenance": { "enum": ["provider-value", "provider-confidence", "provider-distribution", "derived", "calibrated"] },
              "calibrationRef": { "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }] }
            },
            "required": ["value", "normalizedBps", "provenance", "calibrationRef"],
            "additionalProperties": false
          }
        }
      },
      "required": ["policyVersion", "uncertaintyProfile", "disposition", "matchedRule", "reason", "values"],
      "additionalProperties": false
    },
    "resultCacheCallerReceipt": {
      "description": "D15 caller-level result-cache receipt. Historical evaluation attempts in a hit belong to the source invocation.",
      "type": "object",
      "properties": {
        "disposition": { "enum": ["cache-hit", "cache-miss-fill", "bypass"] },
        "callerInvocationId": { "type": "string", "minLength": 1 },
        "sourceInvocationId": { "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }] },
        "sourceReceiptId": { "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }] },
        "originalEvaluatedAtEpochMs": { "anyOf": [{ "type": "integer", "minimum": 0 }, { "type": "null" }] },
        "cacheEntryId": { "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }] },
        "createdAtEpochMs": { "type": "integer", "minimum": 0 },
        "providerAttempted": { "type": "boolean" }
      },
      "required": ["disposition", "callerInvocationId", "sourceInvocationId", "sourceReceiptId", "originalEvaluatedAtEpochMs", "cacheEntryId", "createdAtEpochMs", "providerAttempted"],
      "additionalProperties": false,
      "allOf": [
        {
          "if": { "properties": { "disposition": { "const": "cache-hit" } } },
          "then": {
            "properties": {
              "providerAttempted": { "const": false },
              "sourceInvocationId": { "type": "string" },
              "sourceReceiptId": { "type": "string" },
              "originalEvaluatedAtEpochMs": { "type": "integer" },
              "cacheEntryId": { "type": "string" }
            }
          }
        },
        {
          "if": { "properties": { "disposition": { "const": "bypass" } } },
          "then": { "properties": { "providerAttempted": { "const": true }, "cacheEntryId": { "type": "null" } } }
        }
      ]
    },
    "preprocessingLineage": {
      "description": "D24 body-free preprocessing lineage evidence. It links a decision receipt to non-text source preprocessing by pins, digests, counts, locators digests and policy outcomes only.",
      "type": "object",
      "properties": {
        "schemaVersion": { "const": "decision-preprocessing-lineage/v1" },
        "status": { "enum": ["ready", "review"] },
        "dispatchGate": {
          "description": "Evaluator-written pre-dispatch verdict. review and refused results made no credential or transport call.",
          "type": "object",
          "properties": {
            "outcome": { "enum": ["allowed", "review", "refused"] },
            "reasons": { "type": "array", "items": { "$ref": "#/$defs/preprocessingGateReason" } }
          },
          "required": ["outcome", "reasons"],
          "additionalProperties": false
        },
        "references": {
          "type": "array",
          "items": { "$ref": "#/$defs/preprocessingReference" }
        },
        "traces": {
          "type": "array",
          "items": { "$ref": "#/$defs/preprocessingTrace" }
        }
      },
      "required": ["schemaVersion", "status", "references", "traces"],
      "additionalProperties": false
    },
    "preprocessingReviewReason": {
      "enum": [
        "low-quality", "truncated", "incomplete", "stale", "policy-limited", "untrusted",
        "raw-egress-denied", "derived-egress-denied", "unsupported-locator",
        "lifecycle-unavailable", "legal-hold"
      ]
    },
    "preprocessingGateReason": {
      "anyOf": [
        { "$ref": "#/$defs/preprocessingReviewReason" },
        { "enum": ["unverified", "unavailable", "destination-mismatch", "destination-unbound", "malformed-lineage", "input-unbound", "input-mismatch", "input-undeclared", "lineage-missing"] }
      ]
    },
    "pin": {
      "type": "object",
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" },
        "digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
      },
      "required": ["id", "version", "digest"],
      "additionalProperties": false
    },
    "preprocessingReference": {
      "type": "object",
      "properties": {
        "evidence": { "$ref": "#/$defs/pin" },
        "sourceAssetId": { "type": "string", "minLength": 1 },
        "sourceDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
        "outputId": { "type": "string", "minLength": 1 },
        "outputVersion": { "type": "integer", "minimum": 1 },
        "outputDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
        "destination": {
          "type": "object",
          "properties": {
            "provider": { "type": "string", "minLength": 1 },
            "origin": { "type": "string", "minLength": 1 }
          },
          "required": ["provider", "origin"],
          "additionalProperties": false
        },
        "selectedSegments": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": { "type": "string", "minLength": 1 },
              "ordinal": { "type": "integer", "minimum": 1 },
              "locatorDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
              "textDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
              "preprocessingDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
            },
            "required": ["id", "ordinal", "locatorDigest", "textDigest", "preprocessingDigest"],
            "additionalProperties": false
          }
        },
        "quality": {
          "type": "object",
          "properties": {
            "source": { "enum": ["preprocessor", "human-reviewer"] },
            "profileDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
            "labelDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
            "score": { "type": "number", "minimum": 0, "maximum": 1 },
            "flags": {
              "type": "array",
              "items": { "enum": ["low-quality", "truncated", "incomplete", "stale", "policy-limited", "human-corrected"] }
            }
          },
          "required": ["source", "profileDigest", "labelDigest", "score", "flags"],
          "additionalProperties": false
        },
        "policy": {
          "type": "object",
          "properties": {
            "trust": { "enum": ["verified", "untrusted"] },
            "sensitivity": { "enum": ["public", "internal", "confidential", "restricted"] },
            "retentionDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
            "residencyDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
            "rawEgressAllowed": { "type": "boolean" },
            "derivedEgressAllowed": { "type": "boolean" }
          },
          "required": ["trust", "sensitivity", "retentionDigest", "residencyDigest", "rawEgressAllowed", "derivedEgressAllowed"],
          "additionalProperties": false
        }
      },
      "required": [
        "evidence", "sourceAssetId", "sourceDigest", "outputId", "outputVersion",
        "outputDigest", "destination", "selectedSegments", "quality", "policy"
      ],
      "additionalProperties": false
    },
    "preprocessingTrace": {
      "type": "object",
      "properties": {
        "evidence": { "$ref": "#/$defs/pin" },
        "stepIds": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "stepCount": { "type": "integer", "minimum": 0 },
        "noOpStepIds": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "sourceDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
        "outputDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
        "selectedSegmentCount": { "type": "integer", "minimum": 0 },
        "durationMs": { "type": "integer", "minimum": 0 },
        "qualityFlags": {
          "type": "array",
          "items": { "enum": ["low-quality", "truncated", "incomplete", "stale", "policy-limited", "human-corrected"] }
        },
        "policyOutcome": { "enum": ["allowed", "review"] },
        "reasons": {
          "type": "array",
          "items": { "$ref": "#/$defs/preprocessingReviewReason" }
        }
      },
      "required": [
        "evidence", "stepIds", "stepCount", "noOpStepIds", "sourceDigest", "outputDigest",
        "selectedSegmentCount", "durationMs", "qualityFlags", "policyOutcome", "reasons"
      ],
      "additionalProperties": false
    }
  },
  "type": "object",
  "properties": {
    "apiVersion": {
      "const": "decision.aiwg.io/v1alpha2"
    },
    "kind": {
      "const": "RulesetResult"
    },
    "metadata": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "type": "string",
          "pattern": "^\\d+\\.\\d+\\.\\d+$"
        },
        "description": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "version",
        "description"
      ],
      "additionalProperties": false
    },
    "spec": {
      "type": "object",
      "properties": {
        "ruleset": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "version": {
              "type": "string",
              "pattern": "^\\d+\\.\\d+\\.\\d+$"
            },
            "digest": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            }
          },
          "required": [
            "id",
            "version",
            "digest"
          ],
          "additionalProperties": false
        },
        "binding": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "version": {
              "type": "string",
              "pattern": "^\\d+\\.\\d+\\.\\d+$"
            },
            "digest": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            }
          },
          "required": [
            "id",
            "version",
            "digest"
          ],
          "additionalProperties": false
        },
        "runId": {
          "type": "string",
          "minLength": 1
        },
        "invocationId": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "enum": [
            "completed",
            "defaulted",
            "review",
            "error",
            "cancelled"
          ]
        },
        "reason": {
          "enum": [
            "none",
            "invalid-input",
            "invalid-definition",
            "digest-mismatch",
            "unauthorized",
            "data-boundary-denied",
            "unsupported-capability",
            "executor-unavailable",
            "invalid-output",
            "low-confidence",
            "missing-confidence",
            "confidence-profile-mismatch",
            "insufficient-information",
            "timeout",
            "network-transient",
            "rate-limited",
            "overloaded",
            "service-error",
            "authentication",
            "invalid-request",
            "budget-exhausted",
            "cancelled",
            "persistence-error",
            "replay-mismatch",
            "execution-uncertain",
            "batch-record-unavailable",
            "no-match",
            "conflicting-outcomes",
            "evaluation-failed",
            "context-plan-stale",
            "context-unqualified"
          ]
        },
        "outcome": {},
        "matchedRules": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "context": {
          "$ref": "DecisionContextEvidence.v1.schema.json"
        },
        "cache": {
          "$ref": "#/$defs/resultCacheCallerReceipt"
        },
        "preprocessingLineage": {
          "$ref": "#/$defs/preprocessingLineage"
        },
        "projection": {
          "description": "Present only when the host explicitly dispatched unprojected input (D10 opt-out).",
          "type": "object",
          "properties": {
            "mode": { "const": "unprojected-local" },
            "authority": { "const": "host" }
          },
          "required": ["mode", "authority"],
          "additionalProperties": false
        },
        "batchRequests": {
          "type": "array",
          "minItems": 1,
          "description": "Request-owned usage for native batches without durable receipts; answer batch groupId and ordinal reference this owner.",
          "items": {
            "type": "object",
            "properties": {
              "groupId": { "type": "string", "minLength": 1 },
              "ordinal": { "type": "integer", "minimum": 1 },
              "questionIds": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
              "usage": {
                "type": "object",
                "properties": {
                  "inputTokens": { "type": ["integer", "null"], "minimum": 0 },
                  "outputTokens": { "type": ["integer", "null"], "minimum": 0 },
                  "costUsd": { "type": ["number", "null"], "minimum": 0 }
                },
                "required": ["inputTokens", "outputTokens", "costUsd"],
                "additionalProperties": false
              },
              "requestId": { "type": ["string", "null"] }
            },
            "required": ["groupId", "ordinal", "questionIds", "usage", "requestId"],
            "additionalProperties": false
          }
        },
        "contextFailure": {
          "type": "object",
          "description": "Body-free D06 context preflight rejection diagnostic.",
          "properties": {
            "schemaVersion": { "const": "decision-context-failure/v1" },
            "reason": {
              "enum": [
                "invalid-input",
                "invalid-profile",
                "estimator-profile-mismatch",
                "oversized-state",
                "oversized-question",
                "dependency-error",
                "stale-plan",
                "rollout-unqualified"
              ]
            },
            "plannedDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
            "currentDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
          },
          "required": ["schemaVersion", "reason"],
          "additionalProperties": false
        },
        "evaluations": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "apiVersion": {
                "const": "decision.aiwg.io/v1alpha2"
              },
              "kind": {
                "const": "DecisionResult"
              },
              "metadata": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "version": {
                    "type": "string",
                    "pattern": "^\\d+\\.\\d+\\.\\d+$"
                  },
                  "description": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "id",
                  "version",
                  "description"
                ],
                "additionalProperties": false
              },
              "spec": {
                "type": "object",
                "properties": {
                  "decision": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "minLength": 1
                      },
                      "version": {
                        "type": "string",
                        "pattern": "^\\d+\\.\\d+\\.\\d+$"
                      },
                      "digest": {
                        "type": "string",
                        "pattern": "^sha256:[0-9a-f]{64}$"
                      }
                    },
                    "required": [
                      "id",
                      "version",
                      "digest"
                    ],
                    "additionalProperties": false
                  },
                  "ruleset": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "minLength": 1
                      },
                      "version": {
                        "type": "string",
                        "pattern": "^\\d+\\.\\d+\\.\\d+$"
                      },
                      "digest": {
                        "type": "string",
                        "pattern": "^sha256:[0-9a-f]{64}$"
                      }
                    },
                    "required": [
                      "id",
                      "version",
                      "digest"
                    ],
                    "additionalProperties": false
                  },
                  "binding": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "minLength": 1
                      },
                      "version": {
                        "type": "string",
                        "pattern": "^\\d+\\.\\d+\\.\\d+$"
                      },
                      "digest": {
                        "type": "string",
                        "pattern": "^sha256:[0-9a-f]{64}$"
                      }
                    },
                    "required": [
                      "id",
                      "version",
                      "digest"
                    ],
                    "additionalProperties": false
                  },
                  "alias": {
                    "type": "string",
                    "minLength": 1
                  },
                  "runId": {
                    "type": "string",
                    "minLength": 1
                  },
                  "invocationId": {
                    "type": "string",
                    "minLength": 1
                  },
                  "status": {
                    "enum": [
                      "success",
                      "abstained",
                      "error",
                      "unsupported",
                      "cancelled"
                    ]
                  },
                  "value": {
                    "anyOf": [
                      {
                        "type": "number"
                      },
                      {
                        "type": "string"
                      }
                    ]
                  },
                  "reason": {
                    "enum": [
                      "none",
                      "invalid-input",
                      "invalid-definition",
                      "digest-mismatch",
                      "unauthorized",
                      "data-boundary-denied",
                      "unsupported-capability",
                      "executor-unavailable",
                      "invalid-output",
                      "low-confidence",
                      "missing-confidence",
                      "confidence-profile-mismatch",
                      "insufficient-information",
                      "timeout",
                      "network-transient",
                      "rate-limited",
                      "overloaded",
                      "service-error",
                      "authentication",
                      "invalid-request",
                      "budget-exhausted",
                      "cancelled",
                      "persistence-error",
                      "replay-mismatch",
                      "execution-uncertain",
                      "batch-record-unavailable",
                      "no-match",
                      "conflicting-outcomes",
                      "evaluation-failed"
                    ]
                  },
                  "uncertainty": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "source": {
                            "enum": [
                              "provider",
                              "model-self-report",
                              "derived"
                            ]
                          },
                          "profile": {
                            "type": "string",
                            "minLength": 1
                          },
                          "calibration": {
                            "enum": [
                              "vendor-claimed",
                              "uncalibrated",
                              "measured"
                            ]
                          },
                          "confidence": {
                            "anyOf": [
                              {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 1
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "distribution": {
                            "anyOf": [
                              {
                                "type": "object",
                                "minProperties": 2,
                                "additionalProperties": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 1
                                }
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "calibrationRef": {
                            "anyOf": [
                              {
                                "type": "string",
                                "minLength": 1
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "calibratedRisk": {
                            "type": "object",
                            "properties": {
                              "value": { "type": "number", "minimum": 0, "maximum": 1 },
                              "calibrationRef": { "type": "string", "minLength": 1 }
                            },
                            "required": ["value", "calibrationRef"],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "source",
                          "profile",
                          "calibration",
                          "confidence",
                          "distribution",
                          "calibrationRef"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "acceptance": {
                    "$ref": "#/$defs/acceptanceEvidence"
                  },
                  "attempts": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "ordinal": {
                          "type": "integer",
                          "minimum": 1
                        },
                        "adapter": {
                          "type": "string",
                          "minLength": 1
                        },
                        "adapterVersion": {
                          "type": "string",
                          "minLength": 1
                        },
                        "requestedModel": {
                          "type": "string",
                          "minLength": 1
                        },
                        "actualModel": {
                          "anyOf": [
                            {
                              "type": "string",
                              "minLength": 1
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "subagent": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string",
                                  "minLength": 1
                                },
                                "version": {
                                  "type": "string",
                                  "pattern": "^\\d+\\.\\d+\\.\\d+$"
                                },
                                "digest": {
                                  "type": "string",
                                  "pattern": "^sha256:[0-9a-f]{64}$"
                                }
                              },
                              "required": [
                                "id",
                                "version",
                                "digest"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "status": {
                          "enum": [
                            "success",
                            "abstained",
                            "error",
                            "unsupported",
                            "cancelled"
                          ]
                        },
                        "reason": {
                          "enum": [
                            "none",
                            "invalid-input",
                            "invalid-definition",
                            "digest-mismatch",
                            "unauthorized",
                            "data-boundary-denied",
                            "unsupported-capability",
                            "executor-unavailable",
                            "invalid-output",
                            "low-confidence",
                            "missing-confidence",
                            "confidence-profile-mismatch",
                            "insufficient-information",
                            "timeout",
                            "network-transient",
                            "rate-limited",
                            "overloaded",
                            "service-error",
                            "authentication",
                            "invalid-request",
                            "budget-exhausted",
                            "cancelled",
                            "persistence-error",
                            "replay-mismatch",
                            "execution-uncertain",
                            "batch-record-unavailable",
                            "no-match",
                            "conflicting-outcomes",
                            "evaluation-failed"
                          ]
                        },
                        "durationMs": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        },
                        "usage": {
                          "type": "object",
                          "properties": {
                            "inputTokens": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "outputTokens": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "costUsd": {
                              "anyOf": [
                                {
                                  "type": "number",
                                  "minimum": 0
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "inputTokens",
                            "outputTokens",
                            "costUsd"
                          ],
                          "additionalProperties": false
                        },
                        "requestId": {
                          "anyOf": [
                            {
                              "type": "string",
                              "minLength": 1
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "requestIdSource": {
                          "enum": [
                            "typesafe",
                            "legacy",
                            "body"
                          ]
                        },
                        "httpStatus": {
                          "type": "integer",
                          "minimum": 100,
                          "maximum": 599
                        },
                        "retryDelayMs": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "termination": {
                          "enum": [
                            "caller-cancelled",
                            "target-timeout",
                            "total-deadline",
                            "backend-cancelled"
                          ]
                        },
                        "remoteExecution": {
                          "const": "unknown"
                        },
                        "admission": {
                          "$ref": "DecisionAdmissionEvidence.v1.schema.json"
                        },
                        "providerPrefix": {
                          "$ref": "DecisionProviderPrefixEvidence.v1.schema.json"
                        },
                        "batch": {
                          "type": "object",
                          "properties": {
                            "mode": { "enum": ["native", "single"] },
                            "groupId": { "type": "string", "pattern": "^(batch|single)_[0-9a-f]{24}$" },
                            "questionId": { "type": "string", "pattern": "^q_[0-9a-f]{24}$" },
                            "degradationReason": { "enum": ["disabled", "unsupported", "ineligible"] }
                          },
                          "required": ["mode", "groupId", "questionId"],
                          "additionalProperties": false
                        }
                      },
                      "required": [
                        "ordinal",
                        "adapter",
                        "adapterVersion",
                        "requestedModel",
                        "actualModel",
                        "subagent",
                        "status",
                        "reason",
                        "durationMs",
                        "usage",
                        "requestId"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 0
                  },
                  "calibrationCompatibility": {
                    "type": "object",
                    "required": ["schemaVersion", "pinId", "runId", "requestedAlias", "actualModel", "aliasRevision", "artifactId", "artifactDigest", "state", "action", "reasons", "decidedAt"],
                    "properties": {
                      "schemaVersion": { "const": "decision-calibration-compatibility/v1" },
                      "pinId": { "type": "string", "minLength": 1 },
                      "runId": { "type": "string", "minLength": 1 },
                      "requestedAlias": { "type": "string", "minLength": 1 },
                      "actualModel": { "type": "string", "minLength": 1 },
                      "aliasRevision": { "type": ["integer", "null"], "minimum": 1 },
                      "artifactId": { "type": ["string", "null"] },
                      "artifactDigest": { "anyOf": [{ "type": "null" }, { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }] },
                      "state": { "enum": ["exact", "approved-compatible", "shadow-required", "incompatible", "unknown"] },
                      "action": { "enum": ["allow", "fail", "defer", "shadow", "require-approval"] },
                      "reasons": { "type": "array", "items": { "type": "string", "minLength": 1 } },
                      "decidedAt": { "type": "string", "format": "date-time" }
                    },
                    "additionalProperties": false
                  },
                  "batchResult": {
                    "type": "object",
                    "properties": {
                      "schemaVersion": { "const": "decision-batch-result-ref/v1" },
                      "batchId": { "type": "string", "minLength": 1 },
                      "receiptRevision": { "type": "integer", "minimum": 1 },
                      "questionId": { "type": "string", "minLength": 1 },
                      "answerId": { "type": "string", "minLength": 1 }
                    },
                    "required": ["schemaVersion", "batchId", "receiptRevision", "questionId", "answerId"],
                    "additionalProperties": false
                  },
                  "context": {
                    "$ref": "DecisionContextEvidence.v1.schema.json"
                  }
                },
                "required": [
                  "decision",
                  "ruleset",
                  "binding",
                  "alias",
                  "runId",
                  "invocationId",
                  "status",
                  "reason",
                  "uncertainty",
                  "attempts"
                ],
                "additionalProperties": false,
                "allOf": [
                  {
                    "if": {
                      "properties": {
                        "status": {
                          "const": "success"
                        }
                      }
                    },
                    "then": {
                      "required": [
                        "value"
                      ],
                      "properties": {
                        "value": {},
                        "reason": {
                          "const": "none"
                        },
                        "attempts": {
                          "type": "array",
                          "minItems": 1
                        }
                      }
                    },
                    "else": {
                      "not": {
                        "properties": {
                          "value": {}
                        },
                        "required": [
                          "value"
                        ]
                      },
                      "properties": {
                        "reason": {
                          "not": {
                            "const": "none"
                          }
                        }
                      }
                    }
                  }
                ]
              }
            },
            "required": [
              "apiVersion",
              "kind",
              "metadata",
              "spec"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "ruleset",
        "binding",
        "runId",
        "invocationId",
        "status",
        "reason",
        "matchedRules",
        "evaluations"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "$comment": "An incomplete-context downgrade (D06/D10) is review with reason insufficient-information and no outcome.",
          "if": {
            "anyOf": [
              { "properties": { "status": { "enum": ["completed", "defaulted"] } } },
              {
                "properties": { "status": { "const": "review" } },
                "not": { "properties": { "reason": { "const": "insufficient-information" } }, "required": ["reason"] }
              }
            ]
          },
          "then": {
            "properties": {
              "outcome": {}
            },
            "required": [
              "outcome"
            ]
          },
          "else": {
            "not": {
              "properties": {
                "outcome": {}
              },
              "required": [
                "outcome"
              ]
            }
          }
        }
      ]
    }
  },
  "required": [
    "apiVersion",
    "kind",
    "metadata",
    "spec"
  ],
  "additionalProperties": false
}
