Skip to content

Interactive tutorial recording can save before its after-snapshot observes the write, so the workflow is refused as an UNBOUND placeholder #1680

Not planned

Description

@soarkit

Project: OpenAdaptAI/OpenAdapt
Affected snapshot: ac3fee7

Summary

The guided recording route (record_tutorial_interactive) hands the recorder a bare _records reader as its system-of-record observer and wires persistence only into stop_when. The scripted route in the same module (record_tutorial) instead wraps the reader so that the save action's after-read waits, bounded by SAVE_LANDS_TIMEOUT_S, until the record lands. The recorder retains its before/after system-of-record state when it reads it, and stop_when is consulted only after the queued events are persisted, so a save that lands after the after-read leaves the saved-state transition unobserved. Effect mining then emits a needs_operator_confirmation placeholder for the save step, and consequential_step refuses the workflow.

Expected behavior

A demonstration that saves an encounter should produce a recording whose save action carries an observed authoritative-state delta, so that effect mining binds record_written to the saved step and consequential_step accepts the compiled workflow. The module already states this obligation for the save action: the scripted route's comment says the after-read "waits (bounded) for the write to land instead of racing it", and the timeout constant's comment says that a save which has not landed shows no delta and produces the placeholder the tutorial refuses.

Actual behavior

Running the module's interactive recording route against a save whose persistence lands after the recorder's after-read produces:

Guided recording
  1. Open the first task.
  2. Select New encounter, then Triage.
  3. Select the Note field and type a short synthetic note.
  4. Select Save encounter.
  5. Wait for the saved message. The recording browser closes automatically.

OpenAdapt records your actions and observes the separate local system of record.
INTERACTIVE_SAVE_AFTER_SNAPSHOT_MISSING

The guided banner is the target's own output; the final line marks the observation. At that point the completion condition had already returned true and the store held the persisted row, while the recorder's retained save after-snapshot was still empty — the save state was observed by stop_when but never recorded.

Root cause

packages/flow/openadapt_flow/tutorial.py:397-404 passes an unwrapped reader and puts persistence only in the completion predicate:

    return record_interactive(
        entry_url,
        recording_dir,
        param_fields=("note",),
        headless=False,
        system_of_record_reader=lambda: _records(base_url),
        stop_when=lambda: len(_records(base_url)) > baseline_records,
    )

The scripted route in the same file guards the identical read (tutorial.py:332-348): it counts reader calls, records the pre-save baseline on the read before the save click, and on the after-read polls until the record count exceeds that baseline or SAVE_LANDS_TIMEOUT_S expires:

        def read_records() -> list[dict[str, Any]]:
            records = _records(base_url)
            calls = save_watch.get("calls")
            if calls is None:
                return records
            save_watch["calls"] = calls + 1
            if calls == 0:  # the read before the save click
                save_watch["baseline"] = len(records)
                return records
            deadline = time.monotonic() + SAVE_LANDS_TIMEOUT_S
            while (
                len(records) <= save_watch["baseline"] and time.monotonic() < deadline
            ):
                time.sleep(0.05)
                records = _records(base_url)
            save_watch.clear()
            return records

The recorder's own contract makes stop_when unable to repair the snapshot. record_interactive's docstring (packages/flow/openadapt_flow/interactive_recorder.py:4437-4443) says the reader's observed before/after state is what the recorder retains for compilation, and that stop_when "is evaluated after queued events are persisted and before the browser closes". The retained state is captured where it is read (interactive_recorder.py:4367-4374):

        if self._system_of_record_reader is not None:
            try:
                records = self._system_of_record_reader()
            except Exception:
                records = None
            if records is not None:
                state["sor"] = records

The recorded save step therefore has an empty after-snapshot, the compiler emits an unbound placeholder effect, and consequential_step at tutorial.py:407 refuses it (tutorial.py:424-430):

    if any(effect.needs_operator_confirmation for effect in step.effects):
        raise TutorialError(
            "the compiler emitted an UNBOUND placeholder effect: the "
            "demonstration observed no system-of-record delta to bind, so "
            "there is nothing to verify against and the tutorial refuses to "
            "claim otherwise"
        )

Impact

  • The guided route is the documented real-human demonstration path. A user completes the entire demonstration, the save is accepted by the application, and the tutorial then rejects the workflow it just recorded, with no actionable diagnosis beyond the placeholder message.
  • The failure is latency-dependent: a save whose screen settles before the write lands loses its delta, so the interactive route fails intermittently and more often on loaded machines — the same race the scripted route was changed to remove.
  • Because the delta is missing rather than corrupt, the compiled effect contract cannot bind record_written to the save, so the recording cannot be admitted even though the system of record did receive the write.
  • The scripted route is unaffected, which makes the two recording routes behave differently for the same demonstrated workflow.

Suggested fix

  • Lift the save-aware reader out of record_tutorial into a shared helper and pass it to both routes. The helper should arm itself for the save action (first read after arming records the baseline, next read polls the bounded timeout until the count increases) and clear its state afterwards.
  • Have record_tutorial_interactive use that helper as system_of_record_reader, so the recorder's after-snapshot for the save is taken only after the record is visible; keep stop_when for completion only.
  • Alternatively, add an explicit save-completion wait in the interactive recorder itself (for example an after-action wait hook armed for the save action), so that any caller of record_interactive gets the same guarantee.
  • Keep the existing fail-closed behavior for a save that genuinely never lands: no delta, placeholder, refusal. Add a regression test that arms the interactive route with a reader that returns the record only on the read after the save, and assert that the retained save after-snapshot contains the record.

Activity

  1. abrichr commented on Nov 25, 2026

    @abrichr
    Member

    Legacy interactive tutorial recording timing issue (Oct 2026); the tutorial quickstart path has been rebuilt and verified in Flow 4.0 (#2669, #2683).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions