Warden retention cleanup
The guard-side retention task: it deletes Warden records that have passed the retention windows set on Warden guard parameters, and it removes side records whose subject no longer exists. It never touches policy versions, and it never touches the audit evidence store (the Auditor half has its own purges).
At a glance
| Batch class | MGCWardenRetentionCleanup (it also calls MGCWardenDiffSetBuilder::archiveAgedSets and MGCWardenAuditLeaverIntakeRetention::purge) |
| Menu item | MGCWardenRetentionCleanupMenuItem, label Warden retention cleanup |
| Menu path | System administration → Setup → Warden retention cleanup |
| Who may run it | MGCWardenPolicyAuthorPriv (granted at Delete) → MGCWardenPolicyAuthoringDuty → Warden guard administrator (MGCWardenGuardAdministrator). The API operation MGCWardenBatchService.runRetentionCleanup is granted on the same privilege and re-checks the same menu item |
| Feature toggle | None. The class reads no feature toggle, so it runs, and purges, whichever of the seven Warden features are on or off |
| Company scope | Per legal entity: every select runs in the company the task runs in. Three of the tables it purges are global and are cleaned in full by a run in any company (see Inputs and outputs) |
| Scheduled by default | No. Nothing in the product creates a batch job for it |
| Recurrence | You choose. Neither the code nor the existing docs state one |
| Setup-gap rules watching it | None. No MGCWardenSetupGapRule value reports whether this task is scheduled or has run |
| Run record | None. The batch log carries three summary lines |
| Overlap guard | Not guarded by MGCWardenBatchOverlapGuard |
Purpose and business justification
Warden writes holds, execution exceptions, diff sets, governance events, signatures, run records and several kinds of side record on every governed document. Without a deleter they grow without bound, and several of them carry personal data (user IDs, signer names, the roles a leaver held). This task enforces these rules:
- Operational records (released holds, resolved exceptions, run records) go after a short window.
- Evidence (governance events, diff sets, signatures, evidence packs and five governance tables that hold personal data) is kept for the company's own evidence retention floor, and goes only after it.
- Derived side records (the requisition index, approved baselines, governance side records, count queues) are on no window at all. They live exactly as long as the record they describe, and are removed once that record is gone.
The class summary states the doctrine behind every guard: age says a row is old; it never says the matter is closed. So each purge also carries a "never purged" guard that keeps a row, at any age, while something can still act on it.
Several tables block their own delete() and name this task as their only deleter: MGCWardenEventLog,
MGCWardenDiffSet (and its lines), MGCWardenESignature and MGCWardenAuditLeaverIntake. This task uses
the sanctioned bypass (skipDeleteMethod or skipDataMethods, then doDelete()) on those tables only.
How and when it is triggered
- A batch job you create. Open the menu item, set a recurrence on the Run in the background tab and
submit it. The dialog has no fields of its own:
pack()returnsconNull()and the class reads everything fromMGCWardenParameters. - Run now. The same menu item without batch processing runs it at once.
canRunInNewSession()returns true, so the interactive run happens in a second session for the same user, with a cancellable progress form. - The batch API.
MGCWardenBatchService.runRetentionCleanupruns it synchronously in the caller's session and company, behindMGCWardenApiDispatch::canRunon the menu item. It returns Failed if anything escapesrun(), and Completed when every purge ran to its end. The service summary warns that this deletes data exactly as a scheduled run would, and can be long on a first run over a mature estate.
Nothing else calls the class: no event handler, workflow or other batch triggers it.
Configuration and scheduling options
All four windows are on System administration → Setup → Warden guard parameters, Retention group
(MGCWardenParametersForm, table MGCWardenParameters). The full parameter list is in
Configuration reference.
| Field | Label | Shipped default | Bound | Zero means |
|---|---|---|---|---|
HoldRetentionDays | Released hold retention (days) | 90 | 0 to 36525 days | This purge is off; released holds are kept |
ExceptionRetentionDays | Resolved exception retention (days) | 90 | 0 to 36525 days | This purge is off; resolved exceptions are kept |
EvidenceRetentionYears | Evidence retention (years) | 7 | 0 to 100 years | The whole evidence block is off (see below) |
OperationalRetentionDays | Operational run record retention (days) | 365 | 0 to 36525 days | The run-record purge is off |
- Defaults come from
MGCWardenParameters.defaultValues(), reached throughinitValue()when the singleton is created. Initialize Warden creates it; so does any first call toMGCWardenParameters::find(), including this task's own. In a company where nobody has run Initialize Warden, the first cleanup run therefore creates the row and purges on the shipped defaults. See Getting started. validateFieldandvalidateWriterefuse a value outside its bound. They also refuse a day window longer than the evidence floor (retentionWindowExceedsEvidenceFloor, 365 days to the year), unless the evidence floor or the day window is zero.OperationalRetentionDaystravels with copy-config. Its help text warns that a source file that omits the column imports it as zero, which switches the run-record purge off.- Batch group: the class sets none. The customer chooses.
- Choosing a recurrence. No interval is required. What the choice trades: a row is removed at most one recurrence after it passes its window, and every purge runs as one transaction per table, so a long interval makes each run larger and holds its locks longer (see Impact). Schedule one job in each legal entity that uses Warden.
Screenshot to add: the Retention group on Warden guard parameters, showing the four fields and their shipped defaults.
What it does
run() reads the parameters once and takes now once. It then runs these steps in order. Each numbered
purge is its own ttsbegin/ttscommit, covering the whole scan of that table.
run()
|-- 1 Released holds ............ if HoldRetentionDays > 0
|-- 2 Resolved exceptions ....... if ExceptionRetentionDays > 0
|-- 3 Evidence block ............ if EvidenceRetentionYears is in 0..100 and > 0
| 3a event log 3b diff sets (archive aged, then purge)
| 3c deprovisioning entries 3d health alerts 3e purge-proposal runs
| 3f firming requests 3g duplicate overrides
| 3h leaver intake records 3i signature manifestations 3j evidence pack runs
|-- 4 Referential purges ........ always (no window)
| index, baselines, three side records, two count queues
|-- 5 Operational run records ... if OperationalRetentionDays > 0
| sales sweep runs, TA sweep runs, duplicate sweep runs, simulations, drop tallies
'-- 6 Three info lines (only reached if every step above succeeded)
1. Released holds. Deletes MGCWardenHold rows in status Released, Cancelled or
BreakGlassReleased whose ReleasedDateTime is set and older than now minus HoldRetentionDays.
An Active hold is never touched.
2. Resolved exceptions. Deletes MGCWardenExecutionException rows in status Resolved or Dismissed,
created before now minus ExceptionRetentionDays. A ControlOutage exception is excluded by the query,
and the table's own delete() refuses one in any case. The age is measured on CreatedDateTime,
not on when the row was resolved.
3. The evidence block. If MGCWardenParameters::evidenceYearsOutOfBounds rejects
EvidenceRetentionYears (outside 0 to 100), the task writes an error naming the value, skips the whole
evidence block, and carries on with steps 4 and 5. A bad evidence window is not a reason to stop the other
purges. Otherwise, when the value is above zero, the cutoff comes from
MGCWardenParameters::evidenceCutoff (twelve months per year), and these purges run on it:
| Step | Table | Measured on | Never purged |
|---|---|---|---|
| 3a | MGCWardenEventLog | EventDateTime | A row with AuditForwarded = Yes: its copy lives in the audit store, where the store's own retention governs it |
| 3b | MGCWardenDiffSet with MGCWardenDiffLine | CreatedDateTime | A set that is not Archived, or that has a Pending workflow work item (a break-glass release frees the document without canceling its workflow, and deleting the set would make the approval stamp gate fail open) |
| 3c | MGCWardenAuditDeprovisioningEntry | CreatedDateTime | An entry still Proposed: an open security finding |
| 3d | MGCWardenAuditHealthAlert | RaisedDateTime | An alert not yet Reviewed |
| 3e | MGCWardenAuditPurgeProposalRun | StartedDateTime | A run still Running, or one with any proposal still Proposed, Approved or Certified |
| 3f | MGCWardenFirmingRequest | CreatedDateTime | A request still PendingApproval, or one whose hold is still Active |
| 3g | MGCWardenDuplicateOverride | CreatedDateTime | An override whose sales order still exists: it is still suppressing a duplicate warning |
| 3h | MGCWardenAuditLeaverIntake | CreatedDateTime (the import time) | See below |
| 3i | MGCWardenESignature | SignatureDateTime (when the act was signed) | A manifestation whose governed document still exists, or whose document is under an Active Warden hold |
| 3j | MGCWardenAuditPackRun with MGCWardenAuditPackSection | PeriodTo, the end of the period the pack covers | A run in Created or Running, or a run with no period end |
Notes on the evidence purges:
- Diff sets (3b). Before the purge loop, inside the same transaction,
MGCWardenDiffSetBuilder::archiveAgedSetsarchives every un-archived set older than the cutoff whose document has nothing outstanding (noActivehold of any type and no reconfirmation stillRequired) and which has noPendingwork item. This reaches the sets no decision ever closes, such as those recorded under a LogOnly posture. The loop then deletes them in the same pass, so no reader ever sees a set archived by age. The loop reads underpessimisticlock, soMGCWardenCorrelationBackfillwaits rather than causing an update conflict. - Leaver intake records (3h).
MGCWardenAuditLeaverIntakeRetention::purgelocks the intake chain head first, then deletes only final records (Raised,Linked,Quarantined,Withdrawn) that carry a seal (ChainSequence> 0) and whose deprovisioning entry no longer exists. An open record (received, pending, nothing to revoke, hired again) is kept until it settles, at any age. It counts the removals on the chain head so the chain still verifies, and writes one governance event of typeRetentionCleanupnaming chain sequences and counts. See HR deprovisioning scan and leaver intake. - Signatures (3i). Policy-activation manifestations are in effect kept for ever, because policy versions are never purged and so their document always exists. Count-case manifestations age out once count retention has removed the case.
- Evidence packs (3j). Sections are deleted set-based immediately before their run. A
FailedorSkippedrun is purged too: the builder's rollback already discarded its sections.
4. Referential purges. These run on every run, whatever the windows say, including when
EvidenceRetentionYears is zero. None has an age test.
| Table | Removed when | Never purged |
|---|---|---|
MGCWardenCustReqIndex | Its SalesId no longer exists in SalesTable | Nothing else: the row lives exactly as long as its order |
MGCWardenFieldBaseline | Its owning record (TableName, LineRefRecId) no longer exists | A row with LineRefRecId = 0 (left for MGCWardenBaselineScopeUpgrade) |
MGCWardenSalesGovState | Its document (RefTableId, RefRecId) no longer exists | A row whose Hold is still Active |
MGCWardenJournalGovState | Its reversing journal no longer exists | A row whose Hold or ReviewHold is still Active |
MGCWardenTAGateState | Its price journal no longer exists | A row whose Hold is still Active, or one the workflow runtime still holds an instance against (MGCWardenWorkflowInstanceHold::heldInstanceExists) |
MGCWardenCountJournalQueue | Its count case no longer exists and the row is Posted | Any row not Posted (an adjustment still owed), or one with no count case |
MGCWardenMissingQueueEntry | Its count case no longer exists and the entry is WrittenOff or Resolved | An entry still Quarantined or Aged, or one with no count case |
The existence probe (recordExists) fails safe: a zero RecId, or a table this deployment does not have,
reads as "exists", so the row is kept. The baseline scan is ordered so each owning record is probed once,
however many governed fields it has.
5. Operational run records. When OperationalRetentionDays is above zero, run() walks the list
MGCWardenRetentionCleanup::operationalRunTables() and dispatches each table to its purge
(purgeOperationalRunTable). The list is also what MGCWardenAuditGuardIngestion reads to decide which
event-log subjects are telemetry rather than evidence.
| Table | Measured on | Never purged |
|---|---|---|
MGCWardenSalesGovSweepRun with MGCWardenSalesGovSweepLine | StartedDateTime | A run still Running, or one with any line whose document is under an Active hold |
MGCWardenTAGovSweepRun with MGCWardenTAGovSweepLine | StartedDateTime | A run still Running |
MGCWardenDuplicateSweepRun | StartedDateTime | A run still Running, or the latest run for its CustomerFilter: the next duplicate sweep resumes from its cursor |
MGCWardenSimulationRun with MGCWardenSimulationLine | CreatedDateTime | A simulation whose policy version is not Superseded or Retired (still being decided, or still in force) |
MGCWardenAuditDropTally | TallyDateTime | A tally inside the widest window of any enabled DropCountInWindow health rule (60 minutes when none sets one) |
A table on the list with no purge arm makes purgeOperationalRunTable throw, deliberately, but only when
the window is above zero.
Extensible data security. Wherever a row is kept because something still exists (an order, a pending
work item, an Active hold, an undecided proposal, a live count case, a live policy version, a held
workflow instance), that question is asked inside unchecked(Uncheck::XDS). A data security policy that
hides a live record from the batch account therefore cannot make its dependent row look orphaned. The duplicate sweep run purge is left under data security on purpose: a hidden row there can only
keep a run, never delete the newest one.
Idempotency. Every purge deletes only what still qualifies, so a second run straight after the first deletes nothing more. Re-running after a failure is safe.
Concurrency. The task has no overlap guard and takes no claim. MGCWardenBatchService records the
argument that each purge's single transaction, with its optimistic updates and row locks, makes a
concurrent run roll back rather than delete twice, and that the loser may then read as failed.
Not confirmed: how two overlapping runs behave on a live estate; nothing in the repository exercises it.
Do not let two jobs for this class overlap in one company.
Dependencies and prerequisites
- A parameters row in the company (created by Initialize Warden, or on first read with shipped defaults).
- The audit retention classes, if you rely on the audit store to keep forwarded events: the event-log purge skips forwarded rows, and the store is governed by its own classes and dual-control purge, not by this task. See Audit purge proposals and Audit purge execution.
- No feature toggle, workflow or other batch is required for it to run.
- The leaver intake purge waits for the leaver intake chain head lock if an intake import holds it.
Inputs and outputs
Reads: MGCWardenParameters; SalesTable; WorkflowWorkItemTable; MGCWardenHold;
MGCWardenAuditPurgeProposal; MGCWardenPolicy; MGCWardenAuditHealthRule; MGCWardenCountCase;
MGCWardenAuditDeprovisioningEntry (for the leaver guard); MGCWardenSalesGovState (for the reconfirmation
guard); the workflow runtime's instance table through MGCWardenWorkflowInstanceHold; and any document
table named by a row's RefTableId or TableName.
Deletes: every table named in the purge tables above, plus MGCWardenHold and
MGCWardenExecutionException. Company scope of the purged tables:
| Scope | Tables |
|---|---|
Global (SaveDataPerCompany = No): any company's run cleans every company's rows | MGCWardenAuditHealthAlert, MGCWardenAuditPurgeProposalRun, MGCWardenAuditDropTally |
| Per company: only the running company's rows | Every other table this task purges |
Writes: MGCWardenDiffSet.Archived (step 3b); MGCWardenAuditLeaverIntakeChainHead removal count and
one MGCWardenEventLog row of type RetentionCleanup when leaver records are removed (step 3h). Nothing
else: no run record, no execution exception, no business event, no hold, no work item.
Infolog, printed only after every step has succeeded:
Warden retention cleanup: N holds, N exceptions, N evidence rows, N governance rows purged; N orphaned requisition index rows removed.(Evidence rows are event-log rows plus diff-set headers. Governance rows are steps 3c to 3h.)Warden retention cleanup (operational): N evidence pack runs purged with their sections, N orphaned baseline/state/queue rows removed, N run records purged.Warden retention cleanup (21 CFR 11.50): N signature manifestations purged beyond the evidence window. ...Signatures are reported on their own line because this is the only purge that destroys a 21 CFR Part 11 record.
Plus, when the evidence window is out of range, one error line before them saying the evidence purge did not run.
Logging and monitoring
- Batch job history (System administration → Inquiries → Batch jobs) is the only place a scheduled run leaves its counts: the three info lines above, or the exception that stopped it.
- Governance event log (System administration → Setup → Governance event log) shows the
RetentionCleanupevent for leaver records. The other purges write no event. - No setup-gap rule watches this task. An unscheduled cleanup is visible only as growth of the tables it purges.
- No overlap refusal or execution exception is ever filed by it.
Errors, recovery and troubleshooting
- The class has no
catch. An exception in any purge rolls back that purge's transaction and escapesrun(). The batch task ends in error; purges that had already committed stay done; later purges do not run, and none of the three info lines is printed. The next run starts from the top and repeats only what still qualifies. - Update conflicts. A writer that commits between this task's read of a row and its delete can make
the delete fail with an update conflict, which rolls that purge back. The
MGCWardenTAGateStatepurge names this case: a workflow handler committing mid-loop. The next run repeats the purge. - Evidence window out of range. The error line names the value. Correct Evidence retention (years); the other purges have already run.
- First run on a mature estate. Each purge is one transaction across the whole table, so the first run can be long and hold many row locks. Run it outside working hours.
- What to look at first: the batch job log for the error, then the parameter values. If nothing seems to be purged, check that the windows are not zero and that the job runs in the company you expect.
- Expected behavior: a deleted trade agreement journal's gate record survives the cleanup while the workflow runtime still holds its approval.
Impact on other functionality
When it does not run: nothing is blocked. Tables grow, and personal data outlives the retention floor the company set. Two effects reach users:
- Orphaned
MGCWardenCustReqIndexrows stay, so duplicate detection can warn about a duplicate of an order that no longer exists. - Run inquiries (sweep runs, simulations) and the hold and exception lists keep growing.
While it runs: each purge holds its transaction for the length of its table scan.
MGCWardenDiffSetrows past the window are read underpessimisticlock; other writers of those rows (MGCWardenCorrelationBackfill) wait.- The leaver intake chain head is locked for the length of step 3h; an external-HRIS intake import, which locks the same head, waits.
- Other purged rows are selected
forupdate.
What it can never remove: policy versions, Active holds, ControlOutage exceptions, event-log rows
forwarded to the audit store, anything in the audit evidence store, and the snapshot table behind the
setup-gaps tile (that is replaced by its own batch, see Warden setup-gap snapshot).
Related documentation
- Warden batch framework: how Warden batches are built and scheduled, and the summary of every Warden batch.
- Count case retention cleanup: the count-case retention task, whose deletions leave the queue orphans step 4 removes.
- Role event retention, Audit purge proposals, Audit purge execution: retention on the Auditor side.
- Guard event ingestion: what sets
AuditForwarded, and why run-record subjects are not forwarded. - HR deprovisioning scan and leaver intake: leaver intake records and deprovisioning entries.
- Configuration reference: every parameter on Warden guard parameters.
- Getting started: Initialize Warden and the parameter defaults.