Skip to main content

History and audit

Entity history records retained versions and changes to fields. Entity logs record business or operational events such as payment attempts.

For the team workflow, see Trace a change.

Entity versions​

An entity type can keep the immediately previous version of each entity with the entity itself, which GET /api/{entity}/{id}/previous returns. Add [VoxPreviousVersion] to keep it: every update then stores the entity as it was before the update, so each row holds about twice its document. Without the attribute an update stores only the entity, and /previous answers 404. Concurrency doesn't depend on it: stale writes are caught by versions. Adding or removing the attribute moves no stored data; a type that stops keeping the previous version clears it at the entity's next update.

[VoxPreviousVersion]
public class PriceList : IVoxEntity
{
// ...
}

Add [VoxHistory] when the business needs every earlier version, or a longer record:

[VoxHistory(KeepVersions = 100, KeepForDays = 365)]
public class Campaign : IVoxEntity
{
// ...
}

Each retained version records the entity type and ID, version number, timestamp, principal, cause, changed field paths, deletion state and the variations it changed. The snapshot contains the complete entity and its variations as they were at that version. A separate diff returns the previous and new value of each changed field.

Both kinds of retention store a whole copy of the entity for every change, also for a change of only its calculated values, eg an availability that follows the stock of a supplier. Entity Framework storage otherwise writes only the calculated values in that case, see Calculated values in a column of their own, so for a large entity that's recalculated often, retention roughly doubles what a recalculation writes.

Retention can limit the number of versions, their age, or both. Zero means unlimited for that dimension, and Vox always keeps the newest retained version of an entity. Retention is enforced by background work rather than by slowing down each write: every VoxOptions.HistoryRetentionInterval, an hour by default, one processing host prunes the versions of a batch of entities at a time (VoxOptions.Retention.BatchSize), at most ten versions per entity of the batch in a transaction, so a batch of entities with long histories takes several. It prunes a batch of each entity type in turn, so a type of millions of entities doesn't take the time of the others, for at most VoxOptions.Retention.MaxRunTime per run, and the next run continues from the entity where it stopped, so a pass over millions of entities spans runs without reading the first entities again. The versions of an entity type that a model migration is converging are kept until it's done.

Versions are read a page at a time, newest first: a page has the continuation of the next one (GetVersionsAsync(entityType, id, continuation, take), and ?continuation= in the API), which continues after the last version of the page rather than counting the versions before it, and the versions aren't counted.

History reads use the same entity read scope and sensitive-field redaction as current entities. A principal cannot use an old version or diff to recover data it may not read now.

Cross-entity audit​

The audit view searches version metadata across every entity type with history. It can answer questions such as:

  • What did this user or API client change today?
  • Which campaigns changed because of publication rather than an import?
  • Who changed a price field during a given interval?
  • What happened to this entity across actions, imports and calculations?

Results can be filtered by entity type, entity ID, principal, change cause, property and time range. Access to this cross-entity view requires the dedicated audit permission; ordinary per-entity history remains governed by that entity's read scope.

History is useful for audit, comparison and recovery workflows. It is not an event stream for integrations: use events and subscriptions when another system must react durably to changes.

Edits of drafts and releases​

Drafts and releases aren't in the history of an entity until they're published. Every edit of one is recorded in an append-only audit log instead: who made it, when, in which draft or release, and the fields it changed with their values before and after, the relations it linked and unlinked, and the variations it changed. Publishing, reverting, scheduling, resolving conflicts and unpublishing are recorded too. The log is kept after a draft is published or reverted, and after a release is published or deleted, so who changed what in a release stays known, unless VoxOptions.Retention.CellAuditAge is set. It's a record, not a source for restores.

Every edit is an entry of its own, also the quick autosaves of the visual preview: entries are never merged.

Read it with IVoxCellAuditLog, or over HTTP:

  • GET /api/{entityType}/{id}/audit lists the edits of an entity, the latest first, each with its scope. Add scope=draft, or scope=release:{releaseId}, for the edits in one draft or release. It's read like the entity's history, and the changes of sensitive fields the principal may not read are left out.
  • GET /api/content-releases/{id}/audit lists the edits in a release. It requires vox:ContentReleases, leaves out the entity types the principal may not read, and leaves out the changes of sensitive fields.

Sanitizing or purging an entity removes its edits from the log, since they hold its values.

Entity logs​

Implement IVoxEntityLogEntry<TEntity> for a payload and append it either through IVoxEntityLog, or from an action or import through changes.Log.Append(...). Entries collected by a handler are written atomically with its entity change. No automatic entry is created for ordinary writes, so applications that do not use entity logs do not pay a per-write allocation or storage cost. Standalone appends need {EntityType}:Log:Append; reads need {EntityType}:Log:Read and the ordinary entity read permission. Both log permissions may be limited with :My. Log payload fields can use [VoxSensitive] and are masked by the same classification permissions as entities.

Entity logs complement history. A history version says that an order's fulfilment status changed; a log entry can say that a carrier request timed out, which endpoint was attempted and whether the next retry succeeded. Logging the latter as fake entity versions would make both the entity model and its audit trail less clear.

Set VoxOptions.EntityLogKeepForDays to a positive value to enable retention. Zero keeps retention disabled. The oldest entries are removed a batch at a time, like versions, every VoxOptions.EntityLogRetentionInterval, an hour by default. Entity logs, sanitization, and purge are capabilities of the authoritative storage provider. The Entity Framework provider implements them; a provider without IVoxEntityLogStore or IVoxEntityPrivacyStore fails explicitly when the corresponding operation is requested.

Retention of other records​

Other records grow with time or edits too, and the retention removes them by age, on one processing host every VoxOptions.Retention.Interval (an hour by default), a batch at a time (BatchSize, 500 by default), each in its own transaction, for at most MaxRunTime per run, so a backlog of millions drains over several runs while other work goes on. The retention is Vox background work, not a Nexus job: it records when it last ran, so a host that starts doesn't run it again straight away, and it reports the vox_retention health check. The records, their setting and default:

RecordsRetentionDefault
Audit of the edits of drafts and releasesCellAuditAgeKept
Publications of releases, which their item history and revert read; one with a scheduled revert is keptReleasePublicationAgeKept
Revisions of deleted entities, which order the snapshot of a deletion after the othersTombstoneAge30 days
Retired members of contexts, which keep a late snapshot from bringing their content backTombstoneAge30 days
Finished synchronizations of subscriptions, except the latest of eachBookkeepingAge30 days
Revoked download grants of assets, resolved issues and steps of completed model migrations, and publications of drafts kept for a restore that never ranBookkeepingAge30 days
Finished holds and immediate changes of Accumulators, which recognize a late retry, removed by the vox_accumulator_maintenance work, see limits and reservationsFinishedHoldAge30 days

The revision of a deleted entity is kept while a change of it is still to be delivered, and one whose entity exists again, eg only in a draft, isn't removed. Removing revisions raises a floor that new revisions continue from, so an entity that's created again with the id gets snapshots ordered after those of the one that was deleted. The revisions of the links in a release are removed with its content when it's published or deleted, with the same floor. A retired member is kept while its content is cleaned up.

Some records are kept on purpose: the current state of entities, eg their revisions, dependencies, assessments and journals, which grows with the catalogue rather than with time. Removing an entity type deletes its entities, their cells, history and other records a batch at a time in its model migration step, without delete events, search index removals or recalculations.

Sanitization​

Sanitization preserves the entity and its references while replacing business data. Register an IVoxEntitySanitizer<TEntity> with a stable Name, then call IVoxEntityPrivacy.SanitizeAsync. The caller needs {EntityType}:Sanitize:{sanitizer}, optionally limited with :My.

Vox writes the sanitized entity, removes older snapshots and drafts, clears previous log payloads, and adds a safe Sanitized log entry in one storage transaction. A sanitizer may not change the entity id or its relation properties. This is the normal building block for a right-to-be-forgotten workflow because orders and other business records keep valid references to an anonymized subject.

Hard purge​

IVoxEntityPrivacy.PurgeAsync permanently removes every Vox-managed trace of an entity. It requires the unrestricted {EntityType}:Purge permission and rejects the operation while another entity relation or rich-text value references the target. Purge removes current and draft data, history, logs, indexes, memberships, credentials, assessments, release metadata, and stored references. Asset content is deleted after the database transaction commits.

Projection publications delete the purged entity's documents from every sink, like those of a deleted entity. Until each sink has published that deletion, the publication keeps the entity's ID in its pending work and the IDs of the documents a sink still has, never their content; then they're removed. A sink that's down keeps them until it works again.

Downstream consumers receive a VoxEntityChangeKind.Purge tombstone with identity and version only. Snapshot subscriptions use the vox-entity-snapshot/v9 format and have a null entity for delete and purge events. Purge is intentionally distinct from an ordinary delete, whose retained history can still be useful for audit and recovery.