Don't crash on missing action complete events

Note that we will ignore any interrupted actions for the purposes of
computing the critical path of the build, since there were no completion
events for those actions.

Progress on #6394.

PiperOrigin-RevId: 240095667
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CriticalPathComponent.java b/src/main/java/com/google/devtools/build/lib/runtime/CriticalPathComponent.java
index 9cdb78a..31c4ddb 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/CriticalPathComponent.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/CriticalPathComponent.java
@@ -184,7 +184,17 @@
   }
 
   long getElapsedTimeNanos() {
-    Preconditions.checkState(!isRunning, "Still running %s", this);
+    if (isRunning) {
+      // It can happen that we're being asked to compute a critical path even though the build was
+      // interrupted. In that case, we may not have gotten an action completion event. We don't have
+      // access to the clock from here, so we have to return 0.
+      // Note that the critical path never includes interrupted actions, so getAggregatedElapsedTime
+      // does not get called in this state.
+      // If we want the critical path to contain partially executed actions in a case of interrupt,
+      // then we need to tell the critical path computer that the build was interrupt, and let it
+      // artifically mark all such actions as done.
+      return 0;
+    }
     return getElapsedTimeNanosNoCheck();
   }