model: fix Tree.toDict to be side-effect free
Remove reliance on default arg child_nodes which is a dict.
It is unused in client code, breaks tests, and is not needed to build
the dict representation of the tree.
This also refines types on related impacted methods which helps
reasoning about them.