Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/desktop/openadapt_desktop/flow_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,9 @@ def tutorial(

Flow serves its own synthetic clinic app with made-up patients on this
computer, records the sample task, builds it, runs it with the record
check on, and (with ``break_it``) runs it again against a backend that
drops the save after the screen says "saved". Nothing here needs an
check on, and (with ``break_it``) runs it again against a save that
keeps the encounter but drops the typed note while the screen says
"saved". Nothing here needs an
operating-system permission, an account, or the operator's apps.
"""

Expand Down
39 changes: 21 additions & 18 deletions packages/flow/docs/TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ practice-management fixture served through its real transactional backend.
```bash
openadapt-flow demo # both runs, one proof page
openadapt-flow tutorial # the whole loop, VERIFIED
openadapt-flow tutorial --break-it # then watch it catch a failed save
openadapt-flow tutorial --break-it # then watch it catch a dropped note
openadapt-flow tutorial --guided # perform the demo yourself
```

Expand All @@ -16,7 +16,7 @@ openadapt-flow tutorial --guided # perform the demo your
`demo` runs `tutorial --break-it` without the stage-by-stage output, then
writes one self-contained page, `openadapt-demo/index.html`, and opens it when
a display is available (`--no-open` skips that). The page puts the two final
screens side by side, shows the record check under each run (1 note, then 0),
screens side by side, shows the record check under each run (1 typed note, then 0),
lists the choices a person gets when the second run stops, and folds the
engine's exact terms under "Technical details". When the demo goes as
expected, the terminal shows 8 lines. If the first run doesn't end "Done and
Expand Down Expand Up @@ -74,30 +74,33 @@ shown.

## What `--break-it` does

`--break-it` reruns the **same certified bundle** with the save set to fail:
the server rejects the write, so nothing lands, yet every on-screen check
still passes. The independent read of the system of record refutes the mined
`record_written` contract and the engine **HALTS** at the consequential step
instead of reporting done. The
caught fault's evidence is a clearly-labeled local `run-broken/REPORT.md`; no
shareable receipt is emitted for it, because only `VERIFIED` runs may use the
success rail.
`--break-it` reruns the **same certified bundle** against a partial save
(`?fault=partial`): the app stores the encounter but drops the typed note,
the way real apps do when a field fails a length, encoding or mapping rule
without an error. The form closes and the saved message shows the note, so
every on-screen check passes. Reading the record back shows the encounter with
a blank note, which is what a careful person sees when they reopen it. The
mined `field_equals` contract on the note is refuted and the engine **HALTS**
at the consequential step instead of reporting done. The caught fault's
evidence is a clearly-labeled local `run-broken/REPORT.md`; no shareable
receipt is emitted for it, because only `VERIFIED` runs may use the success
rail.

```
The screen claimed: every on-screen check passed -- the app painted its success banner
Injected fault: 'partial' -- the app saves the encounter but drops the typed note
On screen: every on-screen check passed, including the saved message
(observed on screen: "Encountersaved-")
The verifier found: 1/2 declared effect(s) REFUTED by an independent
read of the system of record, which holds 0 record(s)
The verifier found: 1/2 declared effect(s) REFUTED by reading the record
back: 1 encounter(s), 0 with the note as typed
The engine did: HALTED at the consequential step instead of claiming
success (transaction: RECONCILIATION_REQUIRED, billable: no)
Result: Check the record. A save may have gone through. A person checks the record before anything is retried.
```

The halted run doesn't retry the write either: delivery is uncertain, so the
transaction ends in `RECONCILIATION_REQUIRED` for a person to settle. That's
why the plain result is "Check the record" and not "Stopped before saving":
the store really is empty, but the engine says nothing was written only when
it can prove that for every declared effect.
The halted run doesn't retry the write either: part of the save landed, so
a resend could create a second encounter. The transaction ends in
`RECONCILIATION_REQUIRED` for a person to settle. That's why the plain
result is "Check the record" and not "Stopped before saving".

## What `--guided` does

Expand Down
2 changes: 1 addition & 1 deletion packages/flow/docs/design/DECOMPOSITION.md
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ The `build_parser` split lowered `__main__.py`: each top-level command's registr
| File | Line budget |
|---|---:|
| `packages/flow/openadapt_flow/runtime/replayer.py` | 15119 |
| `packages/flow/openadapt_flow/__main__.py` | 10395 |
| `packages/flow/openadapt_flow/__main__.py` | 10346 |
| `packages/flow/openadapt_flow/qualification/__init__.py` | 4891 |
| `packages/flow/openadapt_flow/ir.py` | 6829 |
| `packages/desktop/openadapt_desktop/dispatch.py` | 6501 |
Expand Down
57 changes: 4 additions & 53 deletions packages/flow/openadapt_flow/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2095,59 +2095,10 @@ def _cmd_tutorial(args: argparse.Namespace) -> int:


def _print_break_it_narrative(broken: "BreakItResult") -> None:
"""Tell the caught-fault story from the halted run's own evidence.
"""Print the caught-fault story; the body lives in ``break_it_narrative``."""
from openadapt_flow.break_it_narrative import print_break_it_narrative

Every fact printed here was read back from the broken run's report or the
fault server's ground-truth store by ``run_tutorial``; nothing is scripted.
"""
claim = (
"every on-screen check passed, including the saved message"
if broken.screen_claimed_success
else "the saved message did not appear"
)
if broken.screen_claim_text:
claim += f'\n (observed on screen: "{broken.screen_claim_text}")'
print("\n--- break-it: the same certified bundle, with the save set to fail ---")
print(f"\n Injected fault: {broken.fault!r} -- the server rejects the write")
print(f" On screen: {claim}")
print(
" The verifier found: "
f"{broken.effects_refuted}/{broken.effects_required} declared effect(s) "
"REFUTED by an independent\n"
" read of the system of record, which holds "
f"{broken.system_of_record_records} record(s)"
)
print(
f" The engine did: {broken.execution_outcome} at the consequential "
"step instead of claiming\n"
f" success (transaction: {broken.transaction_outcome}, "
f"billable: {'yes' if broken.transaction_billable else 'no'})"
)
from openadapt_flow.plain_outcome import plain_result

plain = plain_result(broken.transaction_outcome, broken.execution_outcome)
print(f" Result: {plain.label}. {plain.meaning}")
print(
"\n The screen looked the same as a good save. The record check found "
"no new note,\n so the engine stopped instead of reporting done."
)
print(f"\n Engine's own words: {broken.halt_reason}")
print(
"\nCaught-fault evidence (local report, NOT a success receipt):\n"
f" {broken.report_path}"
)
print(
"\nNo shareable receipt for the halted run: only VERIFIED runs may use "
"the\nsuccess rail. The halt itself is the demonstration."
)
from openadapt_flow.cli_hints import command

print(
"\nSee both runs side by side on one page:\n"
f" {command('demo')}\n"
"\nNext: record your own workflow:\n"
f" {command('record --backend web --url https://your-test-app.example --out my-task')}"
)
print_break_it_narrative(broken)


def _demo_progress() -> Optional[Callable[[str], None]]:
Expand Down Expand Up @@ -2187,7 +2138,7 @@ def _cmd_demo(args: argparse.Namespace) -> int:

Composes the unchanged tutorial path (``run_tutorial(..., break_it=True)``):
the same record, compile, certify, and Standard-profile run, then the same
bundle against the ``optimistic`` fault. Presentation only: the page and
bundle against the ``partial`` fault. Presentation only: the page and
the short summary read each run's ``transaction_outcome`` and artifacts.

Exit codes: 0 when the pair showed the difference (the first run ended
Expand Down
79 changes: 79 additions & 0 deletions packages/flow/openadapt_flow/break_it_narrative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""Print the ``tutorial --break-it`` story from the halted run's own evidence.

``openadapt-flow tutorial --break-it`` reruns the certified bundle against a
save that drops the typed note. This module prints what that run saw on
screen, what reading the record back found, and what the engine did.
"""

from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING: # pragma: no cover
from openadapt_flow.tutorial import BreakItResult


def print_break_it_narrative(broken: BreakItResult) -> None:
"""Tell the caught-fault story from the halted run's own evidence.

Every fact printed here was read back from the broken run's report or the
fault server's ground-truth store by ``run_tutorial``; nothing is scripted.
"""
claim = (
"every on-screen check passed, including the saved message"
if broken.screen_claimed_success
else "the saved message did not appear"
)
if broken.screen_claim_text:
claim += f'\n (observed on screen: "{broken.screen_claim_text}")'
print(
"\n--- break-it: the same certified bundle, with a save that drops the note ---"
)
print(
f"\n Injected fault: {broken.fault!r} -- the app saves the encounter "
"but drops the typed note"
)
print(f" On screen: {claim}")
print(
" The verifier found: "
f"{broken.effects_refuted}/{broken.effects_required} declared effect(s) "
"REFUTED by reading the record\n"
" back: "
f"{broken.system_of_record_records} encounter(s), "
f"{broken.notes_as_typed} with the note as typed"
)
print(
f" The engine did: {broken.execution_outcome} at the consequential "
"step instead of claiming\n"
f" success (transaction: {broken.transaction_outcome}, "
f"billable: {'yes' if broken.transaction_billable else 'no'})"
)
from openadapt_flow.plain_outcome import plain_result

plain = plain_result(broken.transaction_outcome, broken.execution_outcome)
print(f" Result: {plain.label}. {plain.meaning}")
if broken.system_of_record_records and not broken.notes_as_typed:
found = "the encounter with its note blank"
else:
found = "something other than what was typed"
print(
"\n The screen looked the same as a good save. The record read back held"
f"\n {found}, so the engine stopped instead of reporting done."
)
print(f"\n Engine's own words: {broken.halt_reason}")
print(
"\nCaught-fault evidence (local report, NOT a success receipt):\n"
f" {broken.report_path}"
)
print(
"\nNo shareable receipt for the halted run: only VERIFIED runs may use "
"the\nsuccess rail. The halt itself is the demonstration."
)
from openadapt_flow.cli_hints import command

print(
"\nSee both runs side by side on one page:\n"
f" {command('demo')}\n"
"\nNext: record your own workflow:\n"
f" {command('record --backend web --url https://your-test-app.example --out my-task')}"
)
8 changes: 4 additions & 4 deletions packages/flow/openadapt_flow/cli/try_and_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ def register_tutorial(
dest="break_it",
help=(
"After the clean VERIFIED run, rerun the SAME certified bundle "
"against a backend that silently rejects the write AFTER the app "
"paints its success banner -- and watch the engine HALT instead of "
"believing the screen. The halted run's evidence lands in "
"<out>/run-broken/REPORT.md"
"against an app whose save keeps the encounter but drops the typed "
"note while still showing it as saved -- and watch the engine HALT "
"when it reopens the record and finds the note blank. The halted "
"run's evidence lands in <out>/run-broken/REPORT.md"
),
)
p.set_defaults(func=main._cmd_tutorial)
Expand Down
Loading
Loading