Skip to content

Claude/gate answer persistence flag 4b55da#537

Merged
BigSimmo merged 4 commits into
mainfrom
claude/gate-answer-persistence-flag-4b55da
Jul 12, 2026
Merged

Claude/gate answer persistence flag 4b55da#537
BigSimmo merged 4 commits into
mainfrom
claude/gate-answer-persistence-flag-4b55da

Conversation

@BigSimmo

Copy link
Copy Markdown
Owner

Summary

Verification

  • npm run verify:pr-local

During development, use npm run verify:cheap as the faster iteration gate before the final PR-local preflight.

  • npm run verify:ui when UI, routing, styling, browser behavior, reduced-motion, or forced-colors behavior changed
  • npm run verify:release before release or handoff confidence claims

For retrieval, ranking, selection, chunking, source/citation rendering, or answer-contract changes, verify:pr-local runs eval:rag:offline automatically. Run the offline command directly during iteration before spending a live eval.

  • npm run eval:retrieval:quality (must stay 36/36) when retrieval, ranking, selection, chunking, or scoring behavior changed — CI cannot run it (needs live keys), so run it locally and paste the summary. A metadata/governance-weighting change once buried correct docs (recall 1.0→0.76) and only this eval caught it.
  • npm run eval:rag -- --limit 15 + npm run eval:quality -- --rag-only when answer generation, the synthesis prompt, or answer post-processing changed (grounded-supported must not drop; citation-failure 0)
  • npm run check:production-readiness when clinical workflow, privacy, environment, Supabase, source governance, or deployment behavior changed
  • npm run check:deployment-readiness when deployment startup, hosting, or rollout behavior changed

Clinical Governance Preflight

Complete this section when the change touches ingestion, answer generation, search/ranking, source rendering, document access, privacy, production env, or clinical output.

  • 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

BigSimmo and others added 2 commits July 13, 2026 01:43
…_ANSWER_TEXT (PIA-3)

rag_queries.answer stored the full generated answer text un-redacted — PHI-derived
content at rest even though the query itself is hashed. Gate answer-text persistence
behind a new RAG_PERSIST_ANSWER_TEXT flag (default off), mirroring the existing
RAG_PERSIST_RAW_QUERY_TEXT precedent.

- env: new RAG_PERSIST_ANSWER_TEXT (default false)
- query-privacy: answerTextForStorage() + answerPrivacyMetadata() helpers
- rag.ts insertRagQuery: central chokepoint nulls the answer and records
  metadata.answer_retained; covers every logRagQuery caller at once
- eval-cases route: answer persistence moved onto the dedicated flag so one
  switch governs answer text everywhere (free-text note stays on raw-query flag)
- production-readiness: block RAG_PERSIST_ANSWER_TEXT=true in production
- docs: .env.example + privacy-impact-assessment (PIA-3 -> Resolved)

The offline eval pipeline reads the in-memory answer (logQuery:false) and never
reads the persisted column, so default-off does not affect eval.

Tests: answerTextForStorage/answerPrivacyMetadata unit tests; rag_queries insert
nulls the answer by default at the real chokepoint; eval-cases decoupling test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Review fix: the earlier PIA-3 wording overclaimed that generated answer text is
"dropped at rest by default." The durable rag_queries.answer log is gated by
RAG_PERSIST_ANSWER_TEXT, but rag_response_cache.payload still holds the full
answer (owner-scoped, ~5-min TTL). Tighten the register/APP-11/recommendation
wording to the durable log and add an explicit "Residual (scoped out)" note for
the short-lived response cache, which is intentionally not gated (nulling its
payload would defeat caching).

No behaviour change; documentation accuracy only.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@supabase

supabase Bot commented Jul 12, 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 12, 2026 19:10
@BigSimmo

Copy link
Copy Markdown
Owner Author

@copilot resolve the merge conflicts in this pull request

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The head commit changed during the review from a3f498e to 47206d8.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/gate-answer-persistence-flag-4b55da
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch claude/gate-answer-persistence-flag-4b55da

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

auto-merge was automatically disabled July 12, 2026 19:11

Head branch was pushed to by a user without write access

Copilot AI commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Done — resolved all merge conflicts in docs/privacy-impact-assessment.md (47206d8). The 5 conflict regions all arose from origin/main adding PIA-1/PIA-5 progress notes (PR #513), an updated rag_response_cache retention description, and a revised §11 recommendation; I took the origin/main side for each, which is the most current state.

@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

Database/src/lib/env.ts

Lines 116 to 120 in c26e54f

// answer is not). Default OFF: do not persist generated answer text at rest.
// The offline eval/quality pipeline reads the in-memory answer (logQuery:false)
// and never reads this column back, so persistence-off is safe. Set true only
// where retaining answer text is permitted and a retention policy exists
// (owner-scoped + 30-day purge). Blocked in production readiness.

P1 Badge Gate cached answers behind the retention flag

When RAG_PERSIST_ANSWER_TEXT is left at its default false but RAG_ANSWER_CACHE_TTL_MS is enabled (default 300000), answered requests still call setSharedCachedAnswer and insert { answer: cloneAnswer(answer) } into rag_response_cache.payload (src/lib/rag-cache.ts:523-524). I only found lookup-time expires_at filtering/invalidation, not a purge that removes expired cache rows, so generated PHI-derived answer text can still remain at rest while this new flag and production-readiness check report answer persistence as off. A focused proof is to run any non-skipped answer request with the default cache TTL and inspect the inserted rag_response_cache payload.

ℹ️ 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 enabled auto-merge (squash) July 12, 2026 19:17
@BigSimmo

Copy link
Copy Markdown
Owner Author

@codex

fix this issue below please

P1 Badge Gate cached answers behind the retention flag
When RAG_PERSIST_ANSWER_TEXT is left at its default false but RAG_ANSWER_CACHE_TTL_MS is enabled (default 300000), answered requests still call setSharedCachedAnswer and insert { answer: cloneAnswer(answer) } into rag_response_cache.payload (src/lib/rag-cache.ts:523-524). I only found lookup-time expires_at filtering/invalidation, not a purge that removes expired cache rows, so generated PHI-derived answer text can still remain at rest while this new flag and production-readiness check report answer persistence as off. A focused proof is to run any non-skipped answer request with the default cache TTL and inspect the inserted rag_response_cache payload.

@BigSimmo
BigSimmo merged commit 8ec6196 into main Jul 12, 2026
15 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown

Summary

Testing

  • ⚠️ npm test -- --run tests/rag-cache-invalidation.test.ts initially could not run because node_modules was missing and the shell resolved Node 20 before setup.
  • npm ci
  • npm test -- --run tests/rag-cache-invalidation.test.ts
  • npm run typecheck
  • ⚠️ npm run check:production-readiness not run because repo instructions mark this provider/live-environment-adjacent check as confirmation-required.

View task →

@BigSimmo
BigSimmo deleted the claude/gate-answer-persistence-flag-4b55da branch July 13, 2026 16:35
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