Fix clinical dose-verification & safety gaps missed by early-merged #38#41
Merged
Conversation
…rged #38 Re-applies the 6 blocking clinical-safety fixes (B1-B6) on top of current main. PR #38 merged 22 RAG fixes before these blockers landed, and #39/#40 did not address them, so main still trusts wrong doses. - B1: numeric verification now matches by exact normalized token-set membership instead of substring, so "2.5 mg" no longer verifies against "12.5 mg" (5x dose error). Fails closed. - B2: fold unicode superscripts (×10⁹/L) to ASCII before extraction/match. - B3: percentage branch no longer ends in \b (which could never match), so percentages extract and percentage mismatches are flagged. - B4: numeric gate now scans answerSections[].body (medication_dose), scoped to each section's citation_chunk_ids. - B5: safeFallbackAnswer fails closed on parse failure (ungrounded, no citation back-fill) and still runs the numeric gate; extractive recovery and strong-retry routing updated accordingly. - B6: retry route reset is a single conditional UPDATE guarded on status/locked_at; 0 rows affected => 409, closing the TOCTOU race. - N1: verifyAnswerNumbers fails closed when no cited chunk maps to a result. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
3 tasks
BigSimmo
added a commit
that referenced
this pull request
Jul 25, 2026
cursor Bot
pushed a commit
that referenced
this pull request
Jul 25, 2026
* docs: close ledger #9 #10 #32 #41 #63 Record ops-only /api/jobs decision, coming-soon audit, governance ranking REFUTED guardrail, Factsheets reading-model brief, and Current Clinical Work privacy/persistence brief. Archive the five open items; no RAG or application behavior changes. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com> * fix(ci): prettier ledger docs and drop stale PR_POLICY_BODY Static PR checks failed on Prettier for five docs files. Also remove leftover PR_POLICY_BODY.md from merged #1134 so Sync PR policy body stops overwriting this docs PR description. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com> * docs: record PR #1175 review ledger outcome Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com> * chore: restore PR #1175 description via PR_POLICY_BODY sync Temporary template so CI Sync PR policy body replaces the polluted search-performance description left from merged #1134. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com> * chore: remove temporary PR_POLICY_BODY after description sync Keep the corrected PR #1175 description without leaving the sync template on the branch for merge to main. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com> * docs: supersede PR #1175 review ledger after body sync Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com> * style: prettier-format outstanding-issues after ledger merge --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
PR #38 (22 RAG fixes) was merged early at
ab27de3, before the 6 critical blocking safety fixes were added. Those fixes lived onfix/rag-pipeline-stage3-generation(26a8a6d) and never reachedmain. PR #39 (security/safety) and PR #40 (RAG/search) since landed but did not address any of B1-B6. This PR re-implements the still-missing blockers against currentmain.Gap analysis — all 6 were still missing on main
2.5 mg⊂12.5 mg)despacedHaystack.includes(...))×10⁹/Lmangled to2.0×10⁰¹²…⁹→ ASCII before extract/match\bafter%)%branch no longer ends in\banswerSections[].bodyanswer.answer)citation_chunk_idssafeFallbackAnswerback-fills citations +grounded:true, skips numeric gateUPDATE … WHERE status≠processing OR lock stale/null; 0 rows ⇒ 409None of B1-B6 were already addressed by #39/#40; #39/#40 only hardened the regex units and the warning text. All six were re-applied here, ported to main's diverged code (e.g. retry route keeps main's
status:"pending", regex keeps main'smmol/[lL]units).Empirical B1 verification (the top-priority dose fix)
Run against the new
verifyAnswerNumbers:All four required outcomes confirmed — wrong doses now fail closed; exact doses verify.
Testing
npm run typecheck— passesnpm run lint— passes (0 errors; 1 pre-existing unrelated warning insrc/lib/chunking.ts)npm run test— 381 passed (55 files), including the new B1-B6/N1 regression testsanswer-verification,rag-trust,private-access-routes) — 79 passedNew/updated regression tests cover: B1 (2.5↔12.5, 500↔1500, 2.0↔12.0 + exact match), B2 (superscript extract + superscript↔ASCII match), B3 (percentage extract + mismatch flag), B4 (section-body dose flagged / verified), B5 (fail-closed fallback + numeric gate on parse-failure prose), B6 (refuse fresh-processing 409 / allow stale-or-non-processing), N1 (fail closed on unmapped citation).
🤖 Generated with Claude Code