Skip to content

fix(supabase): make GUC-set migration hosted-safe; neutralize obsolete N+1 migration - #212

Merged
BigSimmo merged 1 commit into
mainfrom
claude/migration-hosted-safety
Jul 2, 2026
Merged

fix(supabase): make GUC-set migration hosted-safe; neutralize obsolete N+1 migration#212
BigSimmo merged 1 commit into
mainfrom
claude/migration-hosted-safety

Conversation

@BigSimmo

Copy link
Copy Markdown
Owner

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 the ALTER DATABASE SET

Hosted Supabase denies alter database ... set app.indexing_v3_agent_base_url to the migration role (42501 insufficient_privilege), which aborts the whole migration on replay. Wrapped it in a DO block that swallows insufficient_privilege (still sets the GUC on self-hosted / local where the role is permitted). The function body is unchanged and keeps its current_setting('app.indexing_v3_agent_base_url', true) → hardcoded production-URL fallback, so invoke_indexing_v3_agent behaves identically whether or not the GUC is set. The mirrored statement in supabase/schema.sql gets the same guard.

2. 20260702170000_fix_match_chunks_text_n1 — neutralize (documented no-op)

Obsolete and hazardous:

  • It would error: it adds a lexical_score output column to match_document_chunks_text via CREATE OR REPLACE, which is illegal on an existing RETURNS TABLE function without a DROP first.
  • It would regress live: the deployed match_document_chunks_text already 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) into schema.sql + migrations remains a golden-eval-gated backlog item — deliberately out of scope here.

3. Test

tests/supabase-schema.test.ts now 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 guarded ALTER DATABASE form).
  • 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 --check clean 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

  • Patient-data / PHI touched? No.
  • Retrieval / ranking / answer-generation behaviour changed? No — match_document_chunks_text is left exactly as deployed; the invoke-agent function keeps identical fallback behaviour.
  • Golden retrieval eval impact? None expected (no retrieval path changed); drift reconciliation that would need eval:retrieval:quality 23/23 is explicitly deferred to backlog.
  • Deployment classification: repo hygiene / migration-replay safety only.

🤖 Generated with Claude Code

…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>
@BigSimmo
BigSimmo merged commit 2783645 into mainJul 2, 2026
4 checks passed
@BigSimmo
BigSimmo deleted the claude/migration-hosted-safety branch July 2, 2026 19:41
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>
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
BigSimmo added a commit that referenced this pull request Aug 17, 2026
Sign up for freeto 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.

1 participant

@BigSimmo