title: AWS SWF Respond Activity Task Completed
body: <p>I can see in the SWF Management Console a Workflow has around 18 events, with the 16th event being my <code>ActivityTaskCompleted</code> event however whenever i poll for decisions i only get up to the 15th event so i never get to call <code>RespondDecisionTaskCompleted</code> with the decision type <code>CompleteWorkflowExecution</code> as such my workflows are always sitting in the Active state until they timeout. </p>
  
  <p>The flow i'm using is from a PHP SWF git i found a while ago, i unfortunately do not have the link to it anymore though.</p>
  
  <pre><code>$response = $this-&gt;swf-&gt;PollForDecisionTask($opts);
  $decision_list = self::_decide(new HistoryEventIterator($this-&gt;swf, $opts, $response), $this-&gt;swf);
  if(count($decision_list) &gt; 0)
  {
      //Some decisions
  }
  else
  {
      //No decisions
  }
  </code></pre>
  
  <p>Where the HistoryEventIterator looks like so</p>
  
  <pre><code>public function __construct(Aws\Swf\SwfClient $swf_client, $original_request, $original_response) {
      $this-&gt;swf = $swf_client;
      $this-&gt;events = array();
      $this-&gt;event_index = 0;
      $this-&gt;next_page_token = null;
      $this-&gt;original_poll_request = $original_request;
  
      $this-&gt;_process_poll_response($original_response);
      $this-&gt;workflow_id = $original_response-&gt;get('workflowExecution')['workflowId'];
      $this-&gt;run_id = $original_response-&gt;get('workflowExecution')['runId'];
  }
  
  protected function _process_poll_response($response) {
      if ($response-&gt;hasKey("nextPageToken")) {
          $this-&gt;next_page_token = (string) $response-&gt;get("nextPageToken");
      } else {
          $this-&gt;next_page_token = null;
      }
  
      $next_events = $response-&gt;get("events");
      $next_events_object = new ArrayObject($next_events);
      $next_events_copy = $next_events_object-&gt;getArrayCopy();
      $this-&gt;events = array_merge($this-&gt;events, $next_events);
  }
  </code></pre>
  
  <p>I have omitted error checking and functions of <code>HistoryEventIterator</code> that would not be called in this scenario. 
  I have output the <code>next_page_token</code> of <code>HistoryEventIterator</code> and found it was always <code>NULL</code>.</p>
  
  <p>Should the <code>RespondDecisionTaskCompleted</code> called from an Activity reach the decider? If so, what could be the cause for mine not? Surely it wouldn't be paging after 15 events, and simply not paging correctly. </p>
  
  <p>I can verify that the Domain, Activity Task List, and Decider Task List are accurate as the Workflow shows up in the SWF Management Console, as does the decisions and the Activity (The Activity even has the status Completed) There is appropriate error checking and Try/Catch blocks and in no cases are there any exceptions. </p>