← Model losses

Head-to-head comparison

xai / grok-4.7-efficient / high / high effort preferred over xai / grok-4.7-efficient / 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

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.

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

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

The operator-match predicate is not null/whitespace-safe across the two in-packet match implementations, so the same inspection can merge on one path and duplicate on the other. The supplied frontend hook never builds an inspection filter request.

**Primary risk (high confidence).** `InspectionKeys.matches_row` and `find_existing_inspection` disagree on whitespace-only `performed_by`.

Intended semantics, stated in `inspection_match.py` and implemented by `normalize_operator` (lines 48–55, 129–134): an operator is missing when it is null, empty, or whitespace-only; missing on either side accepts; otherwise compare case-insensitively after trim.

- Python path: `normalize_operator('   ')` is `None`, so `matches_row` returns `True` against a real operator such as `'Alice'`.
- SQL path (`find_existing_inspection`, lines 244–249): `performed_by IS NULL OR performed_by = ''` does not treat `'   '` as missing. `LOWER(TRIM(performed_by))` becomes `''`, which is not equal to `'alice'`, so the row is rejected when `:op` is non-null.

Incoming operators are normalized before bind (`op_norm` at line 213), so the reverse case (whitespace only on the candidate) already matches in SQL via `CAST(:op AS text) IS NULL`. Only a whitespace-only stored `performed_by` diverges. Chunk dedup and the sequential probe can therefore disagree, and the strict-match invariant (one canonical row) fails. `LIMIT 2` also undercounts that warning; it does not change the chosen id.

Minimal correction — make the SQL missing-check the same as `normalize_operator`:

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

Boundary cases (same muni/project/asset/UTC date/direction; both times non-midnight and equal unless noted):

1. DB `performed_by='   '`, candidate `'Alice'` → both paths match (today: Python matches, SQL does not).
2. DB `'Alice'`, candidate `'   '` / `None` / `''` → both match.
3. DB `'  Alice  '`, candidate `'alice'` → both match.
4. DB `'Alice'`, candidate `'[REDACTED: person name]'` → both reject.
5. DB `NULL` or `''`, candidate `'[REDACTED: person name]'` → both match.
6. Direction `NULL`/`NULL` matches; `NULL`/`'U'` does not.
7. Both times non-midnight and unequal → reject; either side midnight UTC → accept.

**Second filter risk (medium confidence; reachability not in packet).** `asset_id_in` treats `[]` as match-nothing because SQLAlchemy `in_([])` drops the clause (lines 144–150). `asset_type_ids` does not (lines 141–142). If an empty list is accepted by `InspectionFilterSpec`, the grid returns every asset type in scope instead of none. Same sentinel as `asset_id_in` (`sa_false()` when the list is empty). Regress `[]` → empty set, `None` → no predicate, `[id]` → that type only. Schema validation is outside this packet.

**Discarded or weaker.** Viewport bounds are inclusive and drop null centroids; antimeridian behavior is unspecified here. `project_id` wins over `in_project` by `if/elif`; whether both can be set is outside the packet. `useInspectionData.ts` only gates review-boot and `inspection.json`; it does not construct filter predicates, so it is not on this path. Nullable `direction` inside `hard_key` is unsafe for SQL `IN` (`NULL` never matches `NULL`) even though sequential SQL uses `IS NOT DISTINCT FROM`; the bulk `IN` caller is not in this packet. `matches_row` uses `astimezone` on a naive datetime (local zone), while `parse_inspection_datetime` uses `replace(tzinfo=UTC)`; that diverges only if a naive value reaches `matches_row`.

**Missing.** `InspectionFilterSpec`, `compile_filters`, `apply_search`, `archival_filter`, and the bulk probe that consumes `hard_key` are outside the packet. Consequence: empty `asset_type_ids` and null-direction bulk `IN` cannot be confirmed as live callers from this snapshot alone. The operator whitespace split does not depend on those files.

**Next action.** Add a differential test for case 1 above (whitespace-only DB operator vs named candidate) against both `matches_row` and the SQL text, then align the SQL `NULLIF(BTRIM(...))` check. Separately, mirror the `asset_id_in` empty-list sentinel on `asset_type_ids` if the spec allows `[]`.

Primary judge's stated reason

A earns a slight forced preference because its explicit residual-whitespace case helps prevent treating the minimal SQL change as complete normalization parity. B offers useful broader matching boundaries. This is not an established material quality difference; an independent review could reasonably favor B's regression coverage.

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