Skip to content

[WIP] Refactor monolithic front‑end and decouple domain logic#58

Closed
BigSimmo with Copilot wants to merge 8 commits into
mainfrom
copilot/refactor-monolithic-front-end
Closed

[WIP] Refactor monolithic front‑end and decouple domain logic#58
BigSimmo with Copilot wants to merge 8 commits into
mainfrom
copilot/refactor-monolithic-front-end

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor
  • Extract pure utility functions from worker/main.ts to worker/utils.ts
  • Extract image-processing stage from worker/main.ts to worker/stages/images.ts
  • Extract chunk/embed stage from worker/main.ts to worker/stages/chunks.ts
  • Update worker/main.ts to import from new stage modules
  • Extract source-display utilities from ClinicalDashboard.tsx to src/lib/source-display.ts
  • Extract useRecentQueries custom hook to src/components/clinical-dashboard/use-recent-queries.ts
  • Update ClinicalDashboard.tsx to import from new modules
  • Add tests/worker-utils.test.ts for worker utility functions
  • Add tests/source-display.test.ts for source display utilities
  • Run full test suite to verify nothing is broken

@BigSimmo
BigSimmo removed their request for review June 23, 2026 05:43
@BigSimmo
BigSimmo marked this pull request as ready for review June 23, 2026 05:51
@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

https://github.com/BigSimmo/Database/blob/76e9b609ed6004815ef89772b78f3eab4f7106c2/.github/workflows/codeql.yml#L12
P2 Badge Restore the CodeQL scanning workflow

For pushes/PRs to main/protection and the scheduled scan, deleting this workflow means CodeQL no longer analyzes the repo's Actions, JS/TS, or Python code. I checked the remaining .github/workflows/ci.yml and secret-scan.yml plus a repo-wide codeql search; only tests and gitleaks remain, so environments that rely on GitHub code-scanning alerts or branch checks lose that coverage unless this workflow is restored or replaced.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@BigSimmo BigSimmo closed this Jun 26, 2026
@BigSimmo
BigSimmo deleted the copilot/refactor-monolithic-front-end branch June 26, 2026 12:18
BigSimmo pushed a commit that referenced this pull request Jul 21, 2026
BigSimmo added a commit that referenced this pull request Jul 21, 2026
…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>
BigSimmo pushed a commit that referenced this pull request Jul 21, 2026
…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
BigSimmo pushed a commit that referenced this pull request Jul 21, 2026
BigSimmo pushed a commit that referenced this pull request Jul 21, 2026
…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
BigSimmo added a commit that referenced this pull request Jul 21, 2026
…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>
BigSimmo pushed a commit that referenced this pull request Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants