feat(rag): pre-generation validated-extractive short-circuit for routine procedural queries (E-3c PR-B)#1032
Conversation
…ine procedural queries (E-3c PR-B)
Generalizes the existing validated-extractive short-circuit pattern (LAI +
blocked-recovery precedents) to the measured wasted-generation shape: fast
attempts on strong_routine_retrieval procedural queries ('What is the
process/required...') whose deterministic extractive answer already passes the
FULL final-gate stack now skip the doomed generation entirely (marker
validated_routine_extractive_first). Run-#57 evidence: 6 of 44 cases burned a
full generation that the extractive fallback then replaced. The three
predicates move verbatim to a new rag-extractive-first.ts module (machine-
verified), taking rag.ts from 5029 to 4908 lines against its 5030 budget.
Existing marker strings, precedence, and reason formatting byte-identical.
Red-proof: the short-circuit test fails on prior code two independent ways;
negative guards pin 'How is...' shapes, gate-failing candidates, and
dose-class queries on model synthesis. Full suite 3061 passed.
RAG impact: behaviour change (answer routing only) - canary pair #57/#58 -> E-4
planned post-merge; retrieval, ranking, selection, thresholds untouched.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9
…ve gate (governance P2)
Post-review hardening, disclosed: a redirect-only lead sharing query terms
('Refer to the X procedure for...') passed the overlap gate and could ship
from any of the three short-circuit paths. hasValidatedExtractiveCandidate now
screens isBareCrossReferenceAnswer, strictly narrowing what can short-circuit;
such queries stay on model synthesis. Discriminating test added; 61/61 green.
Ledger row records both reviewer verdicts and the pre-merge branch-canary
merge gate.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
📝 WalkthroughWalkthroughAdds centralized validated extractive short-circuit predicates, integrates them into RAG routing before generation, and adds coverage for procedural, recovery, LAI-management, cross-reference, and medication dose-risk cases. ChangesValidated extractive routing
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant RAGRequest
participant RAGRouting
participant ExtractiveSelector
participant TextGeneration
RAGRequest->>RAGRouting: submit query and retrieval results
RAGRouting->>ExtractiveSelector: evaluate route, source backing, and gate status
ExtractiveSelector-->>RAGRouting: reason marker or null
alt validated extractive candidate
RAGRouting-->>RAGRequest: return extractive grounded answer
else no validated candidate
RAGRouting->>TextGeneration: generateStructuredTextResult
TextGeneration-->>RAGRequest: return synthesized answer
end
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Summary
E-3c PR-B — kills the measured 6× wasted-generation class from baseline run #57: fast-model attempts on routine procedural queries ("What is the process for ECT?", "What should a patient safety plan include?") that fail the answer quality gate and get replaced by the deterministic extractive answer anyway, burning seconds and tokens for nothing.
The fix generalizes the codebase's own proven pattern (the LAI and blocked-recovery short-circuits): when such a query's extractive candidate independently passes the complete final-gate stack (
finalizeRagAnswerQuality— core quality + claim support + numeric verification), the route flips to extractive before generation (markervalidated_routine_extractive_first). Scope is deliberately narrow: fast route +strong_routine_retrievalreason + passed confidence gate + source-backed +document_lookup/unsupported_or_generalclass only + "What…process/include/required" shape — dose, threshold, comparison, broad-summary, and "How is X managed" shapes all stay on model synthesis (pinned by negative tests).The three existing predicates move byte-verbatim (machine-verified brace-diff) into new
src/lib/rag/rag-extractive-first.ts, takingrag.tsfrom 5029 to 4908 lines against its 5030 no-growth budget.Both reviewer subagents pre-push, no P0/P1:
isBareCrossReferenceAnswernow screens every short-circuit path, strictly narrowing what can ship (discriminating test added; 61/61 green).Merge gate — held as draft until the live pair is green. Per the standing lesson (offline-green + review-approved proven insufficient for this surface, 2026-07-20), a branch canary dispatch (
ref= this branch,answer_case_limit=44+answer_quality_eval=true, ~$3–6 of the user-approved envelope) runs the full answer-side pair against the banked #57/#58 baselines before this merges. Green = zero per-case regressions, recalls pinned 1.0, quality/targeting rates ≥ baseline, and the 6 target cases showing the short-circuit marker.RAG impact: behaviour change — canary pair: baselines #57 (29786560936) / #58 (29788404357) → branch run (dispatching now; result recorded here before ready-for-review). Answer routing only; retrieval, ranking, selection, and thresholds untouched (adversarially verified).
Verification
npm run test— 3061 passed / 1 known container-only pdf artifactRisk and rollout
Clinical Governance Preflight
Clinical KB Database(sjrfecxgysukkwxsowpy) — no access changes🤖 Generated with Claude Code
https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9
Generated by Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests