{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pdf2html.invalid/quality/job-lifecycle/lifecycle-case.schema.json",
  "title": "Job lifecycle conformance case",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "case_id",
    "title",
    "category",
    "refs",
    "initial",
    "events",
    "expected",
    "authoritative"
  ],
  "properties": {
    "case_id": {
      "type": "string",
      "pattern": "^(?:JL-[0-9]{3}|K(?:10|[1-9])|CANCEL-[1-7])$"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160
    },
    "category": {
      "enum": [
        "acceptance",
        "idempotency",
        "lease",
        "terminalization",
        "cancellation",
        "retry",
        "compensation",
        "expiry"
      ]
    },
    "refs": {
      "$ref": "#/$defs/refs"
    },
    "initial": {
      "$ref": "#/$defs/snapshot"
    },
    "events": {
      "type": "array",
      "minItems": 1,
      "maxItems": 30,
      "items": {
        "$ref": "#/$defs/event"
      }
    },
    "expected": {
      "$ref": "#/$defs/expected"
    },
    "concurrency": {
      "$ref": "#/$defs/concurrency"
    },
    "terminal_matrix": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "initial_status",
          "cancel_result",
          "expected_snapshot"
        ],
        "properties": {
          "initial_status": {
            "enum": [
              "complete",
              "failed",
              "cancelled",
              "artifact_expired"
            ]
          },
          "cancel_result": {
            "enum": [
              "state_conflict",
              "idempotent"
            ]
          },
          "expected_snapshot": {
            "type": "object"
          }
        }
      }
    },
    "variants": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "enum": [
          "stale_generation",
          "replayed_token",
          "foreign_token",
          "current_metadata",
          "diagnostic_metadata"
        ]
      }
    },
    "source_alternatives": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "enum": [
          "source_object",
          "private_copy"
        ]
      }
    },
    "authoritative": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_accepted_at",
        "source_ttl_seconds",
        "lease_ttl_seconds",
        "heartbeat_grace_seconds"
      ],
      "properties": {
        "source_accepted_at": {
          "$ref": "#/$defs/instant"
        },
        "source_ttl_seconds": {
          "const": 172800
        },
        "lease_acquired_at": {
          "$ref": "#/$defs/instant"
        },
        "lease_ttl_seconds": {
          "const": 300
        },
        "heartbeat_grace_seconds": {
          "const": 60
        }
      }
    }
  },
  "$defs": {
    "instant": {
      "type": "string",
      "format": "date-time",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$"
    },
    "id": {
      "type": "string",
      "minLength": 6,
      "maxLength": 128,
      "pattern": "^[A-Za-z0-9_]+$"
    },
    "status": {
      "enum": [
        "queued",
        "processing",
        "cancellation_pending",
        "complete",
        "failed",
        "cancelled",
        "artifact_expired"
      ]
    },
    "refs": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "owner_id",
        "conversion_id",
        "job_id",
        "cycle_id",
        "ledger_id",
        "object_id",
        "source_object_id",
        "zip_object_id",
        "publication_id",
        "account_operation_id",
        "owner_ids",
        "worker_ids",
        "lease_tokens",
        "lease_generations",
        "cancel_request_ids",
        "invocation_ids",
        "attempt_ids",
        "cycle_ids",
        "account_ids",
        "object_ids",
        "ledger_ids",
        "barrier_ids",
        "private_copy_object_id",
        "actor_roles"
      ],
      "properties": {
        "owner_id": {
          "$ref": "#/$defs/id"
        },
        "conversion_id": {
          "$ref": "#/$defs/id"
        },
        "job_id": {
          "$ref": "#/$defs/id"
        },
        "cycle_id": {
          "$ref": "#/$defs/id"
        },
        "ledger_id": {
          "$ref": "#/$defs/id"
        },
        "object_id": {
          "$ref": "#/$defs/id"
        },
        "lease_id": {
          "$ref": "#/$defs/id"
        },
        "lease_token": {
          "$ref": "#/$defs/id"
        },
        "source_object_id": {
          "$ref": "#/$defs/id"
        },
        "zip_object_id": {
          "$ref": "#/$defs/id"
        },
        "publication_id": {
          "$ref": "#/$defs/id"
        },
        "account_operation_id": {
          "$ref": "#/$defs/id"
        },
        "owner_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "worker_ids": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "lease_tokens": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "lease_generations": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "integer",
            "minimum": 0
          }
        },
        "cancel_request_ids": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "invocation_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "attempt_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "cycle_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "account_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "object_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "ledger_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "barrier_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "private_copy_object_id": {
          "$ref": "#/$defs/id"
        },
        "actor_roles": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/actor_role"
          }
        }
      }
    },
    "cycle": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "ordinal",
        "funding_kind",
        "state",
        "closed"
      ],
      "properties": {
        "ordinal": {
          "type": "integer",
          "minimum": 1
        },
        "funding_kind": {
          "enum": [
            "customer_debit",
            "goodwill"
          ]
        },
        "state": {
          "enum": [
            "open",
            "compensated",
            "consumed"
          ]
        },
        "closed": {
          "type": "boolean"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "state": {
                "const": "open"
              }
            }
          },
          "then": {
            "properties": {
              "closed": {
                "const": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "state": {
                "enum": [
                  "compensated",
                  "consumed"
                ]
              }
            }
          },
          "then": {
            "properties": {
              "closed": {
                "const": true
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "funding_kind": {
                "const": "goodwill"
              }
            }
          },
          "then": {
            "properties": {
              "state": {
                "enum": [
                  "open",
                  "consumed"
                ]
              }
            }
          }
        }
      ]
    },
    "counts": {
      "type": "object",
      "required": [
        "credit_balance",
        "jobs",
        "attempts",
        "debits",
        "compensations",
        "terminal_writes",
        "charge_cycles"
      ],
      "properties": {
        "credit_balance": {
          "type": "integer",
          "minimum": 0
        },
        "jobs": {
          "type": "integer",
          "minimum": 0
        },
        "attempts": {
          "type": "integer",
          "minimum": 0
        },
        "debits": {
          "type": "integer",
          "minimum": 0
        },
        "compensations": {
          "type": "integer",
          "minimum": 0
        },
        "terminal_writes": {
          "type": "integer",
          "minimum": 0
        },
        "charge_cycles": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "snapshot": {
      "allOf": [
        {
          "$ref": "#/$defs/counts"
        },
        {
          "type": "object",
          "required": [
            "status",
            "credit_balance",
            "jobs",
            "attempts",
            "debits",
            "compensations",
            "terminal_writes",
            "charge_cycles",
            "active_cycle",
            "attempt_budget"
          ],
          "properties": {
            "status": {
              "oneOf": [
                {
                  "$ref": "#/$defs/status"
                },
                {
                  "type": "null"
                }
              ]
            },
            "credit_balance": {
              "type": "integer",
              "minimum": 0
            },
            "jobs": {
              "type": "integer",
              "minimum": 0
            },
            "attempts": {
              "type": "integer",
              "minimum": 0
            },
            "debits": {
              "type": "integer",
              "minimum": 0
            },
            "compensations": {
              "type": "integer",
              "minimum": 0
            },
            "terminal_writes": {
              "type": "integer",
              "minimum": 0
            },
            "charge_cycles": {
              "type": "integer",
              "minimum": 0
            },
            "active_cycle": {
              "oneOf": [
                {
                  "$ref": "#/$defs/cycle"
                },
                {
                  "type": "null"
                }
              ]
            },
            "source_expires_at": {
              "$ref": "#/$defs/instant"
            },
            "attempt_budget": {
              "type": "integer",
              "minimum": 1
            },
            "lease_generation": {
              "type": "integer",
              "minimum": 0
            },
            "active_lease_token": {
              "$ref": "#/$defs/id"
            },
            "lease_expires_at": {
              "$ref": "#/$defs/instant"
            },
            "heartbeat_grace_until": {
              "$ref": "#/$defs/instant"
            },
            "retryable": {
              "type": "boolean"
            },
            "source_present": {
              "type": "boolean"
            },
            "private_copy_present": {
              "type": "boolean"
            },
            "zip_present": {
              "type": "boolean"
            },
            "publication_present": {
              "type": "boolean"
            },
            "account_operation_state": {
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "enum": [
                    "succeeded",
                    "failed"
                  ]
                }
              ]
            },
            "terminalized_at": {
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "$ref": "#/$defs/instant"
                }
              ]
            },
            "completed_at": {
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "$ref": "#/$defs/instant"
                }
              ]
            },
            "zip_expires_at": {
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "$ref": "#/$defs/instant"
                }
              ]
            }
          }
        }
      ]
    },
    "event": {
      "oneOf": [
        {
          "$ref": "#/$defs/submit"
        },
        {
          "$ref": "#/$defs/claim"
        },
        {
          "$ref": "#/$defs/heartbeat"
        },
        {
          "$ref": "#/$defs/reclaim"
        },
        {
          "$ref": "#/$defs/complete"
        },
        {
          "$ref": "#/$defs/fail"
        },
        {
          "$ref": "#/$defs/cancel"
        },
        {
          "$ref": "#/$defs/terminate"
        },
        {
          "$ref": "#/$defs/cleanup_ack"
        },
        {
          "$ref": "#/$defs/cleanup_failed"
        },
        {
          "$ref": "#/$defs/worker_crash"
        },
        {
          "$ref": "#/$defs/admin_retry"
        },
        {
          "$ref": "#/$defs/artifact_publish"
        },
        {
          "$ref": "#/$defs/private_copy_create"
        },
        {
          "$ref": "#/$defs/source_delete"
        },
        {
          "$ref": "#/$defs/zip_delete"
        },
        {
          "$ref": "#/$defs/artifact_expire"
        },
        {
          "$ref": "#/$defs/account_operation_terminalize"
        }
      ]
    },
    "base": {
      "type": "object",
      "required": [
        "seq",
        "at",
        "type",
        "actor_id",
        "conversion_id",
        "job_id",
        "invocation_id",
        "attempt_id",
        "cycle_id",
        "owner_id",
        "account_id",
        "object_id",
        "ledger_id",
        "barrier_id",
        "winner"
      ],
      "properties": {
        "seq": {
          "type": "integer",
          "minimum": 1
        },
        "at": {
          "$ref": "#/$defs/instant"
        },
        "type": {
          "type": "string"
        },
        "actor_id": {
          "$ref": "#/$defs/id"
        },
        "conversion_id": {
          "$ref": "#/$defs/id"
        },
        "job_id": {
          "$ref": "#/$defs/id"
        },
        "invocation_id": {
          "$ref": "#/$defs/id"
        },
        "attempt_id": {
          "$ref": "#/$defs/id"
        },
        "cycle_id": {
          "$ref": "#/$defs/id"
        },
        "owner_id": {
          "$ref": "#/$defs/id"
        },
        "account_id": {
          "$ref": "#/$defs/id"
        },
        "object_id": {
          "$ref": "#/$defs/id"
        },
        "ledger_id": {
          "$ref": "#/$defs/id"
        },
        "barrier_id": {
          "$ref": "#/$defs/id"
        },
        "winner": {
          "type": "boolean"
        }
      }
    },
    "submit": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "owner_id",
            "idempotency_key",
            "request_hash",
            "source_valid",
            "source_present",
            "accepted_at",
            "source_expires_at",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "submit"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "owner_id": {
              "$ref": "#/$defs/id"
            },
            "idempotency_key": {
              "type": "string",
              "minLength": 16
            },
            "request_hash": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            "source_valid": {
              "type": "boolean"
            },
            "source_present": {
              "type": "boolean"
            },
            "acceptance_committed": {
              "type": "boolean"
            },
            "accepted_at": {
              "$ref": "#/$defs/instant"
            },
            "source_expires_at": {
              "$ref": "#/$defs/instant"
            },
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {}
          }
        }
      ]
    },
    "lease_event_props": {
      "type": "object",
      "properties": {
        "seq": {},
        "at": {},
        "type": {},
        "actor_id": {},
        "conversion_id": {},
        "job_id": {},
        "worker_id": {
          "$ref": "#/$defs/id"
        },
        "lease_token": {
          "$ref": "#/$defs/id"
        },
        "lease_generation": {
          "type": "integer",
          "minimum": 1
        },
        "lease_expires_at": {
          "$ref": "#/$defs/instant"
        },
        "source_present": {
          "type": "boolean"
        },
        "termination_confirmed": {
          "type": "boolean"
        },
        "failure_code": {
          "type": "string",
          "pattern": "^[A-Z][A-Z0-9_]{2,63}$"
        },
        "retryable": {
          "type": "boolean"
        }
      }
    },
    "claim": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "$ref": "#/$defs/lease_event_props"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "worker_id",
            "lease_token",
            "lease_generation",
            "lease_expires_at",
            "source_present",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "claim"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "worker_id": {},
            "lease_token": {},
            "lease_generation": {},
            "lease_expires_at": {},
            "source_present": {},
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {},
            "private_copy_present": {
              "type": "boolean"
            }
          }
        }
      ]
    },
    "reclaim": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "$ref": "#/$defs/lease_event_props"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "worker_id",
            "lease_token",
            "lease_generation",
            "lease_expires_at",
            "source_present",
            "termination_confirmed",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "reclaim"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "worker_id": {},
            "lease_token": {},
            "lease_generation": {},
            "lease_expires_at": {},
            "source_present": {},
            "termination_confirmed": {},
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {},
            "private_copy_present": {
              "type": "boolean"
            }
          }
        }
      ]
    },
    "heartbeat": {
      "allOf": [
        {
          "$ref": "#/$defs/current_lease_event"
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "heartbeat"
            }
          }
        }
      ]
    },
    "complete": {
      "allOf": [
        {
          "$ref": "#/$defs/current_lease_event"
        },
        {
          "type": "object",
          "required": [
            "zip_object_id",
            "publication_id",
            "zip_expires_at"
          ],
          "properties": {
            "type": {
              "const": "complete"
            },
            "zip_object_id": {
              "$ref": "#/$defs/id"
            },
            "publication_id": {
              "$ref": "#/$defs/id"
            },
            "zip_expires_at": {
              "$ref": "#/$defs/instant"
            }
          }
        }
      ]
    },
    "current_lease_event": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "worker_id",
            "lease_token",
            "lease_generation",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "enum": [
                "heartbeat",
                "complete"
              ]
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "worker_id": {
              "$ref": "#/$defs/id"
            },
            "lease_token": {
              "$ref": "#/$defs/id"
            },
            "lease_generation": {
              "type": "integer",
              "minimum": 0
            },
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {},
            "zip_object_id": {
              "$ref": "#/$defs/id"
            },
            "publication_id": {
              "$ref": "#/$defs/id"
            },
            "zip_expires_at": {
              "$ref": "#/$defs/instant"
            }
          }
        }
      ]
    },
    "fail": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "worker_id",
            "lease_token",
            "lease_generation",
            "failure_code",
            "retryable",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "fail"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "worker_id": {
              "$ref": "#/$defs/id"
            },
            "lease_token": {
              "$ref": "#/$defs/id"
            },
            "lease_generation": {
              "type": "integer",
              "minimum": 0
            },
            "failure_code": {
              "type": "string"
            },
            "retryable": {
              "type": "boolean"
            },
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {}
          }
        }
      ]
    },
    "cancel": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "owner_id",
            "idempotency_key",
            "cancel_request_id",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "cancel"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "owner_id": {
              "$ref": "#/$defs/id"
            },
            "idempotency_key": {
              "type": "string",
              "minLength": 16
            },
            "cancel_request_id": {
              "$ref": "#/$defs/id"
            },
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {}
          }
        }
      ]
    },
    "cleanup_ack": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "worker_id",
            "cancel_request_id",
            "lease_token",
            "lease_generation",
            "cgroup_empty",
            "workdir_absent",
            "partial_objects_absent",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "cleanup_ack"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "worker_id": {
              "$ref": "#/$defs/id"
            },
            "cancel_request_id": {
              "$ref": "#/$defs/id"
            },
            "lease_token": {
              "$ref": "#/$defs/id"
            },
            "lease_generation": {
              "type": "integer",
              "minimum": 0
            },
            "cgroup_empty": {
              "const": true
            },
            "workdir_absent": {
              "const": true
            },
            "partial_objects_absent": {
              "const": true
            },
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {}
          }
        }
      ]
    },
    "cleanup_failed": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "worker_id",
            "cancel_request_id",
            "failure_code",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "cleanup_failed"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "worker_id": {
              "$ref": "#/$defs/id"
            },
            "cancel_request_id": {
              "$ref": "#/$defs/id"
            },
            "failure_code": {
              "type": "string"
            },
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {}
          }
        }
      ]
    },
    "terminate": {
      "allOf": [
        {
          "$ref": "#/$defs/termination"
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "terminate"
            }
          }
        }
      ]
    },
    "worker_crash": {
      "allOf": [
        {
          "$ref": "#/$defs/termination"
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "worker_crash"
            }
          }
        }
      ]
    },
    "termination": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "worker_id",
            "termination_confirmed",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "enum": [
                "terminate",
                "worker_crash"
              ]
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "worker_id": {
              "$ref": "#/$defs/id"
            },
            "termination_confirmed": {
              "type": "boolean"
            },
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {}
          }
        }
      ]
    },
    "admin_retry": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "operator_id",
            "idempotency_key",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "admin_retry"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "operator_id": {
              "$ref": "#/$defs/id"
            },
            "idempotency_key": {
              "type": "string",
              "minLength": 16
            },
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {}
          }
        }
      ]
    },
    "concurrency": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "barrier_id",
        "actors",
        "unordered_attempts",
        "allowed_winners"
      ],
      "properties": {
        "barrier_id": {
          "$ref": "#/$defs/id"
        },
        "actors": {
          "type": "array",
          "minItems": 2,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "unordered_attempts": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "attempt_id",
              "actor_id",
              "event_type",
              "barrier_id",
              "event_seq"
            ],
            "properties": {
              "attempt_id": {
                "$ref": "#/$defs/id"
              },
              "actor_id": {
                "$ref": "#/$defs/id"
              },
              "event_type": {
                "enum": [
                  "submit",
                  "claim",
                  "heartbeat",
                  "reclaim",
                  "complete",
                  "fail",
                  "cancel",
                  "terminate",
                  "cleanup_ack",
                  "cleanup_failed",
                  "worker_crash",
                  "admin_retry",
                  "artifact_publish",
                  "private_copy_create",
                  "source_delete",
                  "zip_delete",
                  "artifact_expire",
                  "account_operation_terminalize"
                ]
              },
              "barrier_id": {
                "$ref": "#/$defs/id"
              },
              "event_seq": {
                "type": "integer",
                "minimum": 1
              }
            }
          }
        },
        "allowed_winners": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "event_type",
              "final_status"
            ],
            "properties": {
              "event_type": {
                "enum": [
                  "account_operation_terminalize",
                  "admin_retry",
                  "artifact_expire",
                  "artifact_publish",
                  "cancel",
                  "claim",
                  "cleanup_ack",
                  "cleanup_failed",
                  "complete",
                  "fail",
                  "heartbeat",
                  "private_copy_create",
                  "reclaim",
                  "source_delete",
                  "submit",
                  "terminate",
                  "worker_crash",
                  "zip_delete"
                ]
              },
              "final_status": {
                "oneOf": [
                  {
                    "$ref": "#/$defs/status"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            }
          }
        }
      }
    },
    "expected": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "outcome",
        "final_status",
        "counts",
        "active_cycle",
        "error",
        "evidence",
        "effects"
      ],
      "properties": {
        "outcome": {
          "enum": [
            "apply",
            "idempotent_replay",
            "ignore",
            "reject"
          ]
        },
        "final_status": {
          "oneOf": [
            {
              "$ref": "#/$defs/status"
            },
            {
              "type": "null"
            }
          ]
        },
        "counts": {
          "$ref": "#/$defs/counts"
        },
        "active_cycle": {
          "oneOf": [
            {
              "$ref": "#/$defs/cycle"
            },
            {
              "type": "null"
            }
          ]
        },
        "error": {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "enum": [
                "SOURCE_EXPIRED",
                "HEARTBEAT_GRACE_ACTIVE",
                "TERMINATION_UNCONFIRMED",
                "ATTEMPT_BUDGET_EXHAUSTED",
                "LEASE_FENCED",
                "ACCEPTANCE_ROLLBACK",
                "NOT_FOUND",
                "STATE_CONFLICT",
                "CLEANUP_FAILED"
              ]
            }
          ]
        },
        "evidence": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 240
          }
        },
        "effects": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "source_present",
            "private_copy_present",
            "zip_present",
            "publication_present",
            "account_operation_state",
            "terminalized_at"
          ],
          "properties": {
            "source_present": {
              "type": "boolean"
            },
            "private_copy_present": {
              "type": "boolean"
            },
            "zip_present": {
              "type": "boolean"
            },
            "publication_present": {
              "type": "boolean"
            },
            "account_operation_state": {
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "enum": [
                    "succeeded",
                    "failed"
                  ]
                }
              ]
            },
            "terminalized_at": {
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "$ref": "#/$defs/instant"
                }
              ]
            }
          }
        }
      }
    },
    "artifact_publish": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner",
            "publication_id",
            "zip_object_id"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "artifact_publish"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {},
            "publication_id": {
              "$ref": "#/$defs/id"
            },
            "zip_object_id": {
              "$ref": "#/$defs/id"
            }
          }
        }
      ]
    },
    "private_copy_create": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner",
            "source_object_id",
            "private_copy_object_id"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "private_copy_create"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {},
            "source_object_id": {
              "$ref": "#/$defs/id"
            },
            "private_copy_object_id": {
              "$ref": "#/$defs/id"
            }
          }
        }
      ]
    },
    "source_delete": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner",
            "source_object_id"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "source_delete"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {},
            "source_object_id": {
              "$ref": "#/$defs/id"
            }
          }
        }
      ]
    },
    "zip_delete": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner",
            "zip_object_id"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "zip_delete"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {},
            "zip_object_id": {
              "$ref": "#/$defs/id"
            }
          }
        }
      ]
    },
    "artifact_expire": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner",
            "zip_object_id",
            "publication_id"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "artifact_expire"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {},
            "zip_object_id": {
              "$ref": "#/$defs/id"
            },
            "publication_id": {
              "$ref": "#/$defs/id"
            }
          }
        }
      ]
    },
    "account_operation_terminalize": {
      "allOf": [
        {
          "$ref": "#/$defs/base"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "seq",
            "at",
            "type",
            "actor_id",
            "conversion_id",
            "job_id",
            "invocation_id",
            "attempt_id",
            "cycle_id",
            "owner_id",
            "account_id",
            "object_id",
            "ledger_id",
            "barrier_id",
            "winner",
            "account_operation_id",
            "terminal_state"
          ],
          "properties": {
            "seq": {},
            "at": {},
            "type": {
              "const": "account_operation_terminalize"
            },
            "actor_id": {},
            "conversion_id": {},
            "job_id": {},
            "invocation_id": {},
            "attempt_id": {},
            "cycle_id": {},
            "owner_id": {},
            "account_id": {},
            "object_id": {},
            "ledger_id": {},
            "barrier_id": {},
            "winner": {},
            "account_operation_id": {
              "$ref": "#/$defs/id"
            },
            "terminal_state": {
              "enum": [
                "succeeded",
                "failed"
              ]
            }
          }
        }
      ]
    },
    "actor_role": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "actor_id",
        "role",
        "owner_id",
        "allowed_operations"
      ],
      "properties": {
        "actor_id": {
          "$ref": "#/$defs/id"
        },
        "role": {
          "enum": [
            "owner",
            "worker",
            "operator",
            "system"
          ]
        },
        "owner_id": {
          "$ref": "#/$defs/id"
        },
        "allowed_operations": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "enum": [
              "submit",
              "claim",
              "heartbeat",
              "reclaim",
              "complete",
              "fail",
              "cancel",
              "terminate",
              "cleanup_ack",
              "cleanup_failed",
              "worker_crash",
              "admin_retry",
              "artifact_publish",
              "private_copy_create",
              "source_delete",
              "zip_delete",
              "artifact_expire",
              "account_operation_terminalize"
            ]
          }
        }
      }
    }
  }
}
