Skip to content

Make medication safety status provenance-aware - #19

Merged
pmanko merged 8 commits into
mainfrom
codex/medication-safety-honesty
Aug 8, 2026
Merged

Make medication safety status provenance-aware#19
pmanko merged 8 commits into
mainfrom
codex/medication-safety-honesty

Conversation

@pmanko

@pmanko pmanko commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Summary

Makes deterministic medication-safety results explicit about what was checked, what data was used, and what remains limited or unavailable.

The hub returns one canonical drug_safety.v1 result with package identity, review state, coverage, warnings, and issues. Incomplete source data cannot be presented as a completed safety check, while valid primary warnings remain available when only the relationship package is limited.

Key guarantees

  • Primary medication rules and cross-reactivity data are approved independently.
  • Missing, malformed, partial, retired, or unapproved data cannot look checked.
  • Prompt evidence and warning emission use the same severity policy.
  • Incomplete QueryStore charts fail explicitly before temporal or medication-safety checks use them.

What Changed

  • Reports medication-rule and cross-reactivity package metadata independently.
  • Requires package id, version, source, valid content collections, and clinical approval before related rules execute.
  • Rejects malformed numeric, age, severity, ATC, relationship, dose, interaction, and contraindication fields at the parser boundary.
  • Preserves parser diagnostics through unavailable and limited early returns.
  • Prevents unapproved relationship data from producing class or cross-reactivity warnings.
  • Applies the configured severity floor to both warnings and model-visible knowledge.
  • Adds concrete In-Depth validation reasons to the real product envelope.
  • Rejects missing or true QueryStore chartTruncated metadata before caching a patient ledger.
  • Keeps raw experimental-leg compatibility intact.

Reviewed DDI content and CIEL mapping remain a separately governed medication-knowledge track.

Review Focus

  1. Primary approval cannot implicitly approve relationship data.
  2. Parser drops and malformed package data remain visible.
  3. Unapproved or invalid packages cannot emit dependent warnings or prompt evidence.
  4. Missing patient context, incomplete mappings, and source failures cannot look clean.
  5. A relationship-package failure does not suppress valid primary-package findings.

Verification

  • Exact head: cb4e05f853f4e9ac545ebe62a6ed7732fd167aa7
  • 664 hub tests passed.
  • Focused package, malformed-data, relationship-isolation, In-Depth, QueryStore-completeness, and stage-engine tests passed.
  • git diff --check passed.
  • GitHub unit, container-build, and security checks are green at this head.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the hub’s deterministic medication-safety output provenance-aware by returning a canonical drug_safety.v1 object that separates package identity/review state from mapping/exposure/execution completeness, ensuring incomplete or unapproved data cannot appear “checked”.

Changes:

  • Introduces a canonical SafetyCheckResult (drug_safety.v1) with package metadata, coverage, identity confidence, issues, and warnings; updates engine/team streaming envelopes to emit it.
  • Hardens drug-safety dataset parsing and governance (package identity + review state gates; parser-boundary validation; severity-floor handling).
  • Improves QueryStore completeness handling and context-slice metadata (projection completeness, snapshot consistency, similarity-rank reuse) and updates tests/fixtures accordingly.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_staged_stream.py Updates In-Depth and context overflow tests to use required_ids and new validation metadata.
tests/test_stage_engine_v2.py Ensures drug-safety preparation receives exposure_complete and asserts canonical safety payload presence.
tests/test_querystore_client.py Extends fake pages and adds tests for chartTruncated / projectionComplete handling.
tests/test_patient_ledger_cache.py Adds coverage for snapshot/projection retention in the cached ledger view.
tests/test_dual_provider_conformance_adapter.py Adapts conformance assertions to required_ids.
tests/test_drug_safety.py Adjusts fixtures to clinically-approved test datasets and adds unresolved-drug limitation tests.
tests/test_drug_safety_status.py Reworks fixture adapter to drive real completeness dimensions and adds extensive provenance/validation tests.
tests/test_drug_safety_integration.py Patches load_dataset to an approved dataset for integration tests; asserts package/coverage fields.
tests/test_drug_safety_followthrough.py Adds tests ensuring relationship-package governance isolates dependent warnings/selection.
tests/test_drug_safety_atc.py Updates ATC behavior to “limited/no deterministic warnings” under unapproved classification data.
tests/test_context_sources.py Adds projection completeness + snapshot/rank reuse + snapshot race retry/fail tests; renames mandatory_ids.
tests/test_context_budget.py Expands context-budget tests for protected tiers and required_ids overflow reporting.
tests/factories.py Ensures test ledgers carry patient_ledger_complete metadata.
tests/conformance/dual-provider-conformance.v1.json Updates fixture expectations for tiering (panel) and adds explicit-signal retention case.
server/team.py Replaces _compute_safety_warnings with _compute_safety_check and threads exposure_complete into context building.
server/querystore_client.py Validates chart completeness/projection metadata; adds slice snapshot/projection metadata and similarity rank support.
server/patient_ledger_cache.py Introduces get_ledger returning records + snapshot + projection completeness; keeps get_records as compatibility.
server/engine.py Emits safetyCheck in streaming envelopes; improves In-Depth draft selection and adds validation summaries.
server/drug_safety.py Adds package/review-state governance, strict parsing/validation, severity-floor support, and canonical SafetyCheckResult.
server/drug_data/drug-reference.json Adds package identity + review state marking bundled data as unreviewed research seed.
server/drug_data/cross-reactivity-groups.json Adds package identity + review state marking bundled cross-reactivity as unreviewed research seed.
server/context_sources.py Renames mandatory_idsrequired_ids; adds snapshot consistency checks, similarity-rank reuse, and projection completeness metadata.
README.md Documents drug_safety.v1 contract, package governance, and interaction severity-floor behavior.
env.recommended Adds DRUG_SAFETY_MIN_INTERACTION_SEVERITY.
Suppressed comments (1)

server/engine.py:1197

  • Same issue as the bare mode: the combined output mode adds safetyStatus (and optionally safetyWarnings) but does not include the canonical safetyCheck payload. Clients consuming blocking/combined results won't see package/coverage/issue provenance.
            bool(request.profile.policies.get("drug_safety")),
        )
        payload["safetyStatus"] = safety_check.status
        if safety_check.warnings:

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread server/engine.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@pmanko

pmanko commented Aug 8, 2026

Copy link
Copy Markdown
Owner Author

@copilot resolve the merge conflicts in this pull request

…ty-honesty

# Conflicts:
#	server/engine.py

Co-authored-by: pmanko <711826+pmanko@users.noreply.github.com>
Co-authored-by: pmanko <711826+pmanko@users.noreply.github.com>
@pmanko
pmanko merged commit 8b81320 into main Aug 8, 2026
3 checks passed
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.

3 participants