Repository: dmwm/wmcore
Issue: MSRuleCleaner potentially not cleaning unlocked input dataset rules

**Impact of the bug**
MSRuleCleaner

**Describe the bug**
A possible issue with MSRuleCleaner has been reported in the past week, where it leaves Rucio rules behind for some of the input datasets. Amanda initially provided these 3 RelVal input datasets (blocks):
```
/RelValZMM_14/CMSSW_12_5_0_pre3-124X_mcRun3_2022_realistic_v8-v2/GEN-SIM-DIGI-RAW#621aab39-d57d-4308-b38c-fa8bfeb65fdb
/RelValTTbar_14TeV/CMSSW_12_5_0_pre3-124X_mcRun4_realistic_v8_2026D88noPU-v1/GEN-SIM-DIGI-RAW#fef08bee-3d76-485d-b4b4-68ed0b181b70
/RelValTTbar_14TeV/CMSSW_12_5_0_pre3-124X_mcRun3_2022_realistic_v8-v2/GEN-SIM-DIGI-RAW#4c88cda3-eebb-4e7f-9860-ef201108d9d8
```

which are still locked under the account `wmcore_transferor`, even though all the relevant workflows processing it are no longer active in the system (they have been archived).

A non-relval input dataset example is:
https://cmsweb.cern.ch/reqmgr2/data/request?inputdataset=/BTohh_hToMuNu_BsBdMixture_modHadLifetime_TuneCP5_13TeV-pythia8-evtgen/RunIISummer20UL17RECO-106X_mc2017_realistic_v6-v3/AODSIM

which has been archived in December 2021, leaving these two rucio rules behind:
```
c55dcaa65f2b443b9824fff1983228e1
61fa02b8b4694f27b80f91adec4d1591
```

**How to reproduce it**
No clue

**Expected behavior**
From a quick debugging that I have done so far, MSRuleCleaner seem to be properly deleting rules for the input dataset. So there might be a specific scenario that triggers this ill behaviour.

On what concerns this issue, we should:
* improve logging, such that we can explicitly see whenever an input data is looked up, and under which classification (primary, parent or secondary);
* ensure that rules allowed for deletion are actually removed, especially for input dataset

**Additional context and error message**
None


Changed files:
src/python/WMCore/MicroService/MSRuleCleaner/MSRuleCleaner.py

diff --git a/src/python/WMCore/MicroService/MSRuleCleaner/MSRuleCleaner.py b/src/python/WMCore/MicroService/MSRuleCleaner/MSRuleCleaner.py
index 54d1cd049..f903d045d 100644
--- a/src/python/WMCore/MicroService/MSRuleCleaner/MSRuleCleaner.py
+++ b/src/python/WMCore/MicroService/MSRuleCleaner/MSRuleCleaner.py
@@ -302,20 +302,6 @@ class MSRuleCleaner(MSCore):
             msg = "Skipping cleanup step for workflow: %s - RequestType is %s."
             msg += " Will try to archive it directly."
             self.logger.info(msg, wflow['RequestName'], wflow['RequestType'])
-        elif wflow['RequestStatus'] in ['rejected', 'aborted-completed']:
-            # NOTE: We do not check the ParentageResolved flag for these
-            #       workflows, but we do need to clean output data placement
-            #       rules from the agents for them
-            for pline in self.agentlines:
-                try:
-                    pline.run(wflow)
-                except Exception as ex:
-                    msg = "%s: General error from pipeline. Workflow: %s. Error: \\n%s. "
-                    msg += "\\nWill retry again in the next cycle."
-                    self.logger.exception(msg, pline.name, wflow['RequestName'], str(ex))
-                    continue
-                if wflow['CleanupStatus'][pline.name]:
-                    self.wfCounters['cleaned'][pline.name] += 1
         elif wflow['RequestStatus'] == 'announced' and not wflow['ParentageResolved']:
             # NOTE: We skip workflows which are not having 'ParentageResolved'
             #       flag, but we still need some proper logging for them.
@@ -340,7 +326,7 @@ class MSRuleCleaner(MSCore):
             msg += " Will retry again in the next cycle."
             self.logger.info(msg)
             self.alertStatusAdvanceExpired(wflow, additionalInfo=msg)
-        elif wflow['RequestStatus'] == 'announced':
+        elif wflow['RequestStatus'] in ['announced', 'rejected', 'aborted-completed']:
             for pline in self.cleanuplines:
                 try:
                     pline.run(wflow)