Commit 1fc031a
Phase H.2: autofix-and-retry loop + divide-by-singularity check
examples/self_healing_h2.omc — the healer becomes iterative and gains
a third diagnostic class.
New diagnostic class: divide-by-singularity. In heal_expr, when a
BIN `/` operator's right operand is a literal NUM, the healer
evaluates value_danger(v). If the result exceeds 0.5 (fold_escape's
danger threshold), the whole expression is rewritten as
CALL safe_divide(left, right). The host's safe_divide primitive
does the rest — it fold_escapes the divisor at runtime, so
safe_divide(8, 0) returns 8 (8 / fold_escape(0) → 8 / 1 → 8), not
an error. The healer turns a runtime crash into a finite answer
that lands on a Fibonacci attractor, with no special-case
error-handling code anywhere. The math is the rule.
The loop heal_until_fixpoint(stmts, max_iter):
for iter in 1..max_iter:
(healed, diags) = heal_program(current)
record (iter, |diags|) in trajectory
if |diags| == 0: return ("converged", iter - 1)
if |diags| == prev: return ("stuck", iter)
current = healed
return ("exhausted", max_iter)
Three terminal states: converged, stuck, exhausted.
Three demos, three convergences:
Demo 1 (H.1 regression): 12→13, fbi→fib. fib(13) = 233.
Demo 2 (new): numerator / 0 → safe_divide(8, 0) → 8.
Demo 3 (all three): 7→8, safef→safe, n/0 → safe_divide(n,0).
The bytecode VM gains ONN primitive dispatch: safe_divide,
fold_escape, value_danger, harmony_value, is_fibonacci. Healed
programs run end-to-end on the V.7c executor without falling back
to tree-walk.
Why iteration matters even when one pass suffices: H.1's checks
already run in parallel during one AST walk. H.2's loop is mostly
empty-confirmation passes. But the LOOP IS THE RIGHT SHAPE for
H.3 (parse-level recovery: rewrite-and-re-parse is naturally
iterative) and H.4 (runtime-guarded primitives: adding a guard can
expose new diagnostics on adjacent nodes). H.2 lands the substrate
so H.3/H.4 plug in without re-architecting.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 7c59537 commit 1fc031a
2 files changed
Lines changed: 1969 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
7 | 59 | | |
8 | 60 | | |
9 | 61 | | |
| |||
0 commit comments