fix(supabase): make GUC-set migration hosted-safe; neutralize obsolete N+1 migration - #212
Merged
Merged
Conversation
…e N+1 migration Applying the pending audit-follow-up migrations against hosted Supabase surfaced two migration-set hazards. This makes the set replay-safe on hosted without changing runtime behaviour. - 20260702160000_fix_invoke_agent_url_to_guc: the bare `alter database ... set app.indexing_v3_agent_base_url` is denied to the migration role on hosted Supabase (42501), which aborts a fresh migration replay / preview branch. Wrap it in a DO block that swallows insufficient_privilege (still sets the GUC on self-hosted / local where the role may). The function keeps its `current_setting(..., true)` -> hardcoded production URL fallback, so behaviour is identical whether or not the GUC is set. Same guard applied to the mirrored statement in supabase/schema.sql. - 20260702170000_fix_match_chunks_text_n1: replace the body with a documented no-op. The live match_document_chunks_text already batches the N+1 label/summary lookups and carries a superior title-boost dual-path impl; the original CREATE OR REPLACE would both error (adds a lexical_score output column, illegal on an existing RETURNS TABLE function without DROP) and regress the live function. The file is retained for migration ordering. Full retrieval-RPC drift reconciliation into schema.sql/migrations remains a golden-eval-gated backlog item. - tests/supabase-schema.test.ts: assert the guarded GUC-set form (`alter database %I set ... = %L` + `when insufficient_privilege then`) instead of the removed bare literal. Verified: schema test 29/29; verify:cheap lint + typecheck + unit green (2 unrelated 15s flaky timeouts confirmed passing in isolation, 45/45). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Uh oh!
There was an error while loading. Please reload this page.
BigSimmo added a commit
that referenced
this pull request
Aug 17, 2026
…state Resolve the HANDOVER.md status-table conflict against main after PR #2022 (S1, squash 2bd146e) and PR #2023 (#212 T3, squash 440a34f) merged. - HANDOVER §1 snapshot re-dated to 2026-08-17: S1 landed (rung 1, canary pair green), residuals R1/R2/R3 recorded, owner decisions (R1 before S2; governance Option B), #212 sibling stream cross-referenced. - HANDOVER §2 rows: S1 merged; new S1b (R1 routing), S1c (R2+R3), G1 (Option B), #212 T1-T3 / T4 rows; §3 packet bodies and §7 prompts for S1b, S1c, G1. - COORDINATION §3 wave table re-cut (Wave 0: D1 + S4 + S1b + T4; C1 canary done), per-task model/effort table, §7 current state with the canary evidence and the live board link. - clinical-hazard-analysis H5a: partial mitigation noted; document-summary residual and the Option B decision recorded. - Six immutable inbox requests: R1 (P1), R2+R3 (P2), Sentry search error (P2), source_metadata pin (P3), eval-canary post-merge-only note (P3), G1 implementation (P3). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Aug 17, 2026
BigSimmo pushed a commit
that referenced
this pull request
Aug 17, 2026
…re, and record the branch review Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWVin3ToF7qvWjnCB9Ti3X
BigSimmo pushed a commit
that referenced
this pull request
Aug 17, 2026
… cancellations CI's docs:check-links (and every other planRequestBatch consumer) fails on the merge ref because tranche 3's #212 update request and this PR's #212 done request are both pending. Cancel both and queue one closure request that carries the T3 row correction and the T4 outcome, leaving exactly one pending mutation for #212. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWVin3ToF7qvWjnCB9Ti3X
This was referenced Aug 17, 2026
BigSimmo added a commit
that referenced
this pull request
Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Applying the pending audit-follow-up migrations against the hosted Clinical KB Supabase project surfaced two migration-set hazards that would break a fresh migration replay / preview branch (they don't affect the already-live DB, where the safe halves were hand-applied). This PR makes the migration set hosted-safe with zero runtime-behaviour change.
1.
20260702160000_fix_invoke_agent_url_to_guc— guard theALTER DATABASE SETHosted Supabase denies
alter database ... set app.indexing_v3_agent_base_urlto the migration role (42501 insufficient_privilege), which aborts the whole migration on replay. Wrapped it in aDOblock that swallowsinsufficient_privilege(still sets the GUC on self-hosted / local where the role is permitted). The function body is unchanged and keeps itscurrent_setting('app.indexing_v3_agent_base_url', true)→ hardcoded production-URL fallback, soinvoke_indexing_v3_agentbehaves identically whether or not the GUC is set. The mirrored statement insupabase/schema.sqlgets the same guard.2.
20260702170000_fix_match_chunks_text_n1— neutralize (documented no-op)Obsolete and hazardous:
lexical_scoreoutput column tomatch_document_chunks_textviaCREATE OR REPLACE, which is illegal on an existingRETURNS TABLEfunction without aDROPfirst.match_document_chunks_textalready batches the N+1 label/summary lookups and carries a superior title-boost dual-path impl (chunk_seed/title_docs/title_matches) this file lacks.Replaced the body with a documented
select 1;no-op, kept for migration ordering. Full retrieval-RPC drift reconciliation (the known hybrid-RPC drift) intoschema.sql+ migrations remains a golden-eval-gated backlog item — deliberately out of scope here.3. Test
tests/supabase-schema.test.tsnow asserts the guarded GUC-set form (alter database %I set ... = %L+when insufficient_privilege then) instead of the removed bare literal.Verification
tests/supabase-schema.test.ts: 29/29 (directly validates the guardedALTER DATABASEform).verify:cheap(lint + typecheck + unit): green — 905/907, with 2 unrelated 15s flaky timeouts (api-validation-contract,rag-answer-fallback) that pass 45/45 in isolation; a SQL/schema-string change cannot affect API-route or RAG-fallback logic.prettier --checkclean on the changed.ts.Scope / risk
SQL-only + one test assertion. No application code, no live-DB change, no edge-function change. Does not re-activate enrichment or touch the retrieval-RPC drift.
Clinical governance preflight
match_document_chunks_textis left exactly as deployed; the invoke-agent function keeps identical fallback behaviour.eval:retrieval:quality23/23 is explicitly deferred to backlog.🤖 Generated with Claude Code