small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo

fix(state): keep restored instances instances of their class

save_state pickles each top-level value on its own, so a value referring to a class or function bound to another name carried its own copy. After a release and restore, an instance's class was a different object from the class its name held (and load_state's replay of the class definition made a third), so isinstance(boxed, Box) was False and class-level state split. dill also restored functions with a copy of the classes they named. Each value is now pickled with a persistent_id that saves a reference to another top-level class or function as that name, and load_state resolves it against the restored namespace, loading values in the order their references need (a value naming one that never loads waits for the definitions replay, as values deferred on AttributeError already did). After replay, loaded classes are put back, since restored instances belong to them; replayed functions keep the replay, whose globals are the live namespace. The cross-interpreter loader treats a reference as an incompatible value, which replay may still recover. Regression: kernel_snapshot_test (failed before this change). The e2e kernel_state scenarios, both engines checked in process, restore_loss and persisted-term fixtures still pass. robot-docs/kernel-state.md says so.


Author aly.codes
Date Commit Parent cab5686b
+168 -34
3 changed files
+168 -34
3 changed files