def all_handler_ids(model_tree: Any) -> list[HandlerId]:
  """Collects the set of all handler IDs inside a model or submodel.

  Args:
    model_tree: A pytree for a model or submodel.

  Returns:
    A list of all handler IDs that appear in the model or submodel.
  """
  results = ordered_set.OrderedSet()

  def _go(thing_with_id: HandledEffectRef | EffectHandler):
    results.add(thing_with_id.handler_id)
    if isinstance(thing_with_id, EffectHandler):
      selectors.select(thing_with_id).at_children().at_instances_of(
          HandledEffectRef | EffectHandler
      ).apply(_go)

  selectors.select(model_tree).at_instances_of(
      HandledEffectRef | EffectHandler
  ).apply(_go)

  return list(results)
Collects the set of all handler IDs inside a model or submodel.

  Args:
    model_tree: A pytree for a model or submodel.

  Returns:
    A list of all handler IDs that appear in the model or submodel.
  
penzai/deprecated/v1/data_effects/effect_base.py