Skip to content

refactor(types,desktop): generalize healthcare/clinic core contracts and policies - #2487

Merged
abrichr merged 9 commits into
mainfrom
gemini/core-generality-types-desktop
Nov 22, 2026
Merged

abrichr merged 9 commits into
mainfrom
gemini/core-generality-types-desktop

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

Summary

Generalizes healthcare/clinic/insurance concepts in packages/types and packages/desktop to domain-neutral core contracts and policies, keeping narrow backward-compatible wire shims only where serialized receipts or configs require compatibility.

packages/types

  • Managed job contracts (openadapt_types/managed_job.py): Introduced domain-neutral ManagedInboxV1, ManagedOutboxV1, ManagedToolResultV1, ManagedMcpToolCatalogV1, ManagedBoundToolCallV1, ManagedToolStatusV1, and openadapt.managed-*/v1 schemas (subject_token, collect, attach_artifact, create_task) exported via scripts/export_managed_job_schemas.py.
  • Legacy compat shim (openadapt_types/clinic_job.py): Marked as a legacy compatibility shim for existing openadapt.clinic-*/v1 wire payloads, reusing ManagedToolStatusV1, ManagedActuationDecisionV1, ManagedActuationHeld, and ManagedToolUnknown.
  • Approval contracts (openadapt_types/approval.py): Generalized StepClass.CLINICAL_WRITE -> StepClass.HIGH_RISK_WRITE (high_risk_write), ApproverPolicyRefusal.CLINICAL_WRITE_NEEDS_OPT_IN -> HIGH_RISK_WRITE_NEEDS_OPT_IN, and clinical_write_opt_in_sha256 -> high_risk_write_opt_in_sha256, with wire-level deserialization shims and legacy aliases for previously serialized policies/receipts. Re-exported JSON schemas.
  • Outcome vocabulary (openadapt_types/vocabulary/outcomes.json, outcome-vectors.json, plain_results.py, docs/VOCABULARY.md): Generalized clinic_tool_status -> managed_tool_status with backward-compatible input handling in plain_outcome() and PlainOutcomeInputsV1.

packages/desktop

  • Default qualification/check policies: Switched POLICY / DEFAULT_QUALIFICATION_POLICY from "clinical-write" to Flow's domain-neutral "record-write" in openadapt_desktop/check_setup.py, openadapt_desktop/qualification.py, src/screens/CheckIt.tsx, src/screens/Qualification.tsx, and src/screens/QualificationLifecycle.tsx.
  • Domain-neutral UI copy & acronyms: Replaced clinic/healthcare-specific acronyms (dos, mrn, npi, icd, cpt) in src/screens/NeedsYou.tsx and src/lib/outcomes.ts with general system-of-record acronyms (id, url, api, sku, po, dob, ssn, ein, zip); generalized healthcare/clinic wording in src/screens/Welcome.tsx, src/screens/Sample.tsx, src/ui/ApprovalSwitch.tsx, openadapt_desktop/approval_mode.py, openadapt_desktop/config.py, and openadapt_desktop/portal/ingress.py.

Generality Gate

  1. No per-app code in the engine: Yes — removes hardcoded healthcare/clinic policy names, step classes, tool status names, and domain-specific acronyms from core packages/types and packages/desktop, replacing them with domain-neutral contracts (managed_job, high_risk_write, managed_tool_status, record-write).
  2. Fix the class, not the instance: Yes — addresses the entire class of domain-specific vertical leakage across wire contracts, JSON schemas, outcome vocabulary, approval policies, and desktop screens/acronyms in one coherent model, with explicit backward-compatibility shims only at serialization boundaries.
  3. Held-out evidence: Not yet shown on a new held-out live app; validated across the full packages/types test suite (820 tests, including new domain-neutral contract and legacy-compat tests) and targeted packages/desktop engine/portal tests (112 tests).

Verification

  • packages/types: uv run ruff check openadapt_types tests scripts, uv run ruff format --check on new files, uv run mypy --follow-imports=silent openadapt_types/managed_job.py openadapt_types/approval.py, uv run pytest -q (820 passed)
  • packages/desktop: uv run ruff check on edited modules, uv run pytest -q tests/test_engine/test_check_setup.py tests/test_engine/test_approval_mode.py tests/test_engine/test_qualification.py tests/test_engine/test_check_it_drills.py tests/test_portal/test_ingress.py tests/test_oracle_vocabulary.py (112 passed)

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 8b7db55

  1. Desktop cannot open qualification with its bundled Flow. The UI sends record-write on initial load. Desktop pins Flow 2.4.1, which ships only clinical-write and permissive. The exact-head bundled qualification job recorded 38 failures and 10 passes, including the missing-policy error. On newer Flow, opening an existing certified bundle under the new default also compares its recorded policy name against a different name. Select a supported default for new bundles and use the recorded policy identity for existing evidence. Desktop pin · Certificate comparison · Hosted failure
  2. The v1 approval contract no longer round-trips between Types, Flow and JSON Schema. I passed a base-generated policy and approval record through the old and new schemas. Both passed the old schemas and failed the new ones. Types can read the legacy policy, but re-emits different canonical bytes. Flow rejects that output on both the step-class key and opt-in field, even for the default person-only policy. Flow's existing refusal string also fails to parse in the renamed Types enum. Preserve the v1 wire representation used by existing grants and audit records, or version the new representation and support both at the boundary. Cover both round-trip directions and the existing Flow conformance test. The Types model still requires the opt-in for a non-person high-risk approval. Approval types · Flow reader · Conformance test
  3. A saved v1 outcome can no longer be read, and mixed status names can report a false success. The base's published HALTED vector emits clinic_tool_status=HALTED. The new outcome model rejects that technical code, and the exported schema rejects the old field in exact. Separately, plain_outcome() takes managed_tool_status=VERIFIED over a simultaneous legacy RECONCILIATION_REQUIRED and returns done. Its input model already rejects this disagreement. Preserve complete saved v1 outcomes and apply the same conflict check through the public function. Old vector · Outcome validator · Public resolver
  4. The new managed catalog schema accepts entries the Python contract refuses. Its three slots all accept the same unconstrained tool specification. A schema reader can accept repeated names or a requires_outbox value inconsistent with the tool. Encode each admitted tool's name, action and outbox requirement in the published schema and check the same invalid fixtures in both readers. Published schema · Python contract

Evidence covers immutable source, synthetic serialized artifacts and the existing hosted run. No live app, signing or dispatch was exercised.

…schema, and support bundled Flow policy fallback
@abrichr

abrichr commented Nov 21, 2026 •

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 0ed308d

Three findings from the previous review still affect ordinary readers or commands.

  1. Desktop inspection and certification can select different policies. The fallback now handles bundled Flow 2.4.1's missing record-write policy. On Flow versions that support both names, opening an existing clinical-write bundle selects its recorded policy, but the UI's Run certification sends record-write again. certify_bundle() uses it directly. Flow rejects case evidence governed by the previous policy and persists the failed certification. The new regression test passes clinical-write explicitly at this step, unlike the UI. There is also a regression for custom policies: certification accepts a YAML path and saves the bundle, then reopens it by the policy's internal name. For the tracked policy.yaml named qualification-gate-campaign, that lookup fails and the dispatcher returns an error after the save. Carry the resolved policy and its source through inspection, certification and readback. Exercise the UI request and a custom path. UI call · Certification and save · Evidence check · Custom policy

  2. The managed catalog readers still disagree on the outbox flag's wire type. Both now reject repeated slots, mismatched actions and inverted booleans. The new Python slot types replace StrictBool with boolean literals, so the JSON reader accepts numeric 0 for collection and 1 for attachment. The shipped Draft 2020-12 schema rejects both. Preserve strict boolean input alongside the per-slot value check and run these two fixtures through both readers. Python slots · Wire schema

  3. A saved v1 outcome loads on this head, but saving it again breaks older readers. A base-generated HALTED outcome now reads correctly as check_the_record with retry disabled, and the public resolver refuses conflicting status fields. However, its normal model_dump(mode="json") adds exact.managed_tool_status: null. Both the old Python v1 reader and the old exported schema reject the added field. Invoking the existing plain_outcome(clinic_tool_status="HALTED") API also emits the new technical-code spelling under the same version. Keep ordinary v1 serialization readable to deployed readers, or introduce a separately versioned wire format. Outcome fields · Public producer

Resolved. The exact Flow mirror test passes. Base-generated person-only and opt-in policies, plus approved and declined records, retained identical canonical v1 bytes through both Types readers and validated against both shipped schemas. Flow's policy digests matched, and its normal unsigned-policy loader retained the delegation refusal.

These checks used immutable source and synthetic unsigned inputs. Hosted CI for this revision is pending. Current run

…catalog slots, and canonical v1 outcome bytes
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 834bfaa

One Desktop policy-selection regression remains. An operator can explicitly request the stricter record-write policy when recertifying a bundle previously qualified under the built-in permissive policy. The dispatcher passes record-write, but this revision makes certification prefer the recorded policy whenever the argument equals the default string. Flow therefore evaluates and saves the new qualification under permissive. The previous head honored the explicit selection. The two policies have different requirements for identity and system-of-record checks. Dispatcher · Policy selection · Certification

Preserve the distinction between an omitted policy and an explicit selection through the dispatcher. A request to reuse the recorded policy can retain the old identity. An explicit selection should evaluate that policy or return a clear error. A focused regression can assert which policy reaches the evaluator for both requests on the same previously permissive bundle.

The other cases from the previous review are resolved. The qualification screen forwards the inspected policy, including the legacy clinical-write identity, and the custom YAML path survives save and readback. The archived HALTED outcome, its default reserialization and both API spellings produce the original v1 bytes and pass the older Python reader and schema. Contradictory statuses are refused. The managed catalog's Python reader and JSON Schema also agreed on all six cases, including rejection of numeric 0 and 1. The previously verified v1 approval contract is unchanged.

The policy finding comes from tracing the exact dispatcher and certification source. The serialization and catalog checks used synthetic inputs. Hosted CI is pending. Current run

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: ecf42f6

Desktop still sends a policy selection when the user simply opens an existing bundle. The dispatcher now preserves an omitted policy and honors an explicit record-write request on a previously permissive bundle. But both the Qualification and Check it screens insert policy: "record-write" into their initial inspection requests. On the source Flow runtime, which ships both policy names, opening a bundle previously certified under clinical-write therefore evaluates record-write. The certificate comparison requires the recorded name, so a current certificate appears stale. Qualification then sends that inspection result back as its certification policy. The bundled 2.4.1 fallback masks this for the legacy clinical case. Qualification request · Check it request · Certificate comparison

Omit the initial UI policy argument when the user has made no selection. Carry the policy returned by inspection through subsequent certification actions, including Check it's shared request helper. Keep the new backend behavior for a caller who expressly selects a policy. The existing regression invokes the dispatcher directly and does not cover the field the screens insert. Check it helper · Dispatcher regression

This finding follows the exact request literals, dispatcher branches and certificate comparison. I did not run a certification. Hosted CI is queued. Current run

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Codex
Reviewed-Head: 80d5137

The remaining UI finding is resolved. Both Qualification and Check it now send only the workflow ID on initial inspection. The dispatcher therefore receives an omitted policy and can reuse the bundle's recorded policy. Both screens carry the inspected value into certification. The lifecycle screen carries it into its follow-up requests, and an explicitly supplied value in the shared request helper takes precedence. Qualification inspection · Qualification certification · Check it request helper

The new Check it component test renders the screen, clicks approval and asserts the exact IPC arguments: the initial inspection omits policy, and certification sends the clinical-write value returned by the mocked inspection. I reviewed those assertions and the real routing code. I did not run the component test locally. Hosted CI is pending. Regression test · Hosted run

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 3de4afd

Delta confirmation versus Codex APPROVE at 80d5137e (#2487 (comment)). This is Gemini-authored; this is a cross-vendor review of the new head only.

Delta

  1. Merge 69a804546 of main d8bb8ffdd (Merge fix(flow): print next-step CLI hints through command() #2530) into the Codex-approved 80d5137e. Combined --cc patch is empty (clean merge, no conflict-resolution hunks). Overlap with this PR's unique tree is packages/desktop/openadapt_desktop/dispatch.py, packages/types/openadapt_types/__init__.py, and packages/types/openadapt_types/vocabulary/outcomes.json (CHANGELOG.md and openadapt_desktop/__init__.py had no leftover unique-versus-new-main after the merge). The Codex-approved policy fix in dispatch.py (omit DEFAULT_QUALIFICATION_POLICY; treat a missing policy as omitted rather than an implicit default) is byte-identical after the merge. The types __init__.py unique export/__all__ hunks are preserved (only hunk line numbers shifted because main added other exports). The outcomes.json unique wording (ManagedToolStatusV1 / managed tool result) is preserved.

  2. 3de4afd68 (chore(desktop): bump openadapt-desktop to 0.31.1, AuthorDate Sun Nov 22 08:20:17 2026 -0500): consistent 0.31.0 → 0.31.1 bump in the nine release-intent files (CHANGELOG.md, __init__.py, package-lock.json, package.json, pyproject.toml, src-tauri/Cargo.lock, Cargo.toml, tauri.conf.json, uv.lock). CHANGELOG adds v0.31.1 (2026-11-22) documenting the omitted-policy / certification-readback / v1 wire-compat and managed-catalog work. 0.31.1 is not present on the merge's main parent.

I did not re-litigate the previously approved unique body. The unique tree at 80d5137e is intact on top of current main, and the only unique follow-up is the 0.31.1 bump.

Merge-order residual (not a blocker of this PR's own content)

#2532 (#2532, currently c62b703e8, already approved) also bumps openadapt-desktop 0.31.0 → 0.31.1. Whichever of #2487 or #2532 merges second must rebump to 0.31.2 so the published version stays unique.

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: 347577e

Delta confirmation versus my APPROVE at 3de4afd68 (#2487 (comment)) and the earlier Codex APPROVE at 80d5137e (#2487 (comment)). I did not write these changes.

Delta

First-parent delta is two commits:

  1. Merge 2cd05405c of origin/main 7afc296d2 (Merge fix: restore green main #2533) into 3de4afd68. Incoming files are the fix: restore green main #2533 / test(ci): report governed coverage and diff full rows against the seed #2258 main changes (exception_queue.py, approver_anchor.py, Windows governed-safety tests, Cargo.lock, etc.). Combined unique-versus-new-main after this merge matches the previously approved types/desktop unique tree: the only files that drop out of the unique diff are the nine 0.31.1 release-intent files, which were already 0.31.1 on both sides. The merge takes main's v0.31.1 CHANGELOG (Windows reparse-point / ACL checks and url 2.5.9 / RUSTSEC-2026-0592) and main's Cargo.lock url 2.5.9. It does not alter the approved policy-omission / types unique body.

  2. 347577ebf (chore(desktop): bump openadapt-desktop to 0.31.2, AuthorDate Sun Nov 22 09:09:02 2026 -0500): consistent 0.31.1 → 0.31.2 bump in the nine release-intent files. CHANGELOG adds v0.31.2 (2026-11-22) with the same four policy / certification / v1-compat bullets that previously sat under this PR's 0.31.1 section — the right place now that 0.31.1 on main is fix: restore green main #2533. url remains 2.5.9 at this head.

This also clears the earlier merge-order residual against #2532 / #2533: this head no longer ships 0.31.1. I did not re-litigate the previously approved unique body.

No merge from this review.

@abrichr
abrichr merged commit aeb7823 into main Nov 22, 2026
67 checks passed
@abrichr
abrichr deleted the gemini/core-generality-types-desktop branch November 22, 2026 15:24
abrichr added a commit that referenced this pull request Nov 22, 2026
….1 notes

#2487 declared the domain-neutral alias before the v1 member in StepClass,
ApproverPolicyRefusal and OutcomeSourceV1, so .name, str() and repr() of the
v1 member changed (StepClass.CLINICAL_WRITE.name became HIGH_RISK_WRITE).
The v1 member now comes first and the new name is the alias, as in 0.24.0.
Values, wire bytes and schemas are unchanged.

The 0.24.1 notes now list #2487: the managed_job module and schemas, the
domain-neutral aliases and accepted input forms, and that output stays
byte-identical to 0.24.0.
abrichr added a commit that referenced this pull request Nov 23, 2026
…accepts Flow 4 (#2540)

* release: openadapt-types 0.24.1 and openadapt-verify 0.2.1; accept Flow 4

openadapt-flow 3.4.0 imports openadapt_types.receipt, which openadapt-types
0.24.0 does not have, so a clean install of 3.4.0 fails on every receipt
path. openadapt-types 0.24.1 adds the receipt, receipt callback, run ledger
and exception card modules. It stays inside the <0.25.0 range every released
Flow 3 accepts, so it also repairs Flow 3.4.0 installs.

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; asking then earns no credit.

This is the first of two release PRs. Flow 4.0.0 needs openadapt-types
0.24.1 on PyPI first: its on-prem wheelhouse is built from Flow's lock,
which can only pin a types version PyPI serves. So this PR also lifts the
caps that would break CI once the in-tree Flow is 4.0.0:

- the launcher accepts openadapt-flow >=3.3.0,<5.0.0, in its requirements
  and in `openadapt doctor`'s supported range; the platform manifest is
  regenerated with the same component selection so its compatibility block
  matches. The launcher releases only on dispatch, so nothing ships here.
- openadapt-verify 0.2.1 accepts openadapt-flow <5 (#2535).

* release: address review of types 0.24.1 and verify 0.2.1

- verify's distribution check asserted the old <4 Flow cap; it now expects
  <5, so the verify job and its release build pass.
- RewardScoringPolicyV1 leaves escalated_after_effect_reward out of its
  serialization at the default, so a contract file 0.24.1 writes stays
  readable by 0.24.0 and hashes the same; the digest needs no special case.
  A test checks the serialized form against the 0.24.0 fixture.
- The types notes move the validator change into Features and add a
  Compatibility section. The verify note names the extras it widens.

Verify's suite passes against the Flow 4.0.0 source (91 passed; the 3
installed-CLI tests need an installed openadapt-verify and fail the same
way without this change).

* fix(types): an undeclared escalation earns nothing

escalated_after_effect_reward now defaults to 0, not 0.5. A contract
written or certified before the escalated_after_effect outcome existed
never declared it, so the outcome must not start paying under it.

- The field is still left out of serialization at its default, so 0.24.0
  contracts and certificates hash, verify and load as before, and 0.24.1
  writes files 0.24.0 can read.
- The validator no longer needs a default exception: any value at or above
  verified_reward is refused, and 0 is always below it.
- The 0.24.0 fixture now also records how 0.24.0 scored every outcome it
  knew (tier 2, policy update 120). The test checks 0.24.1 scores them the
  same and gives the new outcome 0. A declared value is paid as declared.
- Flow's synthetic reward bundle declares escalated_after_effect_reward 0.5,
  so its demo and Harness² tests keep their partial credit. That contract
  declares it, so it is paid.

* docs: the escalated_after_effect default is 0 everywhere it is described

REWARD.md, the reward worker docstring, HARNESS2.md and REWARD_WORKER.md
still said the default was 0.5. The types notes and docstring restore the
below-1 bound beside the below-verified_reward one. The exported contract
schema carries the new docstring.

* release(types): keep 0.24.0 enum member names; note #2487 in the 0.24.1 notes

#2487 declared the domain-neutral alias before the v1 member in StepClass,
ApproverPolicyRefusal and OutcomeSourceV1, so .name, str() and repr() of the
v1 member changed (StepClass.CLINICAL_WRITE.name became HIGH_RISK_WRITE).
The v1 member now comes first and the new name is the alias, as in 0.24.0.
Values, wire bytes and schemas are unchanged.

The 0.24.1 notes now list #2487: the managed_job module and schemas, the
domain-neutral aliases and accepted input forms, and that output stays
byte-identical to 0.24.0.

* release(types): publish the reviewed content as openadapt-types 0.24.2

0.24.1 was stamped on main by #2543 without this PR's reviewed types code
and was never published; that tree breaks 0.24.0 contracts. The reviewed
content ships as 0.24.2. Only the version (pyproject, uv.lock) and the
changelog change; every other types and verify file is byte-identical to
the reviewed 45f0cd5.
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