Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Concordia_Design/architecture/API_CONTRACTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ All identifiers are opaque UUIDs, timestamps UTC ISO-8601, byte digests SHA-256
| GET `/api/v1/runs/{id}/manifest` | none | provenance manifest 200 | member |
| GET `/api/v1/runs/{id}/findings` | severity filter | report 200 | member |
| POST `/api/v1/evaluations` | frozen fixture set and protocol ID | evaluation result 200 | operator only |
| GET `/api/v1/runs/{id}/evidence` | none | published bundle metadata 200 | member |
| GET `/api/v1/runs/{id}/report` | format | report 200 | member |
| POST `/api/v1/runs/{id}/explanations` | bounded question | validated explanation 200/202 | member + policy |
| GET `/api/v1/runs/{id}/evidence` | none | verified bundle and permitted evidence 200 | member |
| GET `/api/v1/runs/{id}/report` | `format=markdown|html` | deterministic report 200 | member |
| GET `/api/v1/evidence/search` | bounded FTS query and limit | evidence IDs, excerpts, source metadata 200 | member |
| POST `/api/v1/runs/{id}/explanations` | bounded question | validated grounded explanation 200 | member + policy |
| GET `/api/v1/artifacts/{id}` | none | authorized artifact 200 | membership + sensitivity policy |

## Core payloads
Expand All @@ -52,7 +53,7 @@ All identifiers are opaque UUIDs, timestamps UTC ISO-8601, byte digests SHA-256

`RunManifest`: run and plan IDs, input artifact ID/hash, plan hash, registered method ID/version, source commit, lock digest, runtime, peak memory, terminal status, result/diagnostic artifact IDs and hashes, split/calibration/missing-modality manifests, limitations, manifest digest, and creation time. `RunManifest` is published only after result and diagnostic artifacts are written and verified.

`ResultRow`: evidence ID, metric, value or null, unit, denominator or null, uncertainty bounds or null, uncertainty method or null, calibration status or null, modality mask or null, applicability status, evidence artifact ID. Never substitute zero for missing. `Finding`: stable finding ID, check ID/version, severity, reason, evidence references, limitation, and suggested review. Acknowledgement of a Phase 1 warning never changes a Phase 3 finding to a pass. `EvidenceBundle`: bundle ID, run ID, manifest digest, source and result refs, findings, approved chart specs, provenance, calibration and missing-modality summaries, limitations, bundle digest. `EvaluationResult`: frozen protocol ID/version, fixture set, precision/recall, false positives, missed blocking cases, runtime, memory, limitations, and result digest. `Explanation`: source bundle ID, provider/model version, claim array, verified evidence IDs, validation status, fallback status.
`ResultRow`: evidence ID, metric, value or null, unit, denominator or null, uncertainty bounds or null, uncertainty method or null, calibration status or null, modality mask or null, applicability status, evidence artifact ID. Never substitute zero for missing. `Finding`: stable finding ID, check ID/version, severity, reason, evidence references, limitation, and suggested review. Acknowledgement of a Phase 1 warning never changes a Phase 3 finding to a pass. `EvidenceBundle`: bundle ID, run ID, manifest digest, source and result refs, findings, provenance, calibration and missing-modality summaries, limitations, bundle digest, bundle/report artifact IDs and hashes. Evidence payloads are canonical JSON and are verified against every referenced artifact before export. `EvaluationResult`: frozen protocol ID/version, fixture set, precision/recall, false positives, missed blocking cases, runtime, memory, limitations, and result digest. `Explanation`: source bundle ID, provider/model version, claim array, verified evidence IDs, validation status, source status, and fallback status. Reports are deterministic and offline.

## Error envelope

Expand Down
2 changes: 1 addition & 1 deletion Concordia_Design/architecture/BACKEND.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ infra/ Compose, proxy, CI

## Data persistence

`projects`, `memberships`, `datasets`, `quality_reports`, `acknowledgements`, `analysis_plans`, `runs`, `jobs`, `artifacts`, `findings`, `evidence_bundles`, `explanations`, `audit_events`. Foreign-key references include project ownership; unique constraints on idempotency tuple and relevant digest; append-only logical audit events. SQLite WAL and migration-managed schema, single writer/worker for local MVP; Phase 2 persists plans/runs/results through the existing generic local record adapter; Phase 3 persists versioned findings and blocked-run diagnostics through the same adapter; Postgres optional when concurrency justifies it. Use UTC wall time and monotonic runtime measurements.
`projects`, `memberships`, `datasets`, `quality_reports`, `acknowledgements`, `analysis_plans`, `runs`, `jobs`, `artifacts`, `findings`, `evidence_bundles`, `explanations`, `audit_events`. Foreign-key references include project ownership; unique constraints on idempotency tuple and relevant digest; append-only logical audit events. SQLite WAL and migration-managed schema, single writer/worker for local MVP; Phase 2 persists plans/runs/results through the existing generic local record adapter; Phase 3 persists versioned findings and blocked-run diagnostics through the same adapter; Phase 4 persists canonical evidence bundles and Markdown/HTML report artifacts and indexes permitted report/finding fragments in SQLite FTS5; Postgres optional when concurrency justifies it. Use UTC wall time and monotonic runtime measurements.

Artifacts stored separately under managed IDs, never user-supplied path. Save canonical metadata and hash bytes; normalize deterministic JSON serialization (sorted keys, no NaN). Preserve original and normalized input digests. Atomically commit file + record via staged write and recovery reconciliation. Hash alone is not tamperproof: for higher assurance use protected signing keys and restricted audit storage, not claims of immutability solely from a hash chain.

Expand Down
2 changes: 1 addition & 1 deletion Concordia_Design/architecture/WORKFLOW.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ A researcher imports a permitted cohort/sample table with derived multi-omics fe

Every request has correlation ID; every job has run ID. Worker writes artifacts to a temporary location, verifies digest and atomically publishes metadata; interrupted jobs cannot appear successful. Reconcile stale jobs on restart using leases; cap retries and preserve failed logs. Progress is coarse and factual, based on completed stages; no fabricated percent. API status and job events exclude data values.

Phase 3 credibility checks are deterministic registered code over immutable Phase 1/2 artifacts. Any block finding leaves the run `BLOCKED`, suppresses result/evidence access, and preserves only non-sensitive reasons and evidence references. Acknowledgements are provenance records, never pass states. The authorized evaluation endpoint is operator-only and uses frozen development and held-out fixture manifests. MVP uses local loopback, local file system, SQLite jobs and one worker; production adapter can add Postgres and object storage without changing public contracts. Avoid cross-service network hops merely because phases are separate.
Phase 3 credibility checks are deterministic registered code over immutable Phase 1/2 artifacts. Any block finding leaves the run `BLOCKED`, suppresses result/evidence access, and preserves only non-sensitive reasons and evidence references. Acknowledgements are provenance records, never pass states. Phase 4 creates a canonical bundle only for a verified published run, verifies all referenced hashes before report/export, indexes only permitted fragments in SQLite FTS5, and falls back to the deterministic report when an optional explanation cannot be validated. MVP uses local loopback, local file system, SQLite jobs and one worker; production adapter can add Postgres and object storage without changing public contracts. Avoid cross-service network hops merely because phases are separate.
42 changes: 39 additions & 3 deletions Concordia_Design/docs/STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- Scope reconciliation completed on 2026-11-29.
- ADR-0001 records the approved multi-omics and ML direction.
- Phase 0 completed previously; Phases 1 and 2 are implemented and audited. Phase 3 credibility checks and the frozen evaluation harness are implemented and audited on 2026-11-29. Phases 4–7 remain unadvanced.
- Phase 0 completed previously; Phases 1 and 2 are implemented and audited. Phase 3 credibility checks and the frozen evaluation harness are implemented and audited on 2026-11-29. Phase 4 evidence/report/retrieval work is implemented on this branch; Phase 5–7 remain unadvanced.
- Existing Concordia, BioLab MCP, GlucoPulse, and CellForge repositories are not used or modified.

## Scope decision
Expand All @@ -16,7 +16,7 @@ Concordia is a CPU-first observational multi-omics cohort analysis product for p
- Phase 1: authenticated project creation, durable safe CSV/Parquet intake, declared modality specs, explicit availability and missingness masks, source/license metadata, original/normalized provenance hashes, missingness quality ledger, target-leakage guard, and restart-safe normalized artifacts.
- Phase 2: implemented and audited on 2026-11-29. Phase 3 and later remain unadvanced.
- Phase 3: implemented and audited on 2026-11-29. Versioned checks gate publication and the operator-only evaluation endpoint uses frozen development and held-out synthetic fixtures.
- Phase 4: not advanced; export and explanation work remains deferred.
- Phase 4: implemented and audited on 2026-12-02; optional external model execution remains disabled by design.
- Phase 5: not advanced; Phase 1 upload/project boundary was corrected in the existing static workflow.
- Phase 6: not audited or advanced in this Phase 1 change.
- Phase 7: not audited or advanced in this Phase 1 change.
Expand Down Expand Up @@ -109,6 +109,42 @@ docker build --tag concordia:phase3-local .
- Rule findings establish consistency and provenance gates over the artifacts they inspect; they do not establish causality, clinical utility, or scientific novelty.
- Hosted RBAC, signed artifact attestations, distributed jobs, and later evidence/LLM or frontend phases remain out of scope.

## Phase 4 acceptance audit

| Criterion | Implementation location | Test evidence | Status |
|---|---|---|---|
| Immutable verified bundle for published runs | `packages/core/src/concordia_core/evidence.py`, `workflow.py`, `FilesystemArtifactStore` | `tests/test_phase4_evidence.py`; published-only gate, canonical digest, artifact hash checks, immutable overwrite test | Implemented |
| Required provenance, plan, method, missingness, calibration, findings, limitations, and permitted results | `build_evidence_payload`, `EvidenceBundle` | `test_evidence_report_artifacts_search_and_explanation_contract` and existing Phase 2/3 tests | Implemented |
| Deterministic offline Markdown and HTML reports | `evidence.py` templates and report API | report format/content assertions and full suite | Implemented |
| SQLite FTS5 read-only retrieval over permitted evidence | migration `0003_evidence_fts.py`, storage repository, `/api/v1/evidence/search` | search/auth assertions in Phase 4 tests | Implemented |
| Authorized, hash-verified artifact export | `workflow.get_verified_artifact`, `/api/v1/artifacts/{artifact_id}` | artifact API and tamper tests | Implemented |
| Standalone bundle verification | `scripts/verify_evidence_bundle.py` | direct verifier test and documented command | Implemented |
| Grounded explanation contract and fail-closed fallback | `packages/core/src/concordia_core/explanations.py` | fabricated citation, unsupported language, prompt-injection, and API fallback tests | Implemented; deterministic adapter only |
| Restart and corruption behavior | durable run reload and verification on read | existing persistence tests plus Phase 4 tamper coverage | Implemented |
| Phase 4 checks and documentation | README, API/backend/workflow docs, migration | 45 passed; Ruff and mypy clean; Alembic head `0003_evidence_fts`; pip-audit no known vulnerabilities; Docker image build passed | Implemented |

### Phase 4 reproduction commands

```bash
export UV_CACHE_DIR="$PWD/.uv-cache"
uv sync --locked
uv run pytest -q
uv run ruff check packages services tests scripts
uv run mypy packages services
uv run alembic upgrade head
uv run alembic current
uv run pip-audit --strict
docker build --tag concordia:phase4-local .
```

The evidence verifier accepts a bundle artifact and the managed artifact directory:

```bash
uv run python scripts/verify_evidence_bundle.py .concordia/artifacts/<bundle-artifact-id>.bin --artifact-root .concordia/artifacts
```

Reports contain computed summaries only. Synthetic fixtures are not biological validation, and this phase establishes neither causation nor clinical utility. The optional language boundary is disabled; the deterministic report is the required fallback. The installed ECC trash-guard hook remains unavailable because its `ModuleNotFoundError` packaging defect causes a fail-open warning; a manual review of changed code, artifact path handling, suppression behavior, and tests was performed instead.

## Next ticket

P4-01 — export bundle and template, after owner review of the Phase 3 acceptance evidence.
P5-01 — guided UI and charts. Phase 5 was not started in this change.
4 changes: 2 additions & 2 deletions Concordia_Design/phases/04-evidence-llm.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

1. Build immutable evidence bundle: approved plan, manifest, quality report, permitted result summaries, findings, source IDs, chart specs, software/model metadata, checksums. Exclude suppressed groups and confidential records.
2. Create deterministic Markdown/HTML template report; include limitations, missingness, estimates, uncertainty, provenance and no causal claims. Export works without model service.
3. Build a read-only retrieval index over permitted documentation and report fragments, using lexical search first, optional MiniLM embeddings second. Return evidence IDs and snippets.
3. Build a read-only SQLite FTS5 retrieval index over permitted documentation and report fragments. Return stable evidence IDs, excerpts, and source metadata. No vector database or hosted embedding dependency is part of Phase 4.
4. Implement optional language adapter for general-language summarization only. Send bounded, permitted evidence and a constrained output schema (`claims`, `evidence_ids`, `limitations`). Verify every claim reference exists; numerics and units must exactly match evidence. Unsupported text is omitted or replaced by template output.
5. Evaluate claim attribution, numeric fidelity, omission of limitations, untrusted-content handling and refusal. Disable model if validation or service fails; report source status.

**Stack:** Jinja2, JSON Schema/Pydantic, SQLite FTS5, optional sentence-transformers, ONNX Runtime/llama.cpp for local inference, HF Hub CLI, optional approved external provider adapter. `GET /api/v1/runs/{id}/evidence`, `GET /api/v1/runs/{id}/report`, `POST /api/v1/runs/{id}/explanations` with bounded question; `GET /api/v1/artifacts/{id}`.
**Stack:** bounded offline templates, JSON Schema/Pydantic, SQLite FTS5, and an optional adapter boundary that is disabled unless explicitly configured. `GET /api/v1/runs/{id}/evidence`, `GET /api/v1/runs/{id}/report`, `POST /api/v1/runs/{id}/explanations` with bounded question; `GET /api/v1/artifacts/{id}`.

**Network / security:** model adapter receives redacted text, never filesystem paths, credentials, database access or tools. Local process / localhost; external provider HTTPS only after consent, project policy and allowed-domain check. Model responses treated as untrusted; no automatic execution or new analysis authorization. Evidence returns a content digest, model outputs versioned separately.

Expand Down
Loading
Loading