Index: trunk/pstamp/scripts/pstamp_checkdependent.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_checkdependent.pl	(revision 27795)
+++ trunk/pstamp/scripts/pstamp_checkdependent.pl	(revision 27805)
@@ -124,4 +124,6 @@
         ($whole_run or ($it->{data_state} eq 'cleaned'))) {
 
+    # Update has not been queued for this component yet.  
+
     # XXX: if $whole_run this is going to repeatedly call -setimfiletoupdate. This will be a no-op
     # but is wasteful.
@@ -140,4 +142,9 @@
     }
 } else {
+    # update for this component has been queued by hasn't completed yet
+    # 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
+
+
     print "${stage}Run $stage_id state is $it->{state} $component data_state is $it->{data_state}\n";
 
@@ -169,4 +176,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});
     }
@@ -256,5 +264,5 @@
             if !$data or scalar @$data == 0;
 
-        my $good_to_go = 1;
+        my $chips_ready = 1;
         my @chipsToUpdate;
         my $chip_id;
@@ -262,5 +270,5 @@
             $chip_id = $chip->{chip_id};
             if (($chip->{data_state} ne 'full') or ($need_magic and ($chip->{magicked} <= 0))) {
-                $good_to_go = 0;
+                $chips_ready = 0;
                 push @chipsToUpdate, $chip;
             } else {
@@ -269,5 +277,5 @@
         }
 
-        if ($good_to_go) {
+        if ($chips_ready) {
             # the reason we defer setting the warp to update is so that we can handle error conditions at previous
             # stages more easily.
@@ -335,6 +343,4 @@
     my $need_magic = shift; 
 
-# XXXX This is not ready to go yet XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxx
-
     my $diff_id   = $metadata->{diff_id};
     my $diff_mode = $metadata->{diff_mode};
@@ -346,5 +352,5 @@
         my $IPP_DIFF_MODE_WARP_WARP   = 1;
         my $IPP_DIFF_MODE_WARP_STACK  = 2;
-        my $IPP_DIFF_MODE_STACK_WARP  = 2;
+        my $IPP_DIFF_MODE_STACK_WARP  = 3;
         my $IPP_DIFF_MODE_STACK_STACK = 4;
         if ($diff_mode == $IPP_DIFF_MODE_WARP_STACK ) {
@@ -364,5 +370,5 @@
             $command = "$warptool -warped -warp_id $skycell->{warp1} -skycell_id $skycell_id";
             my $warp = runToolAndParseExpectOne($command, $verbose);
-            my_die("failed to find warpSkyfile for warpRun $skycell->{warp_id} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp;
+            my_die("failed to find warpSkyfile for warpRun $skycell->{warp1} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp;
 
             if ($warp->{data_state} ne 'full') {
@@ -373,8 +379,11 @@
             my $command = "$warptool -warped -warp_id $skycell->{warp1} -skycell_id $skycell_id";
             my $warp1 = runToolAndParseExpectOne($command, $verbose);
-            my_die("failed to find warpSkyfile for warpRun $skycell->{warp_id} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp1;
-
+            my_die("failed to find warpSkyfile for warpRun $skycell->{warp1} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp1;
+
+            my $warps_ready = 1;
+            my $status = 0;
             if ($warp1->{data_state} ne 'full') {
-                my $status = queue_update_warp($warp1, 0, $rlabel, $need_magic);
+                $warps_ready = 0;
+                $status = queue_update_warp($warp1, 0, $rlabel, $need_magic);
                 if ($status) {
                     return $status;
@@ -383,14 +392,65 @@
             $command = "$warptool -warped -warp_id $skycell->{warp2} -skycell_id $skycell_id";
             my $warp2 = runToolAndParseExpectOne($command, $verbose);
-            my_die("failed to find warpSkyfile for warpRun $skycell->{warp_id} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp2;
+            my_die("failed to find warpSkyfile for warpRun $skycell->{warp2} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp2;
 
             if ($warp2->{data_state} ne 'full') {
-                return queue_update_warp($warp2, 0, $rlabel, $need_magic);
-            }
-            # fall through to queue the diff update
+                $warps_ready = 0;
+                $status = queue_update_warp($warp2, 0, $rlabel, $need_magic);
+            }
+
+            if (!$warps_ready) {
+                # don't queue the diff update yet
+                return $status;
+            }
+
+        } elsif ($diff_mode == $IPP_DIFF_MODE_STACK_STACK ) {
+            # check the state of the input stack
+            my $command = "$stacktool -sumkskyfile -stack_id $skycell->{stack2}";
+            my $stack1 = runToolAndParseExpectOne($command, $verbose);
+            my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack2}", $PS_EXIT_UNKNOWN_ERROR) if !$stack1;
+
+            if ($stack1->{state} ne 'full') {
+                print STDERR "input stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n";
+                # this faults all jobs depending on this dep_id
+                faultJobs('stop', 'diff', $diff_id, $PSTAMP_GONE);
+                return $PSTAMP_GONE;
+            }
+            # check the state of the template stack
+            $command = "$stacktool -sumkskyfile -stack_id $skycell->{stack2}";
+            my $stack2 = runToolAndParseExpectOne($command, $verbose);
+            my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack2}", $PS_EXIT_UNKNOWN_ERROR) if !$stack2;
+
+            if ($stack2->{state} ne 'full') {
+                print STDERR "template stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n";
+                # this faults all jobs depending on this dep_id
+                faultJobs('stop', 'diff', $diff_id, $PSTAMP_GONE);
+                return $PSTAMP_GONE;
+            }
+
+            # inputs are ready fall through and queue the diff update
+        } elsif ($diff_mode == $IPP_DIFF_MODE_STACK_WARP ) {
+            # check the state of the input stack
+            my $command = "$stacktool -sumkskyfile -stack_id $skycell->{stack1}";
+            my $stack = runToolAndParseExpectOne($command, $verbose);
+            my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack1}", $PS_EXIT_UNKNOWN_ERROR) if !$stack;
+
+            if ($stack->{state} ne 'full') {
+                print STDERR "input stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n";
+                # this faults all jobs depending on this dep_id
+                faultJobs('stop', 'diff', $diff_id, $PSTAMP_GONE);
+                return $PSTAMP_GONE;
+            }
+
+            # now check the template warp
+            $command = "$warptool -warped -warp_id $skycell->{warp2} -skycell_id $skycell_id";
+            my $warp = runToolAndParseExpectOne($command, $verbose);
+            my_die("failed to find warpSkyfile for warpRun $skycell->{warp2} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp;
+
+            if ($warp->{data_state} ne 'full') {
+                return queue_update_warp($warp, 0, $rlabel, $need_magic);
+            }
+            # warps are ready fall through and queue the diff update
         } else {
-            # XXX: check stack stack
-            print STDERR "unexpected diff_mode found: $diff_mode\n";
-            return $PS_EXIT_PROG_ERROR;
+            my_die("unexpected diff_mode found: $diff_mode", $PS_EXIT_PROG_ERROR);
         }
 
@@ -411,5 +471,6 @@
         return $PS_EXIT_PROG_ERROR;
     }
-    # return value may be the return status of script so zero is good
+
+    # return value is a unix style exit status so zero is good
     return 0;
 }
