db: add fail-safe document-change ingestion trigger - #1100
Conversation
Updates to Preview Branch (codex/supabase-document-change-trigger) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
📝 WalkthroughWalkthroughAdds a fail-safe Supabase trigger that posts an allowlisted webhook when ChangesDocument change webhook
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/outstanding-issues.md`:
- Line 59: Replace the future-dated verification record in
docs/outstanding-issues.md:59 with the actual replay/test date, or mark
verification as pending if it has not occurred; update the review date in
docs/branch-review-ledger.md:23 to the actual date as well. Keep the documented
evidence and status consistent with dates on or before 2026-07-23.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 8fe5b47f-c2fd-404e-ad8e-66eb9923d8ea
📒 Files selected for processing (7)
docs/branch-review-ledger.mddocs/outstanding-issues.mddocs/webhooks.mdsupabase/drift-manifest.jsonsupabase/migrations/20260723150000_document_change_ingestion_webhook.sqlsupabase/schema.sqltests/supabase-schema.test.ts
| | #024 | P3 | issue | WebKit e2e `_rsc`-prefetch access-control-checks errors | verify:release:offline on `main` ce32fe170 (2026-07-22) reproduced #023's webkit clause: **6/6 deterministic** failures in `tests/ui-route-coverage.spec.ts` (Therapy Compass; DSM home/comparison; Specifier comparison/map; Differential stream), each a `pageerror … ?_rsc=… due to access control checks` on Next.js RSC prefetch — Chromium + Firefox clean. Not merge-blocking (required gate `test:e2e:pr` is chromium-only; the full webkit matrix is advisory/release-time). Most likely a Playwright route-interception × WebKit interaction, not a Safari user defect. Next: decide (a) allow/mock the `_rsc` routes for the `webkit` e2e project, or (b) confirm real Safari impact — before trusting the full-matrix webkit gate at release. NB the 2 other webkit fails (`ui-stress:412`, `ui-universal-search:210`) passed on isolated re-run = true flake. | session 2026-07-22 (verify:release:offline, `main` ce32fe170); refines #023 | 2026-07-22 | | ||
| | #025 | P2 | task | Activate the three webhooks (operator secrets) | Merged (#968) + deployed but inert — verified live: `POST /api/webhooks/railway` returns `503 webhook_not_configured`. To turn on: (1) Railway → set `RAILWAY_WEBHOOK_SECRET` + add the `?token=…` webhook URL; (2) the chat URLs `SLACK_WEBHOOK_URL`/`DISCORD_WEBHOOK_URL` must be set in BOTH places — the Railway **app/server env** (the receiver forwards deploy alerts via `postChatNotification`, which reads server env, so repo-secret-only leaves the Railway webhook authenticated but returning `delivered:false`) AND as **GitHub repo secrets** (the CI-failure workflow reads `secrets.*`); (3) `SUPABASE_INGESTION_WEBHOOK_SECRET`. Each fails closed until set, so this is pure ops. See docs/webhooks.md. | session 2026-07-22; PR #968; docs/webhooks.md | 2026-07-22 | | ||
| | #026 | P2 | task | Wire the Supabase document-change trigger | Locally implemented on `codex/supabase-document-change-trigger` in dedicated worktree `C:\\Users\\joshs\\.codex\\worktrees\\supabase-trigger-20260723\\Database`: forward migration `20260723150000_document_change_ingestion_webhook.sql`, schema mirror, update-only/minimal/fail-safe contract test and rollback docs. Focused schema tests 69/69 plus migration-role, function-grant and owner-scope guards pass. Not committed or applied: disposable replay and `drift:manifest` are blocked because Docker cannot start and `wsl --status` returns `Wsl/0x80070422` (WSL service disabled). Next: enable WSL/Docker, replay and regenerate drift, run broad gates, then use a protected-main PR before configuring the Vault secret/base-URL GUC. Never apply the SQL raw to live. | local branch/worktree; `docs/webhooks.md` section 3; session 2026-07-23 | 2026-07-22 | | ||
| | #026 | P2 | task | Wire the Supabase document-change trigger | Implementation is complete on `codex/supabase-document-change-trigger`: forward migration `20260723150000_document_change_ingestion_webhook.sql`, schema mirror, update-only/minimal/fail-safe contract test and rollback docs. On 2026-07-24, `drift:manifest` replayed the full schema successfully in disposable Supabase Postgres 17.6.1.127, regenerated the manifest and removed the container; focused schema/drift tests passed 79/79 plus migration-role, function-grant and owner-scope guards. Next: protected-main PR and hosted migration-chain replay, then apply the committed migration through the normal Supabase path before configuring the Vault secret and base-URL GUC. The trigger remains inert until all three live steps are complete. | local branch/worktree; `docs/webhooks.md` section 3; session 2026-07-24 | 2026-07-22 | |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Use actual dates for completed verification records. Both entries claim evidence from 2026-07-24, which is future-dated relative to 2026-07-23.
docs/outstanding-issues.md#L59-L59: replace the future completion date with the actual replay/test date, or keep the verification pending.docs/branch-review-ledger.md#L23-L23: replace the future review date with the actual review date.
📍 Affects 2 files
docs/outstanding-issues.md#L59-L59(this comment)docs/branch-review-ledger.md#L23-L23
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/outstanding-issues.md` at line 59, Replace the future-dated verification
record in docs/outstanding-issues.md:59 with the actual replay/test date, or
mark verification as pending if it has not occurred; update the review date in
docs/branch-review-ledger.md:23 to the actual date as well. Keep the documented
evidence and status consistent with dates on or before 2026-07-23.
Summary
documentsmetadata trigger that enqueues the existing document-change ingestion webhook only whenreindex_requestedtransitions to JSON booleantrue.RAG impact: no retrieval behaviour change — this database trigger only enqueues the existing ingestion path.
Verification
npm run verify:pr-local— exit 0; 365 files, 3241 passed, 1 skipped; build correctly skipped by path selection.npm run verify:ui— not run; no UI, routing, styling, or browser behavior changed.npm run verify:release— not run; this is a focused database handoff, not a release-confidence run.npm run drift:manifest -- --container clinical-kb-drift-manifest-supabase-trigger-20260724-2340 --port 56673— disposable PostgreSQL 17 replay passed and the scratch container was removed.npm run test -- tests/supabase-schema.test.ts tests/drift-detection.test.ts tests/webhooks-supabase-document-change-route.test.ts— 89/89 passed.npm run check:migration-role— passed.npm run check:function-grants— passed; all 30 security-definer functions conform.npm run check:owner-scope— passed; 40 API files and 25 owner-scoped tables checked.npm run check:production-readiness:ci— READY; the isolated worktree intentionally has no local provider secrets, so configuration warnings were expected.npm run eval:rag:offline— 21 suites / 307 tests passed.npm run verify:cheap— exit 0; 365 files, 3241 passed, 1 skipped.Risk and rollout
pg_netdelivery is intentionally at-most-once. A dropped request is recovered by clearing and re-setting the reindex flag. The trigger is inert when the Vault secret or base URL is missing, and trigger failures never abort the document update.documents_ingestion_webhook, then droppublic.notify_document_change_ingestion_webhook(); no document rows are modified or deleted.Clinical Governance Preflight
Clinical KB Database(sjrfecxgysukkwxsowpy)Notes
Note
Medium Risk
Touches production database ingestion wiring and outbound HTTP from triggers; mitigated by fail-open writes, no prod URL default, and narrow payload, but live migration plus operator secret/GUC setup is required before it becomes active.
Overview
Adds a Supabase
documentsmetadata trigger that POSTs to the existing/api/webhooks/supabase/document-changereceiver whenmetadata.reindex_requestedtransitions to JSON booleantrue(not string"true"). Delivery uses Vault (ingestion_webhook_secret) and a per-environmentapp.ingestion_webhook_base_urlGUC—no production URL fallback—and sends only allowlistedid/owner_id/status/reindex_requestedfields.The trigger is
AFTER UPDATE OF metadataonly, runs as SECURITY DEFINER with execute revoked frompublic/anon/authenticated, and fails open (missing config orpg_neterrors never block the row update). Docs cover at-most-once delivery recovery (clear/re-flip the flag) and data-preserving rollback; drift manifest and schema contract tests lock the migration in.Reviewed by Cursor Bugbot for commit 67c96b8. Configure here.
Summary by CodeRabbit
New Features
Documentation
Bug Fixes