So the way Valtio works is the proxy() function is passed an object, which it wraps in a proxy via proxyFunction(). This proxy has a trap for "set" and "deleteProperty" which notifies interested listeners whenever a value is set on any of the keys of the object.
If the proxy finds that you assign another object, it recursively calls proxyFunction again with this object, wrapping it in another similar proxy, in case it too has values assigned to its keys. And so on. On first call to proxy() the entire object is traversed, applying proxy traps to nested objects.
Thereafter, whenever a value is assigned to a key, subscribed listeners to those keys are called recursively up to the top of the object, finalizing with a call to the callback supplied to useSyncExternalStore in useSnapshot hooks, resulting in a re-render of its containing component, if that component accessed changed keys.
The way the subscription mechanism works is that when useSnapshot subscribes to the proxy, it recurs