PackedScene.pack() - how does it work?

Godot Version

v4.2.stable.official [46dc27791]

Question

I’m trying to use PackedScene to save my game, but I’ve run into a lot of intuitive behaviors that makes me want to know just how the system works. I hope someone can explain to me a step-by-step process of how godot decides which nodes should be saved when the pack function is called.

My naive understanding was:
you can created a .tscn file by calling PackedScene.pack on a node, which will become the root node of the .tscn file.
for each descendant node of the root node, you must set the owner of the descendant to the root node.

However, the process is not nearly as simple as marking everything you want to save by assigning owner and then calling pack():

if a node X already has an owner, reassigning the owner will cause orphaned copies of X to appear when instantiated the saved .tscn file.
if a node Y was instantiated during runtime, Y will not be added to the .tscn file if its parent is not the root node of a scene that is also instantiated during runtime (see PackedScene won't save nodes added to non-root nodes · Issue #90823 · godotengine/godot · GitHub)

the first problem is simple enough to solve with some if statements, but the second one leads to a lot of ugly workarounds where components of a scene tree either have to be instantiated during run time just for the sake of saving or child nodes need to be reparented to a root node then moved back to appropriate extensions.

At this point I just want someone to explain the backend process of pack and why it does or doesn’t choose to save something