checkpoint: objects are saved by their class and attributes, pickle as the fallback - #40
Merged
Merged
Conversation
…s the fallback A checkpoint refused any value that was not JSON, a File or a dataclass, so a run passing a task's own objects could not be resumed. Now an object of a class that can be found by its name and keeps its attributes in a __dict__ or Python __slots__ is written as its class name and attributes, and read back by setting them on a bare object of the class -- which survives the class's code changing between the failure and its resume, the change a fix is. Pickle is the fallback, for a class that says how it is saved itself or one built on a builtin container. Builtins are matched by exact type, so a Counter, a named tuple or an IntEnum is not flattened into its base; enums, datetimes, Decimal, UUID and complex have their own tags. A lock, an open file, a generator or a local class still make the checkpoint not resumable, naming the value; a value the current code cannot read back fails the resume, naming the checkpoint. The overlay and run record writers failed the run outright on such a token; they now write it as its repr (a dataclass as its fields). Claude-Session: https://claude.ai/code/session_015VK7fH1c4aKbexnq2QcuKU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #39. A checkpoint refused any value that was not JSON, a
Fileor a dataclass, so a run passing a task's own objects could not be resumed.Encoding order (
_checkpoint_runtime.encode):Path,File/Resource,Enummembers,datetime/date/time/timedelta,Decimal,UUIDandcomplex. Because the match is exact, aCounter, a named tuple or anIntEnumis not flattened into its base.{"$wfType": "object", "type": "module:Qualname", "state": {…}}, read back withcls.__new__plusobject.__setattr__(frozen dataclasses and__slots__included). It survives the class's code changing between the failure and the resume. This applies to classes findable by name that keep their attributes in a__dict__or Python__slots__, are not built on a builtin container, and define no pickle hooks.__getstate__/__reduce__and for subclasses of builtin containers.Also fixed: the overlay and run-record writers failed the run outright on such a token. They now write it as its
repr(a dataclass as its fields).Tests: round-trips for 30+ value kinds, each checked for both equality and exact type. Also: an object written by name rather than pickled, an object read back after its class changed, and a run passing objects that fails and resumes end to end. Full suite: 679 passed, 9 skipped.
https://claude.ai/code/session_015VK7fH1c4aKbexnq2QcuKU