{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.example.com/prw/queue/resolution.job.v1.json",
  "title": "ResolutionJobV1",
  "description": "PROP · Internal resolver queue message (queue resolution.job.v1, interface if_resolution_job). Producer: resolver intake after the capture commits, and each stage for the next stage. Consumers: extraction, normalization and identity. Delivery is at-least-once with no ordering guarantee. Consumers dedupe on job_id through a durable inbox and ack after commit. Dead-letter after 5 attempts (PROP). The message carries refs and sha256 only, never raw artifacts. tenant_id and catalog_id are copied from the committed capture row and re-checked by the consumer. Size: at most 16 KB (PROP; verify against provider limit).",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "job_id",
    "stage",
    "tenant_id",
    "catalog_id",
    "capture_id",
    "receipt_id",
    "source_id",
    "artifacts",
    "pins",
    "enqueued_at",
    "attempt_group",
    "history_epoch"
  ],
  "properties": {
    "schema_version": {
      "const": "resolution.job/1"
    },
    "job_id": {
      "type": "string",
      "description": "capture_id:stage:attempt_group. The idempotency key for consumer dedupe.",
      "pattern": "^cap_[A-Za-z0-9_]+:(extract|normalize|identity|llm_extract|llm_review):[0-9]+$"
    },
    "stage": {
      "enum": [
        "extract",
        "normalize",
        "identity",
        "llm_extract",
        "llm_review"
      ]
    },
    "tenant_id": {
      "type": "string",
      "pattern": "^ten_[a-z0-9_]+$"
    },
    "catalog_id": {
      "type": "string",
      "pattern": "^cat_[a-z0-9_]+$"
    },
    "capture_id": {
      "type": "string",
      "pattern": "^cap_[A-Za-z0-9_]+$"
    },
    "receipt_id": {
      "type": "string",
      "pattern": "^rcpt_[A-Za-z0-9_]+$"
    },
    "source_id": {
      "type": "string",
      "pattern": "^src_[a-z0-9_]+$"
    },
    "artifacts": {
      "type": "array",
      "minItems": 1,
      "maxItems": 20,
      "items": {
        "$ref": "#/$defs/ArtifactRefOnly"
      }
    },
    "pins": {
      "description": "Pinned adapter/profile versions, or null for automatic selection.",
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "adapter": {
              "type": "string",
              "pattern": "^pa_[a-z0-9_]+@[0-9]+\\.[0-9]+\\.[0-9]+$"
            },
            "profile": {
              "type": "string",
              "pattern": "^np_[a-z0-9_]+@[0-9]+$"
            }
          }
        }
      ]
    },
    "enqueued_at": {
      "type": "string",
      "format": "date-time"
    },
    "attempt_group": {
      "type": "integer",
      "minimum": 1,
      "description": "Incremented only by an operator-initiated reprocess. Platform redeliveries keep the same job_id."
    },
    "trace_id": {
      "type": "string"
    },
    "history_epoch": {
      "type": "string",
      "minLength": 1,
      "description": "External restore fence. Consumer rejects old/unknown epoch before processing; never relabel old deliveries."
    }
  },
  "$defs": {
    "ArtifactRefOnly": {
      "type": "object",
      "additionalProperties": false,
      "description": "A reference to a stored, verified artifact. Raw bytes are never allowed here.",
      "required": [
        "artifact_id",
        "ref",
        "sha256",
        "media_type",
        "bytes"
      ],
      "properties": {
        "artifact_id": {
          "type": "string",
          "pattern": "^art_[A-Za-z0-9_]+$"
        },
        "ref": {
          "type": "string",
          "pattern": "^r2://evidence-private/"
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "media_type": {
          "type": "string"
        },
        "bytes": {
          "type": "integer",
          "minimum": 0
        }
      }
    }
  },
  "examples": [
    {
      "schema_version": "resolution.job/1",
      "job_id": "cap_lum_0310:extract:1",
      "stage": "extract",
      "tenant_id": "ten_primary",
      "catalog_id": "cat_primary",
      "capture_id": "cap_lum_0310",
      "receipt_id": "rcpt_0310",
      "source_id": "src_lumen_web",
      "artifacts": [
        {
          "artifact_id": "art_0310_html",
          "ref": "r2://evidence-private/ten_primary/a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192",
          "sha256": "a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192",
          "media_type": "text/html",
          "bytes": 233904
        }
      ],
      "pins": null,
      "enqueued_at": "2026-10-10T03:32:01Z",
      "attempt_group": 1,
      "trace_id": "trc_0310",
      "history_epoch": "history-demo-1"
    }
  ]
}
