Index: trunk/pstamp/scripts/pstamp_checkdependent.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_checkdependent.pl	(revision 27852)
+++ trunk/pstamp/scripts/pstamp_checkdependent.pl	(revision 27853)
@@ -30,5 +30,5 @@
     'stage_id=i'    =>  \$stage_id,
     'component=s'   =>  \$component,
-    'imagedb=s'     =>  \$imagedb,      # dbname for images
+    'imagedb=s'     =>  \$imagedb,      # dbname for images.
     'rlabel=s'      =>  \$rlabel,
     'need_magic'    =>  \$need_magic,
@@ -56,9 +56,10 @@
 }
 
+# Append imagedb to the ippTools
 $chiptool    .= " -dbname $imagedb";
 $warptool    .= " -dbname $imagedb";
 $difftool    .= " -dbname $imagedb";
+$stacktool   .= " -dbname $imagedb";
 $magicdstool .= " -dbname $imagedb";
-
 
 my $ipprc = PS::IPP::Config->new();
@@ -67,5 +68,4 @@
     $dbserver =  metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBSERVER');
 }
-
 
 
@@ -107,5 +107,5 @@
         and (!$need_magic or $it->{magicked} > 0)) {
 
-    # This Dependency is satisfied. all done
+    # This Dependency is satisfied. All done!
     my $command = "$pstamptool -updatedependent -set_state full -dep_id $dep_id";
     $command .= " -dbname $dbname" if $dbname;
@@ -142,5 +142,5 @@
     }
 } else {
-    # update for this component has been queued by hasn't completed yet
+    # update for this component has been queued by hasn't completed yet or the state is an error state
     # XXX: in this state we aren't checking the dependents anymore. If something goes wrong this
     # will never complete. Consider calling the 'queue_update' functions again just to check. They are relatively cheap
@@ -157,5 +157,5 @@
 
     # temporary hack to deal with data with old burntool tables. This check is now done by pstampparse.pl
-    # so runs in this state will not get queued
+    # so runs in this state should not get queued
     if ($stage eq 'chip') {
         my $burntool_state = $it->{burntool_state};
@@ -177,5 +177,5 @@
     if (!$job_fault and ($stage eq 'chip')) {
         # chip processing is done, start destreaking.
-        $job_fault = queue_update_magicDSRun($stage, $stage_id, $rlabel, $it->{raw_magicked}, $it->{dsRun_state});
+        $job_fault = queue_update_magicDSRun($stage, $stage_id, $rlabel, $need_magic, $it->{raw_magicked}, $it->{dsRun_state});
     }
     if ($job_fault) {
@@ -194,4 +194,5 @@
     my $need_magic = shift; 
 
+
     my $dsRun_state;
     my $raw_all_magicked = 1; # this gets cleared if any of the inputs aren't destreaked
@@ -201,5 +202,7 @@
             $raw_all_magicked &= ($chip->{raw_magicked} > 0);
 
-            if ($chip->{data_state} ne 'update') {
+            if ($chip->{state} =~ /error/) {
+                faultJobs('stop', undef, undef, $PSTAMP_GONE);
+            } elsif (($chip->{data_state} ne 'update') and ($chip->{data_state} ne 'full')) {
                 my $command = "$chiptool -setimfiletoupdate -chip_id $chip_id -class_id $chip->{class_id}";
                 $command .= " -set_label $rlabel" if $rlabel;
@@ -236,5 +239,5 @@
     }
 
-    my $status = queue_update_magicDSRun('chip', $chip_id, $rlabel, $raw_all_magicked, $dsRun_state);
+    my $status = queue_update_magicDSRun('chip', $chip_id, $rlabel, $need_magic, $raw_all_magicked, $dsRun_state);
 
     return $status;
@@ -255,4 +258,11 @@
 
     my $warp_id = $metadata->{warp_id};
+    my $state = $metadata->{state};
+    if ($state =~ /error/) {
+        print STDERR "warpRun $warp_id has state $state faulting jobs\n";
+        faultJobs('stop', undef, undef, $PSTAMP_GONE);
+        exit 0;
+    }
+
     if (!$whole_run) {
         my $skycell = $metadata;
@@ -584,8 +594,9 @@
     my $stage_id = shift;
     my $rlabel  = shift;
+    my $need_magic = shift;
     my $input_magicked = shift;
     my $dsRun_state = shift;
 
-    # XXX: this code is only fully coded and tested for chip stage
+    # XXX: this code assumes that destreaking is handled at the chip stage
     my_die ("queue_update_magicDSRun only works for stage chip", $PS_EXIT_PROG_ERROR) if $stage ne 'chip';
 
@@ -613,4 +624,7 @@
                 print "skipping $command\n";
             }
+        } elsif ($dsRun_state eq 'failed_revert') {
+            print "magicDSRun.state = $dsRun_state for chipRun $stage_id is in state failed_revert cannot update";
+            faultJobs('stop', undef, undef, $PSTAMP_NOT_AVAILABLE);
         } else {
             print "magicDSRun.state = $dsRun_state for chipRun $stage_id";
