← Model losses

Head-to-head comparison

xai / grok-4.7-efficient / high / high effort preferred over cursor / composer-2.5 / Composer 2.5 default / unknown 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.

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

cursor / composer-2.5 / Composer 2.5 default / unknown effort answer

## Evidence packet

### 1. Conclusion (primary risk)

**Asymmetric empty-list semantics for asset narrowing** in `apply_inspection_filters` can make the visible inspection set **wider than intended** when the client sends “no asset types selected” as an empty array.

| Dimension | When list is present but empty | Effect |
|-----------|--------------------------------|--------|
| `asset_id_in` | Explicit `sa_false()` → **match nothing** | ```144:150:[REDACTED: private project name]/backend/app/services/inspection_filter_pipeline.py``` |
| `asset_type_ids` | `Asset.asset_type_id.in_([])` only — **no empty-list guard** | ```141:142:[REDACTED: private project name]/backend/app/services/inspection_filter_pipeline.py``` |

The pipeline already documents that SQLAlchemy `in_([])` **silently drops** the clause for `asset_id_in` and fixes it with `sa_false()`. The same hazard is **not** handled for `asset_type_ids`. Depending on SQLAlchemy compilation, an empty `IN ()` may become a no-op or an always-false predicate; either way, behavior is **not aligned** with the documented “empty list = match nothing” contract used for `asset_id_in`, and UI that maps “zero selected types” → `asset_type_ids: []` can show **all types** instead of **none**.

**Confidence:** High for **internal pipeline inconsistency** and the documented `in_([])` hazard; medium for **exact SQLAlchemy compile outcome** without `filter_compiler` / router spec parsing in the packet.

**Secondary risk (viewport + nulls):** Step 9 applies bbox only after requiring non-null centroids:

```181:190:[REDACTED: private project name]/backend/app/services/inspection_filter_pipeline.py```

Any inspection whose joined `Asset` has null `centroid_lat`/`centroid_lng` is **excluded** when `viewport_bbox` is set, even if the map/list elsewhere still shows those rows under other filters. That is a **null-sensitive combined filter** (viewport + Asset join), not necessarily a bug, but it is a common FE/BE divergence if the map draws assets without centroids.

**Confidence:** High that the predicate excludes null centroids; medium that the product intends that.

---

### 2. Path trace (what the packet actually supports)

**Backend predicate assembly (complete in packet)**

Single entry: `apply_inspection_filters(stmt, spec, …)` with fixed order:

1. Tenant `scope.inspection_filter()` + `archival_filter(spec.current_only)`  
2. `project_id` / `in_project` (mutually exclusive branches: `project_id` wins if set)  
3. `asset_type_ids` → `IN` (no empty guard)  
4. `asset_id_in` → empty → `FALSE`  
5. `compile_filters(saved_filter_ids)`  
6. `constrain_parent_by_observation_filters(..., current_only=spec.current_only)`  
7. `nl_filter_group` via `compile_transient_condition_group` (strict; no silent widen)  
8. `apply_search`  
9. `viewport_bbox` + non-null centroid range checks  

```112:122:[REDACTED: private project name]/backend/app/services/inspection_filter_pipeline.py```

**“Matching” in packet = import merge, not grid filters**

`inspection_match.py` builds **dedup/merge** predicates for ingest (`find_existing_inspection`, `InspectionKeys.matches_row`), keyed on muni/project/asset/UTC date/direction/soft time/operator — **not** on `InspectionFilterSpec`. It is a **different** “matching” lane from grid filtering; no wire path links `useInspectionData.ts` to this module.

**Frontend request (incomplete in packet)**

`useInspectionData.ts` only loads `/inspections/{id}/review-boot` and `/review-pack/{id}/inspection.json`, gated on `review_pack_path`. It does **not** build or send grid filter specs (`nl_filter_group`, `viewport_bbox`, `asset_type_ids`, etc.). The packet **cannot** establish how the inspections grid serializes filters or which query endpoint is called.

```74:83:[REDACTED: private project name]/frontend/src/hooks/useInspectionData.ts```

**Discarded hypothesis:** Treating `useInspectionData` as the inspections **filter** request path — **not supported** by the file’s API usage.

---

### 3. Minimal correction

Mirror the `asset_id_in` sentinel for asset types:

```python
if spec.asset_type_ids is not None:
    if not spec.asset_type_ids:
        stmt = stmt.where(sa_false())
    else:
        stmt = stmt.where(Asset.asset_type_id.in_(spec.asset_type_ids))
```

Optional product clarification (not required for the empty-list bug): document that `viewport_bbox` **implicitly** filters to assets with centroids.

---

### 4. Boundary regression cases

| Case | Expected after fix |
|------|----------------------|
| `asset_type_ids=[]`, other dims default | **Zero rows** (parity with `asset_id_in=[]`) |
| `asset_type_ids=None` | No asset-type narrowing (unchanged) |
| `asset_id_in=[]` | Zero rows (existing behavior) |
| `viewport_bbox` set, asset with `centroid_lat/lng` NULL | Row **excluded** |
| `viewport_bbox` set, centroid on min/max lon/lat | **Included** (`>=` / `<=` inclusive) |
| `project_id=5` and `in_project=false` both sent | Only **project_id** branch runs (`elif` chain) |
| `observation_filter_ids` + `nl_filter_group` both set | Both apply; NL **after** observation parent constrain (order pinned) |

For **import match** (separate suite): UTC date-only vs timed same day, one side midnight UTC; `direction` NULL vs value (`IS NOT DISTINCT FROM` in SQL); `performed_by` NULL/empty vs conflicting non-empty on both sides.

---

### 5. Missing evidence / uncertainty

- **Frontend filter client:** No hook/page building `InspectionFilterSpec` or calling `/inspections/query` / pill-state — cannot prove how empty `asset_type_ids` is encoded or whether map viewport always sends bbox with Asset join assumptions.
- **Dependencies:** `inspection_filter_spec.py` (defaults), `inspections.py` router (spec from query body), `filter_compiler.py`, `observation_parent_filters.py`, `apply_search`, `archival_filter` — behavior of combined saved + observation filters and search null/empty strings unknown here.
- **Consequence:** Strongest **end-to-end** parity claim is pipeline-internal (`asset_type_ids` vs `asset_id_in`); reproducing in UI requires the missing FE/router slice.

---

### 6. Next useful action

Add a backend parity test next to existing SQL parity tests for `/inspections/query`: same base `stmt`, `asset_type_ids=[]` vs `asset_id_in=[]` should both yield empty sets; optionally assert compiled SQL contains a false sentinel for both. Extend packet with the router handler that maps query params → `InspectionFilterSpec` to close the FE gap.

---

**Alternatives / false positives:** If the API never sends `asset_type_ids=[]` (only `null` when unset), the defect may be latent. If SQLAlchemy version always compiles `in_([])` to false, user-visible bug might still be absent, but parity with the explicit `asset_id_in` contract and comments would remain wrong.

Primary judge's stated reason

B provides an actionable, source-supported matching discrepancy that can change match decisions, rather than principally proposing a redundant empty-list guard. This is a clear task-relevant advantage, not merely a forced slight preference, despite B's incorrect secondary finding and overstatement of downstream insertion behavior.

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