feat(adr-0249): P4 turn-program compiler + chained-relaxation executor #69
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/adr-0249-p4-turn-program"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The composition frontier. P1–P3 gave the corridor single-relation arithmetic and deduction; this makes it solve multi-step problems by chaining certified relaxation turns — the actual "wall is COMPOSITION" lesson getting its mechanism.
What it does
evals/turn_program.py—compile_turn_program(graph)turns aMathProblemGraphinto an orderedTurnProgram(a seed + affine steps);execute_turn_program(program)runs it as a chain of relaxation turns and returns the decoded answer plus a certified turn ledger. The accumulator flows turn-to-turn as a field state and is decoded only once, at the end (anti-hollow, spike §2/§4.1) — the substrate performs every step and composition depth lives in the certified chain, not in matrix size.Verified end-to-end:
((5+3)*2)-4 = 12,(10/2+7)*3 = 36,(100-40)/4 = 15,4*3+5 = 17— every turnground_state_certified.Ring-2 correction (verified in-tree)
The spike said "chain turns through the Ring-2 residual protocol." Grounding against the code,
run_residual_protocol(core/ports/residual_protocol.py:222) is zero-bound / non-mutating — its stage-5 recertification re-witnesses the subject and raisesrecertification_witness_changedif it moved. Arithmetic turns mutate, so they cannot be routed through the protocol as the transforming subject; it certifies a fixed state's admissibility, not a state transition. Handled honestly, without forcing a hollow integration:RelaxationCertificate(carriescertificate_id,converged,psi_digestbinding it to the exact state).TurnRecordchain that reuses the Ring-2 chain-integrity pattern (content-addressed,GENESIS_DIGEST-linked,verify_turn_chainmirroringverify_replay_chain). Records carry certificate ids + step provenance, never a decoded value. Tampering any non-terminal record breaks the successor link; the terminal record's integrity comes from deterministic re-execution (the same propertyverify_replay_chainhas).Tier-1 scope (ruling #1), fail-closed
Single-accumulator chains over add / subtract / multiply / divide with constant
Quantityoperands and positive scale. Everything else — multi-entity, transfer, rate, comparison, fraction, partition, non-positive scale, unit mismatch — is refused with a typedTurnProgramErrorand is the recorded composition frontier, never a silent drop. Off-serving (A-04): bridges the generate-side graph to the corridor; never imported bychat/runtime.py.Tests
tests/test_adr_0249_turn_program.py— 15/15 green. Five multi-step arithmetic chains, answer-unit propagation, chain verification + tamper detection, determinism, anti-hollow record shape, pure-compile check, and four refusal classes (multi-entity, transfer, non-positive scale, unit mismatch).Next
P5 integrates this into the generalized-lift instrument against a real GSM8K holdout slice (honest-NULL, recorded Tier-1 coverage); then ADR-0249 lands with acceptance evidence. No self-Accept.
[Verification]:
uv run python -m pytest tests/test_adr_0249_turn_program.py -q→ 15 passed;uv run core test --suite smoke -q→ 176 passed.