Skip to content

feat(quickstart): replace act 3 with a crash and restart of a batch - #2840

Merged
abrichr merged 4 commits into
mainfrom
claude/quickstart-crash-restart
Dec 1, 2026
Merged

abrichr merged 4 commits into
mainfrom
claude/quickstart-crash-restart

Conversation

@abrichr

@abrichr abrichr commented Nov 30, 2026

Copy link
Copy Markdown
Member

Problem

Act 3 of openadapt quickstart on MockMed made one save fail silently (the screen showed its saved message, the database had nothing, and OpenAdapt stopped). We no longer lead with that framing anywhere, and the quickstart is the first command people run at launch.

Change

Act 3 on MockMed is now a crash and a restart, built on the engine's own at-most-once ledger:

  • A batch of two new notes runs in a separate worker process, started during Act 1 so it is ready in time. Each note's run is the tutorial's governed run (Standard run gate, record check against the app's database) with the replayer's IdempotencyLedger attached on disk (<out>/restart/ledger/). The replayer reserves the note's key before its first action and records the outcome after the record check.
  • When note 1's run has returned, the quickstart stops the worker's process group with SIGKILL, before note 2 starts.
  • The batch then runs again in the main process with the same ledger. The replayer finds note 1's key and sends no save for it (idempotent_replay, 0 actions). Note 2 runs and saves.
  • Each note's database is read afterwards and the note is counted there.
  • Every line printed comes from the run reports, the ledger and the databases. A run that goes another way prints what happened, the finale points at the reports instead of the next step, and the command exits 1. If the second process can't start, the act says it was skipped.
  • No change under packages/flow: this composes Flow 4.0.1's public pieces (run gate, Replayer(idempotency_ledger=...), IdempotencyLedger), so it works with the Flow on PyPI.

Limits, stated plainly:

  • Each note has its own copy of the clinic's database, as each run in Act 2 does, not one shared database. The tutorial program's record check matches one logical record per patient (MockMed's fixed demo key), so two different notes can't both be checked in one database.
  • The database count alone would not catch a resend. MockMed de-duplicates saves on that fixed demo key, so a resent note 1 would still read as 1 record. The evidence that no second save was sent is note 1's restart report (idempotent replay, 0 actions). The summary line leads with that, not with the count.

Also:

  • --no-restart replaces --no-break (kept as a hidden alias). --break-it stays hidden; with a current Flow it runs this quickstart. With engine-only flags or a Flow older than the quickstart minimum it still reaches the engine's own tutorial --break-it, unchanged.
  • The banner-specific code is gone from the views and the scene (the "screen-trusting bot" row, the red cross, the stopped run's Seal page and the side-by-side page for MockMed).
  • --app openemr keeps its Act 3 (a referral that matches an existing chart; the program stops before saving). It is not a fake banner. Its code path moved into _break_act in the story, and its plain-view label column is narrower now that the bot row is gone (snapshot updated). Not run in Docker here.
  • Docs: CLI help, README, docs/cli.md, docs/getting-started/quickstart.md, docs/quickstart/README.md, packages/agent/README.md, and a new capability row file. CAPABILITIES.md and llms-full.txt are left for the refresh workflow. Dated terminal captures and timing files are left as they were.

Real run (headless, this checkout, Flow 4.0.1 from PyPI, macOS, fresh key and Seal homes)

stdout below; stderr was empty. Exit code 0.

OpenAdapt quickstart: show a task once, run it, then stop it mid-batch and watch the restart skip what was already saved.
Synthetic data only. Files go to <tmp>/qs4

      [1/4] Loading OpenAdapt runtime
      [2/4] Prewarming OCR engine
      [3/4] Starting browser engine
      [4/4] Starting synthetic clinic app
[1/5] ✓ Clinic app ready · synthetic data, on this computer
[2/5] Show it once · a demonstration in a synthetic clinic app, in a hidden browser
      ✓ Click Open                               0.4s
      ✓ Click New Encounter                      0.7s
      ✓ Click Triage                             1.0s
      ✓ Click Note                               1.4s
      ✓ Type "Synthetic follow-up in two weeks"  1.8s
      ✓ Click Save Encounter                     2.1s
[3/5] ✓ Turn it into a program · 6 steps, local-quickstart  5.4s
[4/5] Run it on a new note
      1/1  Follow-up in two weeks             ✓ checked in the database  3.7s
      1 of 1 saved and checked · 0 AI calls · $0.00 · 3.7s

✓ Saved and checked
  The record, read back from the database:
    ✓ patient_id  p1
    ✓ type        Triage
    ✓ source      replay
    ✓ key         mockmed-triage-p1-v1
    ✓ note        "Follow-up in two weeks"
  1 of 1 run · 0 model calls · $0.00 · 3.7s

[5/5] Stop it mid-batch, then restart
      A batch of 2 new notes, each in its own copy of the clinic's database. The runner process is stopped hard after note 1 saves, then started again.
      1/2  Refer to physical therapy          ✓ checked in the database  3.9s
      ■ Runner process stopped with SIGKILL after note 1, before note 2
      Restarted with the same ledger:
      1/2  Refer to physical therapy          · Skipped: the ledger has it as done, no save sent  0.3s
      2/2  Repeat labs before next visit      ✓ checked in the database  3.6s
      The database: each note saved once (note 1: 1 record, note 2: 1 record)
      Why: OpenAdapt records each note in a ledger on disk before it saves it, and records the outcome after the record check. On restart it found note 1 marked done, so it sent no save for note 1 and saved only note 2.

The runner was killed partway through the batch. On restart, OpenAdapt sent no save for note 1 and saved note 2.

Your receipt: Saved and checked
  6 of 6 steps · 2 of 2 record checks · 0 model calls
  ed25519 over report sha256 5af7a796e433
  Signed by this computer
  key seal-ed25519-5211b4c2a79ea2cd · 1 report signed
  Open it: <tmp>/qs4/run-1/seal.html
    checks the signature in your browser, offline; nothing is uploaded
  Real receipts from OpenEMR runs: https://openadapt.ai/seals

Next: Give your agent this task as a tool
  claude mcp add openadapt -- openadapt agent serve --allow-run
  Any other MCP client: openadapt agent serve --allow-run
  Your own app: openadapt record --backend web --url https://your-app.example --out my-task
  Playwright/CUA drop-in: with checked_write("verify.yaml", values): ...  # from openadapt_verify
More next steps: openadapt quickstart --more
Done in 38.2s. Reports: <tmp>/qs4, one REPORT.md per run
The receipt pages in <tmp>/qs4 are unencrypted: each embeds its run's report (synthetic data only)
Created a local encryption key at <tmp>/home4/at-rest/keys/at-rest.key, <tmp>/home4/at-rest/keys/device-software.key; back it up: what it encrypts can't be read without it

No browser or driver process from the run was left afterwards.

Tests and gates

  • Root tests/ (repo .venv, Flow 4.0.1, via the shared CPU-slot runner): 3493 passed, 32 skipped, 31 xfailed.
  • OPENADAPT_REAL_QUICKSTART=1 pytest tests/test_quickstart.py::test_real_quickstart (real browser, fresh at-rest home; asserts the restart held, note 1 skipped with 0 actions, and the restart/note-1 folder is encrypted): passed.
  • New tests/test_quickstart_restart.py: the restart reuses the ledger after the kill, a duplicate isn't reported as held, a missing worker skips the act, and a real spawned worker is stopped with SIGKILL.
  • ruff check openadapt tests scripts and ruff format --check openadapt/: clean.
  • mypy on the touched quickstart modules: 2 errors, both in view.py's _draw_screenshot, which this PR doesn't change (also on main).
  • scripts/check_file_size_ratchet.py --base origin/main: passes. scripts/build_capabilities.py --check-pr origin/main and --guard: pass. There is no check_verdict_folds.py in this repo.
  • End-to-end time: 25.8 s to 38.2 s over five headless runs on this Mac at load average 10 to 20; the help text now says about 30 seconds.
  • Not run: --watch (no headed browser on this Mac), Linux, Windows, --app openemr, Flow from packages/flow source.

Act 3 on MockMed no longer makes a save fail silently. It runs a batch of
two notes in a worker process, stops it with SIGKILL after note 1 is saved
and checked, and restarts the batch with the same on-disk IdempotencyLedger.
The replayer sends no save for note 1 and saves note 2; each note's
database is read afterwards. --no-restart replaces --no-break (kept hidden).
OpenEMR's Act 3 is unchanged.
MockMed drops a save whose key it already holds, so one record per note
can't rule out a resend. The database line now credits 'saved once' only
when the restart report shows note 1 skipped with no actions and a
VERIFIED ledger outcome. A worker that doesn't finish note 1 is reported
as not finishing, not as stopping early (a timeout leaves it running).
Review findings 1, 2 and 5 on #2840.
@abrichr
abrichr enabled auto-merge November 30, 2026 21:52
Read settled outcomes through one helper (says_verified) instead of four
literal comparisons, narrow the optional REPORT.md handler, report a worker
failure with contextlib.suppress and exit it cleanly, and update the agent
README test to the new plain quickstart command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant