Understanding DynamicSupervisor & no initial children

I think it’s because of the restart strategy of the Task module, here’s the documentation:

Opposite to GenServer, Agent and Supervisor, a Task has a default :restart of :temporary . This means the task will not be restarted even if it crashes. If you desire the task to be restarted for non-successful exits, do:

You can simulate this by creating a Task module yourself,

defmodule MyTask do
  require Logger
  # use Task, restart: :transient
  use Task

  def start_link(arg) do
    Task.start_link(__MODULE__, :run, [arg])
  end

  def run(arg) do
    Logger.info("Hello")
  end
end

Then put in in your supervision tree like normal {MyTask, []}. Kill the first process and you’ll see that MyTask doesn’t restart, then now try with the restart: :transient flag, and you’ll see it works