Skip to content

refactor(flow): generalize Execute seeding, reward bundles, and identity chrome - #2486

Merged
abrichr merged 7 commits into
mainfrom
gemini/core-generality-strip-1
Nov 22, 2026
Merged

abrichr merged 7 commits into
mainfrom
gemini/core-generality-strip-1

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

Summary

Burns down 53 engine-generality baseline hits in openadapt_flow/ (301 -> 248) by removing MockMed and healthcare/app-specific coupling from core engine modules:

  • Execute service & dispatch (execute/registry.py, service.py, app.py, dispatch.py — 37 hits -> 0):
    • Replaced seed_mockmed: bool with caller-supplied seed_admissions: Iterable[AdmittedBundle] in ExecuteService, create_app, serve, and seed_admissions() in execute/registry.py.
    • Moved MockMed demo seed constants and helpers out of execute/registry.py into openadapt_flow/mockmed/execute_seed.py; --seed-mockmed in __main__.py now passes demo_admissions() as data.
    • Renamed synthetic_mockmed -> synthetic_runner with domain-neutral evidence tags (synthetic-verified / synthetic-banner-lie).
    • Generalized live_replay so any bundle with an explicit deployment config (including web bundles) runs through _surface_replay; demo fallback delegates to tutorial.run_demo_workflow_replay.
  • Reward bundle builder (reward/bundle.py — 3 hits -> 0):
    • Replaced MockMed-named defaults (SYNTHETIC_TASK_ID, SYNTHETIC_ENVIRONMENT_ID, DEFAULT_CERTIFICATE_ID) with domain-neutral defaults and explicit task_id / environment_id / certificate_id parameters; reward/seed.py passes its demo IDs explicitly.
  • Identity row chrome (runtime/identity.py — 1 hit -> 0 + D14 fix):
    • Stripped EMR/MockMed vocabulary (patient, chart, charts, discharged, admitted, appointment, demo) from _GENERIC_IDENTITY_WORDS, keeping only domain-neutral status/UI words.
    • Added derive_sibling_chrome_words(rows, min_fraction=0.5) to derive repeated non-identifying row chrome from sibling rows across any domain.
  • Core engine docstrings/metadata (report_redaction.py, runtime/actuators/web_form.py, ensure_record.py, rollback_state.py, compile_agent/code_action.py, ir.py — 12 hits -> 0):
    • Replaced app-specific identifier and vendor references with domain-neutral descriptions.
  • Baseline ratchet (scripts/generality_baseline.json):
    • Lowered strictly downward from 301 to 248 hits via python3 scripts/check_engine_generality.py --update-baseline.

Generality Gate

  1. No per-app code in the engine: Yes — execute/, reward/bundle.py, runtime/identity.py, runtime/actuators/web_form.py, report_redaction.py, ensure_record.py, rollback_state.py, compile_agent/code_action.py, and ir.py now have zero app-specific hits under scripts/check_engine_generality.py. Demo seed data lives in mockmed/execute_seed.py and reward/seed.py and is passed into the engine as data.
  2. Fix the class, not the instance: Yes — replaced app-specific seeding booleans (seed_mockmed) with data-driven seed_admissions across registry.py/service.py/app.py, parameterized write_bundle IDs across reward/bundle.py, and added data-driven derive_sibling_chrome_words() instead of hand-maintained domain word lists.
  3. Held-out evidence: Demonstrated with non-healthcare unit tests (test_generic_seed_admissions_writes_non_demo_bundle with an ERP invoice admission and TestSiblingChromeDerivation.test_derive_sibling_chrome_words_across_domains on ERP invoice rows). Live multi-app replay on held-out web targets has not yet been re-run for this PR.

Verification

  • python3 scripts/check_engine_generality.py -> Engine generality OK (248 baseline hits left) (down from 301)
  • python3 scripts/check_release_consistency.py -> Release version 3.4.0 is synchronized across project, module, and lock.
  • ruff check & ruff format --check -> clean across all modified files
  • mypy -> Success: no issues found in 12 source files
  • pytest (12 targeted test suites: test_execute_ref, test_execute_post_dispatch_faults, test_execute_dispatch_mapping, test_jit_draft_execution, test_backend_parity_refusals, test_reward_worker, test_reward_trust_boundary, test_identity, test_identity_evidence, test_report_redaction, test_probe_induction, test_undo_proposal) -> 940 passed, 0 failed

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 8923548

  1. P1. Shared headings can now verify record identity. I ran the same synthetic heading-only band through verify_target_identity on the parent and this head. The parent returned abstain. This head returned verified. Removing the previous exclusions makes shared headings count as names. The new sibling-row helper is tested directly, but the verifier never calls it. Carry the shared-word evidence into plain and template verification and preserve abstention when sibling evidence is unavailable. Add an end-to-end regression for a heading shared by separate records. Identity rule · Template token classification
  2. P1. A non-synthetic admission can receive a verified receipt without executing a bundle. The new seed API accepts ordinary admissions. Their defaults are synthetic=False and bundle_dir=None. The existing no-directory fallback sends that combination to the synthetic runner, which can return VERIFIED at independent-system-of-record strength. The service records those assertions with the request’s qualification and environment in a self-signed receipt. Restrict the synthetic runner to explicit synthetic admissions and refuse a missing bundle before effects. Cover the new seed-to-dispatch path. Admission defaults · Runner selection · Receipt construction
  3. P2. A worker-wide desktop configuration now rejects existing web admissions. A web admission without its own deployment now inherits the worker’s desktop backend and fails the surface check. The CLI documents the worker default for off-web bundles. Preserve the existing web tutorial path when a desktop default is present, while continuing to reject an explicitly mismatched admission deployment. Dispatch selection · Surface check · CLI contract
  4. P2. The generic reward writer still chooses clinical effects and identity keys. Its new neutral IDs can label a contract that implicitly requires Triage, forbids Discharge and selects patient_id. Both demo seeds still depend on these inherited defaults. Pass the demo’s effects and keys from the seed and make the generic writer require an explicit contract or use documented domain-neutral semantics. Preserve the demo contract digests. Reward defaults · Demo callers

The Execute and reward findings come from source review. The identity result comes from a local synthetic verifier check. The submitted ERP test exercises the helper in isolation. The reduction from 301 to 248 counts scanner matches and does not establish runtime behavior.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 910f4a9

The template writer and reader disagree on sibling-derived headings. With a synthetic band containing a distinct record name, shared invoice headings and a date, plaintext verification returned verified for the matching record and mismatch for a different record. The salted template returned abstain for both. Holding the matching band and salt fixed, adding sibling rows marked two tokens as labels outside the static label set. That changed _punctuation_metadata_complete from true to false, so verification exited before checking the record. The heading-only template test passes through that same early exit. Make the writer and reader agree on how to validate derived roles while retaining the checks on malformed templates. Cover both the matching distinct record and the heading-only case. Writer · Metadata validation

The standard compiler and replay still omit sibling evidence. The principal template builder call and the plaintext replay call both use the empty default. The synthetic ERP heading-only band abstained in both public verifiers when supplied sibling rows and verified in both when those rows were omitted. Connect available sibling evidence at the ordinary caller, or describe this as an opt-in API and narrow the runtime claim. The restored vocabulary does preserve abstention on the original heading-only regression without sibling data. Compiler · Replay

The other three findings are resolved in source. A non-synthetic admission without a bundle now fails before effects. A desktop worker default preserves the existing web tutorial route, while an explicit admission deployment still gets its surface check. Both reward demo tiers now pass their clinical effects, identity keys and IDs explicitly. Dispatch · Mixed-worker routing · Reward seed

I ran the identity controls against the exact-head implementation and data models. The Execute and reward conclusions come from their changed source, callers and test assertions.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 38a0a1c

P2. An existing template can change verdict even when no sibling evidence is supplied. I compiled a synthetic matching band with a lowercase entity name and a date on the previous head and this head using the same salt and default arguments. The serialized templates were byte-identical and passed metadata validation in both revisions. Replaying that stored template returned verified on the parent and abstain on this head. The plaintext verifier still returned verified. Capitalizing the same name restored agreement.

The changed template reader uses bearing is not False to decide whether a token can count as name evidence. Lowercase names already had bearing=False for the coverage calculation. The plaintext verifier distinguishes name evidence from coverage. Preserve that distinction for existing templates and represent sibling-derived exclusions separately. Add the lowercase default case alongside the opt-in controls. Template reader · Name evidence · Coverage rule

The previous opt-in blocker is closed. With sibling rows supplied, both exact-head verifiers verified the matching distinct record, reported a mismatch for the other record and abstained on shared headings alone. In all three cases the template passed metadata validation. The opt-in API scope is documented. The three earlier Execute and reward findings remain resolved. Scope · Exact-head CI

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 7d7a5b6

The new reader resolves the previous lowercase-name finding in source. A stored template without sibling_generic_hashes gets an empty exclusion list. Name evidence now uses the explicit sibling hashes, and the ordinary bearing=False coverage flag no longer disqualifies the name. Reader

P2. Empty sibling metadata changes serialized templates on supported Pydantic versions. Flow declares Pydantic ≥2.5. In 2.11.2, Field accepts exclude_if through its extra-keyword path and stores the keyword in JSON Schema metadata. It does not use it to exclude values during serialization. The existing IdentityTemplate._serialize_compatible documents this compatibility issue and removes other empty fields itself. It leaves the new field in the result, so an ordinary template can acquire "sibling_generic_hashes":[] when serialized again. Remove the empty key in the existing wrap serializer and retain populated hashes. This keeps legacy sealed bytes stable at the declared dependency floor. I inspected the model and the 2.11.2 implementation. I did not execute a new serialization test on this head. Field and wrap serializer · Pydantic 2.11.2 field handling

CI also blocks this head. The smoke job stopped at the file-size check before installing packages. It measured 6,838 lines in ir.py against a budget of 6,830. Keep the model declaration and serializer repair within the existing budget. Failed job

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: af83040

The file-size finding is resolved. I counted 6,822 lines in ir.py against the 6,830-line budget. The only commit since the previous review shortened field declarations and descriptions. Exact delta

The legacy serialization finding remains. On supported Pydantic 2.11.2, Field(exclude_if=...) is treated as schema metadata. The wrap serializer still returns an empty sibling_generic_hashes list when an older template is loaded and serialized, changing the bytes used for its digest. Remove that key in the wrap serializer when empty and retain it when populated. I verified the source delta. I did not repeat the runtime checks. Field declaration · Wrap serializer · Pydantic 2.11.2

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 5c567b8

Delta versus the prior Codex REQUEST CHANGES at af83040a (7070841118), plus the conflict hunks from merging main 53a9bba6. I reviewed those unique changes, not the already-merged main trees.

The remaining serialization finding is addressed. Field(exclude_if=...) is gone from sibling_generic_hashes. The wrap serializer now pops that key when the list is empty and leaves it when populated, which is supported on the package's Pydantic >=2.5 floor. test_identity.py asserts the empty key is absent from model_dump(). I did not find a dedicated assertion that a populated list is retained; the wrap serializer clearly does so, and I am not treating the missing positive test as a blocker.

The serve-execute conflict resolution is behavior-equivalent: __main__._cmd_serve_execute delegates to run_serve_execute in execute/app.py, which still builds ExecuteService with the resolved data dir, token, seed admissions, and deployment, prints the same banner fields, and calls serve. The generality baseline is 199. __main__.py mockmed hits went 42→41 because the banner and MockMed wording left that file; execute/app.py has no remaining counted token, which matches dropping its prior baseline entry after #2488 already removed the eligibility rows on main. File-size ratchet still holds: ir.py is 6,822 lines against the 6,830 budget, and __main__.py is 14,320 against 14,331.

This source review traced the wrap serializer, the conflict hunks, and the ratchet/baseline numbers. I did not rerun suites or the generality script.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 113e9b3

Delta versus my prior APPROVE at 5c567b81 (7071485741). This head is a clean GitHub "Update branch" merge: parents are the approved first parent 5c567b81 and main 7ea502b7 (the #2496 merge I already approved at a0c67d62). The combined merge diff is empty, so there were no conflict resolutions. The unique-versus-main patch is byte-identical to the approved tree, including the wrap serializer that omits empty sibling_generic_hashes.

I reviewed only this merge delta, not the already-reviewed unique work or the already-merged main trees. I did not rerun CI.

@abrichr
abrichr merged commit 2f506d6 into main Nov 22, 2026
53 of 54 checks passed
@abrichr
abrichr deleted the gemini/core-generality-strip-1 branch November 22, 2026 03:11
abrichr added a commit that referenced this pull request Nov 22, 2026
- The Flow 3.5.0 notes use the openadapt-flow spellings. The launcher's
  hooks, proxy, plan, handoff and flight commands are on main, not in
  launcher 1.23.0. The breaking-changes list now names every rename in
  #2486 and says openadapt-eligibility is not on PyPI yet.
- The openadapt-types 0.24.1 notes say the reward contract digest changes
  for every contract.
- CAPABILITIES.md marks the handoff list, follow-up receipt and plan rows as
  shipping too, and names the spelling that works on PyPI.
- The floor check tells a missing tag from an unanswered query: it asks
  origin with ls-remote and fails closed when it can't, or when fetching
  a tag origin has fails.
abrichr added a commit that referenced this pull request Nov 22, 2026
…ypes 0.24.1

Flow's removals (openadapt_flow.eligibility) and renames (#2486) are
breaking, so this is Flow 4.0.0, not 3.5.0. The notes gain an "Upgrading
from 3.x" section with the eligibility install and import change, the
seed_admissions replacement for seed_mockmed, the synthetic_runner rename
and the new reward bundle default ids. An identity-words change the PR
description named never reached main, so it is not listed.

openadapt-agent 2.3.0 widens its Flow requirement to <5. The launcher
requires openadapt-agent<3, and agent 2.2.2 caps Flow below 4, so without
it `pip install openadapt` could not resolve Flow 4.0.0. Its version moves
in pyproject, manifest.json, server.json and openadapt_flow.agent, which
the agent shim reports. The eligibility connector now requires Flow 4.

openadapt-types 0.24.1 keeps every 0.24.0 digest. escalated_after_effect_reward
enters RewardContractV1.digest only when it differs from its default, and
the pinned contract digest is back to its 0.24.0 value. A fixture of
contracts and certificates issued by openadapt-types 0.24.0 from PyPI
checks that they hash and verify unchanged. A 0.24.0 contract with
verified_reward of 0.5 or less still loads: left at the default, an
escalation then earns no credit, so asking never pays as much as finishing.
A declared value at or above verified_reward is still refused.
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