← Model losses

Head-to-head comparison

openai / gpt-6.1-sol / low / low effort preferred over openai / gpt-6-luna / low / low effort · clear win.

Primary judge: Sol 6.1, requested Low. Effective provider effort and internal attempts were not verified. A close win is still a scored preference; it does not establish a material defect.

Reviewed public evidence

Task goal

Assess a safe, backward-compatible rollout and rollback for the current [REDACTED: private project name] tenant schema represented by these migrations and SQL tests. Treat the schema as already deployed with existing tenant data while API services and workers may run mixed versions during rollout. Ground every claim in the supplied files and cite the relevant definitions or assertions. Identify concrete ordering, compatibility, lock/backfill, integrity, tenant-isolation, and rollback risks; separate proven behavior from assumptions about application code not included here. Give a phased expand/migrate/verify/contract plan, explicit rollback boundaries after writes, and measurable pre/post-deployment checks using the existing test contracts. Do not invent application APIs, claim tests were run, or edit code.

openai / gpt-6.1-sol / low / low effort answer

## Conclusion

**Do not replay these migrations or treat the SQL test comments as proof of deployment safety.** For an already-populated database, use additive, versioned changes and defer privilege contraction until all live API and worker versions demonstrably work with it.

This is an independent, read-only assessment of the supplied snapshot. No tests were run.

### Evidence-backed risks

| Finding | Evidence | Implication / confidence |
|---|---|---|
| Hardening is a breaking access change, not an expansion. | `supabase/migrations/00015_hardening.sql:4–22` revokes authenticated access to app tables, sequences and functions, then grants SELECT on five public API views. | Old authenticated clients using app tables or functions can fail immediately after commit. Whether existing clients do so is unknown. **High confidence.** |
| Public-view isolation is unproven. | Hardening grants access to `public.api_*` views (`00015:16–22`), while integration tests query `app.v_*` views (`supabase/test-integration.sql:315–337`). Neither view definitions nor ownership/security settings are supplied. | Passing the app-view tests would not establish isolation of the newly granted public surface. **High confidence.** |
| Membership policies do not implement member-role authorization. | `app.is_member` checks tenant/user only (`00002_create_schema_and_tenant.sql:36–47`); the modification policy allows every member (`00008_enable_rls_and_policies.sql:42–46`). Role documentation describes viewers as read-only (`00002:27,33`). | Where underlying grants permit writes, viewers also satisfy write policies. Hardening restricts direct authenticated access but does not make the policies role-aware. **High confidence.** |
| Cross-tenant parent links are possible under the declared constraints. | Survey has separate tenant and asset FKs (`00003_create_core_tables.sql:29–30`); observation has separate tenant and survey FKs (`00003:46–47`). | Neither FK establishes that child and parent have equal tenant IDs. RLS checks the child’s tenant, not its parent’s. This can produce contaminated joins and cross-tenant cascade effects; actual exploitation depends on effective privileges. **High confidence.** |
| Cascades make deletion an irreversible boundary without recovery evidence. | Tenant membership cascades (`00002:25`); assets, surveys and observations cascade through their FKs (`00003:8,29–30,46–47`). | Dropping a tenant or parent can delete existing descendants, including incorrectly linked cross-tenant descendants. Reverting DDL does not restore deleted rows. **High confidence.** |
| Security-definer functions need privilege review. | Both helpers are `SECURITY DEFINER` (`00002:40`; `00008:24`). Policy helper interpolates a caller-provided relation using `%s` (`00008:33–45`); neither declaration fixes a function search path. | Inspect ownership, executable roles, effective PUBLIC privileges and search-path safety. Revoking authenticated’s direct function grants (`00015:9`) alone does not prove PUBLIC/inherited execution is denied. Actual exploitability is not established. **High confidence on review need.** |
| RLS coverage is time-dependent. | `00008:10–17` enables RLS on app base tables existing at execution; policy application is an explicit list (`00008:52–66`). | Future tables are not automatically protected by this loop. An additive rollout must explicitly establish RLS and policies before granting access. **High confidence.** |
| Replay is unsafe and dependency order matters. | Table creation uses `IF NOT EXISTS`, but index creation does not (`00002:52–53`); named tenant/audit policies are created without replacement (`00008:71–91`). `00008:55–66` and `00015:16–21` reference objects not defined in this packet. | `IF NOT EXISTS` does not reconcile an existing table’s shape. Replay can fail or overwrite selected policies. Referenced tables/views must already exist; their definitions remain external dependencies, not presumed absent. **High confidence.** |

Additional integrity limits: `tenant_member.user_id` has only a comment referencing auth users, not a declared FK (`00002:26`); nullable grade/coverage/direction remain allowed despite checks (`00003:33–35,49`); no survey business-key uniqueness or observation deduplication key is declared (`00003:27–56`). Consequently, test `ON CONFLICT DO NOTHING` does not make repeated survey/observation fixtures idempotent (`supabase/test-rls.sql:82–102`).

Audit policies also differ from their comment: SELECT permits any tenant member, not only the event’s user, and INSERT checks user identity without tenant membership (`00008:68–77`). Actual audit grants and table constraints are unknown.

## Phased rollout

### 1. Baseline and prepare

Before changes:

- Capture live schema, constraints, indexes, policy expressions, view definitions/security settings, owners, role memberships, effective grants and default privileges.
- Establish which roles and database objects each deployed API/worker version actually uses. The packet contains no application implementation or version compatibility evidence.
- Record tenant-scoped row counts and ingestion progress; audit:
  - survey/asset tenant mismatches;
  - observation/survey tenant mismatches;
  - membership user IDs without corresponding auth users;
  - unexpected duplicates against the intended, explicitly agreed business keys.
- Require **zero unresolved cross-tenant links** before enforcing tenant-consistent relationships.
- Verify recovery with a restore rehearsal and record a recovery point before repairs or destructive changes.

Do not run these fixture scripts unmodified against existing production tenants. Integration tests update unit costs, create AMP versions and modify unmatched records (`test-integration.sql:165–171,183–187,235–238,271–275`); optional cleanup deletes all AMP sections and LOS targets for the tenant (`:428–432`).

### 2. Expand

- Preserve current columns, read surfaces and safe grants needed by old versions.
- Add replacement structures without requiring old writers to populate new mandatory fields immediately.
- Establish tenant protection before exposing new objects.
- If repairing cross-tenant relationships, prepare tenant-qualified parent uniqueness and corresponding composite FKs while retaining current identifiers and FK interfaces.
- Do not apply the broad authenticated revocations as the first compatibility step.

**Lock controls:** use bounded lock/statement timeouts, inspect blockers, and stage work in short transactions. The supplied index statements are ordinary, non-concurrent creation (`00002:52–53`); RLS changes execute across tables (`00008:6–18`); hardening bundles privilege changes in one transaction (`00015:1–24`). None specifies lock budgets or an online backfill strategy.

For new integrity enforcement, consider concurrent supporting-index construction where applicable, staged FK validation and separately scheduled short-lock operations. These are proposed techniques, not behavior implemented in this snapshot.

### 3. Migrate

- Deploy compatible application versions before relying on new representations or access paths.
- Establish a single authoritative write representation or verified dual-write strategy; no such strategy is evidenced here.
- Backfill in restartable, bounded batches with tenant-level progress, mismatch counts, latency and replication/WAL monitoring.
- Prevent old writers from recreating invalid links while repairs run. Composite FKs staged without validating historical rows can constrain subsequent writes, but may reject legacy behavior: test it first.
- Do not “repair” child tenant IDs automatically. That changes visibility; determining the correct tenant requires evidence beyond these files.
- Test old-worker retries and processing of records written by new versions. The scripts name manifests/jobs and expected states but do not define queue claiming, retry or idempotency behavior (`test-integration.sql:95–123`).

### 4. Verify

Require all checks below across old/new API and worker combinations, including delayed jobs and retries.

### 5. Contract

Only after old versions and incompatible queued work are drained:

- Enforce validated constraints and any new mandatory fields.
- Remove compatibility paths individually.
- Apply privilege contraction only after proving intended public-view access and tenant isolation.
- Revoke narrowly and verify effective privileges; do not assume direct-role revocations remove inherited access.
- Retain rollback artifacts and old representations until the agreed observation window expires.

The supplied database-level search-path change (`00002:9`) also warrants connection-pool verification: do not assume existing and fresh sessions resolve unqualified names identically.

## Measurable verification gates

1. **RLS catalog checks:** reproduce rowsecurity and policy inspection (`test-rls.sql:116–131`), expanding coverage to every exposed tenant table. Require intended policy expressions, not merely matching names.

2. **Real identity tests:** test a non-bypass member and outsider with genuine request identity, plus the two-tenant case (`test-rls.sql:188–231,276–285`). Require zero foreign-tenant rows and rejected cross-tenant INSERT/UPDATE attempts.

   The integration script’s `SET ROLE postgres` plus JWT setting (`test-integration.sql:55–60,312–337`) does not prove non-bypass RLS enforcement. Its `SET ... = (SELECT ...)` expressions also require adaptation to executable identity setup. The RLS script explicitly acknowledges service-role limitations (`test-rls.sql:170–176`).

3. **Post-hardening access matrix:** authenticated app-table/function denial where intended; successful permitted public-view reads; zero outsider/foreign-tenant results through **each of the five public views** (`00015:16–21`). Permission denial and an RLS-filtered zero-row result are different outcomes.

4. **Ingestion fixture contract:** in an isolated, tagged tenant, meet B2 expectations: ≥3 assets, ≥2 manifests queued/parsed, ≥2 parse jobs, ≥6 surveys across ≥3 assets, ≥15 observations, and ≥3 deltas including ≥1 deteriorating and ≥1 severe (`test-integration.sql:75–150`). Compare against baseline deltas, not only absolute counts. These thresholds alone do not prove correctness or deduplication.

5. **Directus contracts:** reproduce unit-cost 70.00 update, LOS targets, AMP authoring and unmatched resolution (`test-integration.sql:160–287`); require `rolsuper=false`, `rolbypassrls=false`, `rolcanlogin=true` (`:349–357`). Verify both USING and WITH CHECK expressions and tenant isolation.

6. **Operational gates:** zero unexplained count changes, zero tenant-link mismatches, zero unvalidated required constraints, and no regression beyond predetermined latency/error/backlog thresholds. The packet supplies no operational thresholds; agree them before deployment.

## Explicit rollback boundaries

- **Before commit:** `00015` is transaction-wrapped; aborting before commit restores that transaction’s prior privilege state (`00015:1–24`).
- **After privilege-only commit:** a narrowly reconstructed prior privilege configuration can restore compatibility without changing rows. Restoring blanket access may reopen security risks; use the captured baseline, not an indiscriminate grant.
- **After compatible additive writes:** application rollback is safe only if old versions can read/process every new row and retained columns remain authoritative. Otherwise stop or gate writers and reconcile first.
- **After backfill or tenant-link repair:** DDL rollback cannot undo data changes. Use recorded row-level before-images or a verified recovery/replay procedure; tenant changes can alter visibility immediately.
- **After new-only writes or destructive contract:** old binaries are not a safe rollback by default. Restore/translate the representation or roll forward.
- **After cascaded deletes:** require data recovery. Neither re-creating schema objects nor reinstating grants restores descendants.
- **After external ingestion/upload actions:** database rollback cannot undo S3 objects or processing side effects; the integration plan explicitly includes uploads (`test-integration.sql:80–93,291–302`).

## Uncertainty and next action

A legitimate alternative is that later, unsupplied migrations already implement Directus policies, safe public views and required grants. That possibility prevents declaring the live system broken—but does not validate it. Likewise, privilege contraction may already match every production client; the snapshot cannot prove this.

**Next action:** produce a live privilege/policy/view inventory and an old/new-version compatibility matrix, then run the corrected identity and isolated-fixture checks before any contraction.

MATERIAL_EVIDENCE_CONFLICT: Viewer roles are documented as read-only (`supabase/migrations/00002_create_schema_and_tenant.sql:33`) but member modification policies ignore role (`supabase/migrations/00008_enable_rls_and_policies.sql:42–46`); integration expects `app.is_directus()` policies (`supabase/test-integration.sql:377–390`) while the supplied policy creation uses only `app.is_member()` (`supabase/migrations/00008_enable_rls_and_policies.sql:36–46,52–66`).

openai / gpt-6-luna / low / low effort answer

## Conclusion

The packet describes a tenant-scoped schema, but it does **not** establish that a mixed-version rollout or rollback is safe. Treat the migrations as already deployed and preserve existing data: use additive changes first, keep old and new service/worker versions compatible during transition, and delay destructive contract changes until no old version can read or write the affected schema. The supplied files do not include a specific proposed schema change, application queries, or worker behavior, so exact compatibility and backfill requirements remain uncertain.

## Evidence and risks

- **Tenant identity is not enforced across relationships.** `app.survey` stores both `tenant_id` and `asset_id`, but its foreign key checks only `asset_id` (`00003`, lines 27–30). Likewise, `app.observation` stores `tenant_id` and `survey_id`, but its foreign key checks only `survey_id` (lines 43–48). The RLS helper checks membership for the row’s `tenant_id` (`00002`, lines 35–47), and standard policies apply that check to each row (`00008`, lines 36–46). Thus the packet does not prove that a survey’s tenant matches its asset’s tenant, or an observation’s tenant matches its survey’s tenant. Do not assume RLS closes this integrity gap.
- **Policy coverage and expectations are not fully aligned.** The RLS migration applies policies to a fixed list of tables (including `asset`, `survey`, and `observation`; `00008`, lines 51–66), while its initial RLS-enabling loop covers all base tables present at migration time (lines 5–18). A newly added table would not automatically receive a policy from that fixed list. Also, the integration test expects back-office policies to include `app.is_directus()` (`test-integration.sql`, lines 377–390), whereas the supplied policy helper uses `app.is_member(tenant_id)` (`00008`, lines 20–46). The packet does not show a later migration reconciling these definitions.
- **Privileges differ by role and test contract.** Hardening revokes authenticated access to app tables/functions and grants read-only access to named `public.api_*` views (`00015`, lines 3–22). Separately, integration tests expect Directus to insert/update back-office tables (`test-integration.sql`, lines 160–199, 201–248) and not access core tables (`lines 361–375`). The relevant Directus grants, policies, and view definitions are not supplied, so these expected behaviors are not proven by this snapshot.
- **Potential lock and backfill exposure depends on the change.** The supplied migrations create tables, indexes, policies, and alter database settings, but do not specify a new rollout’s DDL or data volume. No lock duration, online index strategy, batching, or backfill behavior can be established. Measure these on production-scale data before scheduling any constraint validation, index build, or table rewrite.
- **Test scripts are partly plans, not reliable proof of isolation.** `test-rls.sql` explicitly says SQL Editor/service-role testing cannot truly impersonate users (`lines 108–115`, `170–176`); its cross-tenant section describes expected results but queries both tenants as service role (`lines 218–230`). The integration smoke test sets `role postgres` before setting a JWT subject (`test-integration.sql`, lines 54–64), and the packet does not prove that this role is subject to RLS. Treat those SQL assertions as contracts/checklists, not demonstrated test results. The integration script also expects all listed views to return rows for a member (`lines 310–325`), which may depend on seeded data.
- **Rollback is not necessarily data-safe after writes.** Additive schema changes can generally be left in place while application versions are rolled back, but a reverse migration that drops columns, constraints, or tables could lose data written by the new version. No migration rollback scripts, write semantics, or application-version compatibility guarantees are included. After new-version writes begin, rollback should mean reverting application traffic while retaining the expanded schema and data until compatibility and recovery are verified—not blindly reversing DDL.

## Phased rollout and rollback boundaries

1. **Baseline and prepare:** Record current schema, row counts, tenant membership counts, and existing policy/privilege state. Run the supplied RLS and integration checks using real member and outsider JWTs, not only privileged SQL sessions. Confirm the Directus and API access paths separately.
2. **Expand:** Apply only additive, backward-compatible schema changes. Keep existing columns and constraints available to old versions; avoid renames, drops, or changed meanings. Prefer nullable/default-safe additions and online/batched index or constraint work where appropriate, after checking the actual PostgreSQL operation and version. The packet does not establish which technique is safe for a particular DDL statement.
3. **Mixed-version migration:** Deploy compatible readers/writers, then backfill in bounded, restartable batches. If both old and new versions may write, use a verified dual-write or equivalent compatibility strategy; its availability is an application-code dependency not present here. Track progress, failures, and per-tenant completeness.
4. **Verify:** Check constraints and tenant-parent consistency, compare source and destination counts, inspect failed batches, and exercise member, outsider, cross-tenant, Directus, and view paths. Do not proceed on a test that only runs as `postgres` or service role.
5. **Contract:** Only after old API services and workers are drained, backfill is complete, and new-version reads/writes have been verified, remove obsolete schema in a separate deployment. Keep an agreed observation window before destructive cleanup.
6. **Rollback boundaries:** Before new-version writes, application rollback with the additive schema retained is the conservative option. After new-version writes, do not drop new fields or constraints until data written there has been reconciled or safely copied back. After contract DDL or irreversible transformations, assume rollback requires a forward repair or restore from backup; no reversible path is demonstrated by the packet.

## Measurable checks

Use the existing test contracts as gates, with real authenticated sessions:

- **Before and after each phase:** RLS enabled for `asset`, `survey`, and `observation`; expected `r_<table>_select` and `r_<table>_mod` policies present (`test-rls.sql`, lines 116–131).
- **Isolation:** Member sees its tenant’s rows; outsider sees zero; a user belonging only to another tenant sees only that tenant’s rows. Verify through authenticated app/JWT access, as the scripts themselves require (`test-rls.sql`, lines 156–230, 273–285; `test-integration.sql`, lines 31–64, 329–341).
- **Integrity:** Count rows where `survey.tenant_id` differs from its asset’s tenant, and where `observation.tenant_id` differs from its survey’s tenant; require zero before enforcing any corresponding constraint. These checks follow the independent tenant and foreign-key fields in `00003`, lines 27–30 and 43–48.
- **Functional regression:** Preserve the integration script’s stated E2E thresholds—3+ assets, 2+ manifests/jobs, 6+ surveys, 15+ observations, and 3+ deltas with deteriorating/severe examples (`test-integration.sql`, lines 73–150)—when the test dataset is applicable.
- **Privileges:** Verify Directus is not superuser or `BYPASSRLS`, remains able to perform its intended back-office operations, and remains blocked from core data (`test-integration.sql`, lines 347–390). Separately verify authenticated users retain only the intended public API view access after hardening (`00015`, lines 15–22).
- **Backfill/operations:** Record total eligible rows, completed rows, failed rows, mismatch counts, runtime, lock waits, and replica/queue lag before and after each batch. The packet provides no numeric operational thresholds; set them from production baselines before rollout rather than inventing them.

**Missing dependencies:** Application and worker SQL/code, proposed schema diff, database version and table sizes, Directus grants/policies, view definitions, migration transaction behavior, and backup/restore objectives. These determine exact mixed-version compatibility, DDL lock risk, backfill design, and rollback feasibility. **Next useful action:** review the concrete proposed migration and application read/write paths against these gates before authorizing deployment.

Primary judge's stated reason

B is preferred because its rollback gates more clearly prevent sending old binaries or delayed workers traffic containing incompatible new-version writes. Its separate checks for the five granted public views also close an assurance gap not covered by the existing app-view tests. These are supported practical advantages across the requested safety assessment, rather than a preference for additional length or optional refinements.

This reason is the judge's assessment. No independent factual-defect finding is asserted by this record.

Battle wave: e1d38d25-feb4-4436-82c7-b4ad3c059a64. Pair: brp1_a8aa82d27dd04e7cf775e5683bbcf409bc92c45e363c8b2e2bec981959cbff3c. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.