feat(L10): rung-3b runtime — per-variable delta residue replay#55
Merged
Conversation
Refine `reverse <name>` to restore only the state fields its `reversible as <name>` body mutated (a before-image delta), not the whole agent state map. Fixes a real clobber: under the whole-checkpoint cut a reverse would silently revert an unrelated field that an intervening handler had changed. - eval: `collect_set_fields` statically scans the body (descending nested control) for `set` targets; `ReversibleAs` captures the before-image of just those fields as `Holding(delta)`; `ReverseNamed` writes them back rather than replacing the whole `AgentInstance.state`. Over-approximation is harmless (a field set only on an untaken branch is captured at its current value, so write-back is a no-op). - test: residue_reverse_is_per_field_delta_not_whole_checkpoint — a reverse restores `balance` but preserves a `note` an intervening handler changed. - spec §11b.8 / example / design-note: "checkpoint" -> "per-variable delta" in lockstep. 914 oo7-core lib tests pass; fmt + clippy clean; example + e2e green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018CaSgNjNURC7ocsyjYh9We
hyperpolymath
marked this pull request as ready for review
June 20, 2026 19:21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Refines the L10 rung-3b runtime residue (landed in #54) from a whole-state checkpoint to a per-variable delta.
reverse <name>now restores only the state fields its matchingreversible as <name>body actually mutated, leaving everything else intact.Why
The #54 checkpoint cut snapshotted/restored the entire
AgentInstance.statemap. That has a real clobber bug: if a handler firing between thereversible asand thereversechanged some unrelated field,reversewould silently revert it too. Per-variable delta is the correct "undo just this block's effect" semantics.How
collect_set_fields(eval.rs): a static scan of the reversible body forset <field>targets, descending through every nested control construct (mirrors the type checker'scollect_reversible_as_bindingsrecursion shape).ReversibleAscaptures a before-image delta — the prior values of exactly those fields — asHolding(delta)before running the body.ReverseNamedwrites those captured fields back (for (k,v) in delta { state.insert(k,v) }), rather than replacing the whole map; then marks the cellSpent.setonly on an untaken branch is captured at its current value, so writing it back is a no-op.Test
New
residue_reverse_is_per_field_delta_not_whole_checkpoint:debitarmsundotouching onlybalance; a separateannotatehandler changes the unrelated fieldnote;reverse undorestoresbalanceto its pre-debit value but preservesnote— which a whole-checkpoint restore would have clobbered.Verification
914oo7-corelib tests pass (was 913 + this one)cargo fmt --checkclean,clippy -D warningsexit 0examples/transactional_rollback.007parse + check + run greenjust run-examplesexit 0; error-line count identical toorigin/main(98 — all in unrelated pre-existing examples, no regression)Docs
Spec §11b.8, the example header, and
docs/echo-residue-integration.adocall updated from "checkpoint / whole state map" to "per-variable delta" wording. New CHANGELOG entry (the #54 historical entry is left intact).🤖 Generated with Claude Code
https://claude.ai/code/session_018CaSgNjNURC7ocsyjYh9We
Generated by Claude Code