← Model losses

Head-to-head comparison

openai / gpt-6.1-sol / low / low effort preferred over xai / grok-4.7-efficient / high / high 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

Trace inspection filtering and matching from frontend request through backend predicate construction. Identify a concrete parity or data-integrity risk (including nulls, ranges, or combined filters) where the visible result set can diverge from intended semantics; show the precise path and propose a minimal correction and boundary regression cases.

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

## Finding: operator normalization differs between matching paths

**Confirmed predicate-parity defect; high confidence.** In `inspection_match.py`, Python accepts an existing whitespace-only operator as missing, but SQL does not.

Reproducible trigger:
- Existing inspection: `performed_by = '   '`.
- Incoming inspection: operator `"Alice"`.
- Municipality, project, asset, UTC date, time, and direction otherwise match; existing row is not deleted.

**Precise path**
- Incoming operator becomes `"Alice"` through `normalize_operator()` (lines 48–55, 213).
- Python `InspectionKeys.matches_row()` normalizes the existing operator to `None`, so accepts it (lines 129–134).
- SQL `find_existing_inspection()` accepts existing operators only when NULL, exactly `''`, or normalized-equal to the incoming operator (lines 244–249). Spaces are neither NULL nor empty, and `LOWER(TRIM('   '))` differs from `"alice"`, so SQL rejects the row.

Consequently, bulk/chunk matching can merge a record that sequential matching rejects. Rejection can lead to duplicate canonical inspections **if the caller inserts after a nonmatch**; that caller is outside this packet. Such duplicates can subsequently appear in filtered result sets.

### Minimal correction and regressions

Replace SQL’s `performed_by = ''` missing-value branch with `NULLIF(TRIM(performed_by), '') IS NULL`. This fixes the demonstrated spaces-only case.

Python `str.strip()` also handles tabs, newlines, and broader whitespace that PostgreSQL’s default `TRIM` does not. For complete parity, explicitly define and implement the same whitespace-normalization contract on both sides.

Differential SQL/Python regression cases:
- Existing operator NULL, `''`, spaces-only, tabs-only, and newline-only against incoming `"Alice"`.
- Reverse those missing-value cases.
- `" Alice "` against `"alice"`; `"Alice"` against `"[REDACTED: person name]"`.
- Hold other keys equal, then vary NULL/non-NULL direction, midnight versus non-midnight time, unequal non-midnight times, and UTC date boundaries to ensure independent predicates still constrain matching.

## Frontend-to-filter trace: evidence limitation

`useInspectionData.ts` requests `/inspections/{id}/review-boot` (lines 17–29), then conditionally requests `/review-pack/{id}/inspection.json` (lines 74–90). **It does not construct a filtering request.** An end-to-end frontend filter serialization trace cannot be established from this snapshot.

Once an `InspectionFilterSpec` reaches `apply_inspection_filters()`, the visible construction is:
tenant/archive → project → asset type → asset IDs → saved filters → observation-parent filters → transient NL → search → viewport (lines 129–190).

Successive `.where()` calls combine these dimensions conjunctively. Explicit empty asset IDs match nothing (lines 146–150); viewport bounds are inclusive and exclude NULL coordinates (lines 181–190). No concrete range or combined-filter defect is established here. Spec validation, router assembly, and delegated compiler semantics remain outside the packet.

**Next useful action:** add the operator differential regression and normalization fix first; independently verify frontend filter serialization against the router/spec contract when that evidence is available.

MATERIAL_EVIDENCE_CONFLICT: `inspection_match.py:99–107` claims Python/SQL predicate parity, but Python treats whitespace-only existing operators as missing at lines 129–134 while SQL rejects them against a named incoming operator at lines 244–249.

xai / grok-4.7-efficient / high / high effort answer

The sequential SQL match and the Python mirror disagree on whitespace-only operators, so the same inspection can merge on one path and insert a duplicate on the other. The supplied frontend hook never builds a filter or match predicate.

**Conclusion.** `find_existing_inspection` and `InspectionKeys.matches_row` are documented as the same strict match, but a stored `performed_by` of only spaces is missing in Python and present in SQL. Confidence is high: both predicates and the intended rule are in `inspection_match.py`.

Intended rule: operator agrees case- and whitespace-insensitively, or is missing on either side. `normalize_operator` (lines 48–55) defines missing as null, `''`, or whitespace-only after `strip()`, and the comment says that definition was extracted so the bulk and sequential paths cannot drift. `matches_row` (lines 129–134) uses it: if the row operator normalizes to `None`, it returns `True`.

The sequential predicate does not:

```244:249:[REDACTED: private project name]/backend/app/services/inspection_match.py
AND (
      performed_by IS NULL
      OR performed_by = ''
      OR CAST(:op AS text) IS NULL
      OR LOWER(TRIM(performed_by)) = LOWER(TRIM(CAST(:op AS text)))
    )
```

Incoming operator is normalized before bind (line 213), so a whitespace-only *request* becomes NULL and both sides accept. The column side is not normalized. `performed_by = '   '` fails `IS NULL` and `= ''`. `TRIM` yields `''`, which is not equal to a real operator, so SQL returns no row. `matches_row` treats that column as missing and accepts.

Trigger: same `municipality_id`, `project_id`, `asset_id`, UTC date, and `camera_direction`; `deleted_at` null; stored `performed_by = '   '`; incoming operator `'Alice'`. Sequential path returns `None` and inserts another canonical row. Chunk filtering and in-chunk dedup via `matches_row` treat them as one inspection. Visible identity of the inspection set then depends on which path ran.

Minimal correction: treat trimmed-empty `performed_by` as missing, matching `normalize_operator` for ordinary spaces (the equality branch already uses `TRIM`):

```sql
AND (
      performed_by IS NULL
      OR TRIM(performed_by) = ''
      OR CAST(:op AS text) IS NULL
      OR LOWER(TRIM(performed_by)) = LOWER(TRIM(CAST(:op AS text)))
    )
```

Boundary cases (both paths must agree):

- `'   '` vs `'Alice'` → match (fails today in SQL only)
- `'   '` vs null → match
- `''` vs `'Alice'` → match
- null vs `'Alice'` → match
- `'Alice'` vs `'  alice  '` → match
- `'Alice'` vs `'[REDACTED: person name]'` → no match
- `'Alice'` vs null → match
- `'\tAlice'` vs `'Alice'` → still diverges after the minimal fix: Python `strip()` removes tabs and other Unicode whitespace; PostgreSQL `TRIM` removes only U+0020 spaces

**Filter path (separate, same packet).** `useInspectionData.ts` only loads review-boot and `inspection.json`. It does not send `InspectionFilterSpec`. Predicate construction is `apply_inspection_filters`. A second result-set footgun is in that function, not on a frontend request: empty `asset_id_in` is forced to `sa_false()` because the same file says `in_([])` silently drops the clause (lines 144–150), but empty `asset_type_ids` is passed straight to `Asset.asset_type_id.in_(...)` (lines 141–142). An empty type list therefore drops the type constraint and returns every inspection allowed by the other predicates, instead of none. Guard it the same way as `asset_id_in`. Viewport bounds are inclusive and reject null centroids; an inverted or antimeridian box (`min_lon > max_lon`) is unsatisfiable. Whether callers can send that box is outside this packet.

**Alternatives discarded.** Direction null-safety in the sequential SQL (`IS NOT DISTINCT FROM`) matches Python `!=` for `None`. The hazard is only if `hard_key` (which includes nullable `direction`) is later used in SQL tuple `IN`, where `NULL = NULL` is unknown. That caller is not in the packet. `inspection_type_id` omitted from the key is documented intent, not drift. Naive `astimezone(timezone.utc)` versus `parse_inspection_datetime`’s `replace(tzinfo=UTC)` can shift the date, but only if a naive value reaches `inspection_candidate_keys` / `matches_row`; those callers are outside the packet. `project_id` winning over `in_project` is explicit `if/elif`, not an accidental widen. Review-pack trim checks in the hook are consistent with each other and are not filter predicates.

**Missing evidence.** `InspectionFilterSpec`, the `/inspections/query` router, the bulk `hard_key` probe, and the SQLAlchemy version are outside the packet. Consequence: empty `asset_type_ids` is a definite clause-drop if `[]` reaches `apply_inspection_filters`, but this snapshot cannot show that the API accepts `[]`. The operator divergence does not depend on those files.

**Next action.** Add one differential case, stored `performed_by = '   '` against incoming `'Alice'`, asserting `find_existing_inspection` and `matches_row` both match; then change the SQL empty check to `TRIM(performed_by) = ''`. Separately, mirror the `asset_id_in` empty-list `sa_false()` guard for `asset_type_ids`.

Primary judge's stated reason

B is preferable because it supplies the actionable supported parity finding without directing the reader toward an erroneous additional result-set defect and unnecessary correction. This is a clear correctness advantage in the audit, not merely a forced preference between equivalent presentations; it does not negate A's valid primary finding.

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

Battle wave: 1a629e2d-f9fa-4128-8962-e007165c19b0. Pair: brp1_3a170f9ea71be44efaa7b1006efdbc4495d9f933856d03eace1dd46c50a3c665. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.