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
## Assessment
**Do not replay these migrations or apply the hardening change ahead of mixed-version compatibility checks.** The safe approach is additive expansion, verified tenant-consistent migration, then delayed privilege/schema contraction. The supplied tests are useful acceptance contracts, but they do **not** establish that the deployed schema currently satisfies them.
This was an independent, read-only analysis of the supplied snapshot; no tests were run.
Citation shorthand below: `00002`, `00003`, `00008`, and `00015` refer to the corresponding files under `supabase/migrations/`; `integration` and `rls` refer to `supabase/test-integration.sql` and `supabase/test-rls.sql`.
## Findings and risks
### 1. Ordering and mixed-version compatibility — high confidence
- Foundation precedes core tables: assets reference tenants; surveys reference assets; observations reference surveys (`00002:12–30`; `00003:6–55`).
- Policy installation requires more than the foundation/core migrations: `00008:52–66` names additional tables, and `00008:69–77` requires `audit_event`. Their definitions are outside this packet. Historical numbering is not proof that those dependencies exist in the deployed database.
- These scripts are not safe general-purpose reconciliation scripts. `CREATE TABLE IF NOT EXISTS` does not upgrade an existing table definition; indexes in `00002:52–53` and named policies in `00008:71–91` are not guarded against existing objects.
- **Hardening is a compatibility-breaking permission contraction.** It revokes authenticated access to all existing app tables, sequences, and functions, while granting SELECT on only five public views (`00015:4–22`). Old clients using direct app-table access or app-function calls may fail after commit. Whether any actual API or worker does so is unknown.
- `00015` requires all five public views to exist. Their definitions, ownership, security mode, grants, and tenant filtering are not supplied; a SELECT grant alone does not prove safe or functional access (`00015:16–22`).
- The database search-path change is not an application compatibility guarantee. Long-lived connections and application-specific search paths must be checked rather than assumed uniform (`00002:8–9`).
**Implication:** keep old object names, column meanings, and required access working until every active service, worker, scheduled task, and pooled connection has been shown compatible with the replacement access path.
### 2. Tenant integrity is weaker than row-level membership — high confidence
Each child has its own tenant FK, but parent links reference only the parent UUID:
- `survey.tenant_id → tenant.id`, independently of `survey.asset_id → asset.id` (`00003:29–30`).
- `observation.tenant_id → tenant.id`, independently of `observation.survey_id → survey.id` (`00003:46–47`).
Consequently, the supplied constraints do **not** enforce matching tenants across either relationship. A survey labeled tenant A can reference an asset belonging to tenant B if the referenced UUID exists; the same issue applies to observations.
Standard policies check membership only against the row’s `tenant_id`, not its parent’s tenant (`00008:36–45`). This does not repair the relational gap. Whether application validation prevents such writes is unproven.
**Implications:**
- Existing mismatches can distort tenant joins and derived results; exact exposure depends on unavailable view/function definitions.
- Cascading parent deletion can delete differently labeled child rows because the cascade follows the UUID FK, not tenant equality (`00003:30,47`).
- Before adding composite tenant-parent constraints, measure and resolve every mismatch. Do not automatically relabel rows without an authoritative ownership decision.
### 3. Authorization and isolation caveats — high confidence for definitions; deployment behavior unverified
- Membership ignores membership role (`00002:36–47`). Standard modification policies authorize **any member**, including viewers (`00008:42–45`), despite the viewer “read-only” comment (`00002:33`). Effective writes still require SQL privileges; hardening removes direct authenticated privileges, but restoring broad old grants could reactivate this policy behavior.
- The “mod” policy uses `FOR ALL`, so it also applies to SELECT; the separate SELECT policy does not narrow it (`00008:36–45`).
- The RLS sweep covers app base tables existing at that moment. It does not automatically enable RLS or install policies on future tables (`00008:6–18`).
- RLS is enabled, not forced. Table owners and bypass-capable roles require separate scrutiny; policy existence is not proof that a production connection is subject to it (`00008:16`; `integration:349–359`).
- `app.is_member` and `app.apply_member_policies` are security-definer functions without a declared fixed search path (`00002:36–47`; `00008:21–47`). The latter also interpolates table input into privileged dynamic SQL. Its executable audience, owner, and exposure must be audited; exploitability is not established by the packet.
- Revocation from `authenticated` does not itself remove privileges inherited through other roles or PUBLIC. Likewise, default-privilege alterations need to be verified for every actual object-creating role (`00015:7–13`).
- Audit behavior is broader than its comment: tenant members can read other users’ tenant events; insertion checks the user identity but shows no tenant-membership check (`00008:68–77`).
- `tenant_member.user_id` has an auth-user reference comment, not an actual FK (`00002:24–29`). Orphan membership UUIDs therefore need an explicit check.
**Implication:** do not treat hardening as proof of complete isolation, and do not roll it back by indiscriminately restoring all authenticated privileges.
### 4. Test limitations and conflicts — high confidence
- Integration outsider and view tests use `SET ROLE postgres` (`integration:54–60,312–337`). Setting a JWT subject does not make a superuser, table owner, or bypass role obey RLS. Inspect role attributes; run acceptance queries through genuinely non-bypassing production-equivalent roles.
- The RLS script explicitly acknowledges that service-role SQL cannot prove outsider isolation (`rls:170–185`) and asks for real authenticated testing (`rls:276–285`).
- Tests mostly contain comments describing expected results, not executable assertions that fail deployment automatically.
- Tests query app tables/views, while hardening explicitly directs authenticated REST access to public views (`integration:315–336`; `rls:279–283`; `00015:15–22`). After hardening, direct authenticated app queries may correctly return permission errors rather than zero rows.
- Integration expects `app.is_directus()` policies, but the supplied standard policies contain only `app.is_member()` (`integration:377–390`; `00008:36–65`). Other policy migrations could explain this; their behavior is not evidenced here.
- Survey and observation fixtures are not retry-idempotent: random UUID defaults and no shown business-key uniqueness mean `ON CONFLICT DO NOTHING` does not prevent repeated logical inserts (`00003:27–55`; `rls:82–102`).
- Integration cleanup includes tenant-wide section and LOS-target deletion. It is unsafe on existing production tenant data (`integration:426–432`).
## Phased rollout
### Phase 0 — Baseline and admission gates
1. Capture deployed definitions, policy expressions, effective grants, owners, default ACLs, RLS flags, and role attributes. Compare actual state to the supplied definitions rather than replaying history.
2. Establish a restorable backup/PITR position and test restoration separately.
3. Record per-tenant counts and invariant violations:
- survey/asset tenant mismatches: **0 required**;
- observation/survey tenant mismatches: **0 required**;
- orphan memberships relative to auth users: investigate every result;
- duplicate proposed business keys: **0 before introducing uniqueness**.
4. Inventory connection identities and old/new version database access. No application routes or worker implementations are supplied, so compatibility must be demonstrated operationally.
5. Establish lock-wait, deployment-duration, error-rate, and queue-age abort thresholds before rollout.
### Phase 1 — Expand
- Add replacement columns, tables, or views without dropping or renaming existing contracts.
- Configure least-privilege grants and tenant policies before exposing new objects; the historical RLS sweep will not cover them automatically.
- Preserve old writes unless they would violate a necessary safety invariant. If a stricter tenant constraint rejects existing writers, stop and correct those writers before enforcement.
- For tenant-consistent parent links, prepare parent uniqueness on `(tenant_id, id)` and composite child FKs as a proposed corrective migration—not as existing behavior.
**Lock controls:** use bounded lock/statement timeouts and avoid long DDL transactions. For large tables, assess concurrent index construction and staged constraint validation. Adding a `NOT VALID` FK still enforces new writes; it is not a compatibility bypass. These are PostgreSQL deployment recommendations, not operations present in the supplied migrations.
### Phase 2 — Migrate
- Backfill only when a concrete replacement representation is defined. None is specified in the packet.
- Use bounded, resumable batches and stable identifiers; monitor lock waits, WAL growth, replica lag, and foreground latency.
- Account for concurrent old/new writes through a documented consistency mechanism. Dual-writing, triggers, or change capture are alternatives—not observed application behavior.
- Quarantine tenant mismatches for ownership resolution. Retain an audit trail of repairs and before-values.
- Keep incompatible new-format writes disabled until their rollback representation is defined.
### Phase 3 — Verify and canary
Use isolated fixtures, then production read-only checks:
| Contract | Measurable gate |
|---|---|
| RLS enabled and named policies | Required core tables show RLS enabled; inspect actual policy expressions, not just names (`rls:116–131`). |
| Membership and cross-tenant access | Member sees own fixture; outsider sees **0** pilot rows; second-tenant member sees only its tenant (`rls:162–231`). |
| Public access surface | Exercise all five granted public views as member and outsider; outsider exposure **0**, with positive authorized fixtures (`00015:16–22`). |
| Ingestion | Isolated golden fixtures meet **3+ assets, 2+ manifests, 2+ parse jobs, 6+ surveys, 15+ observations, 3+ deltas, 1+ deteriorating, 1+ severe** (`integration:75–150`). |
| Directus functionality | Unit costs editable to **70.00**; LOS, AMP, unmatched-resolution, and S3-path contracts pass (`integration:160–302`). |
| Directus security | `rolsuper=false`, `rolbypassrls=false`; core data inaccessible; required back-office policy behavior verified (`integration:347–390`). |
| Integrity and migration | Tenant mismatches **0**; backfill backlog **0**; reconciliation differences **0**, except explicitly approved changes. |
Distinguish “query denied” from “query succeeded with zero rows.” Both can prevent exposure, but they are different compatibility outcomes.
Canary old/new service and worker combinations against these gates. The golden counts are fixture-specific minimums, not production-wide correctness proofs.
### Phase 4 — Contract
Only after old versions and outstanding old-version jobs are drained:
- Apply justified privilege contraction, including `00015`-style restrictions.
- Validate strengthened constraints and retire obsolete representations.
- Keep compatibility objects for a declared observation window.
- Do not drop old fields or access paths merely because new-version smoke tests pass.
## Rollback boundaries after writes
- **Before transaction commit:** `00015` is explicitly transactional (`00015:1–24`); failure can roll back its own privilege changes. Do not infer equivalent wrapping for the other supplied files.
- **After privilege-only commit:** restore the captured, approved ACL state with a new migration if necessary. There is no data transformation in `00015`, but restoring broad grants may reopen viewer writes or unsafe helper access.
- **After backward-compatible writes:** roll application versions back only if old readers and writers can handle every committed value. Retain additive schema and valid constraints where possible.
- **After tenant repairs/backfills:** do not reverse repairs blindly. Concurrent writes can make saved before-values stale; rollback requires write coordination and reconciliation.
- **After incompatible new writes:** application rollback alone is unsafe. Fence affected writes, drain workers, and either use a verified reverse transformation or forward-fix. No such transformation is supplied.
- **After dropped data or cascaded deletion:** re-creating schema does not recover data. Use scoped recovery or coordinated restore; whole-database restoration risks losing unrelated post-backup tenant writes (`00002:25`; `00003:8,29–30,46–47`).
- External ingestion and file uploads are not undone by database rollback (`integration:80–93,291–302`).
## Next useful action
Produce a deployment-state comparison and compatibility matrix first, then execute the existing contracts with isolated fixtures and real non-bypassing identities. Gate contraction on tenant-invariant checks and explicit proof that no active old-version component requires revoked access.
MATERIAL_EVIDENCE_CONFLICT: The membership-role comment promises viewer read-only access (`00002:33`), while standard modification policies authorize any member (`00008:42–45`); the tests expect direct app-table access and Directus-specific policies (`rls:279–283`; `integration:377–390`), while hardening revokes authenticated app-table privileges and the supplied policies contain only membership checks (`00015:7–22`; `00008:36–65`).
openai / gpt-6-luna / low / low effort answer
## Conclusion
Do not treat this schema as safe for a mixed-version rollout or rollback without first resolving migration compatibility and testing against the deployed database. The supplied migrations define tenant-scoped tables, membership-based RLS and later authenticated-role hardening, but they do not provide a data backfill, an online migration strategy, or evidence about how API services and workers read or write these tables. This assessment is limited to the supplied snapshot.
## Evidence and risks
- **Tenant integrity is not enforced across relationships.** `app.survey` stores both `tenant_id` and `asset_id`, but its foreign key checks only `asset_id` against `app.asset(id)`; `app.observation` similarly checks `survey_id` without ensuring the referenced survey has the same tenant (`00003`, lines 27–30, 44–48). A mismatched tenant/reference pair is therefore not ruled out by these definitions. The RLS policies check membership against the row’s `tenant_id`, not the referenced parent’s tenant (`00008`, lines 36–46). Whether application code prevents mismatched writes is unknown.
- **RLS changes can affect mixed-version access.** The policy helper grants members select and all modifications when `app.is_member(tenant_id)` is true (`00008`, lines 21–46). It is applied to a fixed list of tables, including tables not defined in the supplied core migration (`00008`, lines 51–66); it is not shown as an automatic policy for future tables. The migration also enables RLS on every app base table present when it runs (`00008`, lines 5–18), so the resulting coverage depends on migration ordering and which tables exist at that point. `tenant_member` has only a self-read policy in this migration (`00008`, lines 86–91); membership writes and the service roles’ effective privileges are not established here.
- **Hardening may break existing clients.** `00015` revokes authenticated access to all app tables, sequences, and functions, then grants authenticated only select on five `public.api_*` views (`00015`, lines 3–22). That is not shown as backward-compatible with clients that directly access `app` objects. The packet does not show view definitions, grants to service/worker roles, or whether older versions use those views.
- **Migration order and availability need verification.** `00002` sets the database-wide search path (`00002`, lines 8–9). `00003` creates tables with `IF NOT EXISTS`, but this does not demonstrate that an already-present table has the expected shape (`00003`, lines 6–20, 27–38, 44–56). `00008` applies policies to named tables that must exist, and `00015` grants on named views that must exist. The packet gives no transactional or deployment-order evidence for these migrations beyond `00015`’s explicit transaction (`00015`, lines 1–24). No lock duration, table size, backfill, or operational timing is specified; a safe lock/backfill profile cannot be inferred.
- **Rollback is asymmetric after writes.** No down migrations are supplied. Reversing `00015` by restoring broad grants could re-expose direct table access; reversing RLS or changing policies could expose tenant data. Removing or changing tenant constraints/columns could strand or misattribute writes. These are risks, not demonstrated outcomes: exact rollback behavior depends on the deployed schema and application writes, neither of which is fully supplied.
- **Test contracts have important limits.** `test-rls.sql` explicitly says SQL Editor/service-role checks cannot truly impersonate users and directs production verification via app login (`test-rls.sql`, lines 108–115, 170–185, 273–285). Its cross-tenant section describes expected visibility but its query is run as service role, which can see both tenants (`test-rls.sql`, lines 218–231). The integration test’s outsider smoke check uses `set role postgres` and a JWT claim (`test-integration.sql`, lines 54–64); that is not, by itself, proof of behavior under the actual API/worker roles. The integration script also expects Directus writes and policies including `app.is_directus()` (`test-integration.sql`, lines 160–199, 377–390), while the supplied `00008` policies use only `app.is_member()` (`00008`, lines 36–46). This is a concrete mismatch between the supplied policy definition and stated test expectation; later migrations or role-specific policy definitions are outside the packet.
## Phased rollout and rollback boundaries
1. **Preflight:** On a production-equivalent snapshot, record migration versions, table/view definitions, row counts by tenant, constraints, indexes, RLS flags and policies, grants, and active client versions/roles. Reconcile the Directus policy expectation with the deployed policy catalog before proceeding.
2. **Expand:** Apply only additive, backward-compatible schema changes first. Confirm old services and workers still operate with their existing grants and query assumptions. The supplied migrations do not identify a specific additive change or demonstrate this compatibility, so this is a rollout requirement rather than a claim that these files implement it.
3. **Migrate:** If data transformation is needed, perform a resumable, bounded backfill with tenant-aware validation and observe lock waits, duration, errors, and replication/queue lag. No backfill is defined in the packet; do not assume one is unnecessary.
4. **Verify:** Run the measurable checks below using real authenticated member, outsider, cross-tenant, Directus, and worker credentials. Do not count service-role visibility as an RLS pass.
5. **Contract:** Only after old versions are drained and dependent writes/reads are proven absent should permissions, old columns, or compatibility paths be removed. The `00015` authenticated revocation is a contract-like boundary for clients that directly access `app` tables; verify all such clients have moved before applying it.
6. **Rollback:** Before any transformed or new-format writes, rollback may be feasible by stopping rollout and retaining the expanded schema. After new writes/backfill begin, first stop or fence writers, reconcile data, and preserve the expanded schema; do not blindly reverse DDL or restore broad grants. Once old columns/contracts are removed or `00015` has revoked access relied on by old clients, rollback requires a coordinated application/permission plan and validated recovery—not just rerunning prior migration SQL.
## Measurable checks
Capture a baseline and compare post-deployment:
- **Schema/security:** Compare `pg_tables.rowsecurity` for `asset`, `survey`, and `observation` with the `true` contract (`test-rls.sql`, lines 116–122); enumerate policies and confirm expected select/modification policies (`test-rls.sql`, lines 124–131). Separately verify actual role grants and the Directus `is_directus()` expectation in the catalog (`test-integration.sql`, lines 347–390).
- **Tenant isolation:** With real JWT-backed sessions, member sees its tenant’s seeded assets; outsider sees zero rows for that tenant; a user belonging only to another tenant sees only that tenant’s data. These are the stated expectations in `test-rls.sql`, lines 140–153, 156–185, 218–231, and `test-integration.sql`, lines 54–64, 329–341. Record counts and tenant IDs before and after.
- **Referential integrity:** Check for surveys whose `tenant_id` differs from their asset’s tenant and observations whose `tenant_id` differs from their survey’s tenant. The supplied schema does not prevent these mismatches (`00003`, lines 27–30, 44–48); require zero mismatches before and after any migration that relies on tenant-consistent relationships.
- **Functional compatibility:** Preserve integration-test thresholds: at least 3 assets, 2 queued/parsed manifests, 2 parse jobs, 6 surveys across at least 3 assets, 15 observations, and 3 deltas with at least 1 deteriorating and 1 severe (`test-integration.sql`, lines 75–78, 95–120, 125–150). Check Directus unit-cost/LOS/AMP/unmatched operations and expected values (`test-integration.sql`, lines 160–199, 201–219, 221–248, 250–287), but execute with the actual intended Directus role.
- **Views and permissions:** Member view queries should return data and outsider queries zero as specified (`test-integration.sql`, lines 310–341). Confirm authenticated can select the five granted `public.api_*` views and that no required old client still needs revoked `app` access (`00015`, lines 15–22).
## Alternatives, caveats, next action
A single maintenance-window cutover could avoid mixed-version overlap, but the evidence does not establish that it is necessary or sufficient; it still requires validated backups, role grants, and RLS checks. Nor does the packet prove that a particular backfill, lock, or production failure will occur. Application APIs, worker SQL, deployed migration history, later policy migrations, view definitions, and live privileges are dependencies outside the supplied evidence.
**Next action:** Before scheduling rollout, reconcile the Directus policy mismatch and produce a production-equivalent inventory of deployed schema, grants, policies, and client query patterns; then exercise the phased checks against that inventory.
Primary judge's stated reason
B is preferable because its explicit recovery cases help operators decide when application rollback suffices, when writes must be coordinated, and when data recovery is necessary. Its bounded lock controls and staged-constraint caveats also directly address the requested online rollout assurance. This is a supported coverage advantage rather than a preference based on length or proof of actual deployment behavior.
This reason is the judge's assessment. No independent factual-defect finding is asserted by this record.
Battle wave: d1711a3f-9f3b-4640-a160-e32f42e27c5f. Pair: brp1_e88c20b0764141e480e02c1c6edb21587fc2d30753b7525ba3c36874add22dfb. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.