Repository navigation
Invalidate RAG cache scope revision on table-fact and image edits (stacked on #3640) - #3650
Conversation
Adds draft migration 20261018095804_rag_cache_scope_evidence_revision.sql. It is stacked on #3640 and must merge after it, because it replaces #3640's rag_cache_scope_revision_v1. - public.document_evidence_revisions holds a per-document counter. Statement-level triggers on document_table_facts and document_images bump it in the writing transaction when a fact or image row is inserted, deleted or changed. Every column except created_at/search_tsv counts; a no-op update does not bump it. - rag_cache_scope_revision_v1 keeps its signature, digest shape and grants, and each document's row hash now also carries that counter. The revision stays one pass over documents plus a keyed join, with no per-request scan of facts or images (gitar's cost concern). - tests/sql/rag-cache-scope-evidence-revision.sql runs on the replayed chain in CI. It shows that a fact threshold edit and image caption, relevance and searchability edits change the revision, that a no-op update and an edit on another document do not, and that deleting the document still cascades. - tests/rag-cache-governance-revocation.test.ts shows that a counter bump rejects local and shared cached answers and searches. Sealed with the append-only `npm run migrations:seal`. The owner approved this migration at 17:55 AWST 2026-10-18, relayed by Grok Bot. The drift manifest's schema_sha256 follows schema.sql; the full manifest comes from CI's regenerated artifact. No SQL applied; no clinical or hazard sign-off recorded.
…n-20261018' into grok/rag-cache-evidence-revision-20261018
There was a problem hiding this comment.
BigSimmo has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
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. |
|
Claude encountered an error after 2s —— View job I'll analyze this and get back to you. |
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
| -- DRAFT. Merge only inside the owner's approved database-change window, and only after | ||
| -- 20261018082910_audit_durable_recovery_pairing_and_cache_fences.sql (it replaces that | ||
| -- migration's rag_cache_scope_revision_v1). Owner approval: 17:55 AWST 2026-10-18, relayed by Grok Bot. |
There was a problem hiding this comment.
💡 Quality: Owner approval is recorded only as a bot relay, not the owner's own words
The migration header and the PR body record the owner's approval as "17:55 AWST 2026-10-18, relayed by Grok Bot". The repo's Supabase safety rules (docs/decisions/2026-10-15-database-changes-need-owner-permission.md) require the owner's explicit yes, in words, to this specific change before it reaches main. Approval relayed secondhand by an agent can't be checked against that rule. Before merging, get the owner to confirm directly on this PR (a comment or review) and point to it.
Was this helpful? React with 👍 / 👎
There was a problem hiding this comment.
Acknowledged; not resolving. Grok Bot relayed the owner's approval of this migration at 17:55 AWST 2026-10-18. Automation can't record the owner's own words. The owner needs to confirm this specific change in their own words, and pick the production window, before this merges. Auto-merge is deliberately off.
There was a problem hiding this comment.
Understood. This finding stays open until the owner confirms this specific migration in their own words and a production window is chosen. Keeping auto-merge off is the right call until then. I'm not making any code changes for this.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 998f7c81fb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…n-20261018' into grok/rag-cache-evidence-revision-20261018
The manifest is copied verbatim from artifact drift-manifest-39118948015, which CI Migration replay produced on 998f7c8 from a Docker replay of the chain. It adds document_evidence_revisions, both new functions and the six triggers, and refreshes the def_hash for rag_cache_scope_revision_v1.
|
|
CI failed: One mobile-WebKit Playwright test failed: submitting a new Services query ('housing') never updated the URL from 'crisis', timing out. The analysis marks it unrelated to this RAG cache revision PR, so it looks like a pre-existing UI routing issue rather than something this change introduced.OverviewAnalyzed 8 logs across 1 unique error template. The only failure is a single mobile-WebKit Playwright test (159 passed, 10 skipped, 1 failed) in the Services shared-composer flow, where the FailuresServices shared-composer query not reflected in URL (confidence: high)
Summary
Code Review 👍 Approved with suggestions 1 closed / 2 findings🔴 High risk · The migration changes clinical RAG cache invalidation for table facts and images; missed revision bumps could leave stale evidence in cached answers. Extends
💡 Quality: Owner approval is recorded only as a bot relay, not the owner's own words📄 supabase/migrations/20261018095804_rag_cache_scope_evidence_revision.sql:1-3 The migration header and the PR body record the owner's approval as "17:55 AWST 2026-10-18, relayed by Grok Bot". The repo's Supabase safety rules ( ✅ 1 closed✅ Bug: Drift manifest snapshot is stale: only schema_sha256 was hand-synced
🤖 Prompt for agentsVerificationRules No rules evaluated Functional validation Not enabledAuto-approval Approved For more verification details, comment Tip Comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Important Your trial ends in 3 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more. Was this helpful? React with 👍 / 👎 | Gitar |
|
Auto-fix isn't included in your plan ↗ |
2c0d741
into
codex/full-deep-audit-remediation-20261018
#3650 merged into the old #3640 branch after this rebuild was cut. This applies exactly that branch's new changes, so the tree now equals the old branch merged with main. Includes migration 20261018095804 and its seal entry, which the owner approved by name. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018UBtJDgQZJ3eBsxLWte9r4
Summary
This PR extends
rag_cache_scope_revision_v1so that edits todocument_table_factsanddocument_imageschange the cache scope revision and invalidate cached answers and searches. Before this, editing a fact threshold or action, or an image caption, relevance or searchability flag, could leave a stale cached answer in place.Stacked on #3640. It must merge only after #3640, inside the owner-chosen production DB window. The base is #3640's branch because this migration replaces the function that #3640's
20261018082910_audit_durable_recovery_pairing_and_cache_fences.sqldefines. Once #3640 merges, GitHub retargets this PR tomain.The owner approved this migration at 17:55 AWST on 18 Oct 2026, relayed by Grok Bot. Draft migration:
supabase/migrations/20261018095804_rag_cache_scope_evidence_revision.sql, timestamped after main's newest and after #3640's.Design and cost (gitar's concern)
public.document_evidence_revisionsholds one bigint counter per document. Statement-level triggers with transition tables, on insert, update and delete for both tables, bump it inside the writing transaction.created_atandsearch_tsvare excluded. A no-op rewrite does not invalidate the cache.rag_cache_scope_revision_v1keeps the same signature, digest shape and grants. Each document's row hash now also carriescoalesce(r.revision, 0)through a keyed left join. The revision stays one pass overdocumentsplus a PK join, with no per-request scan or hash of the fact or image tables.Tests
tests/sql/rag-cache-scope-evidence-revision.sqlruns in CI Migration replay on the replayed chain. It shows the revision changes on fact insert, threshold edit, fact delete, image insert, caption edit and relevance/searchable edit. It also shows that a no-op update does not change it, that another document's scoped revision is unaffected, and that deleting the document still cascades and removes the counter.tests/rag-cache-governance-revocation.test.tsshows that an evidence-revision bump changescacheIndexingVersionand rejects local and shared cached answers and searches.Housekeeping
npm run migrations:seal.schema.sqlhas the projection appended. The drift manifest'sschema_sha256is synced; Docker isn't available on the box, so the full manifest snapshot will come from CI's regenerateddrift-manifest-<run_id>artifact.Not sealed or decided here (owner / clinical)
Possible later follow-up
Summary by cubic
Stops cached RAG answers and searches from going stale when a document's table facts or images are edited. Previously the cache scope revision only changed when the document row itself changed, so a fact threshold, image caption, relevance, or searchability edit could leave an outdated cached answer in place. Now those edits bump a per-document evidence counter that feeds into the cache scope revision, invalidating affected cached entries.
document_evidence_revisions(one bigint counter per document) and statement-level triggers ondocument_table_factsanddocument_imagesthat bump it in the writing transaction;created_atandsearch_tsvchanges and no-op updates don't bump it.rag_cache_scope_revision_v1keeps its signature, digest shape, and grants; each document's row hash now includes the evidence counter via a keyed join (no per-request scan of the fact or image tables).Migration
Written for commit 7b47c11. Summary will update on new commits.