Skip to content

feat(db): Phase 3 staging proof + forward-codify three hybrid RPC bodies the chain never received (#316) - #2111

Merged
BigSimmo merged 5 commits into
mainfrom
claude/db-phase3-staging-proof-bodies
Aug 18, 2026
Merged

feat(db): Phase 3 staging proof + forward-codify three hybrid RPC bodies the chain never received (#316)#2111
BigSimmo merged 5 commits into
mainfrom
claude/db-phase3-staging-proof-bodies

Conversation

@BigSimmo

@BigSimmoBigSimmo commented Aug 18, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up to #2106 (database remediation Phase 3, ledger #316): the staging proof that #2106's gate opened for once the Phase 2 re-measure (#2104) merged, plus the one migration it turned out to need. No canonical (schema.sql = production) function body changed; no hosted value changed; no production access.

RAG impact: no retrieval behaviour change — codifying three already-live RPC bodies into the migration chain, byte-for-byte from schema.sql; no canonical function body changed

  • Staging proof RUN (forensics §3.5) — owner-authorised window on Clinical KB Staging (ikoiolksxqxfxgiyqpnu; ref verified via list_projects, project id passed literally on every call; production never targeted). 20260818110000 / 111000 / 112000 applied by the Phase 2 method (file verbatim + explicit schema_migrations row, never apply_migration); md5-identical read-back for all three at apply time; staging 198 rows, no_statements 0, corpus 0. Offline reproduction of check:drift (same categoryKeys / comparedFields, per-object md5 on staging vs. the manifest rendered in jsonb text form; 590/594 objects hash-equal, which validates the method): the 8 never-created objects, the 3 column-set mismatches and 4 of the 7 work_mem mismatches are gone. Residual 4: document_chunks_content_trgm_idx (the expected Phase 4.4 residual) and three functions whose ACL and proconfig now equal the manifest but whose bodies differ.
  • 20260818113000_forward_codify_hybrid_owner_matches_bodies.sql — the reason for those three. On a chain-built database match_document_embedding_fields_hybrid, match_document_index_units_hybrid and match_document_memory_cards_hybrid_v2 still carry the legacy fail-open, sentinel-blind predicate (owner_filter is null or d.owner_id = owner_filter): 20260712000000_forward_codify_retrieval_owner_matches.sql left the body codification to an owner step, five other RPCs were codified later, these three never were (newest chain body 20260701140631). schema.sql == production for all three (manifest def_hash = live def_hash, forensics §3.1), so this is a reproducibility hole for migrations-only environments, not a production tenancy hole. The migration re-creates the three verbatim from schema.sql with every SET clause restated (proconfig preserved; ACLs untouched by CREATE OR REPLACE); no-op on production. Protected RAG surface: this migration contains RPC bodies — copied byte-for-byte from the canonical definitions, nothing edited.Applied to staging in a second owner-authorised window: the three hashes now equal manifest and live (bb975485…, d0e277a2…, ab87a18b…), history row md5 d35c199b… = repo.
  • Final staging comparison: UNEXPECTED DRIFT (1) = document_chunks_content_trgm_idx only — zero function mismatches, zero never-created objects, zero table mismatches (the Phase 3 target); the single residual is the Phase 4.4 trgm rebuild.
  • Deviation found and resolved — before feat(db): codify live SET work_mem on the ten match_* RPCs, the eight schema-only objects, and three chain-stale columns (#316) #2106 was squash-merged, 20260818111000 / 112000 gained a set local lock_timeout / statement_timeout preamble, so the text on main (22585b9e…, ec154770…) differed from what staging had recorded (9d02d14e…, ea5f9c69…; identical DDL). The two staging rows were refreshed to the merged text in the second window; all four rows now read back md5 = repo (forensics §3.5).
  • Ledger — the earlier #316 update requests (4dbcdcce… on main, 10e480da… on this branch) are cancelled in-inbox and replaced by one final update carrying the completed staging result (two updates on one id would block issues:reconcile).

Production window — NOT authorised in this PR (for the coordinator)

MigrationEffect on production
20260818090000_schema_drift_snapshot_history_probereal change — schema_drift_snapshot() v2 (Phase 6.1)
20260818110000_codify_live_rpc_work_memno-op — the ten work_mem values already match
20260818111000_codify_schema_only_indexes_and_triggersno-op — all eight objects already exist
20260818112000_reconcile_chain_stale_table_columnsno-op — column and both defaults already as declared
20260818113000_forward_codify_hybrid_owner_matches_bodiesno-op — identical to the live bodies (hash proof §3.1)

One window, no canary (D2), no index build, no body that production does not already run.

Verification

  • npx vitest run tests/supabase-schema.test.ts tests/migration-history-guards.test.ts tests/search-health-index-coverage.test.ts tests/hosted-migration-role-guard.test.ts tests/migration-history-placeholders.test.ts tests/drift-detection.test.tsTest Files 6 passed (6) · Tests 109 passed (109)
  • npm run check:migration-roleHosted migration-role guard passed: active hosted SQL/tooling uses postgres and immutable applied history is unchanged.
  • npm run check:outstanding-issuesOutstanding-issues guard passed: 361 rows (105 open, 256 archived) …; npm run docs:check-linksdocs link check passed: 1921 repo path references resolve.
  • npm run verify:pr-local not re-run in full for this follow-up: the diff is one migration file (bodies verbatim from the unchanged schema.sql, so drift-manifest.json is unchanged and its freshness test passes), a forensics section, and two inbox JSON files; the full gate ran green on feat(db): codify live SET work_mem on the ten match_* RPCs, the eight schema-only objects, and three chain-stale columns (#316) #2106 (lint, typecheck, full unit suite except the known Windows-environmental/host-load failures) and nothing here touches lint/typecheck surfaces.
  • UI verification not run: no UI, routing, or styling change.
  • eval:retrieval:quality not run: no retrieval, ranking, selection, chunking, or scoring behaviour changed (bodies identical to production; owner decision D2 for the surrounding work).

Risk and rollout

  • Risk: low. The migration text equals production's live definitions; on any migrations-only environment it replaces the legacy fail-open owner predicate with the fail-closed helper production already runs — strictly safer.
  • Rollback: revert the PR (removes the migration file); on a hosted target that already ran it, no rollback is meaningful because the resulting bodies equal production's.
  • Provider or production effects: staging (ikoiolksxqxfxgiyqpnu) received 20260818110000 / 111000 / 112000 / 113000 in two owner-authorised windows (plus the two history-row text refreshes); production untouched.

Clinical Governance Preflight

Complete this section when the change touches ingestion, answer generation, search/ranking, source rendering, document access, privacy, production env, or clinical output.

  • Source-backed claims still require linked source verification before clinical use
  • No patient-identifiable document workflow was introduced or expanded without explicit governance approval
  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy)
  • Service-role keys and private document access remain server-only
  • Demo/synthetic content remains clearly separated from real clinical sources
  • Source metadata, review status, and outdated/unknown-source behavior remain conservative
  • Deployment classification/TGA SaMD impact was checked when clinical decision-support behavior changed

Notes

  • Protected RAG surface flagged (AGENTS.md "RAG ranking protection"): the migration carries three match_* bodies, copied verbatim from schema.sql; the equality of manifest and live hashes for those three is the proof they are production's bodies.
  • The stale re-created remote branch claude/schema-work-mem-codify-6200f1 was deleted (owner-authorised).

… bodies the chain never received (#316)
Staging (ikoiolksxqxfxgiyqpnu, owner-authorised window) received
20260818110000/111000/112000 by the Phase 2 method with md5-identical
history rows. Offline reproduction of check:drift shows the eight
never-created objects, the three column-set mismatches and four of the
seven work_mem mismatches gone; residual: the expected trgm index plus
three functions whose bodies still carry the legacy fail-open owner
predicate on a chain-built database (embedding_fields_hybrid,
index_units_hybrid, memory_cards_hybrid_v2) — never forward-codified
after 20260712000000. schema.sql == production for all three (manifest
hash = live hash), so this is a reproducibility hole, not a production
tenancy hole.
- 20260818113000_forward_codify_hybrid_owner_matches_bodies: the three
definitions verbatim from schema.sql (all SET clauses restated); no-op
on production. Its staging apply is pending owner permission.
- forensics section 3.5 rewritten with the staging evidence; 3.6 window
table now lists five migrations.
- #316: earlier update request cancelled (same-id collision) and replaced
by one combined update carrying the staging result.
RAG impact: no retrieval behaviour change - codifying already-live SET
work_mem attributes, mirror-only objects, and three already-live bodies;
no canonical function body changed
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitaiBot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in:35 minutes

Limit details: You’ve used all 1 included review currently available under your plan. You completed 101 included PR reviews in the past 7 days; at that activity level, included reviews refill at 1 review per hour.

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 63502c2e-e03e-45ad-88fc-a5620350677d

📥 Commits

Reviewing files that changed from the base of the PR and between 511d22f and 7eda04d.

📒 Files selected for processing (8)
  • docs/audit/live-drift-forensics-2026-08.md
  • docs/branch-review-records/374fbb8ab1553ad0ad69733f3456873bf7e30871fdafbd985fd22feaea12279b.record.md
  • docs/branch-review-records/9d9815f1d88e54d6803eca19580348e2e3d9e209af3725527ade39fc5ad9badd.record.md
  • docs/outstanding-issues-inbox/10e480da-b2e3-4e2d-bfc8-15456bf962c1.json
  • docs/outstanding-issues-inbox/22946f19-6197-408e-b154-142d226a2743.json
  • docs/outstanding-issues-inbox/23ba3865-258a-4f24-ace4-05e683776dc1.json
  • docs/outstanding-issues-inbox/8b0650ed-793c-4f05-be9d-2012b6456a72.json
  • supabase/migrations/20260818113000_forward_codify_hybrid_owner_matches_bodies.sql
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/db-phase3-staging-proof-bodies

Comment @coderabbitai help to get the list of available commands.

…w-up)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@supabase

supabaseBot commented Aug 18, 2026

Copy link
Copy Markdown

Updates to Preview Branch (claude/db-phase3-staging-proof-bodies) ↗︎

DeploymentsStatusUpdated
DatabaseTue, 18 Aug 2026 11:18:29 UTC
ServicesTue, 18 Aug 2026 11:18:29 UTC
APIsTue, 18 Aug 2026 11:18:29 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

TasksStatusUpdated
ConfigurationsTue, 18 Aug 2026 11:18:31 UTC
MigrationsTue, 18 Aug 2026 11:18:33 UTC
SeedingTue, 18 Aug 2026 11:18:34 UTC
Edge FunctionsTue, 18 Aug 2026 11:18:35 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

BigSimmoand others added 2 commits August 18, 2026 18:53
…ws refreshed, single trgm residual (#316)
Second owner-authorised staging window on ikoiolksxqxfxgiyqpnu: applied
20260818113000 (three hashes now equal manifest/live), refreshed the
111000/112000 history-row text to the merged files, all four rows md5 = repo;
final offline drift comparison = UNEXPECTED DRIFT (1), document_chunks_content_trgm_idx
only. #316 request superseded by one final update.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…plete)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@BigSimmo
BigSimmo enabled auto-merge (squash) August 18, 2026 11:17
@BigSimmo
BigSimmo merged commit 9b52eb0 into mainAug 18, 2026
24 checks passed
@BigSimmo
BigSimmo deleted the claude/db-phase3-staging-proof-bodies branch August 18, 2026 11:23
BigSimmo pushed a commit that referenced this pull request Aug 18, 2026
One of the two pending #316 requests (10e480da) already had a cancel
from the original batch (8b0650ed, 'superseded within PR #2111').
Cancelled the other stale one (22946f19, whose baseRowFingerprint no
longer matched the current row) and reissued its content -- the more
complete of the two, describing the finished two-window staging proof
-- as a fresh update request against the row's current content.
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