Skip to content

refactor(generality): ratchet engine baseline 199 -> 7 and guard all 4 core packages - #2537

Merged
abrichr merged 3 commits into
mainfrom
gemini/generality-baseline-zero
Nov 22, 2026
Merged

abrichr merged 3 commits into
mainfrom
gemini/generality-baseline-zero

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member

Summary

Burns down the openadapt_flow/ engine-generality baseline from 199 -> 7 (-192 hits, 96.5% reduction) and extends scripts/check_engine_generality.py to guard all 4 core packages (packages/flow, packages/types, packages/desktop, packages/capture) against app-specific leaks:

  • Reward demo seed relocation (reward/seed.py -> mockmed/reward_seed.py, -34 hits):
    • Moved the MockMed demo reward seed (seed_mockmed, MOCKMED_*) out of openadapt_flow/reward/ into openadapt_flow/mockmed/reward_seed.py (preserving git rename history) and updated the 3 internal callers (tutorial.py, test_reward_worker.py, test_reward_trust_boundary.py).
  • Demo app allowlist & CLI delegation (generality.toml, tutorial.py, __main__.py, -62 hits):
    • Added OpenAdapt's own non-healthcare synthetic demo app mockloan/ to generality.toml [allow.terms_in] alongside mockmed/.
    • Delegated __main__.py's bundled demo server/seeding imports through tutorial.py (serve_demo_app, demo_execute_admissions, seed_demo_reward) and reworded demo help/docstrings, leaving only the 6 --seed-mockmed CLI flag compatibility lines in __main__.py and the 1 explicitly documented legacy hash shim (LEGACY_HASHED_DEFAULTS in deployment.py).
  • Domain-neutral core modules (runtime/effects/*, compiler/*, backends/*, validation/dense_surface.py, generate/*, jit/*, risk.py, volatility.py, etc. — -96 hits):
    • Eliminated all remaining app/vendor names from core engine docstrings, comments, and dense_surface.py's synthetic table header (0 hits across all 45+ engine modules outside __main__.py and deployment.py).
  • 4-package generality guard (scripts/check_engine_generality.py, packages/desktop/openadapt_desktop/{cli.py,targets.py}):
    • Cleaned the 2 remaining MockMed references in packages/desktop/openadapt_desktop/.
    • Added scan_core_packages() to check_engine_generality.py enforcing 0 allowed hits for openemr, medplum, mockmed, stedi, and openimis across packages/types/openadapt_types, packages/desktop/openadapt_desktop, and packages/capture/openadapt_capture (with unit tests in tests/test_engine_generality_check.py).

Generality Gate

  1. No per-app code in the engine: Yes — openadapt_flow/ is down to 7 compatibility-only baseline hits (6 --seed-mockmed CLI flag lines in __main__.py + 1 legacy hash-compat shim in deployment.py), and packages/types, packages/desktop, and packages/capture are all at 0 hits.
  2. Fix the class, not the instance: Yes — check_engine_generality.py now guards all 4 core packages (flow, types, desktop, capture) in CI so app-specific references cannot creep back into any core package.
  3. Held-out evidence: Demonstrated via test_core_packages_guard_catches_app_names and test_monorepo_core_packages_have_zero_app_leaks against synthetic leaks in types, desktop, and capture, plus the real monorepo tree. No live external-app replay was needed for this static/structural cleanup.

Verification

  • python3 scripts/check_engine_generality.py -> Engine generality OK (7 baseline hits left) (down from 199)
  • python3 scripts/check_file_size_ratchet.py -> PASS (__main__.py: 14317 <= 14331, ir.py: 6822 <= 6830)
  • python3 scripts/check_release_consistency.py -> Release version 3.4.0 is synchronized across project, module, and lock.
  • ruff format --check -> 55 modified Python files formatted cleanly
  • mypy (mockmed/reward_seed.py, reward/bundle.py, tutorial.py, validation/dense_surface.py) -> Success: no issues found in 4 source files
  • pytest (7 targeted suites: test_engine_generality_check, test_reward_worker, test_reward_trust_boundary, test_execute_ref, test_policy, test_probe_induction, test_undo_proposal) -> 180 passed, 0 failed

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 074c61a

Cross-vendor review of this Gemini-authored PR. I did not write these changes. One commit versus current main; 58 files, +277/−343.

What landed

  • Flow engine baseline generality_baseline.json goes 199 → 7. The remaining hits are the six --seed-mockmed / seed_mockmed / --seed-mockmed help/flag lines in packages/flow/openadapt_flow/__main__.py and one legacy shim: LEGACY_HASHED_DEFAULTS["records_path"] = "/api/db" in deployment.py (the mockmed-records identifier).
  • App-specific reward seeding moves from openadapt_flow/reward/seed.py to openadapt_flow/mockmed/reward_seed.py. __main__ and demo serve paths reach it through tutorial.serve_demo_app, tutorial.demo_execute_admissions, and tutorial.seed_demo_reward wrappers (same underlying mockmed.server.serve / seed functions). Replay still requires --demo-app (or a URL); that default is unchanged.
  • Comment and identifier generalization across compiler, effects (fhir/sql/frame/effect), desktop CLI help, and related tests. I did not find logic changes in those hunks.
  • check_engine_generality.py gains scan_core_packages() over types, desktop, and capture with zero allowed hits. New hits and core violations both fail CI, including --update-baseline. packages.yml still runs the script. Tests cover synthetic leaks in all three sibling packages (including skipping # example: lines) and assert the monorepo checkout is clean for the scanned terms.
  • generality.toml adds an allow.terms_in entry for the existing mockloan/ demo (comparison comments plus the mockloan name). That is the same class of allow as mockmed/.

No CI or safety weakening. No new per-app logic in the engine path.

Residuals (not blockers of this PR's own content)

  • CORE_PACKAGE_APP_TERMS is a five-term subset (openemr, medplum, mockmed, stedi, openimis) of the flow denylist. types/desktop/capture are clean of real app coupling; the only extra hit under the full name list is a cerner negative lookahead inside packages/types/openadapt_types/vocabulary/vocabulary.json. A follow-up should scan every configured term (with a precise allow for that vocabulary pattern) so a future epic/odoo/gitea leak in those packages would fail CI.
  • The fhir.py module docstring now mentions FHIR_BASE_URL, but live tests still gate on OPENEMR_FHIR_BASE_URL, and the verifier itself takes base_url as a constructor argument and reads neither env var. Docs-only mismatch.

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: 5a1e1d4

Delta confirmation versus my APPROVE at 074c61afa (#2537 (comment)). I did not write these changes.

First-parent delta is two commits:

  1. Merge e75fe4411 of origin/main 87fda5968 (Merge fix(flow): close fail-open follow-ups from the receipts stack #2529, which already includes fix: restore green main #2533) into 074c61afa. Incoming files are the main-side fix(flow): close fail-open follow-ups from the receipts stack #2529 / fix: restore green main #2533 / txplan changes. There is no overlap with this PR's unique tree. Unique-versus-new-main after the merge is the same 58-file, +277/−343 set as at the approved head.

  2. 5a1e1d43a (test(e2e): update CLI smoke assertion to 'bundled demo app'): one assertion in packages/flow/tests/e2e/test_record_compile_replay.py changes 'bundled MockMed' to 'bundled demo app', matching the already-approved __main__.py wording.

No unique behavioral change, no CI/safety weakening, no new engine app-name hits. I did not re-litigate the previously approved unique body (including the earlier five-term CORE_PACKAGE_APP_TERMS residual, which is unchanged).

No merge from this review.

@abrichr
abrichr merged commit c71d463 into main Nov 22, 2026
65 of 66 checks passed
@abrichr
abrichr deleted the gemini/generality-baseline-zero branch November 22, 2026 15:54
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