feat(compiler): author data-driven LOOP from a single demonstration - #188
Merged
Conversation
Close the missing authoring wire from a single-demonstration linear bundle to a governed, data-driven "run this for each record" LOOP. The Phase-2 interpreter already executes a LOOP over a worklist safely (bounded, $0, zero-model, identity-gated and effect-verified per iteration, halt-on-ambiguity). The only missing piece was the compile-time step that emits a ProgramGraph whose single LOOP iterates a demonstrated linear body once per record. This adds exactly that and nothing more -- it reuses lift_to_program, LoopSpec/Relation, and every existing safety gate verbatim; no new runtime, no new IR, no new safety surface. - openadapt_flow/compiler/loop_authoring.py: author_data_driven_loop() wraps a linear body in one LOOP over a Relation built from a worklist, binding each record's columns to the body's ParamSpec slots. The column->param mapping is explicit and validated -- an unmapped column, a mapping onto an unknown or secret param, a bound param with no column and no demo default, a ragged worklist, or a worklist longer than the loop bound all FAIL LOUDLY (LoopAuthoringError), never emit a bundle. - CLI: `openadapt-flow for-each <bundle> --records <csv|json> --out ...` with repeatable `--map COLUMN=PARAM`, `--relation`, `--max-iterations`. - tests/test_loop_authoring.py: authoring-shape + fail-loud unit tests, plus real-Replayer evidence -- a healthy 3-record run confirms each record's write INDEPENDENTLY against the in-process MockMed system of record with ZERO model calls and stays bounded; a poisoned record (effect the SoR refutes, and identity mismatch) triggers a safe HALT with no wrong write and no silent skip; and the shipped bundle is a valid program:true loop. - docs/showcase-loop: the first shipped program:true bundle, generated by scripts/build_showcase_loop_bundle.py from the OpenEMR showcase (proof the wire is reachable end to end on a real bundle). PHI-free .gitignore exception, mirroring showcase-openemr. - ci: add loop_authoring.py to the mypy-strict-safety scope. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NyCHrzA1psrKMFfroYbzaM
Member
Author
CI note — the two red jobs are pre-existing and unrelated to this changeAll gates this PR affects are green: lint, mypy-strict-safety (this PR adds Two jobs are red for reasons this branch does not touch (this commit changes only
Neither failure is in scope for this PR; both predate it. Happy to rebase once |
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
Closes the missing authoring wire from a single-demonstration linear bundle to a governed, data-driven "run this workflow for each record in a worklist" LOOP.
Per the core capability review (
.private/core_capability_review_2026_07_20.md): the runtime already executes aLOOPover a worklist safely — bounded,$0, zero-model, identity-gated and effect-verified per iteration, halt-on-ambiguity (replayer._exec_loop_state/_interpret_program). The only missing piece was the compile-time step that produces aProgramGraphwith aLOOPfrom a demonstrated linear body. This PR adds exactly that — and nothing more. It reuseslift_to_program,LoopSpec/Relation, and every existing safety gate verbatim: no new runtime, no new IR, no new safety surface.New vs reused
openadapt_flow/compiler/loop_authoring.py(author_data_driven_loop+ explicit/validated column→param mapping), afor-eachCLI subcommand, tests, and a generator script.LOOPinterpreter, per-iteration identity re-resolution, per-iteration effect verification,max_iterationsbounding, fail-safe HALT, andlift_to_program(body scaffold).Authoring UX
Every worklist column must map to a known non-secret parameter, and every parameter the body binds must be supplied by the worklist or carry a demo default — otherwise authoring fails loudly (
LoopAuthoringError), never emitting a silently under-bound bundle.Real multi-record evidence (through the actual Replayer, zero model calls)
report.model_calls == 0; bounded.program:true shipped bundle
docs/showcase-loop/bundleis the first shippedprogram:truebundle (both prior showcases wereprogram:false), generated byscripts/build_showcase_loop_bundle.pyfrom the OpenEMR showcase — proof the wire is reachable end-to-end on a real bundle. PHI-free, guarded in CI.Honest remaining gap
The worklist here is a provided dataset. When records must instead be read off the screen mid-run (e.g. "process every row in this on-screen queue"), that needs a screen→value extraction primitive that does not exist yet (
ActionKindhas noread/extract;entity_refrun-time re-resolution is a slot). This PR covers the provided-worklist case; the on-screen-worklist case is future work.Checks
loop_authoring.pyadded to the strict scope) green locally.tests/test_loop_authoring.py(13 tests) + related suites (test_program_ir_phase2,test_induction,test_phi_governance,test_consistency,test_ci_workflow_contract,test_cli_*,test_replayer) green.scripts/check_bundle_phi.pypasses over all git-tracked bundles including the new one.Coordination: depends only on the IR; does not touch the parallel program-visualizer work.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NyCHrzA1psrKMFfroYbzaM