Trade agreement approval sweep
Finds unposted trade agreement price journals whose Warden price governance approval was granted under a price-guard policy set that is no longer in force, and supersedes those approvals so the journals are measured against the rule in force when they post. It blocks nothing and routes nothing.
At a glance
| Batch class | MGCWardenTAGovSweep (RunBaseBatch; caption Warden trade agreement approval sweep) |
| Menu item | MGCWardenTAGovSweepMenuItem, label Trade agreement approval sweep |
| Menu path | System administration → Setup → Trade agreement approval sweep |
| Run history | System administration → Setup → Trade agreement approval sweep runs (MGCWardenTAGovSweepRuns), which also has a button for the menu item |
| Who may run it | Privilege MGCWardenTAGovSweepPriv (Run the Warden trade agreement governance sweep), in duty MGCWardenPolicyActivationDuty, in role Warden controls owner (MGCWardenControlsOwner). The run history page is on the same privilege. The API operation MGCWardenBatchService.runTAGovSweep sits on the same privilege |
| Feature toggle | Warden Trade Agreement Governance (MGCWardenTradeAgreementGovFeature), the only Warden toggle that is on by default. With it off the run stands down: it writes a Skipped run record and supersedes nothing |
| Company scope | Per legal entity. It reads and writes the company it runs in only |
| 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; see Configuration and scheduling options |
| Setup-gap rules | None watch this sweep or its schedule |
Purpose and business justification
A trade agreement journal that breaches a price-guard floor is gated and routed for approval.
Once approved, the approval lets the journal post without being re-measured, as long as its content
has not changed (MGCWardenTAPostGuard Guard A2). An edit invalidates the approval. A policy change
deliberately does not: re-gating on a policy move would undo a decision a human took and route the
journal straight back to the approver.
That left a gap. After a floor is tightened, an approved but unposted journal still posts under the old
rule. MGCWardenTAGateState.ApprovedPolicySignature records which policy set each approval was granted
under, so the affected journals can be found by query. This sweep is that query and the action on it
.
The sweep supersedes the stale approval. It does not re-evaluate the journal and does not route a new approval. The only consequence is that the next posting attempt measures the journal against the policy in force:
- compliant under the new rule: it posts, with a cleared at post evidence row and no human involved;
- breaches a Route-posture floor, or its effective dates need approval: the posting guard gates it and routes one approval;
- breaches a Block-posture floor: the posting guard refuses it outright and routes nothing.
Deciding at posting rather than at sweep time is deliberate. A verdict reached by the sweep would be stale again by the time the journal posts, and a sweep that routed on staleness would put compliant journals in front of approvers.
How and when it is triggered
- Manually, from the menu item or from the button on Trade agreement approval sweep runs.
- As a batch job, if you submit it to the batch framework with a recurrence from the same dialog. Nothing in Warden does this for you.
- Through the API,
MGCWardenBatchService.runTAGovSweep(journalFilter, maxJournals, includeUnstamped). See Warden batch framework.
Nothing calls the sweep when a price-guard policy is activated.
Configuration and scheduling options
Dialog fields
| Field | Default | Meaning |
|---|---|---|
| Journal number | Blank | Blank sweeps every unposted journal. The value is matched with like, so a pattern such as TA-2026* sweeps a slice and an exact number sweeps one journal |
| Maximum journals | 500 (#DefaultMaxJournals) | Ceiling on journals examined. Must be 1 to 20,000 (#AbsoluteMaxJournals); validate() refuses anything else |
| Include approvals with no policy stamp | Yes | Yes treats an approval with a blank ApprovedPolicySignature (granted before stamping existed) as stale. The dialog help says to leave it Yes until the estate has been swept once |
The three values are packed (pack() / unpack(), version 1). If they cannot be restored, RunBase
falls back to initParmDefault(). A cap of zero or out of range at run time falls back to 500
(effectiveCap()), and the run record states the cap used.
Scheduling
There is no parameter on MGCWardenParameters for this sweep, and no batch group is set in code. The
interval is your decision. The trade-offs:
- The interval is the window after a price-guard policy change in which an approved journal can still post on the strength of an approval granted under the superseded rule.
- A run is cheap. It reads gate-state rows and writes two columns per stale approval. It evaluates nothing.
- A superseded journal pays a full price-guard walk at its next posting attempt, as a never-approved journal does.
Because nothing runs the sweep on activation, the window after a policy change lasts until the next run, whether that run is scheduled or started by hand.
What it does
run()
|-- Trade Agreement Governance off? --> Skipped run, event row, info line; stop
|-- fingerprint = MGCWardenTAPriceGuardSignature::current()
|-- createRun() own transaction; run row in Running
|-- selectCandidates() approved, stale, not superseded, unposted
| skip gated, skip held (before the cap)
|-- for each candidate: sweepOne()
| re-check exists / posted / gated / held
| MGCWardenTAGate::supersedeApproval own transaction, row locked
| sweep line
|-- closeRun() Completed or Partial; event row; evidence store
'-- anything escapes --> failRun(): run Failed + Error exception
- Feature check. If
MGCWardenTradeAgreementGovFeature::isOn()is false,recordFeatureOff()writes a Skipped run and aPolicySweepevent row. Superseding with the feature off would remove a journal's fast path while the posting guard that takes the decision instead is not running. - Fingerprint.
MGCWardenTAPriceGuardSignature::current(), the same value the submit and posting paths stamp on an approval. Item cost is not in it. - Run record.
createRun()inserts aMGCWardenTAGovSweepRunrow (RunId prefixTS) in status Running, with the fingerprint, filter, cap and a parameter snapshot naming the requester by subject reference. - Candidate selection reads
MGCWardenTAGateStaterows forPriceDiscAdmTablewhereApprovedSignatureis not blank,ApprovedPolicySignaturediffers from the fingerprint andApprovalSupersededDateTimeis empty, joined to journals withPosted= No that match the filter. Posted journals are excluded in the query and not counted. An unstamped approval is skipped when Include approvals with no policy stamp is No. A journal that is gated (an approver already holds an open decision) or carries a Warden hold is skipped before the cap is charged and counted. When the cap is reached the run is marked capped. - Per journal.
sweepOne()re-reads the gate state and the journal and records a line:- journal gone: Skipped: journal no longer exists;
- posted since selection: Skipped: already posted;
- gated or held since selection: Skipped: already gated / Skipped: already held;
- otherwise
MGCWardenTAGate::supersedeApprovalis called. In its own transaction it reads the row withpessimisticlock, re-asks every condition under the lock, and writesApprovalSupersededDateTimeandSupersededPolicySignature. It writes aPolicySweepevent row on the journal naming the old and new fingerprints.ApprovedSignatureandApprovedDateTimeare left in place as the record of what was approved. A true return records Approval superseded. A false return records Not superseded: the write failed and files an Error execution exception.
- Close.
closeRun()sets Completed or Partial, writes the counts (examined, superseded, skipped gated, skipped held, failed) and a summary. A run that found nothing says so in words: NOTHING WAS FOUND: every approval on an unposted price journal in scope was granted under the price-guard policy set in force. It writes aPolicySweepevent row for the run, records a coverage claim in the audit evidence store (MGCWardenAuditSelfAudit,TAApprovalPolicySweep), and prints one info line. A Partial run also files a WarningControlOutageexception.
Transactions
The run holds no transaction of its own. The run row, each supersession, each sweep line and the run
close are separate short transactions. Inside a transaction only a catch naming UpdateConflict or
DuplicateKeyException runs; every other catch does not, which is why each write stands alone.
supersedeApproval and the line writer each catch their own failures. A failure anywhere else in
sweepOne() (reading the gate state or the journal) is not caught per journal: it ends the whole run
as Failed through run()'s catch.
Concurrency
The sweep is not in the MGCWardenBatchOverlapGuard population. It protects itself: the supersession
is a conditional update under a row lock, re-asked under the lock, so a second run finds the approval
already superseded and does nothing. A fresh approval or a new gate arriving between selection and the
write is also seen under the lock.
Idempotency
Re-runs are safe. A superseded approval is excluded by the candidate query, and supersedeApproval
refuses a second supersession on its own account. A journal becomes a candidate again only after an
approver grants a fresh approval (which clears the supersession stamp) and the policy moves again.
Dependencies and prerequisites
- Warden Trade Agreement Governance switched on (it is on by default). See Getting started.
- Approved journals. The sweep acts only on approvals already recorded on
MGCWardenTAGateState(ApprovedSignaturenot blank), which come from the Warden trade agreement approval workflow. - A superseded journal is re-measured by
MGCWardenTAPostGuard::evaluateAtPost, which is called from the trade agreement posting seamMGCWardenPriceDiscAdmCheckPost_Extension. See Standard batch and periodic processes with Warden installed.
Inputs and outputs
| Reads | Writes |
|---|---|
MGCWardenTAGateState | MGCWardenTAGovSweepRun (one row per run, including Skipped and Failed runs) |
PriceDiscAdmTable (exists, Posted, JournalNum) | MGCWardenTAGovSweepLine (one row per journal reached, with outcome, the approval's fingerprint and date) |
| Active price-guard policies (fingerprint) | MGCWardenTAGateState.ApprovalSupersededDateTime, .SupersededPolicySignature |
MGCWardenHold (is the journal held) | MGCWardenEventLog rows of type PolicySweep: one per superseded journal, one per run |
| Execution exceptions (see Errors) | |
| An audit evidence store entry per completed run | |
| One infolog line: examined, superseded, skipped gated, skipped held, Partial flag |
No hold, workflow instance, work item or business event is created by this sweep.
Logging and monitoring
- Trade agreement approval sweep runs shows each run with a Journals tab of lines. The page is read-only. Read the two skip counts beside the superseded count: a run that superseded nothing because everything was gated reads differently from one that found nothing.
- Execution exceptions (System administration → Setup → Execution exceptions) and the Governance event log (System administration → Setup → Governance event log).
- Batch job history for a scheduled run's info line.
- No setup-gap rule reports that this sweep is unscheduled or stale.
Run records are purged by retention cleanup after OperationalRetentionDays
(365 on a new parameters record; zero keeps them). Only a run still Running is kept regardless of
age; the supersession facts live on the gate state, not on the run.
Errors, recovery and troubleshooting
| What happened | What you see | What to do |
|---|---|---|
| Feature off | Run Skipped | Nothing, or switch the feature on and run again |
| Cap reached | Run Partial; Warning ControlOutage | Run again; it continues with the approvals not yet superseded |
supersedeApproval returned false | Line Not superseded: the write failed; Error exception naming the journal | See below |
| The write itself failed | As above, plus a Warning from supersedeApproval saying the supersession could not be written | Fix the cause and run again; the journal is still a candidate |
| Sweep line could not be written | Warning EventLogFailure | Nothing; the event log still records the supersession |
| Whole run failed | Run Failed; Error ControlOutage | Read the exception, fix the cause, run again |
supersedeApproval also returns false when, re-asked under the lock, the row no longer qualifies: a
fresh approval granted under the current policy, or a gate opened, between selection and the write.
The sweep records that case as Failed with the same Error text, which says the journal will still post
on a superseded decision. Before acting on such an Error, open the journal's gate state: if
ApprovedPolicySignature now matches the run's fingerprint, the approval is current and nothing is
owed.
A run killed mid-flight leaves its row in Running; nothing closes it later. It is safe to run again.
Impact on other functionality
- Nothing is blocked by the sweep itself. Users can keep editing and posting journals. The effect appears at the next posting attempt, which may now refuse or gate a journal that would previously have posted on its approval. Pricing users can be surprised by this; the event row on the journal explains it.
- Approvals granted by an earlier build to a journal with a Block-posture breach still stand: the fingerprint did not move, only what Block means, so this sweep does not see them as stale.
- Locks. One
MGCWardenTAGateStaterow per supersession, for one short transaction. - Not covered. A change to item cost can change a minimum-margin verdict without moving the fingerprint.
- If the sweep never runs, approved journals continue to post under the policy set they were approved under, however much it has since been tightened.
Related documentation
- Warden batch framework
- Route drains:
MGCWardenTARouteDrainBatch, which raises the approval a gated trade agreement journal is owed. - Standard batch and periodic processes with Warden installed: what Warden changes in trade agreement journal posting.
- Sales governance policy sweep and Duplicate requisition sweep.
- Warden retention cleanup
- Getting started