← Model losses

Head-to-head comparison

openai / gpt-6.1-sol / 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.

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

## Finding: whitespace-only operators break matching parity

**High confidence; independently assessed from the supplied snapshot.** The Python matcher accepts an existing inspection whose operator is spaces-only, but the SQL matcher rejects it when the incoming operator is named.

In `[REDACTED: private project name]/backend/app/services/inspection_match.py`:

- `normalize_operator()` strips whitespace and converts an empty result to `None` (lines 48–55).
- `InspectionKeys.matches_row()` accepts a match when either normalized operator is missing (lines 129–134).
- `find_existing_inspection()` normalizes the incoming operator, but its SQL considers the stored operator missing only when it is `NULL` or exactly `''` (lines 213, 244–249).

**Reproducible trigger:** use identical municipality, project, asset, UTC timestamp and direction; stored `performed_by = '   '`; incoming operator `'Alice'`.

| Path | Result |
|---|---|
| Python `matches_row()` | `True`: stored operator normalizes to `None`. |
| SQL `find_existing_inspection()` | No match: spaces are neither `NULL` nor `''`, and `LOWER(TRIM('   ')) != 'alice'`. |

The reverse ordering accepts the match: incoming spaces normalize to `None`, satisfying SQL’s `:op IS NULL` branch. Thus record order and sequential-versus-batched matching can change the matching result. A caller that inserts after a miss could produce duplicate canonical inspections, affecting displayed rows and counts; that insertion/display linkage is **not established by this packet**.

## Request-to-predicate trace—and its limit

`[REDACTED: private project name]/frontend/src/hooks/useInspectionData.ts` does **not** issue an inspection-filter request. It fetches:

1. `/inspections/{id}/review-boot`, enabled only for positive IDs (lines 17–29).
2. `/review-pack/{id}/inspection.json`, gated by a fetched boot payload and nonempty trimmed pack path (lines 74–90).

Consequently, this snapshot cannot establish how frontend filter controls become `InspectionFilterSpec`.

Once a spec reaches `apply_inspection_filters()` in `[REDACTED: private project name]/backend/app/services/inspection_filter_pipeline.py`, predicates are composed in this order:

- Tenant scope and archival filtering (line 130).
- Project filtering: explicit `project_id` takes precedence over `in_project` (lines 133–138).
- Asset types and asset IDs; an empty asset-ID list explicitly matches nothing (lines 141–150).
- Saved filters, observation-parent filters, then transient NL conditions (lines 155–175).
- Search (line 178).
- Viewport: non-null coordinates and inclusive longitude/latitude bounds (lines 181–190).

Successive `.where()` calls intersect these dimensions. The internal semantics of the imported compilers and parent-filter helper remain outside the packet.

## Smallest correction and regression cases

For the demonstrated spaces-only defect, replace SQL’s:

```sql
OR performed_by = ''
```

with:

```sql
OR TRIM(performed_by) = ''
```

Keep the existing `performed_by IS NULL` branch.

Add SQL-versus-Python differential tests, holding all other keys equal:

- Stored operator `NULL`, `''`, and `'   '` against `'Alice'`: all match.
- Reverse each pair: all match.
- `' Alice '` against `'alice'`: match.
- `'Alice'` against `'[REDACTED: person name]'`: no match.
- Repeat the whitespace case with both directions `NULL`, midnight/non-midnight timestamps, and unequal non-midnight timestamps; operator normalization must not bypass direction or time restrictions.

**Remaining boundary:** Python `.strip()` also removes tabs, newlines and other whitespace; PostgreSQL’s default `TRIM()` removes spaces. Test these explicitly. Full whitespace parity requires the SQL and Python paths to use the same normalization definition; the minimal patch above fixes only the demonstrated space case.

## Uncertainty and next action

No frontend-to-filter transport, schema validation, compiler internals, bulk-probe implementation or insert-on-miss caller is supplied. Therefore, antimeridian ranges, combined-filter transport bugs and nullable bulk-key failures are hypotheses—not established defects.

Next action: reproduce the operator mismatch with a database-backed differential test, then apply the narrow SQL correction and define broader whitespace handling.

MATERIAL_EVIDENCE_CONFLICT: `inspection_match.py:99–107` claims Python/SQL predicate equivalence, but `48–55,129–134` treat stored whitespace-only operators as missing while `244–249` do not.

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 provides the more actionable investigation: a source-demonstrable SQL/Python mismatch, reproducible inputs, a minimal space-case fix, and differential regressions. B's principal recommendation may only replace an already match-nothing predicate with another equivalent predicate. This is a supported material advantage on the central requested outcome, not merely a forced slight preference; neither answer establishes an actual UI incident.

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