Index: /trunk/ippTasks/pstamp.pro
===================================================================
--- /trunk/ippTasks/pstamp.pro	(revision 38585)
+++ /trunk/ippTasks/pstamp.pro	(revision 38586)
@@ -18,4 +18,5 @@
 $pstampCleanup_DB = 0
 $pstampStopFaulted_DB = 0
+$pstampQCleanup_DB = 0
 
 # give up on dependents with fault_count >= $PSTAMP_MAX_FAULT_COUNT
@@ -1212,2 +1213,41 @@
     end
 end
+
+task pstamp.queue.update.cleanup
+    host        local
+    trange      22:00:00 23:59:59 -nmax 2
+    periods     -poll $RUNPOLL
+    periods     -exec 3600
+    periods     -timeout 120
+    npending    1
+
+    task.exec
+        stdout NULL
+        stderr $LOGSUBDIR/pstamp.queue.update.cleanup.log
+
+        $DBNAME = $DB:$pstampQCleanup_DB
+        $pstampQCleanup_DB++
+        if ($pstampQCleanup_DB >= $DB:n) set pstampQCleanup_DB = 0
+
+        $run = pstamp_queue_update_cleanup.pl  -$PS_DBSERVER --imagedb gpc1 --label ps_ud%
+        add_standard_args run
+        echo $run
+        command $run
+    end
+
+    task.exit $EXIT_SUCCESS
+        # echo nothing to do
+    end
+
+    task.exit   default
+        showcommand failure
+    end
+
+    task.exit   crash
+        showcommand crash
+    end
+
+    task.exit   timeout
+        showcommand timeout
+    end
+end
Index: /trunk/ippTools/share/pstamptool_pendingdependent.sql
===================================================================
--- /trunk/ippTools/share/pstamptool_pendingdependent.sql	(revision 38585)
+++ /trunk/ippTools/share/pstamptool_pendingdependent.sql	(revision 38586)
@@ -10,5 +10,4 @@
 LEFT JOIN Label ON pstampRequest.label = Label.label
 WHERE pstampDependent.state = 'new'
-    AND pstampDependent.fault = 0
     AND pstampJob.state = 'run'
     AND pstampRequest.state = 'run'
Index: /trunk/ippTools/src/pstamptool.c
===================================================================
--- /trunk/ippTools/src/pstamptool.c	(revision 38585)
+++ /trunk/ippTools/src/pstamptool.c	(revision 38586)
@@ -1435,4 +1435,5 @@
     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+    PXOPT_LOOKUP_BOOL(includeFaulted, config->args, "-includefaulted", false);
 
     psString query = pxDataGet("pstamptool_pendingdependent.sql");
@@ -1442,12 +1443,16 @@
     }
 
+    if (!includeFaulted) {
+        psStringAppend(&query, "    AND (pstampDependent.fault = 0)\n");
+    }
+
     if (psListLength(where->list)) {
         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&query, " AND %s", whereClause);
+        psStringAppend(&query, "\n    AND %s", whereClause);
         psFree(whereClause);
     }
     psFree(where);
 
-    psStringAppend(&query, " GROUP BY dep_id ORDER BY priority DESC, MIN(req_id), dep_id");
+    psStringAppend(&query, "\nGROUP BY dep_id ORDER BY priority DESC, MIN(req_id), dep_id");
 
     // treat limit == 0 as "no limit"
Index: /trunk/ippTools/src/pstamptoolConfig.c
===================================================================
--- /trunk/ippTools/src/pstamptoolConfig.c	(revision 38585)
+++ /trunk/ippTools/src/pstamptoolConfig.c	(revision 38586)
@@ -253,4 +253,5 @@
     psMetadataAddStr(pendingdependentArgs, PS_LIST_TAIL, "-rlabel", 0,   "define label for dependent", NULL);
     psMetadataAddStr(pendingdependentArgs, PS_LIST_TAIL, "-imagedb", 0,  "define imagedb for depenent", NULL);
+    psMetadataAddBool(pendingdependentArgs, PS_LIST_TAIL, "-includefaulted", 0,   "include faulted dependents in the output", false);
     psMetadataAddU64(pendingdependentArgs, PS_LIST_TAIL, "-limit",  0,    "limit result set to N items", 0);
     psMetadataAddBool(pendingdependentArgs, PS_LIST_TAIL, "-simple", 0,   "use the simple output format", false);
Index: /trunk/pstamp/scripts/Makefile.am
===================================================================
--- /trunk/pstamp/scripts/Makefile.am	(revision 38585)
+++ /trunk/pstamp/scripts/Makefile.am	(revision 38586)
@@ -13,4 +13,5 @@
 	pstamp_queue_cleanup.pl \
 	pstamp_queue_requests.pl \
+	pstamp_queue_update_cleanup.pl \
 	pstamp_request_file \
 	pstamp_results_file.pl \
Index: /trunk/pstamp/scripts/pstamp_queue_update_cleanup.pl
===================================================================
--- /trunk/pstamp/scripts/pstamp_queue_update_cleanup.pl	(revision 38586)
+++ /trunk/pstamp/scripts/pstamp_queue_update_cleanup.pl	(revision 38586)
@@ -0,0 +1,98 @@
+#!/bin/env perl
+#
+# run pstamptool to queue requests older than preserve-days to be cleaned
+
+use strict;
+use warnings;
+
+use PS::IPP::Config 1.01 qw( :standard );
+use IPC::Cmd 0.36 qw( can_run run );
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+
+my $verbose;
+my $very_verbose = 0;
+my $save_temps;
+my $preserve_days;
+my $dbname;
+my $dbserver;
+my $imagedb;
+my $label;
+
+GetOptions(
+    'preserve-days=s'       => \$preserve_days,     # clean up requests that stopped this many days ago
+    'verbose'               => \$verbose,
+    'save-temps'            => \$save_temps,
+    'imagedb=s'             => \$imagedb,
+    'label=s'               => \$label,
+    'dbserver=s'            => \$dbserver,
+    'dbname=s'              => \$dbname,
+) or pod2usage( 2 );
+
+my $missing_tools;
+my $pstamptool   = can_run('pstamptool') 
+    or (warn "Can't find pstamptool" and $missing_tools = 1);
+my $chiptool   = can_run('chiptool') 
+    or (warn "Can't find chiptool" and $missing_tools = 1);
+my $warptool   = can_run('warptool') 
+    or (warn "Can't find warptool" and $missing_tools = 1);
+my $difftool   = can_run('difftool') 
+    or (warn "Can't find difftool" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+
+if (!$imagedb)  {
+    $imagedb = 'gpc1';
+}
+
+if (!$label)  {
+    $label = 'ps_ud%';
+}
+
+my $ipprc = PS::IPP::Config->new(); # IPP Configuration
+
+if (!$dbserver) {
+    $dbserver =  metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBSERVER');
+}
+$pstamptool .= " -dbserver $dbserver" if $dbserver;
+
+if (!$dbname) {
+    $dbname =  metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBNAME');
+}
+$pstamptool .= " -dbname $dbname" if $dbname;
+
+
+my $command = "$pstamptool -pendingdependent -includefaulted -simple";
+my  ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+    run(command => $command, verbose => $very_verbose);
+unless ($success) {
+    $error_code = (($error_code >> 8) or 1);
+    warn("$command failed. exit status: $error_code");
+    exit $error_code;
+}
+
+my @lines = split "\n", (join "", @$stdout_buf);
+my $nlines = scalar @lines;
+
+if ($nlines) {
+    # printing to stderr so that it shows up in the task's log file. stdout is set to null
+    print STDERR "Skipping cleanup of update labels because there are currently $nlines dependents outstanding.\n";
+} else  {
+    print STDERR "Queuing cleanup of update labels because there are no dependents outstanding.\n";
+    foreach my $tool ($chiptool, $warptool, $difftool) {
+        my $command = "$tool -updaterun -set_state goto_cleaned -set_label goto_cleaned -label $label";
+        $command .= " -dbname $imagedb";
+
+        my  ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $very_verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or 1);
+            warn("$command failed. exit status: $error_code");
+            exit $error_code;
+        }
+    }
+}
+
+exit 0;
