-
Notifications
You must be signed in to change notification settings - Fork 0
docs(drift): forward-codify runbook for live-ahead retrieval RPCs #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
414a4cc
docs(drift): stage forward-codify runbook for live-ahead retrieval RPCs
BigSimmo 333498f
Merge remote-tracking branch 'origin/main' into claude/forward-codify…
BigSimmo e8ee696
fix(drift): tolerate missing capture targets + scope the capture query
BigSimmo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| -- capture-live-retrieval-rpcs.sql (READ-ONLY) | ||
| -- | ||
| -- Captures the VERBATIM live bodies of the retrieval RPCs that are still flagged | ||
| -- "LIVE IS AHEAD" in supabase/drift-allowlist.json, so their definitions can be | ||
| -- forward-codified into a migration + supabase/schema.sql WITHOUT hand-authoring | ||
| -- them. These bodies are complex, have diverged in both directions (e.g. the | ||
| -- fail-closed retrieval_owner_matches predicate was applied to live while live | ||
| -- also grew richer multi-strategy candidate sets), and are under active | ||
| -- concurrent multi-session editing — so only a verbatim capture is correct. A | ||
| -- hand-written body is exactly what got migration 20260705210000 neutralized. | ||
| -- | ||
| -- SCOPE: this covers ONLY the allowlist "LIVE IS AHEAD" retrieval subset — the | ||
| -- guard-tested set (tests/forward-codify-retrieval-targets.test.ts). It is NOT | ||
| -- the complete codification set. The runbook also codifies live-only | ||
| -- (unexpected_live) and "verify" functions — get_visual_evidence_cards, | ||
| -- run_visual_eval_case, run_all_visual_eval_cases, repair_enrichment_quality_batch, | ||
| -- match_document_index_units_hybrid, match_document_memory_cards_hybrid[_v2]. | ||
| -- Capture those from the fingerprint table in | ||
| -- docs/forward-codify-retrieval-rpcs-workorder.md, not here. | ||
| -- | ||
| -- Full procedure: docs/forward-codify-retrieval-rpcs-workorder.md | ||
| -- Backlog item 0: docs/database-drift-detection.md#reconciliation-backlog | ||
| -- | ||
| -- HOW TO RUN — this is a provider action (it reads the live project); get | ||
| -- explicit approval first and run it only when the live DB is QUIESCENT (no | ||
| -- concurrent edits to these functions). It changes nothing — it only reads | ||
| -- pg_proc. Run it via the Supabase Dashboard SQL editor, an approved | ||
| -- service-role SQL path, or the Supabase MCP execute_sql tool. | ||
| -- | ||
| -- Expect EXACTLY 7 rows back (one per target). A target that no longer resolves | ||
| -- on live (renamed, dropped, or already reconciled) is filtered out and simply | ||
| -- yields FEWER rows — the query does not error. If you get fewer than 7, find | ||
| -- which with the "missing signatures" snippet in the work-order and reconcile | ||
| -- the target set + allowlist before continuing. | ||
| -- | ||
| -- search_path is pinned to '' so oid::regprocedure renders fully-qualified and | ||
| -- matches the allowlist keys / schema_drift_snapshot() signatures exactly, and | ||
| -- so pg_get_functiondef emits fully-qualified, replay-safe text (the same style | ||
| -- as migrations 20260701140631 / 20260707000000). This is cosmetic, not | ||
| -- correctness-critical: check:drift hashes pg_get_functiondef under search_path | ||
| -- '' on both live and the schema.sql replay, so a verbatim body always hashes | ||
| -- equal regardless of how it was rendered at capture time. | ||
|
|
||
| set search_path = ''; | ||
|
|
||
| select | ||
| r.signature, | ||
| pg_get_functiondef(r.proc) as definition | ||
| from ( | ||
| select t.signature, to_regprocedure(t.signature) as proc | ||
| from ( | ||
| -- >>> forward-codify targets >>> (kept in lockstep with the "LIVE IS AHEAD" | ||
| -- retrieval entries in supabase/drift-allowlist.json — see | ||
| -- tests/forward-codify-retrieval-targets.test.ts) | ||
| values | ||
| ('public.get_related_document_metadata(uuid[],uuid)'), | ||
| ('public.match_document_chunks(extensions.vector,integer,double precision,uuid,uuid)'), | ||
| ('public.match_document_chunks_hybrid(extensions.vector,text,integer,double precision,uuid[],uuid)'), | ||
| ('public.match_document_chunks_text(text,integer,uuid[],uuid)'), | ||
| ('public.match_document_table_facts_text(text,integer,uuid[],uuid)'), | ||
| ('public.match_documents_for_query(text,integer,uuid)'), | ||
| ('public.repair_strict_enrichment_gate_batch(integer)') | ||
| -- <<< forward-codify targets <<< | ||
| ) as t(signature) | ||
| ) as r | ||
| where r.proc is not null | ||
| order by r.signature; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { readFileSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| // Guards drift backlog item 0 (docs/forward-codify-retrieval-rpcs-workorder.md): | ||
| // the read-only capture query scripts/sql/capture-live-retrieval-rpcs.sql must | ||
| // target exactly the retrieval RPCs still flagged "LIVE IS AHEAD" in the drift | ||
| // allowlist. Reconciling a sibling (removing its allowlist entry) then forces a | ||
| // matching edit to the capture query, so the work-order artifact cannot silently | ||
| // rot as the backlog is worked down. | ||
|
|
||
| const root = join(__dirname, ".."); | ||
| const read = (relative: string) => readFileSync(join(root, relative), "utf8"); | ||
|
|
||
| // Allowlist entries the work-order treats as its authoritative target set. | ||
| const LIVE_AHEAD_PREFIX = "LIVE IS AHEAD"; | ||
|
|
||
| type AllowlistEntry = { category: string; kind: string; key: string; reason: string }; | ||
|
|
||
| function liveAheadRetrievalSignatures(): string[] { | ||
| const { entries } = JSON.parse(read("supabase/drift-allowlist.json")) as { entries: AllowlistEntry[] }; | ||
| return entries | ||
| .filter((e) => e.category === "functions" && e.kind === "mismatch" && e.reason.startsWith(LIVE_AHEAD_PREFIX)) | ||
| .map((e) => e.key) | ||
| .sort(); | ||
| } | ||
|
|
||
| function captureQuerySignatures(): string[] { | ||
| const sql = read("scripts/sql/capture-live-retrieval-rpcs.sql"); | ||
| const start = sql.indexOf(">>> forward-codify targets >>>"); | ||
| const end = sql.indexOf("<<< forward-codify targets <<<"); | ||
| expect(start, "capture query is missing its `>>> forward-codify targets >>>` marker").toBeGreaterThanOrEqual(0); | ||
| expect(end, "capture query is missing its `<<< forward-codify targets <<<` marker").toBeGreaterThan(start); | ||
| const region = sql.slice(start, end); | ||
| // Signatures are single-quoted VALUES literals; regprocedure text never | ||
| // contains a single quote, so this is an exact extraction. | ||
| const matches = [...region.matchAll(/'([^']+)'/g)].map((m) => m[1]); | ||
| return matches.sort(); | ||
| } | ||
|
|
||
| describe("forward-codify retrieval target set stays in sync with the drift allowlist", () => { | ||
| it("finds a non-empty set of live-ahead retrieval functions in the allowlist", () => { | ||
| expect(liveAheadRetrievalSignatures().length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it("the capture query lists every live-ahead retrieval signature, and only those", () => { | ||
| expect(captureQuerySignatures()).toEqual(liveAheadRetrievalSignatures()); | ||
| }); | ||
|
|
||
| it("the capture query has no duplicate target signatures", () => { | ||
| const signatures = captureQuerySignatures(); | ||
| expect(new Set(signatures).size).toBe(signatures.length); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fresh evidence beyond the prior capture-target comment: this newly added section now directs operators to take
run_visual_eval_case,run_all_visual_eval_cases, andrepair_enrichment_quality_batchfrom the fingerprint table, but that table only containsget_visual_evidence_cardsamong the live-only RPCs. When Step 2 asks them to codify and then remove allowlist entries for all four live-only functions, following this path leaves three functions without current definitions or ACL evidence, so the migration cannot be byte-faithful and drift can remain red or be miscodified; either add those signatures to a live capture artifact/table or stop listing them in this work-order.Useful? React with 👍 / 👎.