Program: 4709
Project: 4709
Buggy source:
@Test public void testInvalidFlowRunRecord() throws Exception {
  HttpResponse response=deploy(WordCountApp.class,Constants.Gateway.API_VERSION_3_TOKEN,TEST_NAMESPACE1);
  Assert.assertEquals(200,response.getStatusLine().getStatusCode());
  final Id.Program wordcountFlow1=Id.Program.from(TEST_NAMESPACE1,"String_Node_Str",ProgramType.FLOW,"String_Node_Str");
  Assert.assertEquals("String_Node_Str",getProgramStatus(wordcountFlow1));
  startProgram(wordcountFlow1);
  waitState(wordcountFlow1,ProgramRunStatus.RUNNING.toString());
  Tasks.waitFor(1,new Callable<Integer>(){
    @Override public Integer call() throws Exception {
      return getProgramRuns(wordcountFlow1,ProgramRunStatus.RUNNING).size();
    }
  }
,5,TimeUnit.SECONDS);
  List<RunRecord> runRecords=getProgramRuns(wordcountFlow1,ProgramRunStatus.RUNNING);
  Assert.assertEquals(1,runRecords.size());
  final RunRecord rr=runRecords.get(0);
  Assert.assertEquals(ProgramRunStatus.RUNNING,rr.getStatus());
  RuntimeInfo runtimeInfo=runtimeService.lookup(wordcountFlow1.toEntityId(),RunIds.fromString(rr.getPid()));
  ProgramController programController=runtimeInfo.getController();
  programController.stop();
  Tasks.waitFor(ProgramRunStatus.KILLED,new Callable<ProgramRunStatus>(){
    @Override public ProgramRunStatus call() throws Exception {
      RunRecordMeta runRecord=store.getRun(wordcountFlow1.toEntityId(),rr.getPid());
      return runRecord == null ? null : runRecord.getStatus();
    }
  }
,5,TimeUnit.SECONDS,100,TimeUnit.MILLISECONDS);
  long now=System.currentTimeMillis();
  long nowSecs=TimeUnit.MILLISECONDS.toSeconds(now);
  store.setStart(wordcountFlow1.toEntityId(),rr.getPid(),nowSecs,null,ImmutableMap.<String,String>of(),ImmutableMap.<String,String>of(),ByteBuffer.allocate(0).array());
  store.setRunning(wordcountFlow1.toEntityId(),rr.getPid(),nowSecs + 1,null,ByteBuffer.allocate(1).array());
  RunRecord runRecordMeta=store.getRun(wordcountFlow1.toEntityId(),rr.getPid());
  Assert.assertNotNull(runRecordMeta);
  Assert.assertEquals(ProgramRunStatus.RUNNING,runRecordMeta.getStatus());
  runRecords=getProgramRuns(wordcountFlow1,ProgramRunStatus.FAILED);
  Assert.assertEquals(0,runRecords.size());
  new LocalRunRecordCorrectorService(store,programStateWriter,programLifecycleService,runtimeService).startUp();
  Tasks.waitFor(1,new Callable<Integer>(){
    @Override public Integer call() throws Exception {
      return getProgramRuns(wordcountFlow1,ProgramRunStatus.FAILED).size();
    }
  }
,30,TimeUnit.SECONDS,1,TimeUnit.SECONDS);
}

Fixed version (ground truth):
@Test public void testInvalidFlowRunRecord() throws Exception {
  HttpResponse response=deploy(WordCountApp.class,Constants.Gateway.API_VERSION_3_TOKEN,TEST_NAMESPACE1);
  Assert.assertEquals(200,response.getStatusLine().getStatusCode());
  final Id.Program wordcountFlow1=Id.Program.from(TEST_NAMESPACE1,"String_Node_Str",ProgramType.FLOW,"String_Node_Str");
  Assert.assertEquals("String_Node_Str",getProgramStatus(wordcountFlow1));
  startProgram(wordcountFlow1);
  waitState(wordcountFlow1,ProgramRunStatus.RUNNING.toString());
  Tasks.waitFor(1,new Callable<Integer>(){
    @Override public Integer call() throws Exception {
      return getProgramRuns(wordcountFlow1,ProgramRunStatus.RUNNING).size();
    }
  }
,5,TimeUnit.SECONDS);
  List<RunRecord> runRecords=getProgramRuns(wordcountFlow1,ProgramRunStatus.RUNNING);
  Assert.assertEquals(1,runRecords.size());
  final RunRecord rr=runRecords.get(0);
  Assert.assertEquals(ProgramRunStatus.RUNNING,rr.getStatus());
  RuntimeInfo runtimeInfo=runtimeService.lookup(wordcountFlow1.toEntityId(),RunIds.fromString(rr.getPid()));
  ProgramController programController=runtimeInfo.getController();
  programController.stop();
  Tasks.waitFor(ProgramRunStatus.KILLED,new Callable<ProgramRunStatus>(){
    @Override public ProgramRunStatus call() throws Exception {
      RunRecordMeta runRecord=store.getRun(wordcountFlow1.toEntityId(),rr.getPid());
      return runRecord == null ? null : runRecord.getStatus();
    }
  }
,5,TimeUnit.SECONDS,100,TimeUnit.MILLISECONDS);
  long now=System.currentTimeMillis();
  long nowSecs=TimeUnit.MILLISECONDS.toSeconds(now);
  store.setStart(wordcountFlow1.toEntityId(),rr.getPid(),nowSecs,null,ImmutableMap.<String,String>of(),ImmutableMap.<String,String>of(),ByteBuffer.allocate(0).array());
  store.setRunning(wordcountFlow1.toEntityId(),rr.getPid(),nowSecs + 1,null,ByteBuffer.allocate(1).array());
  RunRecord runRecordMeta=store.getRun(wordcountFlow1.toEntityId(),rr.getPid());
  Assert.assertNotNull(runRecordMeta);
  Assert.assertEquals(ProgramRunStatus.RUNNING,runRecordMeta.getStatus());
  runRecords=getProgramRuns(wordcountFlow1,ProgramRunStatus.FAILED);
  Assert.assertEquals(0,runRecords.size());
  new LocalRunRecordCorrectorService(CConfiguration.create(),store,programStateWriter,programLifecycleService,runtimeService).startUp();
  Tasks.waitFor(1,new Callable<Integer>(){
    @Override public Integer call() throws Exception {
      return getProgramRuns(wordcountFlow1,ProgramRunStatus.FAILED).size();
    }
  }
,30,TimeUnit.SECONDS,1,TimeUnit.SECONDS);
}