- Notifications
You must be signed in to change notification settings - Fork 0
test(eval): scope danger warnings to answered routes; re-accept metadata debt at 0.6#176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
36b7fa5
test(eval): scope danger-warning failures to answered routes; re-acce…
BigSimmo 14b129f
test(eval): key danger-warning failures on grounded, not route (revie…
BigSimmo 3c34fad
Merge branch 'main' into claude/eval-governance-hygiene
BigSimmo 867bb00
Merge branch 'main' into claude/eval-governance-hygiene
BigSimmo 95ce58b
test(eval): fail refusals that drop an expected danger warning
BigSimmo 89ac096
Merge branch 'main' into claude/eval-governance-hygiene
BigSimmo df7c57a
style: prettier-format source-review-priority doc
BigSimmo 79e1aff
fix(eval): mirror governance refusal delivery
BigSimmo 2b78614
fix(eval): flag source-insufficient warning cases
BigSimmo 4447ba8
fix(eval): detect persisted governance warning strings
BigSimmo 23aa990
fix(eval): match only canonical danger messages in captured warnings
BigSimmo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Source review priority list — 2026-07-02 | ||
| ## Why this list exists | ||
| The release quality eval's top-result `review_required_rate` rose from 0.14 (accepted 2026-07-02 morning, | ||
| ceiling 0.2) to 0.5398 in the afternoon run. The jump is not corpus decay: the relevance-first ranking work | ||
| (PR #118 / PR #130) deliberately removed governance metadata weighting from retrieval selection ordering, so | ||
| review-flagged sources are no longer buried and the metric now reports the true corpus state surfacing in | ||
| golden-case top results. The bounded debt acceptance in | ||
| `docs/release-source-metadata-debt-2026-06-30.json` was re-accepted at a 0.6 ceiling (expiry unchanged, | ||
| 2026-07-31) on the condition that the documents below are clinically reviewed first. | ||
| Corpus context (live DB, 2026-07-02): 2,065 indexed documents — 1,397 current/locally_reviewed, 481 | ||
| `review_due`, 132 `unknown` status, 130 `unverified` validation, 0 outdated, 0 poor-extraction. | ||
| ## Burn-down math | ||
| Eval run `retrieval-quality-2026-07-02T08-37-08-387Z`: 113 top-5 slots across 23 golden cases; 61 slots | ||
| review-required (31 `review_due` + 37 `unverified`, overlapping). **25 distinct documents account for all 61 | ||
| slots.** Reviewing the 12 documents with 2+ slots clears 47 slots, taking the rate from 0.54 to roughly 0.12 | ||
| — back under the original 0.2 ceiling. | ||
| ## Priority order (golden top-5 slot count) | ||
| | Slots | Document | Status flag | Validation flag | Golden cases hit | | ||
| | ----: | --------------------------------------------------------------------------------------------- | ----------- | --------------- | ---------------------------------------------------------------------------------- | | ||
| | 8 | Clozapine Management by GP (NMHS).pdf | review_due | — | show-source-table-image, monitoring-threshold-from-chart | | ||
| | 6 | Opioid use disorder.pdf | — | unverified | opioid-use-disorder-management, opioid-withdrawal-doses | | ||
| | 6 | Bipolar disorder in adults.pdf | — | unverified | bipolar-management-summary, bipolar-vs-schizoaffective, lithium-therapy-monitoring | | ||
| | 5 | Alcohol withdrawal.pdf | review_due | unverified | alcohol-withdrawal-management, alcohol-ciwa-threshold | | ||
| | 5 | Postnatal depression.pdf | — | unverified | depression-adults-vs-children, postnatal-depression-treatment | | ||
| | 5 | Alcohol and Other Drugs - Addiction, Toxicity and Withdrawal (FSH).pdf | review_due | — | alcohol-ciwa-scoring, alcohol-ciwa-threshold | | ||
| | 4 | Schizophrenia.pdf | — | unverified | clozapine-anc-threshold, schizophrenia-overview | | ||
| | 2 | Arousal and Agitation Drug Management (CAMHS).pdf | review_due | — | agitation-im-po-options, medication-chart-dose-route | | ||
| | 2 | Depression in adults.pdf | — | unverified | depression-adults-vs-children | | ||
| | 2 | Depression in children.pdf | — | unverified | depression-adults-vs-children | | ||
| | 2 | Schizoaffective disorder.pdf | review_due | unverified | bipolar-vs-schizoaffective | | ||
| | 1 | Clozapine GP Shared Care (FSH).pdf | review_due | — | clozapine-anc-threshold | | ||
| | 1 | ED CNS Roles and Responsibilities (RPBG).pdf | review_due | — | active-community-patient-ed | | ||
| | 1 | Discharge Follow-Up for Inpatients (FSH).pdf | review_due | — | admission-discharge-comparison | | ||
| | 1 | Resuscitation and Responding to Clinical Deterioration - MET Review and Code Blue (CAMHS).pdf | review_due | — | flowchart-next-step | | ||
| | 1 | Dyssomnias in children.pdf | — | unverified | insomnia-assessment-management | | ||
| | 1 | Assessment of fatigue.pdf | — | unverified | insomnia-assessment-management | | ||
| | 1 | Insomnia.pdf | — | unverified | insomnia-assessment-management | | ||
| | 1 | Suicide risk mitigation.pdf | — | unverified | suicide-risk-mitigation-guidance | | ||
| | 1 | Advance Health Directive (AKG).pdf | review_due | — | schizophrenia-overview | | ||
| | 1 | Alcohol use disorder.pdf | — | unverified | alcohol-ciwa-scoring | | ||
| | 1 | NS IPWU Transfer from Methadone to Buprenorphine OST SOP (RPBG).pdf | review_due | — | opioid-withdrawal-doses | | ||
| | 1 | Analgesia and Sedation Assessment in PCC (CAMHS).pdf | review_due | — | opioid-withdrawal-doses | | ||
| | 1 | Electroconvulsive Therapy Policy and Procedure (RKPG).pdf | review_due | — | bipolar-vs-schizoaffective | | ||
| | 1 | ECT Registrar Role (FSH).pdf | review_due | — | bipolar-vs-schizoaffective | | ||
| ## How to clear a flag (per the debt-acceptance follow-up rules) | ||
| - `review_due` → confirm the source is still the current published version, then backfill | ||
| `documents.metadata.document_status` to `current`. Do not mark current without confirming source | ||
| currentness. | ||
| - `unverified` → complete local clinical review, then backfill | ||
| `documents.metadata.clinical_validation_status` to `locally_reviewed`. Do not mark reviewed without an | ||
| actual local review. | ||
| - After updating metadata, re-run `npm run eval:quality:release` and tighten | ||
| `max_review_required_rate` in the debt file back toward 0.2 (or delete the debt file if under threshold). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -109,6 +109,16 @@ export function sourceWarningsForRagQualityAnswer( | ||
| ); | ||
| } | ||
| export function deliveredGroundedAfterSourceGovernancePolicy( | ||
| answer: Pick<RagAnswer, "grounded" | "confidence" | "responseMode">, | ||
| warnings: Array<{ severity: string }>, | ||
| ) { | ||
| const shouldUseSourceGovernanceRefusal = | ||
| answer.grounded !== false && answer.confidence !== "unsupported" && answer.responseMode !== "evidence_gap"; | ||
| if (shouldUseSourceGovernanceRefusal && warnings.some((warning) => warning.severity === "danger")) return false; | ||
| return answer.grounded; | ||
| } | ||
| const qualityThresholds = { | ||
| retrievalTopKHitRate: 0.8, | ||
| retrievalDocumentRecallAt5: 0.8, | ||
| @@ -214,6 +224,34 @@ export function qualityFailureCategory(message: string): QualityFailureCategory | ||
| return "other"; | ||
| } | ||
| export function sourceGovernanceDangerFailuresForAnswer(args: { | ||
| grounded: boolean; | ||
| sourceDangerWarningCount: number; | ||
| expectsDangerWarning?: boolean; | ||
| }): string[] { | ||
| const failures: string[] = []; | ||
| // A danger warning is a governance failure only when a grounded answer was | ||
| // actually delivered on that sourcing. Declined answers carry the danger | ||
| // warning as the expected refusal signal, not a failure. `grounded` is the | ||
| // robust signal for "an answer was delivered": it covers both `unsupported` | ||
| // routes and answers that a fast/strong/extractive route converted into an | ||
| // evidence-gap refusal (finalizeRagAnswerQualityCore sets grounded=false | ||
| // while preserving the original routingMode). | ||
| if (args.grounded && args.sourceDangerWarningCount > 0) { | ||
| failures.push("danger source governance warning present"); | ||
| } | ||
| // Refusal-safety guard: exempting ungrounded answers above must not let a | ||
| // refusal that is *expected* to surface a danger warning pass as clean when it | ||
| // silently drops that warning. For cases flagged expectsSourceDangerWarning, | ||
| // a missing danger warning is a failure regardless of grounded — otherwise a | ||
| // regression that stops emitting the warning would keep the danger failure | ||
| // rate at 0 and go undetected. | ||
| if (args.expectsDangerWarning && args.sourceDangerWarningCount === 0) { | ||
| failures.push("expected danger source governance warning missing"); | ||
| } | ||
| return failures; | ||
| } | ||
| function rate(numerator: number, denominator: number) { | ||
| return denominator === 0 ? 0 : Number((numerator / denominator).toFixed(4)); | ||
| } | ||
| @@ -367,7 +405,12 @@ function summarizeRagQualityResults(results: RagQualityResult[]) { | ||
| result.failures.some((failure) => qualityFailureCategory(failure) === "numeric_grounding"), | ||
| ); | ||
| const sourceGovernanceWarnings = results.filter((result) => result.sourceWarningCount > 0); | ||
| const sourceGovernanceDangerFailures = results.filter((result) => result.sourceDangerWarningCount > 0); | ||
| const sourceGovernanceDangerFailures = results.filter( | ||
| (result) => result.grounded && result.sourceDangerWarningCount > 0, | ||
| ); | ||
| const expectedDangerWarningMissing = results.filter((result) => | ||
| result.failures.includes("expected danger source governance warning missing"), | ||
| ).length; | ||
| const latencies = results.map((result) => result.latencyMs); | ||
| const routeLatencyP95 = Object.fromEntries( | ||
| Array.from( | ||
| @@ -395,6 +438,7 @@ function summarizeRagQualityResults(results: RagQualityResult[]) { | ||
| source_warning_count: results.reduce((sum, result) => sum + result.sourceWarningCount, 0), | ||
| source_governance_warning_rate: rate(sourceGovernanceWarnings.length, results.length), | ||
| source_governance_danger_failure_rate: rate(sourceGovernanceDangerFailures.length, results.length), | ||
| expected_danger_warning_missing_count: expectedDangerWarningMissing, | ||
| median_latency_ms: percentile(latencies, 50), | ||
| p95_latency_ms: percentile(latencies, 95), | ||
| route_p95_latency_ms: routeLatencyP95, | ||
| @@ -468,6 +512,14 @@ export function buildEvalQualityReport(args: { | ||
| `RAG source_governance_danger_failure_rate ${ragSummary.source_governance_danger_failure_rate} above 0`, | ||
| ); | ||
| } | ||
| if (ragSummary.expected_danger_warning_missing_count > 0) { | ||
| // A refusal that was expected to surface a danger warning dropped it. This | ||
| // is a refusal-safety regression and hard-blocks release — it is never | ||
| // waivable via the source-metadata debt acceptance below. | ||
| thresholdFailures.push( | ||
| `RAG expected_danger_warning_missing_count ${ragSummary.expected_danger_warning_missing_count} above 0`, | ||
| ); | ||
| } | ||
| if (ragSummary.p95_latency_ms > qualityThresholds.ragP95LatencyMs) { | ||
| thresholdFailures.push( | ||
| `RAG p95_latency_ms ${ragSummary.p95_latency_ms} above ${qualityThresholds.ragP95LatencyMs}`, | ||
| @@ -752,7 +804,14 @@ async function runRagQualityCases(args: { | ||
| const failures = [...validation.failures]; | ||
| const sourceWarnings = sourceWarningsForRagQualityAnswer(answer); | ||
| const sourceDangerWarningCount = sourceWarnings.filter((warning) => warning.severity === "danger").length; | ||
| if (sourceDangerWarningCount > 0) failures.push("danger source governance warning present"); | ||
| const deliveredGrounded = deliveredGroundedAfterSourceGovernancePolicy(answer, sourceWarnings); | ||
| failures.push( | ||
| ...sourceGovernanceDangerFailuresForAnswer({ | ||
| grounded: deliveredGrounded, | ||
| sourceDangerWarningCount, | ||
| expectsDangerWarning: testCase.expectsSourceDangerWarning, | ||
| }), | ||
| ); | ||
| results.push({ | ||
| id: testCase.id, | ||
| @@ -764,7 +823,7 @@ async function runRagQualityCases(args: { | ||
| missingFiles: validation.expectedCoverage.missingFiles, | ||
| topFiles: answer.sources.slice(0, 5).map((source) => source.file_name), | ||
| expectedHit: validation.expectedHit, | ||
| grounded: answer.grounded, | ||
| grounded: deliveredGrounded, | ||
BigSimmo marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| latencyMs: answer.latencyTimings?.total_latency_ms ?? 0, | ||
| route: answer.routingMode ?? "none", | ||
| model: answer.modelUsed ?? null, | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.