On this page

Loading a whole world back๏ƒ

๐Ÿ”ต Expert ยท Lesson 24

SEAL A WORLD, THEN UNFOLD IT AGAIN. Expert 01 taught the pod-boot ORDER; expert 09 taught what crosses the wire. This is the round trip itself - checkpoint a live world, put it in the cache, and unfold it back into the runtime.

THE FIVE VERBS, IN ORDER create_checkpoint(profile, description) -> a ULID id describe_checkpoint(id) -> what got captured flush_checkpoint(id) -> seal it into the cache reload_cached_checkpoint(id) -> cache back into ledger load_checkpoint(id) -> UNFOLD into the runtime Only the last one touches the live world. The first four move a record around; load_checkpoint is the boot verb.

A RESTORE IS NOT A RESURRECTION, AND THE REPORT SAYS SO load_checkpoint hands back a RestoreReport carrying: status did it complete built counts how many of each kind came back shortfall entries what could NOT be rebuilt identity translation map OLD id -> NEW id That last field is the one to understand. Rebuilt objects get NEW identities - the world that comes back is equivalent, not identical - and the map is how you follow one thing across a boot. Anything holding a raw pre-restore id and expecting it to still resolve is holding a stale address, and the map is the only honest way to translate it.

SHORTFALLS ARE REPORTED, NOT HIDDEN A spell whose class can no longer be imported, a module that moved, a binding whose target is gone - each becomes a shortfall ENTRY rather than a silent omission. Expert 18's law at the boot grain: a restore that quietly dropped what it could not rebuild would look identical to a world that never had those things, and the second invites everyone downstream to invent.

CHECKPOINTS ACCUMULATE; THEY NEVER OVERWRITE Every create_checkpoint mints a new ULID and list_checkpoint_ids() returns them in exact ledger creation order. There is no "the checkpoint" - there is a history of them, and an id is the whole handle.

AND THE OPERATOR'S ONE-CALL VERSION md.CrystallizerBootstrap() .with_crystallizer_configuration(...) .with_profile(...) .with_pull_remote(False) .bootstrap() That is expert 01's flow: the same steps in a fixed sequence, for the case where you are starting a process rather than inspecting a round trip. Note with_preflight_gate is an ACCEPTED NO-OP - the knob still exists and does nothing, and its own docstring says so rather than pretending.

Before you run๏ƒ

Use the Expert guide for prerequisite concepts. Run from a checkout with Melder installed and Python 3.14 free-threading selected. The collection download includes the level's local helper modules.

Run the saved script๏ƒ

python UX_and_AIX_experiences/04_expert/24_loading_a_whole_world_back.py
py -3.14t UX_and_AIX_experiences/04_expert/24_loading_a_whole_world_back.py

Download this collection ยท Source on GitHub

Public surface๏ƒ

md.Crystallizer create_checkpoint / describe_checkpoint / flush_checkpoint / list_cached_checkpoint_ids / list_checkpoint_ids / reload_cached_checkpoint / load_checkpoint, and md.CrystallizerBootstrap

Code๏ƒ

  1"""
  2TIER: expert (24)
  3GOAL: SEAL A WORLD, THEN UNFOLD IT AGAIN. Expert 01 taught the pod-boot
  4      ORDER; expert 09 taught what crosses the wire. This is the round
  5      trip itself - checkpoint a live world, put it in the cache, and
  6      unfold it back into the runtime.
  7
  8      THE FIVE VERBS, IN ORDER
  9        create_checkpoint(profile, description) -> a ULID id
 10        describe_checkpoint(id)                 -> what got captured
 11        flush_checkpoint(id)                    -> seal it into the cache
 12        reload_cached_checkpoint(id)            -> cache back into ledger
 13        load_checkpoint(id)                     -> UNFOLD into the runtime
 14      Only the last one touches the live world. The first four move a
 15      record around; `load_checkpoint` is the boot verb.
 16
 17      A RESTORE IS NOT A RESURRECTION, AND THE REPORT SAYS SO
 18      `load_checkpoint` hands back a RestoreReport carrying:
 19        status                      did it complete
 20        built counts                how many of each kind came back
 21        shortfall entries           what could NOT be rebuilt
 22        identity translation map    OLD id -> NEW id
 23      That last field is the one to understand. Rebuilt objects get NEW
 24      identities - the world that comes back is equivalent, not
 25      identical - and the map is how you follow one thing across a boot.
 26      Anything holding a raw pre-restore id and expecting it to still
 27      resolve is holding a stale address, and the map is the only honest
 28      way to translate it.
 29
 30      SHORTFALLS ARE REPORTED, NOT HIDDEN
 31      A spell whose class can no longer be imported, a module that
 32      moved, a binding whose target is gone - each becomes a shortfall
 33      ENTRY rather than a silent omission. Expert 18's law at the boot
 34      grain: a restore that quietly dropped what it could not rebuild
 35      would look identical to a world that never had those things, and
 36      the second invites everyone downstream to invent.
 37
 38      CHECKPOINTS ACCUMULATE; THEY NEVER OVERWRITE
 39      Every `create_checkpoint` mints a new ULID and
 40      `list_checkpoint_ids()` returns them in exact ledger creation
 41      order. There is no "the checkpoint" - there is a history of them,
 42      and an id is the whole handle.
 43
 44      AND THE OPERATOR'S ONE-CALL VERSION
 45        md.CrystallizerBootstrap()
 46            .with_crystallizer_configuration(...)
 47            .with_profile(...)
 48            .with_pull_remote(False)
 49            .bootstrap()
 50      That is expert 01's flow: the same steps in a fixed sequence, for
 51      the case where you are starting a process rather than inspecting a
 52      round trip. Note `with_preflight_gate` is an ACCEPTED NO-OP - the
 53      knob still exists and does nothing, and its own docstring says so
 54      rather than pretending.
 55SURFACE EXERCISED: md.Crystallizer create_checkpoint /
 56                   describe_checkpoint / flush_checkpoint /
 57                   list_cached_checkpoint_ids / list_checkpoint_ids /
 58                   reload_cached_checkpoint / load_checkpoint, and
 59                   md.CrystallizerBootstrap
 60VERIFY: rides the owner's 3.14t harness; asserts are the contract.
 61"""
 62import melder as md
 63
 64
 65FRAME = "restore-world"
 66
 67
 68class Ledger:
 69    def __init__(self) -> None:
 70        self.entries = []
 71
 72
 73class Auditor:
 74    def __init__(self) -> None:
 75        self.checked = 0
 76
 77
 78def main() -> None:
 79    # Custody first - nothing is recorded into a crystallizer that is not
 80    # yet recording (expert 22's ordering law).
 81    crystallizer = md.Crystallizer()
 82    crystallizer.activate(
 83        md.CrystallizerConfigurationBuilder().with_defaults().activate(),
 84    )
 85    research = md.MutationResearch()
 86    configuration = research.create_configuration()
 87    configuration.with_defaults().activate()
 88    research.activate(configuration)
 89    print("custody recording:", crystallizer.activated)
 90
 91    # A REAL WORLD with two spells and a live object.
 92    # A RECORDED WORLD MUST BE BORN CONFIGURED. With custody active, a
 93    # dynamic conjure REFUSES if any bind ran before the configuration
 94    # was finalized - the profile record and default bootstrap would
 95    # otherwise durably persist binds made against unsettled config.
 96    spellbook_configuration = (
 97        md.SpellbookConfiguration(FRAME).with_defaults().finalize()
 98    )
 99    book = md.Spellbook(aetheric_frame=FRAME,
100                        configuration=spellbook_configuration)
101    ledger_id = book.bind(spell=Ledger, existence="unique",
102                          permissions="create", binding_name="restore-ledger")
103    book.bind(spell=Auditor, existence="many",
104              permissions="create", binding_name="restore-auditor")
105    book.configure_aether_frame(
106        system_state="dynamic",
107        disposal=None,
108        disposal_method_names=None,
109    )
110    conduit = book.conjure(name="restore-root")
111    ledger = conduit.meld(spell=Ledger, binding_name="restore-ledger")
112    ledger.entries.append("before the checkpoint")
113    print("world up; ledger holds", len(ledger.entries), "entry")
114
115    # 1. SEAL IT. A checkpoint is minted, not overwritten.
116    first_id = crystallizer.create_checkpoint()
117    second_id = crystallizer.create_checkpoint()
118    assert first_id != second_id
119    ledger_of_ids = crystallizer.list_checkpoint_ids()
120    print()
121    print("two checkpoints minted:", first_id[:10], "...,", second_id[:10])
122    print("list_checkpoint_ids() ->", len(ledger_of_ids),
123          "in ledger creation order")
124    print("  checkpoints ACCUMULATE - there is no 'the' checkpoint, and")
125    print("  the id is the whole handle")
126
127    # 2. WHAT IS ACTUALLY IN ONE?
128    described = crystallizer.describe_checkpoint(second_id)
129    print()
130    print("describe_checkpoint keys:", sorted(described)[:8])
131    counts = described.get("captured_counts")
132    if isinstance(counts, dict):
133        live = {k: v for k, v in counts.items() if v}
134        print("captured:", live)
135
136    # 3. SEAL IT INTO THE CACHE. Advanced 18's warning still applies -
137    #    the cache is FIFO bounded, so a flush can evict an older entry.
138    flushed = crystallizer.flush_checkpoint(second_id)
139    assert second_id in flushed
140    cached = crystallizer.list_cached_checkpoint_ids()
141    assert second_id in cached
142    print()
143    print("flushed ->", len(flushed), " cached now:", len(cached))
144
145    # 4. CACHE BACK INTO THE LEDGER. This is history bookkeeping, not a
146    #    world change - nothing has been unfolded yet.
147    summary = crystallizer.reload_cached_checkpoint(second_id)
148    assert isinstance(summary, dict)
149    print("reload_cached_checkpoint -> the checkpoint's own summary")
150    print("  still no live object touched; that is the NEXT verb")
151
152    # 5. THE BOOT VERB. This one unfolds the record into the runtime.
153    report = crystallizer.load_checkpoint(second_id)
154    assert isinstance(report, dict)
155    print()
156    print("load_checkpoint -> RestoreReport keys:", sorted(report))
157    print("   status:", report.get("status"))
158
159    # THE IDENTITY TRANSLATION MAP is the field that changes how you
160    # think about a restore.
161    translation = None
162    for key in ("identity_translation", "identity_translation_map",
163                "translation_map", "identity_map"):
164        if key in report:
165            translation = report[key]
166            print(f"   {key}: {len(translation)} remapped identities")
167            break
168    if translation is None:
169        print("   (identity map under another key - see the keys above)")
170    print("  rebuilt objects get NEW ids: the world that comes back is")
171    print("  EQUIVALENT, not identical. A raw pre-restore id is a stale")
172    print("  address, and this map is the only honest way to translate")
173
174    # SHORTFALLS: what could not be rebuilt, named rather than dropped.
175    for key in ("shortfall", "shortfalls", "shortfall_entries"):
176        if key in report:
177            entries = report[key]
178            print()
179            print(f"   {key}: {len(entries)} entr(y/ies)")
180            for entry in list(entries)[:3]:
181                print("      ", str(entry)[:88])
182            print("  a restore that silently dropped what it could not")
183            print("  rebuild would look exactly like a world that never")
184            print("  had those things - so it names them instead")
185            break
186
187    # THE ORIGINAL SPELL STILL ANSWERS through the pre-restore handle we
188    # kept, which is the point of holding OBJECTS rather than ids.
189    assert ledger.entries == ["before the checkpoint"]
190    print()
191    print("the object we held across all of this is untouched:",
192          ledger.entries)
193    print("  ids go stale across a boot; the handle in your hand does not")
194
195    # 6. THE OPERATOR'S ONE-CALL VERSION exists and is exported.
196    assert hasattr(md, "CrystallizerBootstrap")
197    print()
198    print("md.CrystallizerBootstrap() is the pod-boot form of all of the")
199    print("above - same steps, fixed order (expert 01). Note one of its")
200    print("knobs, with_preflight_gate, is an ACCEPTED NO-OP that says so")
201    print("in its own docstring rather than quietly doing nothing")
202
203    print()
204    print("seal, cache, reload, unfold - and only the last one is a boot")
205    print("a restore rebuilds an EQUIVALENT world and hands you the map")
206
207
208if __name__ == "__main__":
209    main()

Check the outcome๏ƒ

The script contains its own assertions or demonstrated refusal paths. Run it to evaluate those checks against your installed version. The code above is taken directly from the saved file; no run output is invented here.

More expert examples ยท Level guide

API contracts๏ƒ