Count case retention cleanup
Deletes closed count cases, with their lineage, and old counter records once they are past the closed-case retention window. Count Governance (Package C).
At a glance
| Batch class | MGCWardenCountRetention (caption Warden count retention) |
| Menu item | MGCWardenCountRetentionMenuItem, label Count case retention cleanup |
| Menu path | System administration → Setup → Count case retention cleanup |
| Who may run it | MGCWardenPolicyAuthorPriv (Update grant) → MGCWardenPolicyAuthoringDuty → Warden guard administrator (MGCWardenGuardAdministrator), plus the platform's System administrator. The Warden count supervisor role does not get it. Also callable over the batch API as MGCWardenBatchService.runCountRetention, behind the same menu item |
| Feature toggle | None. The class does not test MGCWardenCountGovFeature, so it does not stand down: it purges with Count Governance off |
| Company scope | Per legal entity. It reads its own company's parameters and purges its own company's rows |
| Scheduled by default | No. Nothing in the product creates a batch job for it |
| Recurrence | You choose. No recurrence is stated in code or docs |
| Setup-gap rules that watch it | None |
Purpose and business justification
Count cases and counter records name the people who counted and reviewed. Keeping them for ever is
neither necessary nor, for personal data, defensible. A retention window sets when a closed case goes. The counter log (MGCWardenCountWorkerLog, who counted which work line) would otherwise
grow with every counting pass for ever (method summary on purgeWorkerLog).
Two guards keep what is still live:
- a closed case whose MISSING-queue entry is not yet settled (
WrittenOfforResolved) is kept, because stock is still sitting in the MISSING location; - a counter record is kept while any count case still points at its work, because the different-worker recount gate reads it at take time.
How and when it is triggered
- Scheduled batch job, created by an administrator from the menu item's dialog. Nothing schedules it out of the box.
- Run now from the menu item.
canRunInNewSession()returnstrue, so an interactive run is marshalled to a second session for the same user. - Batch API:
MGCWardenBatchService.runCountRetention. Its summary warns: "THIS DELETES DATA."
Configuration and scheduling options
Dialog. No fields. pack() returns conNull(); the dialog shows only the standard batch tab.
Parameter (System administration → Setup → Count governance parameters,
MGCWardenCountParameters, one row per legal entity):
| Field | Label | Default | Effect |
|---|---|---|---|
ClosedCaseRetentionDays | Closed case retention (days) | 365 (initValue) | The window for both purges. 0 switches both purges off and keeps everything. Bounded to 0 - 36525 on write |
The window is measured from the case's CreatedDateTime, not from the day it closed. A case
opened 400 days ago and closed yesterday is purged on the next run under the default window.
Choosing a recurrence. The trade-off is between how long a row outlives its window and how much each run deletes. A run deletes everything past the window in one transaction per purge, so an infrequent schedule makes for larger transactions. A first run on an estate that has never run it deletes the whole backlog at once.
Batch group. No guidance in code.
What it does
run()
|- purgeClosedCases() one transaction
| window <= 0? -> return
| for each Closed case created before (now - window):
| unsettled MISSING entry? (read past XDS) -> keep, skip
| delete its lineage rows (skipDeleteMethod + doDelete)
| delete the case
| info "N closed case(s) purged"
|- purgeWorkerLog() one transaction
window <= 0? -> return
delete counter records created before (now - window)
with no count case whose OriginWorkId is the record's work (past XDS)
info "N counter record(s) purged"
- Closed cases (
purgeClosedCases). Cutoff isutcNow()minusClosedCaseRetentionDays. Candidates areMGCWardenCountCaserows in statusClosedcreated before the cutoff. Open cases are never candidates, andMGCWardenCountCase.delete()refuses one anyway.- Missing-entry guard. A
MGCWardenMissingQueueEntryfor the case in any state other thanWrittenOfforResolvedkeeps the case. The read runs insideunchecked(Uncheck::XDS), so a data security policy that hides the entry from the batch account cannot make it look absent . - Lineage.
MGCWardenCountLineage.delete()throws ("Count case lineage carries Part 11 traceability and cannot be deleted"). This task is the single sanctioned deleter: it setsskipDeleteMethod(true)and callsdoDelete()for the purged case's lineage rows only. - The case row itself deletes through its normal
delete().
- Missing-entry guard. A
- Counter records (
purgeWorkerLog). Same cutoff, onMGCWardenCountWorkerLog.CreatedDateTime, with anotexists jointoMGCWardenCountCaseonOriginWorkId == WorkId. The whole loop runs insideunchecked(Uncheck::XDS).
Transaction boundaries. Two transactions, one per purge. The case purge commits before the counter purge starts, so a failure in the second leaves the first done.
Error handling. The class has no try/catch. Any failure rolls back the purge in progress and
escapes run(); a scheduled task then ends in error.
Concurrency. Not in MGCWardenBatchOverlapGuard's population. Two overlapping runs are not
refused; each purge is one transaction over forupdate reads, so a concurrent loser rolls back rather
than deleting twice (MGCWardenBatchService class summary), and may then read as failed.
Idempotency. A re-run deletes only what is still past the window and unguarded. Running it twice in a row deletes nothing the second time.
Dependencies and prerequisites
- The count parameters row for the company.
MGCWardenCountParameters::find()creates it on first use with theinitValuedefaults, so a company that never opened the parameters page purges on the 365-day default. - Nothing else. Count Governance does not need to be on.
Inputs and outputs
| Direction | Table | What |
|---|---|---|
| Reads | MGCWardenCountParameters | ClosedCaseRetentionDays |
| Reads (past XDS) | MGCWardenMissingQueueEntry | The missing-entry guard |
| Deletes | MGCWardenCountCase | Closed cases past the window, unless guarded |
| Deletes | MGCWardenCountLineage | The purged cases' lineage |
| Deletes | MGCWardenCountWorkerLog | Counter records past the window whose work backs no case |
| Infolog | "Warden count retention: N closed case(s) purged." and "… N counter record(s) purged." (each printed only when the window is above zero) |
It writes no event-log row, no execution exception and no run record. The governance event-log rows about each case are not touched; they live on the evidence retention window and are removed by Warden retention cleanup.
MGCWardenCountCase declares no delete actions, so a purged case's rows in
MGCWardenCountJournalQueue and MGCWardenMissingQueueEntry are left pointing at nothing. Warden
retention cleanup removes them later, but only once a queue row is Posted or a missing entry is
settled (purgeOrphanedCountQueueEntries, purgeOrphanedMissingEntries).
Logging and monitoring
- Batch job history: the two info lines are the only record of what was deleted.
- Counting passes by worker (System administration → Setup → Counting passes by worker) and Count case lineage (System administration → Setup → Count case lineage) show what remains.
- No setup-gap rule reports an unscheduled or failing count retention.
Errors, recovery and troubleshooting
| What happened | What you see | Recovery |
|---|---|---|
Window is 0 | No info lines; nothing deleted | Intended: retention is off |
| A delete failed in the case purge | Task in error; no case deleted in that run | Read the batch log, fix the cause, re-run |
| A delete failed in the counter purge | Task in error; the case purge's line is present and its deletes stand | Re-run; the case purge finds nothing new |
| A case you expected to go is still there | Check its status (only Closed goes), its CreatedDateTime against the window, and whether its MISSING entry is still Quarantined or Aged |
Re-running is always safe: every delete is decided again from the current data.
Impact on other functionality
- Evidence and reports. Once a case is purged its lineage is gone with it. The count KPI entities and tiles count only cases that still exist, so a period older than the window no longer gives true rates (USER_GUIDE §7).
- Different-worker recount gate. Unaffected while a case exists: the counter record behind it is kept.
- Erasure. An erasure request for a worker is deferred until their count cases and counter records
leave this window.
MGCWardenErasurePreconditions.caseLapseOncomputes that date on this batch's rule (CreatedDateTimeplus the company's window; never for a case that is not closed). See Erasure execution. - Locks. Each purge holds one transaction over every row it deletes, for the length of the purge.
- When it does not run, closed cases and counter records simply accumulate past the window. Nothing is blocked.
Related documentation
- Batch framework.
- Count consolidation run and Aged-MISSING monitor.
- Warden retention cleanup - removes the queue rows and missing entries a purged case leaves behind.
- Erasure execution.
- Count supervisor.