Skip to content

Guard schema snapshot against NULL-generation artifact purge regressions - #164

Merged
BigSimmo merged 4 commits into
mainfrom
copilot/keep-schema-commit-artifacts
Jul 2, 2026
Merged

Guard schema snapshot against NULL-generation artifact purge regressions#164
BigSimmo merged 4 commits into
mainfrom
copilot/keep-schema-commit-artifacts

Conversation

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • commit_document_index_generation already had replacement guards in migration logic, but the risk was schema snapshot drift back to unconditional NULL-generation deletes, which would erase legacy artifacts (for example document_images) during commits.

  • Added regression coverage to lock in the guarded-delete contract across both live migration SQL and supabase/schema.sql.

  • Schema snapshot parity guard

    • Added a fixture load for 20260702000000_commit_generation_preserve_legacy_artifacts.sql in tests/supabase-schema.test.ts.
    • Added a focused test asserting replacement-exists guard patterns are present for:
      • document_chunks
      • document_images
      • document_table_facts
      • document_embedding_fields
      • document_index_units
      • document_memory_cards
      • document_sections
  • Example assertion pattern

    expect(sql).toContain(
      "nullif(metadata->>'index_generation_id', '') is null and exists ( select 1 from public.document_images replacement",
    );

Verification

  • npm run verify:cheap
  • npm run verify:ui when UI, routing, styling, browser behavior, reduced-motion, or forced-colors behavior changed
  • npm run verify:release before release or handoff confidence claims
  • npm run format:check
  • npm run check:production-readiness when clinical workflow, privacy, environment, Supabase, source governance, or deployment behavior changed
  • npm run check:deployment-readiness when deployment startup, hosting, or rollout behavior changed

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

  • Scope is intentionally minimal: test-only guardrails to prevent future schema commits from reintroducing destructive NULL-generation artifact deletes.

Copilot AI changed the title [WIP] Fix schema commit to retain NULL-generation artifacts Guard schema snapshot against NULL-generation artifact purge regressions Jul 2, 2026
Copilot AI requested a review from BigSimmo July 2, 2026 10:11
@BigSimmo
BigSimmo marked this pull request as ready for review July 2, 2026 10:28
@BigSimmo
BigSimmo enabled auto-merge July 2, 2026 10:28
@BigSimmo
BigSimmo merged commit 69a26f0 into main Jul 2, 2026
4 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c5914ec3e7

ℹ️ 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".

Comment on lines +183 to +187
expect(sql).toContain("from public.document_table_facts replacement");
expect(sql).toContain("from public.document_embedding_fields replacement");
expect(sql).toContain("from public.document_index_units replacement");
expect(sql).toContain("from public.document_memory_cards replacement");
expect(sql).toContain("from public.document_sections replacement");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Assert the NULL-generation guard for every artifact table

The test claims to guard all artifact deletes, but after document_images these assertions only prove that a same-table replacement subquery exists somewhere in the SQL. A schema regression that changes, for example, document_memory_cards back to an unconditional nullif(metadata->>'index_generation_id', '') is null delete would still pass as long as the from public.document_memory_cards replacement text remains, so the destructive drift this test is meant to catch can slip through. Please assert the full is null and exists (...) guard per table, or isolate each delete block before checking it.

Useful? React with 👍 / 👎.

@BigSimmo
BigSimmo deleted the copilot/keep-schema-commit-artifacts branch July 2, 2026 16:31
BigSimmo pushed a commit that referenced this pull request Jul 31, 2026
Three conflicts, resolved by evidence rather than by side-preference.

scripts/ensure-codex-cloud-git-remote.mjs and tests/codex-cloud-setup.test.ts:
took main's version. The branch carried its own fix for the same defect
(5aa3d6c, judging origin safety from the configured remote URL) on top of
main's #1497, so neither side was obviously newer. main's version introduces a
configuredOriginUrl() helper, already covers the url.*.insteadOf case the
branch's extra test was written for, and passes 12/12 locally — verified
before choosing, since taking a side wholesale is only safe when the other
side's content is genuinely subsumed. This also clears the two
codex-cloud-setup failures this branch has carried all session.

docs/outstanding-issues.md: fifth id collision on this branch. main has since
claimed #151-#153 — the exact ids these rows previously held — and now runs to
#164. main's rows are kept and the follow-ups renumber to #165 (adopt a
consolidated answer-home notice block), #166 (answer mode ships no
verify-before-use caveat) and #167 (verify:pr-local exits 0 when its build
step refuses to run), with their three cross-references and the marker (168)
following.

check:outstanding-issues: 165 rows (50 open, 115 archived), unique ids,
next-id=168 above the highest, no ids deleted from base 23465d5.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NPyFcMfn1jMmphr6AqiWBg
Sign up for free to 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.

**<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Keep schema commit from deleting NULL-generation artifacts**

2 participants