[WIP] Refactor monolithic front‑end and decouple domain logic#58
Conversation
💡 Codex Reviewhttps://github.com/BigSimmo/Database/blob/76e9b609ed6004815ef89772b78f3eab4f7106c2/.github/workflows/codeql.yml#L12 For pushes/PRs to ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9
…lemetry (Phase E-3b) (#1028) * feat(rag): budget-aware generation deadlines + retrieval-exhausted telemetry (E-3b core) Implements the E-3b design: generation attempts are clamped to the route budget minus a measured 2s recovery reserve (single call-site covers all four attempt kinds); the truncation self-heal is gated on retry viability (reserve + 5s floor) with an observable truncation_retry_skipped_budget_reserve marker instead of a guaranteed-discard retry; the runtime records an additive route_budget_exhausted_by_retrieval flag; and the eval route-ceiling gate gains the triple-condition cross-region carve-out (context + runtime flag + zero generation) with a retrieval-exhausted audit cell - local/release gates stay strict, pinned by new unit tests. Unit coverage: route-budget 9/9 (constants + reserve/floor boundaries), eval-quality 27/27 (carve-out matrix). Integration tests for the fallback paths follow in the next commit. RAG impact: no retrieval behaviour change - answer-side timing/gating and telemetry only; retrieval, ranking, selection, comparators untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9 * test(rag): E-3b integration coverage — budget cap red-proof, self-heal gate, retrieval-exhausted flag Five fake-timer integration tests: the reserve-aware timeout is pinned three independent ways (exact 23000ms grant, deadline flag stays clear, total under budget - a revert to requestTimeoutMs fails all three); the truncation self-heal skip pins the exact answer_retry_reasons marker with no retry-count increment and provider called once; the offline harness pins route_budget_exhausted_by_retrieval both true (13s retrieval on a 12s extractive budget, provider never called, grounded extractive answer) and false (fast retrieval). 52/52 across both files. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9 * docs(ledger): clinical-governance review row for the E-3b diff (APPROVE-WITH-NITS) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9 * docs(ledger): E-3b implementation row + run #58 targeting baseline bank Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9 * fix(rag): trim E-3b comments to fit the rag.ts no-growth maintainability budget Static-pr caught rag.ts at 5033 lines vs the 5030 no-growth budget - the E-3b additions tipped the tracked monolith over its cap. Rationale comments live in rag-route-budget.ts and the design record; the rag.ts copies shrink to one-liners (comments only, zero logic change - suites re-verified). The real extraction debt stays tracked in the maturity audit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9 --------- Co-authored-by: Claude <noreply@anthropic.com>
…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
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9
…ers (E-3c PR-C) Dose and monitoring answers must carry the asked-for figure/schedule when a cited chunk verbatim supports it (run-#58 baseline: targeting 1/5 on both intents, every miss = missing figure). Lead-slot promotion swaps/appends the first later figure-bearing fact ONLY when no lead carries one, guarded by the claim-support atom corpus (sourceEvidenceText, now exported) so a promoted figure can never convert a grounded answer into an evidence gap - the guard proven load-bearing by red-testing it disabled. The dose/threshold generation fallback now prefers the safe candidate that carries the intent figure over the first safe one; the safety gate itself is unchanged. Fallback helpers extracted to rag-extractive-answer (cycle-check verified); rag.ts 4908->4901. Six discriminating tests, each verified failing on prior code. Full suite 3068 passed / 1 known container artifact. RAG impact: behaviour change (extractive answer composition + fallback candidate preference only) - E-4 pair vs banked #57/#58/#59 baselines post-merge; retrieval, ranking, selection ordering untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9
…ers (E-3c PR-C) (#1039) * docs(ledger): E-3b + PR-B live pair verdict (run #59 green vs #57/#58) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9 * feat(rag): figure-aware extractive selection for dose/monitoring answers (E-3c PR-C) Dose and monitoring answers must carry the asked-for figure/schedule when a cited chunk verbatim supports it (run-#58 baseline: targeting 1/5 on both intents, every miss = missing figure). Lead-slot promotion swaps/appends the first later figure-bearing fact ONLY when no lead carries one, guarded by the claim-support atom corpus (sourceEvidenceText, now exported) so a promoted figure can never convert a grounded answer into an evidence gap - the guard proven load-bearing by red-testing it disabled. The dose/threshold generation fallback now prefers the safe candidate that carries the intent figure over the first safe one; the safety gate itself is unchanged. Fallback helpers extracted to rag-extractive-answer (cycle-check verified); rag.ts 4908->4901. Six discriminating tests, each verified failing on prior code. Full suite 3068 passed / 1 known container artifact. RAG impact: behaviour change (extractive answer composition + fallback candidate preference only) - E-4 pair vs banked #57/#58/#59 baselines post-merge; retrieval, ranking, selection ordering untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9 * fix(rag): verbatim-corpus check for zero-atom figure promotion (reviewer P2) Both reviewers converged on the gap: bare-number intervals like 'every 6 weeks' match the monitoring figure pattern yet yield no clinical value atom, so the atom-only guard passed them trivially - a figure sourced only from adjacent context could then be promoted and nuked by claim support (safe direction, but converts a shippable answer into an evidence gap). Zero-atom figures now require the matched figure substring verbatim in the citing chunk's claim-support corpus (intentFigureMatchText). Proven both directions by three new tests; comment-precision nit on the corpus lockstep folded in. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9 * fix(rag): full-interval figure matching + genuine zero-atom guard coverage CodeRabbit review on the P2 guard: reorder monitoringIntervalFigurePattern so the unit-bearing "every N unit" alternative precedes bare "every N" — exec() now returns the full schedule instead of a truncated "every 6". Digit+unit intervals turn out to produce quantity atoms (6/week), so atom identity already refuses unit mismatches; the reorder hardens the verbatim fallback against atom-coverage drift, and both comments claiming "every 6 weeks" is zero-atom are corrected. The non-discriminating first guard test is replaced with a mismatched-unit pin (shared number, different unit, figure only in adjacent context) plus two genuinely zero-atom tests ("annually") that exercise the verbatim-corpus path both directions. promotionAtomKey hand-mirror replaced by exporting clinicalValueAtomKey from rag-claim-support. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9 --------- Co-authored-by: Claude <noreply@anthropic.com>
…59) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9
worker/main.tstoworker/utils.tsworker/main.tstoworker/stages/images.tsworker/main.tstoworker/stages/chunks.tsworker/main.tsto import from new stage modulesClinicalDashboard.tsxtosrc/lib/source-display.tsuseRecentQueriescustom hook tosrc/components/clinical-dashboard/use-recent-queries.tsClinicalDashboard.tsxto import from new modulestests/worker-utils.test.tsfor worker utility functionstests/source-display.test.tsfor source display utilities