Executor-Tyrant-Framework commited on
Commit
22c227e
Β·
verified Β·
1 Parent(s): c37887d

Sync from GitHub: c06b3aabc1dbb351966ed76ba2b2c2896c5fbb9b

Browse files
Files changed (1) hide show
  1. nuwave/organism.py +78 -9
nuwave/organism.py CHANGED
@@ -16,6 +16,50 @@ communication protocol (Law 1). Raw experience in, classification
16
  only at extraction (Law 7).
17
 
18
  # ---- Changelog ----
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  # [2026-06-20] Claude Opus 4.7 (1M ctx) β€” Mind-Not-Database: wire canonical RPC mechanisms
20
  # What: Six integration points wired into organism.py to call into a new
21
  # nuwave/substrate/rpc_mechanisms.py module that ports canonical NG's
@@ -838,14 +882,27 @@ class NuWaveOrganism:
838
  def _apply_state(self, state: dict, source: str) -> bool:
839
  """Apply a loaded state dict. Handles new + legacy formats."""
840
  try:
841
- # Graph checkpoint β€” stored as JSON string
842
- graph_json = state.get('graph_checkpoint_json')
843
- if graph_json and self._graph:
844
- tmp = os.path.join(self._state_path, "_tmp_restore.ckpt")
845
- with open(tmp, 'w') as f:
846
- f.write(graph_json)
 
 
 
 
 
847
  self._graph.restore(tmp)
848
  os.remove(tmp)
 
 
 
 
 
 
 
 
849
 
850
  # CES: restore node voltages with temporal decay so the
851
  # substrate comes up energetically warm. Must run AFTER
@@ -2145,10 +2202,22 @@ class NuWaveOrganism:
2145
  for node in self._graph.nodes.values():
2146
  if node.metadata and 'embedding' in node.metadata:
2147
  del node.metadata['embedding']
2148
- tmp = os.path.join(self._state_path, "_tmp_save.ckpt")
 
 
 
 
 
 
 
 
 
 
 
2149
  self._graph.checkpoint(tmp)
2150
- with open(tmp, 'r') as f:
2151
- state['graph_checkpoint_json'] = f.read()
 
2152
  os.remove(tmp)
2153
  except Exception as exc:
2154
  logger.debug("Graph checkpoint failed: %s", exc)
 
16
  only at extraction (Law 7).
17
 
18
  # ---- Changelog ----
19
+ # [2026-06-24] Claude Opus 4.7 (1M ctx) β€” Substrate-restore fix: msgpack-format checkpoint path
20
+ # What: Two surgical edits in organism.py β€” save() and _apply_state().
21
+ # (1) save(): graph checkpoint tmp filename changed from
22
+ # '_tmp_save.ckpt' β†’ '_tmp_save.ckpt.msgpack'. Read back as
23
+ # BYTES (rb) instead of text (r). Field renamed
24
+ # 'graph_checkpoint_json' β†’ 'graph_checkpoint_msgpack' so the
25
+ # restore path can detect format unambiguously. Legacy field
26
+ # is .pop()'d from state to keep sidecars lean.
27
+ # (2) _apply_state(): try msgpack field first (canonical post-fix
28
+ # path), fall back to legacy graph_checkpoint_json for sidecars
29
+ # saved before this fix. The legacy fallback is known-lossy
30
+ # (#325 enforcer drops topology on non-.msgpack restore) but
31
+ # that's the broken behavior we're fixing β€” no regression.
32
+ # Why: Run 41 boot log (2026-06-24 00:56) revealed the smoking-gun
33
+ # pattern: 'Organism restored from local-sidecar: 0 nodes, 0 syn,
34
+ # 355 content, step 119, 120 amps, 0 embs' on a 128KB sidecar with
35
+ # all four state files intact on disk. Topology silently dropping
36
+ # on restore while auxiliary state (content/amplitudes/embeddings)
37
+ # restored fine. Earlier RuntimeWarning had named the root cause:
38
+ # "Restoring topology from non-'.msgpack' path '..._tmp_restore.ckpt':
39
+ # legacy lossy-JSON state (pre-#325). Re-checkpoint to .msgpack
40
+ # to stop the loss." The Mind-Not-Database re-vendor (commit
41
+ # `35ed177`) activated canonical NG's #325 msgpack-enforcer; the
42
+ # pre-existing bespoke JSON checkpoint path NuWave used since
43
+ # pre-BTF was suddenly the wrong side of LAW 2 / the
44
+ # Format-for-Purpose Principle's "topology MUST be msgpack" rule.
45
+ # How: Two-edit surgical fix. Switches NuWave's save/restore tmp
46
+ # filenames to .msgpack so canonical Graph.checkpoint()/restore()
47
+ # use the proper binary format. Storage format in sidecar
48
+ # changes from JSON-text to msgpack-bytes; the sidecar.pt is
49
+ # already a torch.save dict so binary-bytes-as-value is fine.
50
+ # Existing sidecars without the new field fall back to the
51
+ # legacy (lossy) path which is the current broken behavior β€”
52
+ # so no worse than today. Once a save() runs with this fix, the
53
+ # resulting sidecar carries the msgpack field and round-trips
54
+ # topology correctly.
55
+ # The harvest-from-legacy path at line 721 ('_tmp_harvest.ckpt')
56
+ # is unchanged β€” that's the pre-BTF organism_state.pt migration
57
+ # and operates on truly-legacy JSON-text inputs by design.
58
+ # Side-effect: existing substrate state on /data is lost (was already
59
+ # loading as 0 topology). Recovery option: restore from HF dataset
60
+ # `backups/<ts>/` pre-Mind-Not-Database snapshot per MASTER-NuWave
61
+ # Operations procedure.
62
+ # -------------------
63
  # [2026-06-20] Claude Opus 4.7 (1M ctx) β€” Mind-Not-Database: wire canonical RPC mechanisms
64
  # What: Six integration points wired into organism.py to call into a new
65
  # nuwave/substrate/rpc_mechanisms.py module that ports canonical NG's
 
882
  def _apply_state(self, state: dict, source: str) -> bool:
883
  """Apply a loaded state dict. Handles new + legacy formats."""
884
  try:
885
+ # Graph checkpoint β€” try canonical msgpack format first
886
+ # (post-#325 fix 2026-06-24), fall back to legacy JSON path
887
+ # for sidecars saved before this fix. The legacy path is
888
+ # known-lossy (#325 silently drops topology on non-.msgpack
889
+ # restore), so old sidecars restore as 0 topology β€” same as
890
+ # the broken state we're fixing. No regression vs current.
891
+ graph_mp = state.get('graph_checkpoint_msgpack')
892
+ if graph_mp and self._graph:
893
+ tmp = os.path.join(self._state_path, "_tmp_restore.ckpt.msgpack")
894
+ with open(tmp, 'wb') as f:
895
+ f.write(graph_mp)
896
  self._graph.restore(tmp)
897
  os.remove(tmp)
898
+ else:
899
+ graph_json = state.get('graph_checkpoint_json')
900
+ if graph_json and self._graph:
901
+ tmp = os.path.join(self._state_path, "_tmp_restore.ckpt")
902
+ with open(tmp, 'w') as f:
903
+ f.write(graph_json)
904
+ self._graph.restore(tmp)
905
+ os.remove(tmp)
906
 
907
  # CES: restore node voltages with temporal decay so the
908
  # substrate comes up energetically warm. Must run AFTER
 
2202
  for node in self._graph.nodes.values():
2203
  if node.metadata and 'embedding' in node.metadata:
2204
  del node.metadata['embedding']
2205
+ # Canonical NG #325 enforces msgpack-only checkpoint paths β€”
2206
+ # any non-'.msgpack' extension is treated as lossy-JSON and
2207
+ # silently drops topology on restore. The Mind-Not-Database
2208
+ # re-vendor activated this enforcer; the pre-existing
2209
+ # '_tmp_save.ckpt' filename routed to the lossy path,
2210
+ # producing sidecars whose graph checkpoint reloaded as
2211
+ # 0 nodes / 0 synapses while auxiliary state (content,
2212
+ # amplitudes, embeddings) restored fine. Diagnosed Run 41
2213
+ # boot log 2026-06-24. Fix: use .msgpack extension, store
2214
+ # bytes (not text). Field renamed graph_checkpoint_json β†’
2215
+ # graph_checkpoint_msgpack so restore can detect format.
2216
+ tmp = os.path.join(self._state_path, "_tmp_save.ckpt.msgpack")
2217
  self._graph.checkpoint(tmp)
2218
+ with open(tmp, 'rb') as f:
2219
+ state['graph_checkpoint_msgpack'] = f.read()
2220
+ state.pop('graph_checkpoint_json', None) # drop legacy field
2221
  os.remove(tmp)
2222
  except Exception as exc:
2223
  logger.debug("Graph checkpoint failed: %s", exc)