Files
OBLITERATUS/obliteratus/experiments/sequence_cli.py
Joseph MaglyandClaude Opus 5.5 bdc87ce97a feat(experiments): transactional two-step edit sequences
Add F17: promote only validated two-step edit sequences into a
persistent, resumable executor with tested rollback.

- Components must be verified F16 candidates or persistent-pilot
  eligible registrations, and an F14 interaction result must cover the
  exact order requested; untested orders are refused. Plans are
  write-once and content-addressed, so reversed order is a distinct
  identity.
- Each step saves a checkpoint plus ordered adapters and records input
  and output identities, order, file digests, intermediate target and
  collateral results, failure state and recovery path. A reloaded step
  must reproduce the composed temporary operations, keep every applied
  component's effect and pass collateral endpoints.
- A crash leaves an incomplete step that resume discards before
  continuing from the last verified step; incomplete sequences can't be
  published. A failed step is permanent and never selected.
- Rollback restores the reference or a verified step by digest-checked
  copy and reload, never by applying an inverse edit.
- `obliteratus experiments sequence plan|run|resume|rollback|show`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 11:34:03 -05:00

81 lines
4.6 KiB
Python

"""``obliteratus experiments sequence plan|run|resume|rollback|show``."""
import json
def _component(text):
kind, _, rest = text.partition(":")
run, sep, ident = rest.partition("@")
if kind not in ("candidate", "registration") or not sep:
raise ValueError(f"Component {text!r}: use candidate:<run>@<id> or "
"registration:<run>@<id>")
return {"run": run, kind: ident}
def add_sequence(commands):
parser = commands.add_parser(
"sequence", help="Transactional two-step edit sequences of verified candidates or "
"persistent-pilot eligible registrations")
sub = parser.add_subparsers(dest="sequence_command", required=True)
plan = sub.add_parser("plan", help="Admit and freeze an ordered pair (first, then second)")
plan.add_argument("first", help="candidate:<run>@<id> or registration:<run>@<id>")
plan.add_argument("second", help="candidate:<run>@<id> or registration:<run>@<id>")
plan.add_argument("--store", required=True, help="Directory holding sequences/")
plan.add_argument("--source", required=True, help="Selected reference model directory")
plan.add_argument("--interaction", required=True,
help="Interaction result.json that measured this ordered pair")
plan.add_argument("--pack", required=True, help="Evaluation dataset pack")
plan.add_argument("--revision", required=True, help="Evaluation dataset revision")
plan.add_argument("--role", required=True, choices=("select", "calibrate", "test"))
plan.add_argument("--allow-locked-test", action="store_true")
plan.add_argument("--tolerances", help="JSON object: target_rate, agreement, logit_atol")
plan.add_argument("--allow-fixture-results", action="store_true",
help="Count software-contract results for registration components; "
"testing only")
plan.add_argument("--actor")
for name, text in (("run", "Execute a planned sequence"),
("resume", "Continue an interrupted sequence from its last verified step")):
command = sub.add_parser(name, help=text)
command.add_argument("sequence", help="Sequence id (sha256:...)")
command.add_argument("--store", required=True)
command.add_argument("--actor")
back = sub.add_parser("rollback", help="Restore the reference or a verified step into a new "
"directory and test it")
back.add_argument("sequence")
back.add_argument("--store", required=True)
back.add_argument("--to", required=True, help="'reference' or a step position")
back.add_argument("--dest", required=True, help="New directory for the restored artifact")
back.add_argument("--actor")
show = sub.add_parser("show", help="One sequence, or every sequence of a store")
show.add_argument("sequence", nargs="?")
show.add_argument("--store", required=True)
def run_sequence_command(args):
from obliteratus.experiments.inputs import default_pack_resolver
from obliteratus.experiments.sequence_run import run_sequence, show
if args.sequence_command == "plan":
from obliteratus.experiments.sequence import plan_sequence
dataset = {"pack": args.pack, "revision": args.revision, "role": args.role,
"allow_locked_test": args.allow_locked_test}
plan = plan_sequence(args.store, [_component(args.first), _component(args.second)],
args.source, args.interaction, dataset,
tolerances=json.loads(args.tolerances) if args.tolerances else None,
allow_fixture_results=args.allow_fixture_results, actor=args.actor)
return {"id": plan["id"], "location": plan["location"], "scope": plan["frozen"]["scope"],
"interaction": plan["frozen"]["interaction"]}
if args.sequence_command in ("run", "resume"):
found = run_sequence(args.store, args.sequence, pack_resolver=default_pack_resolver,
resume=args.sequence_command == "resume", actor=args.actor)
return {"id": found["plan"]["id"], "state": found["state"],
"steps": [{k: s[k] for k in ("position", "outcome", "checks")}
for s in found["steps"]]}
if args.sequence_command == "rollback":
from obliteratus.experiments.sequence_rollback import rollback
return rollback(args.store, args.sequence, args.to, args.dest,
pack_resolver=default_pack_resolver, actor=args.actor)
return show(args.store, args.sequence)
__all__ = ["add_sequence", "run_sequence_command"]