Skip to content

fix(rag): mirror scoped corrector into schema.sql + regenerate drift manifest (F10)#701

Merged
BigSimmo merged 1 commit into
mainfrom
claude/audit-findings-review-phgz92
Jul 17, 2026
Merged

fix(rag): mirror scoped corrector into schema.sql + regenerate drift manifest (F10)#701
BigSimmo merged 1 commit into
mainfrom
claude/audit-findings-review-phgz92

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

Completes the F10 corrector-tenancy fix by closing the one gap left by #697's migration-only approach — the canonical supabase/schema.sql still carried the unscoped corrector, which a disaster-recovery restore or manifest/schema reconciliation would replay (Codex review P1 on #697).

  • supabase/schema.sql: mirror the owner_id is null scope into all three vocabulary sources of correct_clinical_query_terms (both rag_aliases reads + the document-title scan), matching the merged migration 20260717120000_corrector_public_titles_only.sql.
  • supabase/drift-manifest.json: regenerated via npm run drift:manifest — a real Docker Postgres replay of the updated schema.sql. The only snapshot delta is the corrector function's def_hash (8f1094c4…a5ebdd1e…), plus schema_sha256 / generated_at / replay_seconds; nothing else changed, confirming the sole schema difference is the scoped corrector.

After this, main has the migration, schema.sql, and the drift manifest all consistent — no DR/reconciliation path can reintroduce the cross-tenant vocabulary.

Verification

  • npm run drift:manifest — replayed schema.sql into a scratch supabase/postgres:17.6.1.127 container (60s), regenerated the manifest
  • npx vitest run tests/drift-detection.test.ts tests/supabase-schema.test.ts66 passed (schema_sha256 now matches schema.sql; corrector scope asserted)
  • git diff --check + prettier --check supabase/drift-manifest.json — clean
  • npm run check:drift against live — not run (needs service-role env; belongs to the live-apply step below)

Clinical Governance Preflight

Touches source governance (retrieval query correction) + Supabase schema:

  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy)
  • Service-role confinement unchanged — corrector stays SECURITY DEFINER, execute granted only to service_role
  • Private document access remains server-only; improved: private titles/aliases no longer influence other tenants' query correction
  • No patient-identifiable workflow, no demo/real-source mixing, conservative source behavior preserved
  • No clinical decision-support behavior change (query-term correction only)

Remaining step — live apply (deploy pipeline, confirmation-gated)

The migration is not yet applied to the live project (this sandbox has no service-role env, and a clinical-production mutation belongs in the normal linked-migration deploy workflow). To finish end-to-end:

  1. Apply 20260717120000_corrector_public_titles_only.sql to Clinical KB Database via the normal migration workflow.
  2. npm run check:drift against live — should report clean (live now matches this schema.sql + manifest).
  3. npm run check:supabase-project.

No production mutations or provider calls were performed in this PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FJpsbpsmjJ2tLLXFfSe9GK


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved clinical query term correction by using only publicly available terminology and indexed public document titles.
    • Prevented private or tenant-specific terminology from influencing query corrections.

…manifest (F10)

Completes the F10 corrector tenancy fix. Migration
20260717120000_corrector_public_titles_only (merged in #697) scoped the
SECURITY DEFINER query-term corrector's vocabulary — both rag_aliases reads and
the document-title scan — to the public corpus (owner_id is null). This mirrors
that same predicate into the canonical supabase/schema.sql corrector definition
so a disaster-recovery restore or manifest/schema reconciliation cannot recreate
the unscoped, cross-tenant vocabulary (Codex review P1 on #697).

Regenerated supabase/drift-manifest.json via `npm run drift:manifest` (real
Docker Postgres replay): schema_sha256 and only the corrector function's def_hash
change (8f1094c4… → a5ebdd1e…), confirming the sole schema delta is the scoped
corrector. Offline drift-detection + schema tests pass (66).

Live apply of the migration to the Clinical KB Database project remains a
separate, confirmation-gated deploy-pipeline step (needs service-role env);
after applying, `npm run check:drift` should report clean against live.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FJpsbpsmjJ2tLLXFfSe9GK
@supabase

supabase Bot commented Jul 17, 2026

Copy link
Copy Markdown

Updates to Preview Branch (claude/audit-findings-review-phgz92) ↗︎

Deployments Status Updated
Database Fri, 17 Jul 2026 06:09:23 UTC
Services Fri, 17 Jul 2026 06:09:23 UTC
APIs Fri, 17 Jul 2026 06:09:23 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations Fri, 17 Jul 2026 06:09:30 UTC
Migrations Fri, 17 Jul 2026 06:10:42 UTC
Seeding Fri, 17 Jul 2026 06:10:46 UTC
Edge Functions Fri, 17 Jul 2026 06:10:46 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 49d676fd-65b6-43f9-846c-c5e2c92936b1

📥 Commits

Reviewing files that changed from the base of the PR and between 1ffa139 and cb519d4.

📒 Files selected for processing (2)
  • supabase/drift-manifest.json
  • supabase/schema.sql

📝 Walkthrough

Walkthrough

The clinical query correction function now builds vocabulary from public aliases and indexed public documents only. Drift manifest metadata and the function definition hash were refreshed to reflect the schema change.

Changes

Public vocabulary scope

Layer / File(s) Summary
Scope correction vocabulary and refresh schema metadata
supabase/schema.sql, supabase/drift-manifest.json
public.correct_clinical_query_terms adds owner_id IS NULL filters for aliases, canonical terms, and indexed document titles; the drift manifest updates snapshot metadata and the function definition hash.

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

Possibly related PRs

  • BigSimmo/Database#697: Updates the same clinical query correction function to scope vocabulary to public/null-owner aliases and documents.

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the schema and drift-manifest update.
Description check ✅ Passed The description matches the template with Summary, Verification, and Clinical Governance sections and is sufficiently complete.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/audit-findings-review-phgz92

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

@BigSimmo
BigSimmo enabled auto-merge July 17, 2026 06:10
@BigSimmo
BigSimmo merged commit 561cefe into main Jul 17, 2026
16 checks passed
@BigSimmo
BigSimmo deleted the claude/audit-findings-review-phgz92 branch July 17, 2026 06:46
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