{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.connectsoft.ai/reference/schemas/attempt-outcome.schema.json",
  "title": "Lease and attempt outcome (acquire-lease-v1, lease-v1, attempt-outcome-v1)",
  "description": "Contracts between the runtime worker (BC-06) and Run Control (BC-03): a lease with a fencing token, and the single outcome report per attempt.",
  "$defs": {
    "AcquireLease": {
      "type": "object", "required": ["attemptId", "holder"], "additionalProperties": false,
      "properties": { "attemptId": { "type": "string", "format": "uuid" }, "holder": { "type": "string", "description": "Workload identity of the worker." }, "renewLeaseId": { "type": "string", "format": "uuid" } }
    },
    "Lease": {
      "type": "object", "required": ["leaseId", "attemptId", "fencingToken", "expiresAt"], "additionalProperties": false,
      "properties": { "leaseId": { "type": "string", "format": "uuid" }, "attemptId": { "type": "string", "format": "uuid" }, "fencingToken": { "type": "integer" }, "expiresAt": { "type": "string", "format": "date-time" }, "snapshotId": { "type": "string", "format": "uuid" } }
    },
    "AttemptOutcome": {
      "type": "object", "required": ["attemptId", "leaseId", "fencingToken", "outcome", "receipt"], "additionalProperties": false,
      "properties": {
        "attemptId": { "type": "string", "format": "uuid" },
        "leaseId": { "type": "string", "format": "uuid" },
        "fencingToken": { "type": "integer" },
        "outcome": { "enum": ["Succeeded", "Failed", "TimedOut", "Cancelled", "Uncertain"] },
        "failureClass": { "enum": ["transient", "permanent", "policy-denied", "validation", "cancellation", "uncertain"] },
        "receipt": {
          "type": "object", "required": ["hash"],
          "properties": {
            "hash": { "type": "string" },
            "artifacts": { "type": "array", "items": { "type": "string" } },
            "modelInvocations": { "type": "array", "items": { "type": "string" }, "description": "Model invocation receipt ids." },
            "toolInvocations": { "type": "array", "items": { "type": "string" }, "description": "Tool invocation receipt ids." },
            "usage": { "type": "object", "properties": { "inputTokens": { "type": "integer" }, "outputTokens": { "type": "integer" }, "cachedTokens": { "type": "integer" }, "status": { "enum": ["observed", "estimated", "unknown"] } } },
            "checkpointRef": { "type": "string" },
            "error": { "type": "object", "properties": { "code": { "type": "string" }, "message": { "type": "string" }, "diagnosticsRef": { "type": "string" } } }
          }
        }
      }
    }
  },
  "oneOf": [{ "$ref": "#/$defs/AcquireLease" }, { "$ref": "#/$defs/Lease" }, { "$ref": "#/$defs/AttemptOutcome" }]
}
