Skip to content

feat(flow): add domain-agnostic openadapt onboard pack synthesis and planted-fault qualification loop - #2538

Open
abrichr wants to merge 7 commits into
mainfrom
gemini/onboard-loop-v1
Open

abrichr wants to merge 7 commits into
mainfrom
gemini/onboard-loop-v1

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member

Summary

Adds a single-command, completely domain-agnostic pack onboarding and planted-fault qualification loop (openadapt onboard / openadapt setup onboard) under packages/flow/openadapt_flow/onboard/, keeping __main__.py under its 14,331-line ratchet (14,314 lines via 1-line registration).

Changes

  • packages/flow/openadapt_flow/onboard/ (types.py, engine.py, cli.py, __init__.py):
    • OnboardSpec / KindOnboardingSpec: declarative, zero-per-app specification of read-back config, tables, required/optional/identity/change fields, invariant pins, bookkeeping columns, SQL filter params, and demonstrated field sets (all SQL identifiers validated fail-closed).
    • synthesize_pack(): introspects full table columns from SQLite (preventing unprojected-column sibling-edit blind spots), generates standard openadapt.verify/v1 create/update/found contracts and manifest.yaml (compatible with #2490 compositional field-set synthesis and #2489 null-safe SQL equality binding), validates every query via assert_read_only_sql, and computes a deterministic SHA-256 pack_digest.
    • qualify_pack() & onboard_pack():
      • Runs a deterministic planted-fault mutation suite against isolated sandbox copies of the target DB covering all 6 classes (wrong_value, null_vs_value, missing_write, duplicate_row, sibling_edit, wrong_target) through the real verify_contract.choose -> begin_write -> verify_write pipeline, refusing certification unless 100% of planted faults are caught (0% pass).
      • Runs clean-write verification (including novel composed field unions/subsets and explicit None fields), emits signed record/run/v1 DSSE receipt.json envelopes via receipt_record.write_receipt_record, and writes a structured QUALIFICATION.json report (QualificationResult).
    • cli.py: registers onboard (allow_abbrev=False) with --spec, --out, --json, and --dry-run (exits 0 only on certified pack or dry-run synthesis; exits 2 on refusal).
  • CLI parity: 1-line registration in packages/flow/openadapt_flow/__main__.py and "onboard": "setup onboard" in both packages/flow/openadapt_flow/cli_tasks.py and openadapt/cli_tasks.py.
  • packages/flow/tests/test_onboard_loop.py: end-to-end tests on 2 completely unseen non-healthcare SQLite+REST systems of record (zero engine code referencing either app):
    • Fixture A (ERP / Inventory SQLite+REST — orders): 20/20 planted faults caught (100%, 0% false receipts), 4/4 clean writes verified (0.0% false-stop rate, 3/4 via #2490 compositional synthesis), 4/4 signed record/run/v1 DSSE receipts issued & verified.
    • Fixture B (ITSM / Ticketing SQLite+REST — tickets): 20/20 planted faults caught (100%, 0% false receipts), 4/4 clean writes verified (0.0% false-stop rate, 2/4 via #2490 compositional synthesis + #2489 null-safe SQL filter verification), 4/4 signed record/run/v1 DSSE receipts issued & verified.
    • Plus unreadable-DB fail-closed refusal and end-to-end CLI (onboard + setup onboard + --dry-run) tests.

Generality Gate

  1. No per-app code in the engine: Yes — openadapt_flow/onboard/ contains zero app names or domain branches (check_engine_generality.py passes with 0 new hits).
  2. Fix the class, not the instance: Yes — provides one general declarative onboarding + planted-fault qualification loop over any SQL-backed system of record, refusing certification if any planted fault escapes.
  3. Held-out evidence: Demonstrated on two synthetic, non-healthcare SQLite+REST test fixtures (ERP/Inventory and ITSM/Ticketing) not referenced by the engine. Not yet run against live external SaaS instances.

Verification

  • PYTHONPATH=packages/types uv run --directory packages/flow pytest tests/test_onboard_loop.py -v — 4 passed
  • PYTHONPATH=.:packages/types uv run --directory packages/flow pytest tests/test_cli_tasks.py tests/test_cli_no_abbreviations.py -q — 62 passed
  • PYTHONPATH=.:packages/flow:packages/types pytest tests/test_cli_tasks.py -q — 139 passed
  • python3 scripts/check_file_size_ratchet.py — OK (__main__.py 14,314 / 14,331)
  • python3 packages/flow/scripts/check_engine_generality.py — OK (199 baseline hits left)
  • python3 packages/flow/scripts/check_release_consistency.py — OK
  • ruff check, ruff format --check, mypy — 0 issues

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 24bad3c

Cross-vendor review of this Gemini-authored PR. I did not write these changes. Unique tree versus current main: eight files, 1842 insertions (openadapt_flow/onboard/{__init__,cli,engine,types}.py, tests/test_onboard_loop.py, and one-line onboard / setup onboard hooks in __main__.py and the two cli_tasks.py maps).

The library path is in good shape on the points I checked: declarative OnboardSpec with identifier-safe SQL (^[A-Za-z_][A-Za-z0-9_]*$ plus assert_read_only_sql and bound :params), isolated TemporaryDirectory SQLite sandboxes for planted faults, caught = res.outcome is not Outcome.CONFIRMED, fail-closed except Exception on clean writes, dry-run explicitly uncertified, missing sqlite_database refused, no per-app names in the new engine module, and the two synthetic fixtures (ERP / ITSM) with clean_cases do catch the planted faults and issue signed record/run/v1 DSSE receipts. I am not blocking on those.

Blockers

  1. CLI certification is vacuous on clean writes and receipts. qualify_pack sets certified when faults_total > 0 and faults_caught == faults_total and clean_verified == clean_total and not refusal_reasons. With the default clean_cases=(), that is 0 == 0. _cmd_onboard calls onboard_pack(spec, out_dir) and never accepts clean-write cases, so openadapt onboard / setup onboard can print CERTIFIED with clean_writes=0/0 and receipts_issued=0. test_onboard_cli_end_to_end_and_dry_run asserts exactly that (full_out["certified"] is True) and does not check receipts. That does not match the claimed single-command loop (refuse unless planted faults are caught and verified clean writes get signed receipts). Require clean_writes_total > 0 (and receipts for each verified write) before certified=True, and either give the CLI a way to supply clean writes or stop advertising certification on the CLI-only path.

  2. Two of the six advertised fault classes can be skipped without refusing certification. sibling_edit is planted only when the source DB already has a row; wrong_target (and update-mode sibling_edit) only when another row exists. Those outcomes are simply omitted from fault_outcomes, and faults_caught == faults_total still holds. A sparse or empty system of record can certify without those classes ever running. Certification should refuse, or at least record a hard skip, when a required class was not planted.

Residuals (not additional blockers)

  • Planted-fault sandbox is SQLite-only (spec.read["sqlite_database"]); other SQL read configs are not exercised here (disclosed by the fixtures).
  • _sqlite_insert / _sqlite_update interpolate column names from row keys; keys from the spec are identifier-validated, PRAGMA names are not re-checked.
  • Spaced/quoted SQL table names are out of scope (_SAFE_IDENT).
  • Held-out live external SaaS is not in this PR (disclosed).

No merge from this review.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 74cb5ce

Round-2 delta confirmation versus my REQUEST CHANGES at 24bad3c88 (#2538 (comment)). I did not write these changes. Single follow-up commit 74cb5cea5 on the previous head (3 files, +224/−8).

Prior findings

  1. Vacuous CLI certification — fixed. qualify_pack now refuses when clean_writes_total == 0, and certified also requires clean_total > 0, clean_verified == clean_total, and len(receipt_paths) == clean_verified. The CLI gained --clean-writes PATH (YAML/JSON list with an HTTP target) and passes those cases into onboard_pack. test_onboard_cli_end_to_end_and_dry_run now asserts that openadapt onboard without --clean-writes returns exit 2, certified is False, and a "no clean writes" refusal; with --clean-writes it certifies, clean_writes=1/1, and the issued path is a signed record/run/v1 DSSE receipt.

  2. Skipped mandatory fault classes — fixed. After planting, qualify_pack requires every kind to have actually run its required classes (create: wrong_value, null_vs_value, missing_write, duplicate_row, sibling_edit; update: wrong_value, null_vs_value, missing_write, wrong_target, sibling_edit). Missing classes are refusal reasons, so certified cannot be true. test_onboard_refuses_certification_when_required_fault_class_unplanted covers an empty table that cannot plant sibling_edit and asserts refusal.

The PRAGMA/column identifier residual is also closed: _sqlite_table_columns, _sqlite_insert, and _sqlite_update re-validate table and column names with _validate_ident before interpolating them.

I did not re-litigate the previously accepted library path (sandbox faults, identifier-safe contract SQL, fixture receipts). No merge from this review.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 0f34643

Review only. I am not merging this PR. This is a delta stamp versus my APPROVE at 74cb5cea573273ef399eff65e967912f74bf7d04 (#2538 (comment)).

Since that head the unique work is CI/main-sync, not a change to the onboarding certification logic:

  • f926cc13b lazy-loads openadapt_flow.onboard.engine from onboard/__init__.py (__getattr__) and onboard/cli.py (inside _cmd_onboard) so build_parser() does not import the engine, and registers the onboard line in CAPABILITIES.md / llms-full.txt.
  • 6698aed4c folds the adjacent register(sub) calls in __main__.py into one import loop (including onboard.cli), bringing __main__.py to 14,233 lines under the 14,237 ratchet budget, and refreshes llms-full.txt.
  • 0f3464347 merges current main (including fix(connector): forward stop_requested parameter from run_loop to _run_loop #2544).

onboard/engine.py and tests/test_onboard_loop.py are unchanged since my last APPROVE. Both previously requested blockers remain in force: qualify_pack still refuses certification when clean_total == 0 or receipts do not match verified clean writes, and it still refuses when a mandatory fault class (sibling_edit, wrong_target, …) was not planted. _validate_ident is still applied to SQLite table and column names. The tests for vacuous CLI certification and unplanted sibling_edit are still present.

I approve this head. I am not merging it.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: d40f574

Review only. I am not merging this PR. This is a delta stamp versus my APPROVE at 0f3464347eed730e33a18f82afa8c78bb3a90f9f (#2538 (comment)).

The only new commit is d40f57476 (style(flow): run ruff format on __main__.py). The unique diff versus that head is wrapping the register(sub) module-name tuple in packages/flow/openadapt_flow/__main__.py onto one name per line. The import loop, the lazy-loaded onboard engine, and the certification logic are unchanged.

__main__.py is 14,239 lines here versus 14,241 on current main (e0b6084e2); this change still shrinks the file relative to the base, so the --base origin/main ratchet correctly passes even though both this head and main sit slightly above the 14,237 row still listed in DECOMPOSITION.md. That stale row is a follow-up, not a blocker of this format delta.

Both previously requested certification blockers remain in force, as at the prior head. I approve this head. I am not merging it.

This branch has not been deployed

No deployments
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