On this page

Named scopes in nexus and restore๏ƒ

๐Ÿ”ต Expert ยท Lesson 38

Observe named lesser scopes through Nexus, then restore their recorded structure. New conduit IDs need the normal explicit Rift projection refresh. A known pooled ID keeps its compiled membership while named reuse replaces its payload. Crystallizer records dynamic scope structure and required unnamed ancestry; it does not save application instances or their mutable contents.

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/38_named_scopes_in_nexus_and_restore.py
py -3.14t UX_and_AIX_experiences/04_expert/38_named_scopes_in_nexus_and_restore.py

Download this collection ยท Source on GitHub

Public surface๏ƒ

md.Crystallizer.activate / create_checkpoint / load_checkpoint, md.Spellbook.configure_aether_frame / bind / conjure, md.Nexus.activate / create_rift, md.Rift.create_frame_link / refresh_runtime_projections, capability create_lesser_conduit / get_conduit_by_name, md.Conduit.get_conduit_cloud / cleanup.

Code๏ƒ

  1"""
  2TIER: expert (38)
  3GOAL: Observe named lesser scopes through Nexus, then restore their recorded structure.
  4      New conduit IDs need the normal explicit Rift projection refresh. A known
  5      pooled ID keeps its compiled membership while named reuse replaces its payload.
  6      Crystallizer records dynamic scope structure and required unnamed ancestry;
  7      it does not save application instances or their mutable contents.
  8SURFACE EXERCISED: md.Crystallizer.activate / create_checkpoint / load_checkpoint,
  9                   md.Spellbook.configure_aether_frame / bind / conjure,
 10                   md.Nexus.activate / create_rift, md.Rift.create_frame_link /
 11                   refresh_runtime_projections, capability create_lesser_conduit /
 12                   get_conduit_by_name, md.Conduit.get_conduit_cloud / cleanup.
 13VERIFY: Requires a complete successful in-memory checkpoint replay. No exception is
 14        treated as success. A cold process restart additionally needs flush/reload.
 15"""
 16
 17import melder as md
 18
 19
 20class JobNotebook:
 21    """Application state created inside each job, deliberately excluded from structural replay."""
 22
 23    def __init__(self) -> None:
 24        """Initialize the state that a fresh meld must recreate after restore."""
 25        self.notes: list[str] = []
 26
 27
 28def open_observer(name: str) -> md.Rift:
 29    """Open a capability room on the already-published named-jobs world.
 30
 31    Contract:
 32        Nexus configuration must already allow the target frame. The returned Rift
 33        is caller-owned and must be cleaned before tearing down its observed world.
 34    Args:
 35        name: Unique name for this observer.
 36    Returns:
 37        md.Rift: Attached observer with the current compiled projection.
 38    """
 39    nexus = md.Nexus()
 40    configuration = nexus.create_rift_configuration().with_space_type("capability")
 41    rift = nexus.create_rift(configuration=configuration, rift_name=name)
 42    rift.create_frame_link("named-jobs")
 43    return rift
 44
 45
 46def main() -> None:
 47    """Capture a live named hierarchy, retire it and rebuild fresh structural identities.
 48
 49    Contract:
 50        Single-threaded: no scope acquisition/return races with load_checkpoint.
 51        The recorder remains alive, so this demonstrates in-memory replay; flush
 52        and reload are required when crossing process teardown instead.
 53    Returns:
 54        None.
 55    """
 56    recorder = md.Crystallizer()
 57    recorder.activate(md.CrystallizerConfigurationBuilder().with_defaults().activate())
 58    nexus = md.Nexus()
 59    nexus_configuration = nexus.create_configuration()
 60    nexus_configuration.with_rift_creation_enabled(True)
 61    nexus_configuration.with_allowed_target_frame_names(["named-jobs"])
 62    nexus.activate(nexus_configuration)
 63
 64    configuration = md.SpellbookConfiguration("named-jobs").with_defaults().finalize()
 65    book = md.Spellbook(aetheric_frame="named-jobs", configuration=configuration)
 66    book.configure_aether_frame(
 67        system_state="dynamic", disposal=None, disposal_method_names=None,
 68        rift_enabled=True, ai_native=True,
 69    )
 70    book.bind(spell=JobNotebook, existence="unique_per_conduit", permissions="create")
 71    root = book.conjure(name="job-owner")
 72    observer = open_observer("before-restore")
 73    try:
 74        commands = observer.space.command_system
 75        job = commands.create_lesser_conduit(root.id, frame_name="named-jobs", name="job-42")
 76        observer.refresh_runtime_projections(frame_names=("named-jobs",))
 77        assert commands.get_conduit_by_name("job-42", frame_name="named-jobs") is job
 78        print("The capability command creates a named job; explicit refresh admits its new ID.")
 79
 80        job.cleanup()
 81        assert "job-42" not in commands.list_conduit_names(frame_name="named-jobs")
 82        next_job = commands.create_lesser_conduit(root.id, frame_name="named-jobs", name="job-43")
 83        assert commands.get_conduit_by_name("job-43", frame_name="named-jobs") is next_job
 84        print("Named reuse updates the existing ID's descriptor without an in-command refresh.")
 85
 86        support = root.create_lesser_conduit()
 87        nested = support.create_lesser_conduit(name="nested-job")
 88        original_id, support_id = nested.id, support.id
 89        original = nested.meld("JobNotebook")
 90        original.notes.append("not part of the structural record")
 91        observer.refresh_runtime_projections(frame_names=("named-jobs",))
 92        checkpoint = recorder.create_checkpoint()
 93        print("Checkpoint captured names and unnamed supporting ancestry, not notebook contents.")
 94    finally:
 95        observer.cleanup()
 96        root.permanent_cleanup()
 97
 98    report = recorder.load_checkpoint(checkpoint)
 99    assert report["status"] == "complete"
100    cloud = md.Aether().get_conduit_cloud("named-jobs")
101    restored_root = cloud.get_conduit_by_name("job-owner")
102    restored = cloud.get_conduit_by_name("nested-job")
103    restored_observer = open_observer("after-restore")
104    try:
105        assert restored.id != original_id
106        assert report["identity_map"][original_id] == restored.id
107        assert support_id in report["identity_map"]
108        assert not cloud.has_conduit_id(report["identity_map"][support_id])
109        assert restored.meld("JobNotebook").notes == []
110        assert restored_observer.space.command_system.get_conduit_by_name(
111            "nested-job", frame_name="named-jobs",
112        ) is restored
113        print("Restore rebuilt named scopes with fresh IDs and retained the unnamed ancestor.")
114        print("A new meld creates an empty notebook; earlier application data is not restored.")
115    finally:
116        restored_observer.cleanup()
117        restored_root.permanent_cleanup()
118
119
120if __name__ == "__main__":
121    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๏ƒ