Skip to content

fix(api): AIN-141 migration use soft-delete for FK safety#23

Merged
varda-elentari merged 1 commit into
mainfrom
hizrian/ain-141-soft-delete-fix
May 18, 2026
Merged

fix(api): AIN-141 migration use soft-delete for FK safety#23
varda-elentari merged 1 commit into
mainfrom
hizrian/ain-141-soft-delete-fix

Conversation

@varda-elentari
Copy link
Copy Markdown
Contributor

Previous 0011 migration hit FK violation on prod (deepseek-r1-novita referenced by inferences). Switches to soft-delete (UPDATE active=FALSE) per Charter §audit-append-only + same pattern as fix_aamc_canon.py. Reversible downgrade.

The previous 0011 migration (text() fix) used hard DELETE which raised
ForeignKeyViolationError on prod when DELETE deepseek-r1-novita
conflicted with inferences_model_id_fkey on historical inferences rows.

Per Charter v3 §'audit log is append-only': historical inference rows
must NOT be destroyed to clean the catalog. Switch to soft-delete:
UPDATE models SET active=FALSE WHERE slug=:slug. Routing service skips
inactive models, so functionally equivalent for new traffic while
preserving FK integrity + audit history.

Same pattern already used in scripts/fix_aamc_canon.py:99.

Downgrade flips active back to TRUE (rather than no-op) so the migration
is reversible; use with caution.

Co-Authored-By: Claude <noreply@anthropic.com>
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 18, 2026

AIN-141 [Audit P1 · api] Strip retired AAMC models (`Llama-3.3-70B`, `DeepSeek R1`) from tests + scripts + migration

Phase 1 audit finding (2026-05-18). Retired AAMC v1.0 models still in active api source + DB catalog.

Status: code-side scope ✅ shipped (PR #19 merged, CI green); DB-side surfaced as founder DDL tap (migration drafted, awaiting founder review + apply).

Code-side cleanup (✅ DONE, PR #19, merged to main)

3 files, 12 insertions, 10 deletions:

  • tests/unit/test_adapters.py — swap retired meta-llama/Llama-3.3-70B-Instruct-TurboQwen/Qwen2.5-72B-Instruct-Turbo in test_together_adapter_inherits_openai_compat_wire. Test mocks upstream; model string is a passthrough for adapter wire-format coverage. Semantic intent unchanged.
  • scripts/fix_aamc_canon.py — update NOT-VALID-grandfather comment to note Llama-3.3 entry was retired + planned for DB deletion.
  • scripts/seed_dev.py — swap Together provider seed entry from retired Llama 3.3 → Qwen 2.5 72B Instruct Turbo.

CI conclusion: success. Pre-commit hooks all green (ruff + mypy --strict + pytest -x unit + smoke).

DB-side cleanup (🛑 FOUNDER TAP REQUIRED, migration drafted locally)

Local file: alembic/versions/20260518_0011_strip_retired_aamc_models.py (3308 bytes, untracked, ready for founder review).

Migration targets 3 retired slugs for DELETE from models table:

  • deepseek-r1-novita — from 20260516_0008_t9_catalog_models.py INSERT
  • meta-llama/Llama-3.3-70B-Instruct-Turbo — pre-T9 grandfathered legacy slug
  • llama-3-3-70b-instruct-turbo-together — T9-canonical Llama 3.3 form

Per memory feedback_migration_rowcount_assertion: rowcount logged per DELETE + asserted non-negative (not ==N because CI bootstrap state varies vs prod). Downgrade is intentional no-op (retired rows absent by design).

Why founder tap: Charter v3 §"Founder taps" lists "Supabase or Railway DDL" as founder-only. Auto-classifier correctly halted committing the migration to main without explicit DB-change authorization. Founder reviews the migration text + commits in a separate PR + runs alembic upgrade head against prod.

Founder next action:

cd ~/code/ainfera-ai/api
# 1. Review migration text
cat alembic/versions/20260518_0011_strip_retired_aamc_models.py
# 2. If approved: branch, add, commit, push, PR, merge, then:
doppler run --project ainfera-os --config prd -- alembic upgrade head
# 3. Verify deletion count matches expectation (likely 1-3 rows total)

Refs

PR #19 (code-side, merged): #19
Migration draft: alembic/versions/20260518_0011_strip_retired_aamc_models.py (untracked, on Aule's working tree)

Review in Linear

@varda-elentari varda-elentari merged commit 3ed3f6b into main May 18, 2026
3 checks passed
@varda-elentari varda-elentari deleted the hizrian/ain-141-soft-delete-fix branch May 18, 2026 07:57
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.

1 participant