ModuleState snapshots the mutable state of every Predict leaf in a module into a serializable value, so an optimized program can be saved to disk and reloaded in production without re-running optimization.
ModuleState
A ModuleState holds one PredictState per predictor, keyed by the leaf name the module declares via Predictors (predictors: BTreeMap<String, PredictState>). The BTreeMap keeps JSON output stable across runs. The names are the same ones optimizer candidates and trace spans use — one naming contract across persistence, optimization, and capture.
PredictState and the JSON shape
PredictState is the serializable snapshot of a single predictor’s mutable state.
A saved file therefore looks like:
The install seam
State loading reaches predictors through the object-safe per-leaf viewPredictorInfo (see Modules). Its load_state method is the install seam: a full overwrite of the leaf’s optimizable state (instruction_override: None clears the override, demos replaces the demo set), used by ModuleState::apply and by the optimizer’s one-shot install of the winning candidate. Candidate evaluation never calls it — candidates are injected ambiently per call tree (see Optimizers). Every load_state invalidates the leaf’s cached instance overlay, so a candidate is data applied through the seam, never ad hoc field mutation.
