← Model losses

Head-to-head comparison

xai / grok-4.7-efficient / low / low 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 / 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 `[]`.

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

A is clearly preferable because it supplies an actionable, source-demonstrated matching discrepancy rather than relying chiefly on a disputed interpretation of empty-IN behavior. This is a substantive advantage for the requested concrete risk, not merely a forced slight preference. Actual duplicate creation and frontend-visible impact remain conditional on callers and stored data not shown.

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