def flatten_task_updates(updates):
  """Flatten a list of task updates into a single result.

  This is more or less the equivalent of what task_scheduler.bot_update_task()
  would do after all the bot API calls.
  """
  out = {}
  for update in updates:
    if out.get('output') and update.get('output'):
      # Accumulate output.
      update = update.copy()
      out['output'] += update.pop('output')
      update.pop('output_chunk_start')
    out.update(update)
  return out