Entity assessments
An entity assessment describes the current quality, readiness, risk, or health of an entity. Assessments live beside the entity rather than inside its JSON, so evaluating a product's sellability or an order's fraud risk does not change the entity version, history, search document, or ordinary entity events.
For the team workflow, see Find what needs attention.
Evaluated assessments participate in Vox's dependency graph. A price, relation, market membership or external signal can therefore reevaluate only the assessment results it affects, without rescanning every entity. See Dependency and change tracking.
Each entity can have several named assessments. Assessment names are unique within an entity type, so Readiness can
be used independently for products, pages, and orders. A result can apply to the whole entity or to a combination of
registered Vox contexts such as a market and language.
Evaluated assessments
Implement IVoxEntityAssessment<TEntity, TDefinition> when Vox should calculate the result. Evaluators are discovered
at startup and use the same dependency-aware reads as calculations. Vox reevaluates only the consumers affected by an
entity, relation, context-membership, or custom dependency change.
public class ProductSellabilityDefinition : VoxAssessmentDefinition<Product>
{
public ProductSellabilityDefinition()
: base("Sellability", "1", "Sellability", "Whether the product can be sold in each market.")
{
AddContext<Market>();
MissingPrice = Finding("missing-price", VoxAssessmentFindingSeverity.Error, "No price", path: "prices");
PriceCount = Metric("price-count", "Prices", "prices");
}
public VoxAssessmentFindingDefinition MissingPrice { get; }
public VoxAssessmentMetricDefinition PriceCount { get; }
}
public class ProductSellability
: IVoxEntityAssessment<Product, ProductSellabilityDefinition>
{
public async Task AssessAsync(
Product product,
IVoxAssessmentEvaluationContext<ProductSellabilityDefinition> context,
CancellationToken cancellationToken)
{
var prices = await context.LoadRelatedAsync<Price>(product, cancellationToken);
foreach (var market in product.Markets)
{
var result = context.ForContext(VoxAssessmentContext.For<Market>(market.Id));
var marketPrices = prices.Where(price => price.Market.Id == market.Id).ToList();
if (marketPrices.Count == 0)
{
result.SetOutcome(VoxAssessmentOutcome.Fail)
.Finding(definition => definition.MissingPrice)
.Add("The product has no price in this market.");
}
else
{
result.SetOutcome(VoxAssessmentOutcome.Pass)
.Metric(definition => definition.PriceCount)
.Set(marketPrices.Count);
}
}
}
}
A finding's path is the field it's about, eg prices, or a value within it, eg content.description.sv. Give the
definition the path when every finding of the code is about the same field: a finding reported without a path of its
own gets it, and a list leaves the finding out of what needs attention in a perspective that hides the field. Leave it
out for a finding about the entity as a whole, or one whose field varies.
Use ForEntity() for an entity-wide result. A run may produce zero or more contextual results; after a successful
run, that complete set replaces the evaluator's previous set. Producing no results means “not applicable.”
IVoxAssessmentEvaluationContext is an IVoxEvaluationContext, so an assessment reads entities, relations, tracked
queries and Accumulator balances, declares dependencies and calls ReevaluateAt as a calculation does. Use
ReevaluateAt for evaluator-owned time boundaries. ValidUntil(...) belongs to a particular result and controls
when that stored result becomes stale. An evaluator that reads a
timeline, eg a variant's price, uses
context.Current(timeline) for the value now, which registers the next boundary, and timeline.NextChangeAfter(...) for a
result's ValidUntil.
Assessments produced by calculations and publications
A calculation or durable projection publication can explain its business result by producing an assessment as a side
effect. Use the same definition type through context.Assessments:
var result = context.Assessments.For<ProductAvailabilityDefinition>();
result.Metric(definition => definition.AvailableQuantity).Set(availableQuantity);
if (availableQuantity == 0)
{
result.Finding(definition => definition.NoInventory)
.Add("No inventory is available.", "inventoryLevels");
}
result.SetOutcome(availableQuantity > 0
? VoxAssessmentOutcome.Pass
: VoxAssessmentOutcome.Fail);
One run may produce any number of assessment types. A successful run replaces the results previously owned by that
calculation or publication, including removing a result it no longer produces. A result that a run produces again
unchanged isn't written: its EntityVersion, EvaluatedAtUtc and AttemptedAtUtc stay those of the run that last
changed it. For example, a variant at version 7 can show a visibility result "evaluated for version 5 at 10:02" when
versions 6 and 7 changed nothing it reports. Reported results always record each report's source version and time. A failed producer records Error while
retaining the last successful outcome, findings, and metrics. Assessment persistence failures are logged and do not
turn a successful calculation or external publication into a failure.
Calculations may produce entity-wide results or any context declared by the definition. A publication that projects a source at a combination of members, eg per market, produces its results there in the context of those members, limited to the context types the definition declares. Publication results are persisted once a page of sources has been written to the publication's sinks, so a build keeps none of them in memory; those of a build whose sink fails later are kept until the source is published again. A source is evaluated once for all the sinks of its publication, so its results don't depend on how many sinks there are. Direct projection requests and materialized graphs never persist assessments.
Produced assessments are reporting output. They are deliberately asynchronous sidecars and are not inputs to calculations, projection factories, or subscription selection. This avoids timing-dependent business behavior.
Reported assessments
Use a reported assessment when another system owns the answer, such as a fraud provider. Register its contract explicitly so typos cannot create assessment types at runtime:
builder.AddVox(/* configuration */)
.AddReportedAssessment<Order>("FraudRisk", options =>
{
options.DisplayName = "Fraud risk";
options.Findings.Add(new VoxAssessmentFindingDefinition("address-mismatch", VoxAssessmentFindingSeverity.Warning,
"The addresses differ"));
options.Metrics.Add(new VoxAssessmentMetricDefinition("score", "Risk score"));
});
Report through IVoxAssessmentWriter or the assessment HTTP endpoints. ReportAsync updates one context without
removing the others; ReplaceAllAsync atomically replaces the complete context set. SourceResultId makes retries
idempotent, while SourceVersion and SourceTimestampUtc reject provably older reports.
Reported results require the {EntityType}:Assess:{AssessmentName} permission over HTTP. Reporting never creates an
assessment definition and never mutates the assessed entity.
Scheduled assessments
An evaluated assessment looks at one entity, and runs when what it read changes. Some checks look across entities instead, eg two products with the same EAN, or two pages that publish the same URL: when B changes its EAN to A's, A must get a finding too, although A didn't change and B's evaluation can't write A's results. A scheduled assessment works out for itself which entities have it, and runs on a schedule:
public class SharedEan : VoxAssessmentDefinition<Product>
{
public SharedEan() : base("shared-ean", displayName: "Shared EAN")
{
Shared = Finding("shared-ean", VoxAssessmentFindingSeverity.Warning, "Another product has the same EAN");
}
public VoxAssessmentFindingDefinition Shared { get; }
}
public class SharedEanAssessment(EanIndex eans) : IVoxScheduledAssessment<Product, SharedEan>
{
public TimeSpan Interval => TimeSpan.FromHours(1);
public async Task RunAsync(IVoxScheduledAssessmentContext<SharedEan> context, CancellationToken cancellationToken)
{
// Reads the products that share an EAN a page at a time, eg grouped in SQL
await foreach (var (productId, others) in eans.ListSharedAsync(cancellationToken))
{
(await context.ForEntityAsync(productId, cancellationToken))
.SetOutcome(VoxAssessmentOutcome.Warning)
.Finding(definition => definition.Shared)
.Add($"{others.Count} other products have the same EAN.");
}
}
}
- A run emits the complete set. It emits the result of every entity that has the assessment now, each once, and Vox removes the results of the entities it left out once the run completes. An entity loses the assessment by not being emitted, so the assessment never compares the old results itself. Vox writes the results a page at a time, so a run that emits thousands holds one page; the result of an entity is complete once the next entity is emitted. A run that fails removes nothing, and the pages it wrote stay; the next run starts over.
- Results are entity-wide and published, so the definition declares no contexts.
- One host at a time runs it,
Intervalafter its last run started, with a lease of its own in the database (the health checkvox_scheduled_assessmentsreports the runs). A host that takes it over doesn't run it again straight away, and a run that fails is run again after a short wait. - Reassessing runs it now. The admin UI's reassess button,
IVoxAssessor.ReassessAsyncandReassessAllAsync, and the reassess endpoints request a run of the whole assessment instead of queueing one entity, also from a host that doesn't process. Requests before the run starts lead to one run. The reassess-all endpoint answersEnqueuedAssessments: 0, since no entities are queued.
Findings lag by up to the interval unless someone reassesses. Classes in the application's assemblies are found like
evaluated assessments; an add-on registers its own with AddScheduledAssessment. Routing uses one to report
duplicate URLs.
Results, findings, and metrics
Evaluation state and outcome are separate:
- State is
Pending,Current,Stale, orError. - Outcome is
Pass,Warning, orFail.
This distinction lets Vox retain the last successful outcome and diagnostics while a later attempt is pending or has errored. An evaluator exception is operational state, not a failed business assessment.
A finding has a stable Code, severity, message, and optional path, key, related entity, and JSON details. The
path is the path of a value in the entity's JSON, with its contexts, eg content.description.sv, or the name of a
relation, eg prices, so that a UI can show the finding next to its field. Its
occurrence identity is (Code, Path, Key), which lets changed events distinguish added, changed, and resolved
findings. Metrics are named decimal values with an optional unit and can be filtered or sorted in reports.
ValidUntilUtc stores a pending expiry with the result, with its due time and the result's revision, so a refresh
supersedes the old expiry safely. On expiry, the matching result becomes stale and emits a change; evaluated assessments
are also evaluated again. Vox does not periodically scan all assessment rows. Say an approval that's valid for 30 days is
set on 200,000 products in one import: on the day it ends, the processing hosts pick up the 200,000 expiries that are
due and share them.
Evaluation in the background
A change that an evaluated assessment depends on is dispatched to it with the other work of the change, and stored as a
pending evaluation of the assessment and entity. Evaluations and expiries run in loops of their own, on every processing
host (see background work): each host claims a batch of the pending
ones, evaluates them and completes them, so when adding a market reaches 500,000 products, all the hosts evaluate them
together. A time that an evaluator asks to be evaluated again at, with ReevaluateAt, eg the end time of a campaign,
is stored with the pending evaluation as its due time, and the evaluation runs once it's due.
An evaluation that fails is recorded as the result's Error state, keeping the last successful outcome, and is tried
again later. The evaluations are eventually consistent, separate from the calculations: a failing assessment never
holds back a calculation or a publication. The health checks vox_assessment_evaluation and vox_assessment_expiries
report how the loops do.
In the API
Results are written like the rest of the API: their enums by name, eg "outcome": "Fail", and their contexts by the
query names of their types, eg "contexts": { "market": "se" }. Contexts are read by name in any case, so a report
can use either.
The assessments of an entity type are in its model in GET /api/entity-types, with their names, descriptions, context
types, findings and metrics, for those who may read its entities. With them, a UI shows assessments with the entities:
- Filters: a list is filtered by its entities' results, eg
?assessment.Sellability=Fail,Warningby outcome, whereNoneis the entities without a result,?assessment.Sellability[state]=Staleby state,?assessment.Sellability[finding]=missing-priceby finding and?assessment.Sellability[market]=seby the context of the results. The list's contexts, eg?context=market:se, narrow the results too. An entity matches when one of its results matches.VoxQuery.Assessmentsdoes the same in code. These queries are answered by the database, since assessments aren't in the search documents. - Results with the entities:
?includeAssessments=Sellability, or*for all, adds each entity's results to it, in_assessments, with their states, outcomes and counts of findings, and on a single entity its findings and metrics too. - Summaries:
GET /api/{entityType}/assessment-summary?assessment=Sellabilitycounts the entities of a list by outcome, state and finding, with the list's filters, search, content and contexts, so that the counts are what the filters show.
In a draft or release, the results of an entity with a draft are those of its draft, or its published results while its draft hasn't been assessed yet, and the results of an entity without a draft are its published results, since that's what the draft shows of it.
In the admin UI
The admin UI shows the assessments of an entity type with its entities, with its built-in voxAssessmentsPlugin:
- An entity: the rail has a section with each assessment's outcome in each context, eg as a chip per market,
and the findings and metrics of the one that's selected, the worst first. A finding with a path moves to its field,
and the field has an icon next to its label with its findings. Users with
vox:Calculationsassess it again. - A list: the rail has what needs attention, eg how many products fail or have a finding, and each one filters the list. Each assessment has a filter of its own, with its outcomes, states and findings and how many entities each would show. A summary counts every entity the list matches, so a filter counts when it's opened, and what needs attention while its section of the rail is shown. The list's context picker picks the context of the results, eg the market. In a perspective, the findings whose definition names a field it hides are left out of both, while the outcomes are still counted for the whole assessment.
Results are assessed in the background, so they're pending for a moment after an entity changes. The admin UI reads them again while they are.
Querying and events
The assessment API also has entity-scoped reads, cross-entity queries, reporting, and manual reevaluation.
VoxAssessmentQuery filters by entity, assessment, content scope, assessment context, state, outcome, findings,
metrics, and timestamps. Read authorization is applied in the database before counting and paging.
Assessment changes are delivered independently from ordinary entity events. Implement
IVoxAssessmentChangedHandler to react to state/outcome changes, finding differences, stale transitions, or removed
contexts. Delivery is durable and at least once, so handlers should be idempotent. This is the integration point for
health monitoring or a Slack/Teams bridge; configurable entity subscriptions and policy gates are intentionally
separate concerns.
Assessment storage is current-state sidecar storage, not an audit log. Queryable assessment history can be added as a separate capability if a compliance use case requires it.
Content scopes
Published, draft, and release assessments are stored independently. Both is only a read composition and is never a
stored scope. This lets CMS readiness follow the exact selection of contexts being previewed without contaminating the
published result.
An evaluated assessment is also evaluated at the keys with application contexts where the entity has cells that it
reads, eg {Language=sv} when a category's name is set in Swedish, and reads the entity in those contexts there.
GET /api/assessments/{entityType}/{id}?context=language:sv returns, of each assessment, the results at the most
specific key the selection matches that has results, so Finland Swedish falling back to Swedish gets the Swedish
results, and English, without a cell, the results of the content. Lists resolve them the same way: in a list with
?context=language:sv, the filters, the summaries and includeAssessments use the Swedish results of the entities
that have them, and the results of the content of the others. POST /api/assessments/query reads the results stored
at the key it's given.