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.
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