Skip to content

fix: fail closed on missing answer relevance#1125

Merged
BigSimmo merged 15 commits into
mainfrom
codex/answer-relevance-fail-closed
Jul 24, 2026
Merged

fix: fail closed on missing answer relevance#1125
BigSimmo merged 15 commits into
mainfrom
codex/answer-relevance-fail-closed

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Require explicit isSourceBacked: true before an answer receives high render trust or a grounded dashboard state.
  • Suppress visual/table evidence when relevance is missing or explicitly not source-backed.
  • Make the clinical-notes drawer consume only render-model-approved visual evidence, including its fallback clinical-output path.
  • Add policy and jsdom regressions for missing relevance, canonical tables, clipboard output, and the clinical-notes Tables affordance.

RAG impact: no retrieval behaviour change — this only tightens render-time trust and evidence visibility when relevance metadata is not affirmatively source-backed.

Verification

  • npm run verify:pr-local — before the review follow-ups, runtime, formatting, lint, typecheck, 366 test files (3,254 passed/1 skipped), production build (1,677 pages), client-bundle secret scan, and RAG fixture validation passed.
  • npm run verify:ui — before the review follow-ups, 267/267 Chromium scenarios passed against the isolated production build; fresh exact-head hosted Production UI is required after the final UI fix.
  • npm run check:production-readiness — READY for configured Clinical KB Database; read-only, with no provider request or mutation.
  • npm run eval:rag:offline — 36/36 fixtures, 21 suites, and 308 tests passed.
  • npx vitest run tests/answer-render-policy.test.ts tests/provenance-flow.test.ts tests/clinical-safety.test.ts — 37/37 passed.
  • npx vitest run tests/visual-evidence-tabs.dom.test.tsx tests/answer-render-policy.test.ts — 31/31 passed after the final UI fix.
  • npm run verify:cheap — after the final UI fix, all 20 non-test gates, lint, typecheck, 365/366 files and 3,254 tests passed; only tracked load-sensitive issue Delete .github/workflows/label.yml #67 timed out.
  • Red proofs reproduced all three unsafe paths before their fixes: missing relevance retained high trust, render policy retained a visual table, and clinical notes exposed a raw Tables affordance.
  • Verification not run: a second full local verify:ui, because the focused jsdom regression covers the changed drawer boundary and the mandatory exact-head hosted Production UI gate is running.
  • Verification not run: live RAG/OpenAI evaluation, because retrieval, ranking, generation, synthesis, and answer post-processing are unchanged.
  • Verification not run: Supabase replay, because there is no schema, SQL, persistence, or generated-type change.
  • Verification not run: Railway/deployment checks, because there is no deployment or runtime configuration change.

Risk and rollout

  • Risk: low and intentionally conservative; legacy payloads without relevance metadata now render as low trust and cannot expose rich visual/table evidence. Explicit source-backed payloads retain current behavior.
  • Rollback: revert this PR.
  • Provider or production effects: none. No live RAG, OpenAI request, Supabase mutation, Railway action, production data operation, or deployment ran.

Clinical Governance Preflight

  • Source-backed claims still require linked source verification before clinical use
  • No patient-identifiable document workflow was introduced or expanded without explicit governance approval
  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy)
  • Service-role keys and private document access remain server-only
  • Demo/synthetic content remains clearly separated from real clinical sources
  • Source metadata, review status, and outdated/unknown-source behavior remain conservative
  • Deployment classification/TGA SaMD impact was checked when clinical decision-support behavior changed

Notes

  • Known issue Delete .github/workflows/label.yml #67 is unrelated to this diff: its reconciliation-preflight child process exceeded the 30-second test timeout under current local machine load. It was not repeatedly retried.
  • Both actionable P2 review threads were fixed, replied to, and resolved.

@supabase

supabase Bot commented Jul 24, 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 ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@cursor[bot], you've reached your PR review limit, so we couldn't start this review.

Next review available in: 35 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9a61d5ab-2d67-4ee4-a977-353ee16fd113

📥 Commits

Reviewing files that changed from the base of the PR and between 4725f19 and 181219f.

📒 Files selected for processing (6)
  • docs/branch-review-ledger.md
  • src/components/clinical-dashboard/answer-result-surface.tsx
  • src/components/clinical-dashboard/evidence-panels.tsx
  • src/lib/answer-render-policy.ts
  • tests/answer-render-policy.test.ts
  • tests/visual-evidence-tabs.dom.test.tsx
📝 Walkthrough

Walkthrough

Answer rendering now fails closed when source-backed relevance metadata is absent. Trust derivation and dashboard groundedness require isSourceBacked === true, with tests covering the missing-metadata case and a ledger entry recording verification.

Changes

Answer relevance trust

Layer / File(s) Summary
Strict source-backed trust policy
src/lib/answer-render-policy.ts
Adds isAnswerSourceBacked and uses explicit isSourceBacked: true for trust derivation.
Dashboard groundedness integration
src/components/ClinicalDashboard.tsx
Uses the shared helper when computing answerGrounded.
Fail-closed validation and review record
tests/answer-render-policy.test.ts, docs/branch-review-ledger.md
Adds coverage for absent relevance metadata and records the reviewed behavior and verification status.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: codex

Suggested reviewers: claude

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title is concise and accurately summarizes the main change: failing closed on missing answer relevance.
Description check ✅ Passed The description largely matches the required template and includes summary, verification, risk, governance, and notes sections.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/answer-relevance-fail-closed

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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

🧹 Nitpick comments (1)
tests/answer-render-policy.test.ts (1)

292-304: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add an explicit-false regression case.

The new test covers absent metadata, but the stated contract also requires isSourceBacked: false to remain low trust. Add the same trust/block assertions for that case so future predicate changes cannot reopen it.

🤖 Prompt for 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.

In `@tests/answer-render-policy.test.ts` around lines 292 - 304, Add a regression
test alongside the absent-metadata case using answer() with relevance metadata
explicitly setting isSourceBacked to false. Assert model.trust is "low" and
model.allowedBlocks excludes both "quoteCards" and "relatedDocuments",
preserving the same fail-closed contract.
🤖 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.

Nitpick comments:
In `@tests/answer-render-policy.test.ts`:
- Around line 292-304: Add a regression test alongside the absent-metadata case
using answer() with relevance metadata explicitly setting isSourceBacked to
false. Assert model.trust is "low" and model.allowedBlocks excludes both
"quoteCards" and "relatedDocuments", preserving the same fail-closed contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f0abb835-c9f0-45ad-9d30-c503e45fcedf

📥 Commits

Reviewing files that changed from the base of the PR and between 5ca1ae5 and 4725f19.

📒 Files selected for processing (4)
  • docs/branch-review-ledger.md
  • src/components/ClinicalDashboard.tsx
  • src/lib/answer-render-policy.ts
  • tests/answer-render-policy.test.ts

@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: 4725f19ce0

ℹ️ 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/answer-render-policy.ts
@BigSimmo

Copy link
Copy Markdown
Owner Author

@codex resolve actionable Codex review findings for this pull request and current head using the repository instructions. This is the pull request's single automatic repair pass: do not perform a fresh review, create new standalone findings, or request another review. Work only the existing unresolved Codex threads on the current head. Always fix P0 and P1 findings. For P2 and lower findings, fix only clear, scoped, low-risk issues; otherwise disposition them with a concise reason. After fixing or dispositioning a thread, reply in that thread with as the first line, followed by a concise summary; that marker authorizes the workflow to close that exact thread. If human input or new authorization is required, do not use the marker and leave the thread open with the blocker. Finish only after every actionable thread is fixed or dispositioned and closed, or explicitly left open for a human decision. Do not update the branch from main, address unrelated reviews, broaden scope, or create more than one scoped fix commit. Do not use external APIs, paid services, credentials, dependency changes, or broad refactors unless explicitly authorized. Add targeted tests where behavior changes and run the narrowest relevant validation.

@BigSimmo
BigSimmo enabled auto-merge (squash) July 24, 2026 03:50
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 4725f19ce0

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

@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: 0290694cb1

ℹ️ 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/answer-render-policy.ts

@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: ac0d430547

ℹ️ 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/components/clinical-dashboard/evidence-panels.tsx Outdated
BigSimmo and others added 3 commits July 24, 2026 12:39
…e-fail-closed

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
When relevance.isSourceBacked is false, clear answerSections, quoteCards,
and smartPanel quotes before Clinical Notes renders — not only visualEvidence.
Addresses Codex review on PR #1125.

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@BigSimmo
BigSimmo disabled auto-merge July 24, 2026 04:45
@BigSimmo
BigSimmo enabled auto-merge July 24, 2026 04:45

@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: 41ad7a3ad9

ℹ️ 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/components/clinical-dashboard/evidence-panels.tsx
BigSimmo and others added 5 commits July 24, 2026 13:02
Strip documentBreakdown and comparison metadata when relevance is not source-backed so Clinical Notes cannot rebuild comparison tables via ClinicalOutputPanel fallback.

Co-authored-by: Cursor <cursoragent@cursor.com>
Assert the comparison-detail caption and matrix values stay hidden when
relevance is missing, even if documentBreakdown and comparisonMatrix are present.
Ledger the cleared documentBreakdown/comparison-metadata fail-closed fix
and hardened jsdom regression for PR #1125.
Use the full reviewed commit hash for the PR #1125 comparison clear-out row.

@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: c469697202

ℹ️ 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/components/clinical-dashboard/evidence-panels.tsx
@BigSimmo
BigSimmo merged commit 1cb3ff8 into main Jul 24, 2026
41 checks passed
@BigSimmo
BigSimmo deleted the codex/answer-relevance-fail-closed branch July 24, 2026 05:16
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