Found the problem.
It was outdated python-optree package. Seems that 0.13.0 version doesn't have the issue.
The issue was:
>>> from optree import *
>>> tree_map(lambda x: x, ())
/usr/include/c++/14.1.1/bits/stl_vector.h:1130: constexpr std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = pybind11::object; _Alloc = std::allocator<pybind11::object>; reference = pybind11::object&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.
fish: Job 1, 'python' terminated by signal SIGABRT (Abort)
Empty tuples or arrays raised the issue.
In version 0.13.0:
>>> from optree import *
>>> tree_map(lambda x: x, ())
()
It's not trowing and everything works.