← Model losses

Head-to-head comparison

openai / gpt-6.1-sol / xhigh / xhigh effort preferred over openai / gpt-6.1-sol / low / low effort · close 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 / xhigh / xhigh effort answer

## Conclusion

**Do not replay these migrations or treat rollback as “run them backward.”** For an already-populated deployment, the safe approach is to preserve existing data and interfaces, establish an old/new service compatibility matrix, verify effective tenant isolation, and defer privilege or policy contraction until all incompatible consumers are retired.

This is a direct, independent review of the supplied snapshot. **No tests were run and no code was changed.** Confidence is high in the SQL definitions and test-contract discrepancies; deployed behavior remains conditional on live ownership, grants, view definitions, and application code.

### Citation key

- **M02:** `supabase/migrations/00002_create_schema_and_tenant.sql`
- **M03:** `supabase/migrations/00003_create_core_tables.sql`
- **M08:** `supabase/migrations/00008_enable_rls_and_policies.sql`
- **M15:** `supabase/migrations/00015_hardening.sql`
- **IT:** `supabase/test-integration.sql`
- **RT:** `supabase/test-rls.sql`

## 1. Findings and rollout implications

### Ordering and replay safety

- **These are creation scripts, not convergence migrations.** `CREATE TABLE IF NOT EXISTS` does not reconcile an existing table’s columns or constraints. M02 also creates indexes without `IF NOT EXISTS`; M08 creates several named policies without first dropping them. Replaying can therefore fail or leave drift undetected. [M02:12–30,51–53; M03:6–56; M08:71–91]
- **Replaying M08 can overwrite later policy changes.** Its helper drops the standard policies and replaces them with member-only policies, including on the back-office tables. This would remove Directus allowances if those had subsequently been incorporated into the same policies. [M08:32–46,56–62]
- **Historical dependencies matter:** tenant foundations precede core tables; all named relations must exist before M08 applies policies; the five public API views must exist before M15 grants access. Their definitions, and several named tables, are outside this packet. [M02:12–30; M03:8,29–30,46–47; M08:52–66; M15:16–22]
- **Atomicity differs.** M15 explicitly wraps its changes in a transaction. M02, M03, and M08 do not show whole-file transaction boundaries; migration-runner behavior is unknown. M08’s initial `DO` block enables RLS before subsequent policy statements, so an autocommit execution that later fails could leave a partially configured deployment. [M15:1–24; M08:6–18,52–91]

**Recommendation:** compare migration history and actual catalogs with these definitions; issue targeted forward migrations rather than rerunning the historical files.

### Mixed-version compatibility and privileges

- **M15 is an access-contract change, even though it changes no columns.** It revokes `authenticated` access to app tables, sequences, and functions, then grants SELECT on only five public API views. An old service using direct app-table access or an app function can fail once its effective privileges disappear. [M15:4–22]
- **The SQL tests still exercise the older surface:** app tables, app views, and `app.compute_deltas()`. They do not verify the five granted public API views. Consequently, these tests alone cannot certify post-hardening API compatibility. [IT:75–150,315–323; RT:170–175,237–241; M15:16–22]
- **Revoking a grant from `authenticated` does not prove effective denial.** PostgreSQL privileges can still come through `PUBLIC`, inherited roles, or ownership. M15 does not revoke `PUBLIC` function execution, inherited access, or pre-existing write grants on the public views. Its “read-only” comment is therefore an intent, not proof of effective read-only access. [M15:3–22]
- **Default privileges are not universal.** The statements shown affect defaults associated with the executing object-creator role; they do not establish defaults for every possible future creator. Nor does M08 automatically enable RLS on tables created later. [M15:11–13; M08:10–17]
- **Search-path changes can differ across pooled connections.** M02 changes the database default to `app, public, extensions`; it does not establish an identical path for already-connected sessions or role-specific overrides. Mixed-version code using unqualified names needs explicit verification. [M02:8–9]

Preserve the actual existing access contract during expansion. Do not “restore compatibility” with blanket grants; identify and, where authorized, retain only the privileges each old consumer genuinely needs.

### Tenant integrity is weaker than row-level membership isolation

**The schema permits cross-tenant parent/child links.**

- A survey independently references a tenant and an asset UUID; no constraint requires the asset’s tenant to match the survey’s tenant. [M03:27–38]
- An observation independently references a tenant and survey UUID; again, tenant equality is not enforced. [M03:44–56]
- RLS checks the child row’s `tenant_id`, not the referenced parent’s tenant. [M08:38–45]

Thus, a survey owned by tenant B can reference tenant A’s asset while satisfying the shown foreign keys. This does **not** by itself prove parent data is readable, but it creates integrity and isolation risks. Because the references cascade, deleting the tenant-A asset can also delete the tenant-B survey and its observations through referential actions. [M03:30,47]

Additional implications:

- Asset external codes are unique **within** a tenant, not globally. Worker lookup by external code alone would be unsafe, but no worker implementation is supplied. Also, `asset.asset_id` is text while `survey.asset_id` is a UUID reference; migration/backfill logic must preserve that distinction. [M03:7–9,20,30]
- The policy permits members of both tenants to change a row’s tenant from one to the other, subject to other constraints: `USING` checks the old row and `WITH CHECK` checks the new row. It does not enforce an “active tenant” selected by the application. [M08:44–45; M02:42–46]

**Deployment gate:** measure both parent/child mismatch counts and require zero before claiming tenant-consistent integrity. Application validation alone is not proven by this packet.

### Membership roles and provisioning

- The schema labels viewers read-only, but `is_member()` ignores `role`, and the standard modification policy admits every member for all operations. With sufficient SQL privileges, a viewer passes the same policy as an admin. ACLs may still prevent writes, but the RLS layer does not implement the documented role distinction. [M02:27,33,36–47; M08:42–45]
- `tenant_member.user_id` has only a comment suggesting an auth-user reference; no auth-user foreign key is declared. Auth-user deletion cleanup is therefore not established here. [M02:24–30]
- Tenant and membership policies shown are SELECT-only. Ordinary RLS-controlled provisioning writes need some additional authorized path, which is not supplied. [M08:79–91]

Do not combine a viewer-write restriction or provisioning redesign with an otherwise backward-compatible rollout without explicitly testing those behavioral changes.

### Security-definer and audit-policy risks

- Both helpers are `SECURITY DEFINER`, without a fixed function `search_path`. `is_member()` explicitly qualifies its table and auth function, which limits—but does not eliminate—the need to examine its execution environment. [M02:36–47; M08:21–25]
- `apply_member_policies()` interpolates a caller-controlled relation string with `%s` into privileged DDL rather than safely identifying an allowlisted relation. If untrusted roles can execute it, this is a serious privileged-DDL risk. Actual exploitability depends on effective EXECUTE permission and the function owner’s authority; neither is established. M15’s revocation from `authenticated` alone does not settle this because `PUBLIC` grants may remain. [M08:21–46; M15:9]
- Audit SELECT permits either the event’s user **or any tenant member**, despite the “own events” comment. INSERT checks only `user_id = auth.uid()`, not tenant membership. Subject to unseen table constraints and grants, that can permit a user to submit an event against a foreign tenant. [M08:68–77]

Restrict the policy-management helper to migration administration, verify helper ownership and effective execution permissions, and treat any audit-policy tightening as a separate compatibility change.

### Lock, backfill, and retry risks

- M02’s ordinary index creation is not concurrent; on existing tables it can block writes and requires a scan. M08 performs relation-locking RLS and policy DDL across many tables. Long-running transactions can delay that DDL and extend disruption. [M02:51–53; M08:6–18,32–46]
- **No data backfill appears in the supplied migrations.** M15 changes ACLs, not stored tenant data. Do not attribute a table rewrite or backfill to that file. [M15:1–24]
- `updated_at` has an insertion default, but no automatic update mechanism is shown. It is not a proven watermark for backfill catch-up or rollback journaling. [M02:16–17; M03:18–19,36–37]
- Survey and observation fixtures are not demonstrably retry-idempotent. Their fresh UUID defaults have no shown business-key uniqueness constraint, so `ON CONFLICT DO NOTHING` can insert another row on each execution. Multiple surveys on the same date may also be legitimate; deduplication rules cannot be inferred. [M03:27–56; RT:82–102]

## 2. Phased expand / migrate / verify / contract plan

### Phase 0 — Establish the deployed baseline

Before changing anything:

1. Record actual relation definitions, validated constraints, indexes, policies, function owners/ACLs, view definitions, RLS flags, default privileges, and role membership.
2. Build a compatibility matrix for **old and new API services, workers, and Directus**, using their real database identities and actual read/write operations. The tests show expected ingestion and Directus workflows, but not implementation compatibility. [IT:80–150,162–287]
3. Record per-tenant row counts and both cross-tenant relationship mismatch counts; identify dangling membership users.
4. Establish a recoverable backup/PITR checkpoint and rehearse restoration plus reconciliation of subsequent accepted writes.
5. Use an isolated restored environment for mutation-heavy tests. The supplied integration script alters tenant data; its optional cleanup deletes all AMP sections and LOS targets for the selected tenant. That is unsafe as production cleanup with existing data. [IT:165–171,183–187,205–210,226–238,426–433]

### Phase 1 — Expand without breaking current consumers

- Preserve core column types, UUIDs, tenant-scoped asset codes, current view names, and verified output shapes. [M03:6–56; M15:16–22]
- Do not remove an access path until the compatibility matrix shows no remaining dependent old consumer. If M15 is already effective, preserve that boundary and adapt consumers to the supported surface rather than assuming app-table access remains available.
- Make policy replacements atomic and narrowly scoped. Do not replay M08’s blanket policy helper over already-evolved back-office policies. [M08:32–46,52–66]
- Remove unintended access to privileged management helpers while preserving verified read-helper dependencies. Confirm that the chosen public-view design works with the intended base-table privilege restrictions.

**Important:** blindly making views `security_invoker` is not a complete remedy. Invoker views ordinarily need caller access to their underlying relations, potentially conflicting with M15’s revoked app-table privileges. The actual view definitions must determine the solution.

### Phase 2 — Migrate data and enforce tenant consistency

There is no required historical backfill in these files. If audits find mismatches:

- Identify the authoritative tenant and relationship for each affected record. Do not automatically rewrite child tenants or delete parents.
- Pause or fence affected writers through existing operational controls while repairing those records; no such control mechanism is shown here.
- Repair in bounded, resumable batches keyed by stable UUIDs. Retain before/after values and ownership decisions for rollback.
- To enforce equality, an additive option is composite foreign keys:
  - survey `(tenant_id, asset_id)` → asset `(tenant_id, id)`;
  - observation `(tenant_id, survey_id)` → survey `(tenant_id, id)`.
  
  These require suitable parent uniqueness and must retain intentionally chosen deletion semantics. The need follows directly from the independent references in M03. [M03:8,20,29–30,46–47]
- Where appropriate, build supporting indexes concurrently outside a transaction, check for failed/invalid indexes, then add and validate constraints.

**`NOT VALID` is not a mixed-version bypass:** a newly added foreign key still checks new writes. All active writers must already comply, or the rollout must deliberately accept rejection of noncompliant writes. Validation also scans data and consumes resources; stage and measure it.

### Phase 3 — Verify under real identities and mixed versions

Use the checks below before and after the candidate change, first in the restored environment and then with controlled production checks.

Do not run the unscoped `app.compute_deltas()` call on production merely because it is in the test plan: its implementation and affected tenants are unknown. [IT:139–150]

### Phase 4 — Contract only after the compatibility window

Contract only when:

- No incompatible old API instance or worker remains.
- In-flight and retryable work from old versions has been drained or demonstrated compatible; queue behavior is not supplied.
- Required constraints are validated.
- Public-view isolation, Directus restrictions, and mixed-version workflows pass.
- The rollback retention window and write-reconciliation procedure are approved.

Only then remove obsolete grants/interfaces or tighten role semantics. For ACL contraction, use an exact approved grant manifest, not the assumption that M15 proves all unintended access has disappeared.

## 3. Measurable pre/post-deployment checks

| Check | Required measurement and interpretation | Existing contract |
|---|---|---|
| RLS coverage | Every intended tenant base table has RLS enabled; record owners and `FORCE RLS` status separately. Enabled RLS alone does not prove owner/superuser filtering. | M08:6–18; RT:116–131 |
| Membership isolation | A has pilot membership; B has none. Under real non-bypass identities, A sees authorized pilot records and B sees none. After adding B to the second tenant, each sees only tenants they belong to. | IT:40–64; RT:162–185,191–231 |
| Parent/child integrity | Count surveys where `survey.tenant_id <> asset.tenant_id`, and observations where `observation.tenant_id <> survey.tenant_id`; both must be **0**. Attempted mismatched writes must be rejected once enforcement is installed. | M03:27–56 |
| Effective hardening | For `authenticated`, inherited roles, and `PUBLIC`, inspect schema/table/view/function privileges. Verify intended app-base denial and SELECT-only public-view access, including absence of effective DML grants. | M15:4–22 |
| Public API isolation | Test all five `public.api_*` views with member and outsider identities; compare returned identifiers or aggregates against authorized fixture data. The supplied app-view tests do not cover this surface. | M15:16–22; IT:315–337 |
| Privileged helper exposure | Untrusted roles cannot execute the policy-management helper; owners and search paths are approved. Required read-helper access still works. | M08:21–46; M02:36–47 |
| Ingestion fixture | In the defined golden-data environment: ≥3 assets; ≥2 queued/parsed manifests; ≥2 parse jobs; ≥6 surveys spanning ≥3 assets; ≥15 observations; ≥3 deltas, ≥1 deteriorating, ≥1 severe. Also compare exact fixture identifiers and expected increments so thresholds do not hide duplicate ingestion. | IT:75–150 |
| Directus capabilities | Unit-cost insert/update succeeds and yields `70.00`; LOS, AMP, and unmatched-resolution fixtures meet their expected results. Core access is denied or filtered according to the intended privilege contract. | IT:162–287,363–375 |
| Directus authority | `rolsuper=false`, `rolbypassrls=false`, `rolcanlogin=true`; verify complete policy `USING` **and** `WITH CHECK` semantics, not merely substring presence. | IT:349–390 |
| Operational impact | Set numeric abort thresholds before deployment for lock wait, request permission errors, worker failures, and queue age; monitor against baseline. These are operational additions, not assertions already supplied by the tests. | DDL risk: M02:51–53; M08:6–18; workflow evidence: IT:95–123 |

### Existing test limitations that must be corrected

1. **`SET ROLE postgres` is not a reliable user-RLS test.** Setting a JWT subject does not remove superuser, owner, or bypass privileges. No `FORCE ROW LEVEL SECURITY` is shown. Verify actual role properties and test through genuine non-bypass identities. [IT:54–60,312–337; M08:16; RT:113–114,175–176]
2. **The JWT `SET` statements contain subqueries**, which are not valid PostgreSQL `SET` value syntax. Resolve the UUID first and set it through a supported session-setting mechanism in an isolated test transaction; verify that `auth.uid()` resolves as intended. [IT:56,313,332; M02:45]
3. **Several “simulation” queries never change identity.** Their successful counts establish data existence, not tenant isolation. RT itself acknowledges this distinction and requires actual user testing. [RT:137–176,218–231,276–285]
4. **Permission denial and zero rows are different outcomes.** Post-hardening direct app access can appropriately fail with an ACL error rather than return zero. Neither outcome substitutes for verifying that the supported public views correctly filter outsiders. [M15:7–22; IT:371; RT:173]
5. **“Views inherit RLS” is unproven.** View ownership and security configuration are absent. Owner-executed views can bypass underlying RLS depending on ownership and role properties. [IT:308–341; RT:237–241]
6. **Positive counts require suitable fixtures.** A legitimate empty report is not automatically a security or rollout failure, and minimum counts alone do not prove correct tenant attribution or prevent duplicates. [IT:132–150,325]

## 4. Explicit rollback boundaries after writes

| Boundary | Safe rollback position |
|---|---|
| Candidate transaction fails before commit | Its transactional changes roll back. This is explicit for M15; do not assume whole-file atomicity for the earlier migrations. [M15:1–24] |
| Additive deployment, before incompatible writes | Roll back code while retaining additive schema, provided old versions still accept the data and constraints. Removing expansion objects is usually unnecessary. |
| ACL/policy cutover, with otherwise unchanged compatible data | Restore the **captured** approved ACLs/default privileges or policy definitions if authorized. This reverses access changes, not writes or external effects. Restoring an insecure policy is not a safe default. [M08:32–46; M15:4–22] |
| New tenant-equality enforcement | Old code may now fail if it creates mismatches. Prefer fixing or fencing that writer over dropping the isolation constraint. Removing enforcement would deliberately reopen the proven integrity gap. [M03:29–30,46–47] |
| Data repaired, retagged, or new semantics written | A code rollback alone is insufficient. Use the repair journal and reconcile later writes before reversing values; do not overwrite subsequent legitimate changes. |
| Cascading deletion committed | Regranting privileges or restoring policies cannot recreate deleted rows. Restore/reconstruct from retained data, respecting dependency order and subsequent writes. [M02:25; M03:8,29–30,46–47] |
| Destructive contract or whole-database restore | Old-code rollback may require restoring removed interfaces/data. PITR without replay loses valid post-checkpoint writes; replay idempotence is not proven. External S3 uploads are outside the database transaction. [RT:82–102; IT:80–84,289–302] |

No down migrations, repair journal, or tested post-write replay procedure is supplied. Consequently, **automatic rollback after semantic writes or cascading deletes is not established**.

## 5. Uncertainties, alternatives, and next action

### Important uncertainties

Definitions outside this packet determine:

- Public and app view security, output compatibility, and actual filtering.
- Directus policy extensions and `app.is_directus()` behavior.
- Worker/service roles, tenant validation, retry/idempotency, and queue compatibility.
- `auth.uid()` configuration and `compute_deltas()` scope.
- Live grants, ownership, triggers, migration-runner transactions, and recoverability.

These are uncertainties—not proof that the deployment is broken or that another file is missing.

### Alternatives and likely false positives

- Later policy changes could explain the Directus contract; do not assume member-only M08 policies are still the deployed versions.
- Other grants could explain successful app access after M15, but that success would not prove hardening.
- Public views might safely implement explicit tenant filtering; conversely, a privileged view-owner test might appear successful while bypassing isolation.
- Repeated survey records are not necessarily invalid; the schema declares no business uniqueness suitable for automatic deduplication.

**Next useful action:** produce a read-only live-state and old/new compatibility report, then rehearse the corrected identity tests and rollback-with-write-reconciliation on a restored populated database. Proceed only when that evidence resolves the privilege, view-isolation, Directus-policy, and tenant-equality gates.

MATERIAL_EVIDENCE_CONFLICT: M08:38–45,56–60 defines member-only policies for back-office tables, while IT:377–390 requires those policies to include app.is_directus(); an additional policy change would be needed to reconcile the supplied definitions with that assertion.

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`).

Primary judge's stated reason

A receives a slight, forced preference because its explicit warning helps prevent a verification step from invoking computation with unknown production scope. B's broad production warning substantially covers the same concern. This is not an established material quality difference, and an independent review could reasonably reject the preference.

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_2c243cbe3134936b83d8c272c12d30d1a40a495dacc32c668317acecf05f82c6. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.