Index: src/Actions/ActionQueue.cpp
===================================================================
--- src/Actions/ActionQueue.cpp	(revision abfc95ba5c74e7d73ba21441037391420169955e)
+++ src/Actions/ActionQueue.cpp	(revision a61dbbe03ddbe4f5f0a22574b63fb4d32e312493)
@@ -58,8 +58,9 @@
     AR(new ActionRegistry()),
     history(new ActionHistory),
+    CurrentAction(0),
 #ifndef HAVE_ACTION_THREAD
-    CurrentAction(0)
+    lastActionOk(true)
 #else
-    CurrentAction(0),
+    lastActionOk(true),
     run_thread(boost::bind(&ActionQueue::run, this)),
     run_thread_isIdle(true)
@@ -99,7 +100,12 @@
   try {
     newaction->call();
+    lastActionOk = true;
   } catch(ActionFailureException &e) {
     std::cerr << "Action " << *boost::get_error_info<ActionNameString>(e) << " has failed." << std::endl;
     World::getInstance().setExitFlag(5);
+    actionqueue.clear();
+    tempqueue.clear();
+    lastActionOk = false;
+    std::cerr << "ActionQueue cleared." << std::endl;
   }
 #else
@@ -156,7 +162,13 @@
       try {
         actionqueue[CurrentAction]->call();
+        lastActionOk = true;
       } catch(ActionFailureException &e) {
         std::cerr << "Action " << *boost::get_error_info<ActionNameString>(e) << " has failed." << std::endl;
         World::getInstance().setExitFlag(5);
+        actionqueue.clear();
+        tempqueue.clear();
+        lastActionOk = false;
+        std::cerr << "ActionQueue cleared." << std::endl;
+        CurrentAction = (size_t)-1;
       }
       // access actionqueue, hence using mutex
Index: src/Actions/ActionQueue.hpp
===================================================================
--- src/Actions/ActionQueue.hpp	(revision abfc95ba5c74e7d73ba21441037391420169955e)
+++ src/Actions/ActionQueue.hpp	(revision a61dbbe03ddbe4f5f0a22574b63fb4d32e312493)
@@ -122,4 +122,11 @@
   void redoLast();
 
+  /** Return status of last executed action.
+   *
+   * \return true - action executed correctly, false - else
+   */
+  bool getLastActionOk() const
+  {  return lastActionOk; }
+
 #ifdef HAVE_ACTION_THREAD
   boost::thread &getRunThread()
@@ -205,4 +212,7 @@
   ActionQueue_t tempqueue;
 
+  //!> indicates that the last action has failed
+  bool lastActionOk;
+
 #ifdef HAVE_ACTION_THREAD
   //!> internal thread to call Actions
Index: src/Actions/FragmentationAction/FragmentationAutomationAction.cpp
===================================================================
--- src/Actions/FragmentationAction/FragmentationAutomationAction.cpp	(revision abfc95ba5c74e7d73ba21441037391420169955e)
+++ src/Actions/FragmentationAction/FragmentationAutomationAction.cpp	(revision a61dbbe03ddbe4f5f0a22574b63fb4d32e312493)
@@ -138,9 +138,14 @@
 
     // Phase Two: add MPQCJobs and send
-    const size_t NoJobs = mpqccontroller.addJobsFromQueue(
+    const bool AddJobsStatus = mpqccontroller.addJobsFromQueue(
         params.DoLongrange.get() ? MPQCData::DoSampleDensity : MPQCData::DontSampleDensity,
         params.DoValenceOnly.get() ? MPQCData::DoSampleValenceOnly : MPQCData::DontSampleValenceOnly
         );
-    LOG(1, "INFO: Added " << NoJobs << " from FragmentJobsQueue.");
+    if (AddJobsStatus)
+      LOG(1, "INFO: Added jobs from FragmentJobsQueue.");
+    else {
+      ELOG(1, "Adding jobs failed.");
+      return Action::failure;
+    }
     mpqccontroller.run();
 
Index: src/Fragmentation/Automation/MPQCFragmentController.cpp
===================================================================
--- src/Fragmentation/Automation/MPQCFragmentController.cpp	(revision abfc95ba5c74e7d73ba21441037391420169955e)
+++ src/Fragmentation/Automation/MPQCFragmentController.cpp	(revision a61dbbe03ddbe4f5f0a22574b63fb4d32e312493)
@@ -57,4 +57,5 @@
     )
 {
+  bool status = true;
   // give them all valid ids
   std::vector<FragmentJob::ptr> newjobs = FragmentJobQueue::getInstance().getJobs();
@@ -65,10 +66,16 @@
     job->DoLongrange = _DoLongrange;
     job->DoValenceOnly = _DoValenceOnly;
-    changeJobId((*jobiter), getAvailableId());
+    JobId_t id = getAvailableId();
+    if (id == FragmentJob::IllegalJob) {
+      status = false;
+      break;
+    }
+    changeJobId((*jobiter), id);
   }
   // add the jobs
   addJobs(newjobs);
+  status &= (newjobs.size() != 0);
 
-  return (newjobs.size() != 0);
+  return status;
 }
 
Index: src/UIElements/CommandLineUI/CommandLineWindow.cpp
===================================================================
--- src/UIElements/CommandLineUI/CommandLineWindow.cpp	(revision abfc95ba5c74e7d73ba21441037391420169955e)
+++ src/UIElements/CommandLineUI/CommandLineWindow.cpp	(revision a61dbbe03ddbe4f5f0a22574b63fb4d32e312493)
@@ -72,5 +72,8 @@
     if (AQ.isActionKnownByName(*CommandRunner)) {
 //      LOG1, "INFO: Checking presence of " << *CommandRunner << ": " << "queuing.");
-      AQ.queueAction(*CommandRunner);
+      if (AQ.getLastActionOk())
+        AQ.queueAction(*CommandRunner);
+      else
+        LOG(1, "INFO: Skipping " << *CommandRunner << " as last action failed.");
     } else {
 //      LOG(1, "INFO: Checking presence of " << *CommandRunner << ": " << "absent.");
Index: tests/regression/Fragmentation/FragmentationAutomation/pre/test.conf
===================================================================
--- tests/regression/Fragmentation/FragmentationAutomation/pre/test.conf	(revision a61dbbe03ddbe4f5f0a22574b63fb4d32e312493)
+++ tests/regression/Fragmentation/FragmentationAutomation/pre/test.conf	(revision a61dbbe03ddbe4f5f0a22574b63fb4d32e312493)
@@ -0,0 +1,83 @@
+# ParallelCarParinello - main configuration file - created with molecuilder
+
+mainname	pcp	# programm name (for runtime files)
+defaultpath	not specified	# where to put files during runtime
+pseudopotpath	not specified	# where to find pseudopotentials
+
+ProcPEGamma	8	# for parallel computing: share constants
+ProcPEPsi	1	# for parallel computing: share wave functions
+DoOutVis	0	# Output data for OpenDX
+DoOutMes	1	# Output data for measurements
+DoOutOrbitals	0	# Output all Orbitals
+DoOutCurr	0	# Ouput current density for OpenDx
+DoOutNICS	0	# Output Nucleus independent current shieldings
+DoPerturbation	0	# Do perturbation calculate and determine susceptibility and shielding
+DoFullCurrent	0	# Do full perturbation
+DoConstrainedMD	0	# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD
+Thermostat	Berendsen	2.5	# Which Thermostat and its parameters to use in MD case.
+CommonWannier	0	# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center
+SawtoothStart	0.01	# Absolute value for smooth transition at cell border 
+VectorPlane	0	# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot
+VectorCut	0	# Cut plane axis value
+AddGramSch	1	# Additional GramSchmidtOrtogonalization to be safe
+Seed		1	# initial value for random seed for Psi coefficients
+
+MaxOuterStep	0	# number of MolecularDynamics/Structure optimization steps
+Deltat	0.01	# time per MD step
+OutVisStep	10	# Output visual data every ...th step
+OutSrcStep	5	# Output "restart" data every ..th step
+TargetTemp	0.000950045	# Target temperature
+MaxPsiStep	0	# number of Minimisation steps per state (0 - default)
+EpsWannier	1e-07	# tolerance value for spread minimisation of orbitals
+
+# Values specifying when to stop
+MaxMinStep	100	# Maximum number of steps
+RelEpsTotalE	1e-07	# relative change in total energy
+RelEpsKineticE	1e-05	# relative change in kinetic energy
+MaxMinStopStep	0	# check every ..th steps
+MaxMinGapStopStep	0	# check every ..th steps
+
+# Values specifying when to stop for INIT, otherwise same as above
+MaxInitMinStep	100	# Maximum number of steps
+InitRelEpsTotalE	1e-05	# relative change in total energy
+InitRelEpsKineticE	0.0001	# relative change in kinetic energy
+InitMaxMinStopStep	0	# check every ..th steps
+InitMaxMinGapStopStep	0	# check every ..th steps
+
+BoxLength			# (Length of a unit cell)
+20	
+0	20	
+0	0	20	
+
+ECut		128	# energy cutoff for discretization in Hartrees
+MaxLevel	5	# number of different levels in the code, >=2
+Level0Factor	2	# factor by which node number increases from S to 0 level
+RiemannTensor	0	# (Use metric)
+PsiType		0	# 0 - doubly occupied, 1 - SpinUp,SpinDown
+MaxPsiDouble	0	# here: specifying both maximum number of SpinUp- and -Down-states
+PsiMaxNoUp	0	# here: specifying maximum number of SpinUp-states
+PsiMaxNoDown	0	# here: specifying maximum number of SpinDown-states
+AddPsis		0	# Additional unoccupied Psis for bandgap determination
+
+RCut		20	# R-cut for the ewald summation
+StructOpt	0	# Do structure optimization beforehand
+IsAngstroem	1	# 0 - Bohr, 1 - Angstroem
+RelativeCoord	0	# whether ion coordinates are relative (1) or absolute (0)
+MaxTypes	2	# maximum number of different ion types
+
+# Ion type data (PP = PseudoPotential, Z = atomic number)
+#Ion_TypeNr.	Amount	Z	RGauss	L_Max(PP)L_Loc(PP)IonMass	# chemical name, symbol
+Ion_Type1	8	1	1.0	3	3	1.00800000000	Hydrogen	H
+Ion_Type2	3	6	1.0	3	3	12.01100000000	Carbon	C
+#Ion_TypeNr._Nr.R[0]    R[1]    R[2]    MoveType (0 MoveIon, 1 FixedIon)
+Ion_Type2_1	9.782085945	3.275186040	3.535886037	0 # molecule nr 0
+Ion_Type2_2	8.532785963	4.158586027	3.535886037	0 # molecule nr 1
+Ion_Type2_3	7.283585982	3.275186040	3.535886037	0 # molecule nr 2
+Ion_Type1_1	9.782085945	2.645886050	2.645886050	0 # molecule nr 3
+Ion_Type1_2	9.782085945	2.645886050	4.425886024	0 # molecule nr 4
+Ion_Type1_3	10.672039608	3.904536878	3.535886037	0 # molecule nr 5
+Ion_Type1_4	8.532785963	4.787886018	2.645886050	0 # molecule nr 6
+Ion_Type1_5	8.532785963	4.787886018	4.425886024	0 # molecule nr 7
+Ion_Type1_6	6.393632318	3.904536877	3.535886037	0 # molecule nr 8
+Ion_Type1_7	7.283585982	2.645886050	2.645886050	0 # molecule nr 9
+Ion_Type1_8	7.283585982	2.645886050	4.425886024	0 # molecule nr 10
Index: tests/regression/Fragmentation/FragmentationAutomation/testsuite-fragmentation-fragmentation-automation.at
===================================================================
--- tests/regression/Fragmentation/FragmentationAutomation/testsuite-fragmentation-fragmentation-automation.at	(revision a61dbbe03ddbe4f5f0a22574b63fb4d32e312493)
+++ tests/regression/Fragmentation/FragmentationAutomation/testsuite-fragmentation-fragmentation-automation.at	(revision a61dbbe03ddbe4f5f0a22574b63fb4d32e312493)
@@ -0,0 +1,63 @@
+#
+#    MoleCuilder - creates and alters molecular systems
+#    Copyright (C) 2008-2012 University of Bonn
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+### calculate fragment energies with mpqc
+
+AT_SETUP([Fragmentation Automation - Fragmentation fails correctly])
+AT_KEYWORDS([fragmentation automation fragment-molecule fragmentation-automation])
+
+file=test.conf
+AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Fragmentation/FragmentMolecule/pre/test.conf $file], 0)
+AT_CHECK([chmod u+w $file], 0, [ignore], [ignore])
+AT_CHECK([../../molecuilder \
+	-i $file \
+	--subgraph-dissection \
+	--verbose 1 \
+	--select-molecule-by-id 0 \
+	--select-molecules-atoms \
+	--fragment-molecule BondFragment \
+	--distance 1.55 \
+	--order 2 \
+	--fragment-automation \
+	--fragment-executable /bin/false], 
+	5, [stdout], [stderr])
+
+AT_CLEANUP
+
+AT_SETUP([Fragmentation Automation - Fragmentation fails, more Actions still in queue])
+AT_KEYWORDS([fragmentation automation fragment-molecule fragmentation-automation])
+
+file=test.conf
+AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Fragmentation/FragmentMolecule/pre/test.conf $file], 0)
+AT_CHECK([chmod u+w $file], 0, [ignore], [ignore])
+AT_CHECK([../../molecuilder \
+	-i $file \
+	--subgraph-dissection \
+	--verbose 1 \
+	--select-molecule-by-id 0 \
+	--select-molecules-atoms \
+	--fragment-molecule BondFragment \
+	--distance 1.55 \
+	--order 2 \
+	--fragment-automation \
+	--fragment-executable /bin/false \ 
+	--analyse-fragment-results \
+	--fragment-prefix $FILENAME \
+	--fragment-resultfile ${FILENAME}_results.dat], 
+	5, [stdout], [stderr])
+
+AT_CLEANUP
Index: tests/regression/Fragmentation/testsuite-fragmentation.at
===================================================================
--- tests/regression/Fragmentation/testsuite-fragmentation.at	(revision abfc95ba5c74e7d73ba21441037391420169955e)
+++ tests/regression/Fragmentation/testsuite-fragmentation.at	(revision a61dbbe03ddbe4f5f0a22574b63fb4d32e312493)
@@ -30,2 +30,5 @@
 # check storing saturated fragment
 m4_include([Fragmentation/StoreSaturatedFragment/testsuite-fragmentation-store-saturated-fragment.at])
+
+# check automation
+m4_include([Fragmentation/FragmentationAutomation/testsuite-fragmentation-fragmentation-automation.at])
Index: tests/regression/Makefile.am
===================================================================
--- tests/regression/Makefile.am	(revision abfc95ba5c74e7d73ba21441037391420169955e)
+++ tests/regression/Makefile.am	(revision a61dbbe03ddbe4f5f0a22574b63fb4d32e312493)
@@ -72,4 +72,5 @@
 	$(srcdir)/Fragmentation/testsuite-fragmentation.at \
 	$(srcdir)/Fragmentation/AnalyseFragmentationResults/testsuite-fragmentation-analyse-fragment-results.at \
+	$(srcdir)/Fragmentation/FragmentationAutomation/testsuite-fragmentation-fragmentation-automation.at \
 	$(srcdir)/Fragmentation/FragmentMolecule/testsuite-fragmentation-fragment-molecule.at \
 	$(srcdir)/Fragmentation/FragmentMolecule-MaxOrder/testsuite-fragmentation-fragment-molecule-maxorder.at \
