fix(db): align schema.sql corrector body with the applied migration 20260831100000 - #2493
Conversation
…0260831100000 live-drift has been red since 2026-08-25 and its sole unexpected finding on the 2026-09-01 run was a def_hash mismatch on public.correct_clinical_query_terms(text,real): manifest e2356565 vs live 2ebaf978. The cause is a mirror gap, not a live-database problem. Migration 20260831100000 (PR #2477) redefined the function with a duplicated `and length(canonical) between 4 and 40` predicate in the canonical UNION branch, and supabase/schema.sql was never updated to match — it was still byte-identical to the earlier 20260828000000 form. The drift manifest is generated by replaying schema.sql into the pinned Postgres image, so the manifest and live disagreed even though live is exactly what the applied migration created. Codify live rather than write a migration: auto-deploy is ON, and a migration would push a change to a live clinical-search function in production for a cosmetic reason. Proven offline, with no live access: after this edit the regenerated manifest reports def_hash 2ebaf978b69f3de0c47d9d0924419c74 for that signature — exactly the live value the failing run reported. Regeneration moved that one entry and nothing else across 96 functions, 43 tables, 222 indexes, 53 policies, 207 constraints and 26 triggers. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 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. Comment |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_3465687c-929b-4fef-a9e4-6e1375b1c481) |
|
Updates to Preview Branch (claude/clinical-corrector-mirror) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Summary
public.correct_clinical_query_terms(text,real)body insupabase/schema.sqlwith the already-applied migration20260831100000, adding the one line the mirror was missing.supabase/drift-manifest.jsonfrom the correctedschema.sql.This closes the sole unexpected finding on the failing
live-driftrun. No migration is added, no live database object is changed, and no retrieval or ranking code is touched.The problem
live-driftrun 33484535655 (2026-09-01, onmainatd3074946a) failed with exactly one unexpected finding:This is a mirror gap, not a live-database problem. Migration
20260831100000(merged in PR #2477) redefined the function with a duplicatedand length(canonical) between 4 and 40predicate in the canonical branch of itsUNION, andsupabase/schema.sqlwas never updated to match — it remained byte-identical to the earlier20260828000000form. The drift manifest is generated by replayingschema.sqlinto the pinnedsupabase/postgres:17.6.1.127image, so the manifest and live disagreed even though live is exactly what the applied migration created.Same failure class as the original
#316root cause, whereSET work_memwas absent fromschema.sql. The gap in CI that let it through is already tracked as#QCNE6N.Why codify live rather than fix live
Auto-deploy is ON: merging a migration applies it to the production clinical database within seconds. A migration to remove the duplicate would push a change to a live clinical-search function purely to tidy cosmetic text. The mirror is what is wrong, so the mirror is what this PR corrects.
The duplicated line is obviously accidental and it would be reasonable to drop it from both live and the mirror the next time this function is changed for a real reason. That is deliberately not bundled here.
Evidence
The decisive proof, obtained offline with no live database access. After the
schema.sqledit,npm run drift:manifestregenerated the manifest and reported, for signaturepublic.correct_clinical_query_terms(text,real):That is byte-for-byte the live hash the failing run reported, which confirms the diagnosis is complete: the duplicated line is the whole of the divergence, and nothing else in live is unexplained.
Regenerating the manifest moved exactly one snapshot entry — that function's
def_hash— plus the expectedgenerated_at,schema_sha256andreplay_secondsmetadata. Every other object across 96 functions, 43 tables, 222 indexes, 53 policies, 207 constraints, 26 triggers, 1 view, 6 extensions and 2 storage buckets hashed identically to the committed manifest.Tests.
npm run test:focusedwas run first and is reported here as no coverage, not as a pass: Vitest'srelatedselector works on the module import graph, and.sql/.jsondata files are read at runtime rather than imported, so it found no test files and exited 0. The covering suites were therefore discovered by grep and run explicitly:That set includes
drift-detection,supabase-schema,migration-history-guards,migration-history-alignment,search-health-index-coverage,function-grants,hosted-migration-role-guard,live-drift-workflow,owner-scope-guard,retrieval-access-scopeand the RAG source-pin contract testrag-imputation-contract. Thecheck:function-grants: FAILlines in that run's stdout are that suite's own negative fixtures, which feed deliberately-bad SQL to prove the guard fires.Formatting.
.sqlhas no Prettier parser andsupabase/drift-manifest.jsonis listed in.prettierignore, so neither changed file is within Prettier's remit.prettier --checkover the exact file set in this commit reportsAll matched files use Prettier code style!.Not run, by design.
npm run check:driftreads the live database and was deliberately not run; no Supabase, OpenAI, Railway or other provider-backed command was executed at any point. GitHub remains the authority on whether the alarm actually clears — the post-mergelive-driftrun is the real gate.RAG impact: no retrieval behaviour change — supabase/schema.sql is being aligned to the already-applied migration 20260831100000; the only textual difference is a duplicated, byte-identical AND predicate, which is a boolean no-op. No migration, no live change, and no ranking or retrieval surface is edited.
The equivalence was re-proved rather than inherited. The duplicated conjunct sits in a pure
andchain (where enabled and owner_id is null and P and P and lower(canonical) % tok), andlength(canonical) between 4 and 40is immutable and side-effect free, soP and PisPand the result set is unchanged. A duplicated predicate can in principle lower the planner's row estimate and change the chosen plan, but it cannot change the rows returned, because both the innerorder by … limit 32and the outerorder by … limit 1are deterministic over the selected tuples. In any case this PR changes no live object, so live execution is not affected at all.Clinical Governance Preflight
Clinical KB Database(sjrfecxgysukkwxsowpy)No clinical decision-support behaviour changes in this PR: it edits a mirror file and a generated manifest so that they describe the function the production database is already running.
🤖 Generated with Claude Code
Note
Low Risk
Mirror and generated manifest only; production DB behavior is unchanged and the SQL edit is a redundant predicate with no semantic effect.
Overview
Fixes live-drift by making
supabase/schema.sqlmatch the production definition ofpublic.correct_clinical_query_terms(text,real)from migration20260831100000, which the mirror had not picked up.The only body change is a duplicate
and length(canonical) between 4 and 40in therag_aliasesbranch of the function’sUNION—a logical no-op that already exists on the live database. No new migration and no change to live objects; retrieval and ranking code are untouched.supabase/drift-manifest.jsonwas regenerated (schema_sha256,def_hashfor that function, metadata timestamps) so replayed schema matches live hashes again.Reviewed by Cursor Bugbot for commit 80f72bb. Configure here.