Skip to content

Enforce dose context before text fast path#575

Merged
BigSimmo merged 2 commits into
mainfrom
codex/dose-fast-path-context
Jul 13, 2026
Merged

Enforce dose context before text fast path#575
BigSimmo merged 2 commits into
mainfrom
codex/dose-fast-path-context

Conversation

@BigSimmo

Copy link
Copy Markdown
Owner

Summary

  • resolve the P1 review finding from Fix clinical-subject dose retrieval #571 by applying the contextual medication-dose coverage gate before the earliest text fast-path return
  • require numeric dose amounts only for explicit dose-amount questions, and route evidence for route questions
  • preserve non-dose pathway/monitoring behavior even when the broad query classifier selects medication_dose_risk
  • treat recommendation/patient wording as query framing rather than extra clinical subjects
  • make fallback tests model the embedding rescue path when weak dose evidence is correctly rejected

Verification

  • focused clinical retrieval/fallback suites: 6 files, 151 tests passed
  • npm run eval:rag:offline: 21 files, 265 tests passed
  • TypeScript passed
  • targeted ESLint passed
  • diff check passed

Review resolution

Fixes the P1 inline finding at #571 discussion r3569692474 by preventing mixed opioid-context/unrelated-dose evidence from bypassing evaluateEvidenceCoverageGate.

@supabase

supabase Bot commented Jul 13, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@BigSimmo
BigSimmo enabled auto-merge (squash) July 13, 2026 10:34
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Medication dose query filtering now recognizes more generic terms and detects explicit dose-evidence requests. RAG fast-path decisions use contextual dose, amount, route, and agitation evidence checks, with tests covering accepted and rejected contexts.

Changes

Medication dose evidence gating

Layer / File(s) Summary
Dose evidence query classification
src/lib/clinical-search.ts
Medication dose subject filtering excludes additional generic terms, and a helper detects explicit dose, route, and frequency evidence requests.
Contextual fast-path coverage gate
src/lib/rag.ts, tests/retrieval-query-variants.test.ts, tests/rag-answer-fallback.test.ts
Medication dose fast-pathing uses contextual coverage checks, while tests cover matching and missing dose context and provide a concrete embedding mock.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant decideTextFastPath
  participant isMedicationDoseEvidenceQuery
  participant evaluateEvidenceCoverageGate
  decideTextFastPath->>isMedicationDoseEvidenceQuery: classify query
  isMedicationDoseEvidenceQuery-->>decideTextFastPath: explicit evidence request
  decideTextFastPath->>evaluateEvidenceCoverageGate: evaluate contextual dose coverage
  evaluateEvidenceCoverageGate-->>decideTextFastPath: accepted decision or failure reason
Loading

Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (2 errors)

Check name Status Explanation Resolution
Verification Claims ❌ Error PR verification bullets claim passes generically ('TypeScript passed', 'targeted ESLint passed', etc.) without exact commands/checks; only eval:rag:offline is named. Rewrite each verification item as an exact command/check plus result, e.g. 'Ran npm run typecheck: passed' or 'Not run: reason'.
Api Route Failure Handling ❌ Error Common explicit dose/frequency queries like “how much/how often” still bypass the new gate because isMedicationDoseEvidenceQuery only matches keyword tokens. Expand the detector to cover plain-language dose/route/frequency phrasing, or route all medication_dose_risk queries through evaluateEvidenceCoverageGate.
✅ Passed checks (9 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately captures the main change: enforcing dose context before the text fast path.
Description check ✅ Passed Summary, verification, and review-resolution are present and specific to the change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Generated And Sensitive Files ✅ Passed The PR only changes workflows, package.json, and regenerated package-lock.json; no real secrets, .env files, build artifacts, or local dumps are present.
Risky Git Or Deployment Actions ✅ Passed PASS: The changed workflows/package scripts contain no force-push/reset/clean/delete/rebase guidance or unguarded deployment steps; eval-canary explicitly requires a green workflow_dispatch check.
Supabase Project And Schema Safety ✅ Passed PR only changes clinical-search/RAG logic and tests; no Supabase project refs, env examples, migrations, schema, RLS, or policy files were touched.
Runtime And Package Manager Integrity ✅ Passed package.json/package-lock still pin npm@11.17.0 and Node 24.x, .npmrc keeps engine-strict=true, and workflows still use npm ci.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/dose-fast-path-context
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch codex/dose-fast-path-context

Comment @coderabbitai help to get the list of available commands.

@BigSimmo
BigSimmo merged commit bafceee into main Jul 13, 2026
14 of 15 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 26c93547d8

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

Comment thread src/lib/rag.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/clinical-search.ts`:
- Around line 1147-1152: Expand and make the shared
isMedicationDoseEvidenceQuery detector intent-aware, covering explicit amount,
frequency, and administration wording such as “how much,” “how often,”
“micrograms,” and oral/intramuscular administration. In
src/lib/clinical-search.ts lines 1147-1152 update the shared predicate; in
src/lib/rag.ts lines 2612-2615 ensure every matching explicit query enters the
coverage gate; and in src/lib/rag.ts lines 2929-2931 reuse the shared
amount/route predicates so gate requirements remain consistent.

In `@src/lib/rag.ts`:
- Around line 2953-2962: The failure-reason chain in the acceptance result must
only report missing dose amount evidence when the query requests an amount.
Update the `!hasDoseAmount` branch to also require `asksDoseAmount`, preserving
route-only queries so they can correctly return `missing_route_evidence`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1121ed1f-b25c-4ec5-bf6a-a6646fd962de

📥 Commits

Reviewing files that changed from the base of the PR and between 343531b and 26c9354.

📒 Files selected for processing (4)
  • src/lib/clinical-search.ts
  • src/lib/rag.ts
  • tests/rag-answer-fallback.test.ts
  • tests/retrieval-query-variants.test.ts

Comment thread src/lib/clinical-search.ts
Comment thread src/lib/rag.ts
@BigSimmo
BigSimmo deleted the codex/dose-fast-path-context branch July 13, 2026 16:33
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.

1 participant