← Model losses

Head-to-head comparison

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

Review persisted dashboard-layout parsing and its DashboardBuilderPage/BuilderCanvas consumers for a reproducible runtime crash caused by malformed widget shapes. Use only the supplied source files and the linked read-only reproduction. Establish the exact malformed shapes accepted by parseLayout and the resulting consumer failure; distinguish established behavior from assumptions. Recommend the smallest compatible correction that preserves valid stored layouts and custom widget data, plus focused regression tests. If the evidence does not establish the defect or a safe correction, state that clearly. Do not edit source or run tests.

Exact read-only reproduction stdout:
{"input":"[null]","parserOk":true,"canvasProjectionError":"TypeError: Cannot read properties of null (reading 'position')"}
{"input":"[{\"id\":\"w1\",\"type\":\"kpi_card\"}]","parserOk":true,"canvasProjectionError":"TypeError: Cannot read properties of undefined (reading 'x')"}
{"input":"[{\"id\":\"w1\",\"type\":\"kpi_card\",\"position\":{\"x\":0,\"y\":0,\"w\":4,\"h\":2}}]","parserOk":true,"canvasProjection":[0]}

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

## Conclusion — defect established

Independent, read-only analysis of the supplied snapshot; no tests run or files changed.

`[REDACTED: private project name]/frontend/src/lib/parseLayout.ts:15–17` accepts **every syntactically valid JSON array**, without validating its elements. The `WidgetConfig[]` assertion performs no runtime checks. Accepted malformed shapes therefore include:

- Nulls, primitives, nested arrays, and arbitrary objects.
- Widgets with missing or incorrectly typed `id`, `type`, `title`, or `config`.
- Missing/null `position`, or positions with missing, null, string, or otherwise invalid coordinates.
- Mixtures of valid and malformed widgets.

Acceptance does **not** establish that every such shape crashes.

### Established failure paths

| Input | Established behavior |
|---|---|
| `[null]` | Supplied reproduction reports `parserOk: true` and a null-`position` projection error. In the actual page, `widgets.find((w) => w.id …)` at `DashboardBuilderPage.tsx:49` would throw **earlier**, reading null’s `id`. Likewise, the canvas mapping reads `w.id` before `w.position` (`BuilderCanvas.tsx:43–44`). |
| `[{"id":"w1","type":"kpi_card"}]` | Accepted; the page’s `find` can complete, but canvas construction dereferences absent `position.x` (`BuilderCanvas.tsx:44`). The supplied reproduction confirms this undefined-`x` error. |
| Widget with `{x:0,y:0,w:4,h:2}` position | Supplied reproduction confirms successful projection `[0]`. This does not prove complete rendering succeeds without `title` and `config`. |

Both persisted loading routes pass accepted widgets directly into state (`DashboardBuilderPage.tsx:59–65,132–138`), clear the error, and render the canvas for nonempty layouts (`459–479`). Thus malformed arrays bypass the existing corrupt-layout handling and Save blocking.

The reproduction’s null error identifies an unsafe projection, **not the exact first exception in the supplied page/component**.

## Smallest compatible correction

Validate widget structure at the parsing boundary and reject the **whole layout** on failure:

- Require non-null, non-array widget objects.
- Require string `id` and `type`.
- Require non-null, non-array `position` objects with finite numeric `x`, `y`, `w`, and `h`.
- Return the original parsed objects unchanged on success.

Add an explicit error such as `invalid_widgets` to `LayoutResult` and the page’s `layoutError` type (`DashboardBuilderPage.tsx:32`). Existing failure branches already clear widgets, display the generic unexpected-format banner, and disable Save.

Do **not** filter malformed entries, reconstruct widgets from selected fields, restrict types to the drop allowlist, or impose canvas min/max values on persisted data. Those approaches risk silent data loss or rejecting custom/previously valid layouts. Preserve unknown fields and opaque custom configuration/query data.

This is a supported correction for the demonstrated page/canvas failures—not proof of complete renderer safety. Mandatory `title`/`config` validation or defaults require compatibility evidence beyond their API declarations (`api/dashboards.ts:40–55`); the supplied projection-valid example omits both.

## Focused regression tests

Extend `[REDACTED: private project name]/frontend/src/lib/parseLayout.test.ts` to cover:

1. Rejection of `[null]`, primitive/array elements, absent/null/non-object positions.
2. Rejection of missing or nonnumeric coordinates, and non-finite numbers from valid JSON such as `1e400`.
3. Rejection of one malformed element among valid widgets, without partial success.
4. Preservation of `[]`, existing valid layouts, custom type strings, unknown fields, nested custom configuration, and query data.
5. Preservation of the current `invalid_json` and `not_array` classifications.

Add page-level regressions for **both URL loading and saved-dashboard selection**: malformed layouts must not throw, must show the error banner, must disable Save, and must recover through “Start fresh.”

## Limits and next action

`WidgetRenderer`, `WidgetConfigEditor`, and grid-library implementation are outside the supplied packet. Invalid field values may cause additional failures there, but those are not established. Template loading also bypasses `parseLayout` (`DashboardBuilderPage.tsx:121–124`); that is a separate input path, not evidence of persisted-parser protection.

Next useful action: implement the boundary guard and focused regressions, then verify renderer requirements before broadening validation.

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

## Evidence packet: malformed `layout_json` → `parseLayout` accepts → `BuilderCanvas` crashes

### 1. Conclusion, evidence, implications, confidence

**Defect is established** for a reproducible runtime crash when persisted `layout_json` is a JSON **array** whose elements are not usable `WidgetConfig` shapes for the builder canvas. `parseLayout` only checks `JSON.parse` + `Array.isArray`; it does **not** validate elements. On `ok: true`, `DashboardBuilderPage` assigns `result.widgets` to state and renders `BuilderCanvas`, which **unconditionally** reads `w.position.x` (and siblings) in a `useMemo`.

| Malformed input (reproduction) | `parseLayout` | Consumer failure (reproduction) |
|-------------------------------|---------------|----------------------------------|
| `[null]` | `ok: true` | `TypeError: Cannot read properties of null (reading 'position')` |
| `[{"id":"w1","type":"kpi_card"}]` (no `position`) | `ok: true` | `TypeError: Cannot read properties of undefined (reading 'x')` |
| Full widget with `position: {x,y,w,h}` | `ok: true` | Projection succeeds (`canvasProjection: [0]`) |

**Source chain (no tools; packet only):**

```13:17:[REDACTED: private project name]/frontend/src/lib/parseLayout.ts
export function parseLayout(layout_json: string): LayoutResult {
  try {
    const parsed = JSON.parse(layout_json)
    if (!Array.isArray(parsed)) return { ok: false, error: 'not_array' }
    return { ok: true, widgets: parsed as WidgetConfig[] }
```

```40:47:[REDACTED: private project name]/frontend/src/components/dashboard/BuilderCanvas.tsx
  const layout: Layout = useMemo(
    () =>
      widgets.map((w) => ({
        i: w.id,
        x: w.position.x,
        y: w.position.y,
        w: w.position.w,
        h: w.position.h,
```

```59:62:[REDACTED: private project name]/frontend/src/pages/DashboardBuilderPage.tsx
      const result = parseLayout(urlConfig.layout_json)
      if (result.ok) {
        setWidgets(result.widgets)
        setLayoutError(null)
```

```32:32:[REDACTED: private project name]/frontend/src/pages/DashboardBuilderPage.tsx
  const [layoutError, setLayoutError] = useState<'invalid_json' | 'not_array' | null>(null)
```

**Implications:** Any stored dashboard whose `layout_json` parses to an array but contains `null`, non-objects, or objects without a `position` object with numeric `x/y/w/h` can load with `layoutError === null`, show the builder (when `widgets.length > 0`), and **throw during render** in `BuilderCanvas`’s layout projection. Save is **not** blocked for these cases (`saveBlocked` only when `layoutError !== null`), unlike true JSON/array errors.

**Confidence:** **High** for the two malformed shapes above and the exact error strings (reproduction stdout + cited lines). **High** that the crash site is `w.position` / `w.position.x` in `BuilderCanvas` given those errors.

**Broader malformed shapes accepted by `parseLayout` (logical extension of the same guard, not individually reproduced in stdout):** any array element that is not a plain object with a `position` object exposing `x`, `y`, `w`, `h` as readable properties—e.g. `position: null`, `position: {}`, `position: { x: 0 }`, primitives in the array, arrays as elements—should still yield `ok: true` and fail at the same projection (or adjacent property access on `w`). **Not established** in the packet: whether `WidgetRenderer` throws earlier/later for missing `title`/`config`/`type` (dependency outside packet).

---

### 2. Alternatives / discarded hypotheses

| Hypothesis | Verdict |
|------------|--------|
| Crash is from `invalid_json` / `not_array` paths | **Discarded** — reproduction shows `parserOk: true` for failing inputs. |
| `DashboardBuilderPage` already blocks corrupt layouts | **Partially false** — banner + `saveBlocked` apply only to `invalid_json` and `not_array`, not element-shape errors. |
| Fix only in `BuilderCanvas` (optional chaining / defaults) | **Insufficient alone** — avoids throw but silently feeds bad data to RGL; does not align with explicit error UI for corrupt **saved** layouts; may hide bad persisted data. |
| Filter invalid elements, return `ok: true` with subset | **Riskier** — preserves some widgets but **drops** persisted entries without user-visible “corrupt layout” flow; conflicts with existing “invalid layout → Start fresh” pattern unless separately surfaced. |
| Strict full `WidgetConfig` validation (`title`, `config`, etc.) | **Possible but wider scope** — may reject layouts that are recoverable in the editor if only `position` is wrong; not required to fix the **established** crash. |

---

### 3. Missing evidence / consequences

- **`WidgetRenderer` / `WidgetConfig` from `./WidgetRenderer`** — not in packet; unknown whether missing `title`/`config` causes additional crashes after layout projection is fixed.
- **Other readers of `layout_json`** (runtime dashboard view, API validation) — unknown; fixing `parseLayout` affects all callers of that function (at least URL load and `loadSavedConfig` in this packet).
- **`getDefaultWidgetSize` / templates** — not shown producing malformed layouts; defect is framed as **persisted** malformed arrays, which the parser currently admits.

---

### 4. Smallest compatible correction (recommendation)

**Extend `parseLayout` with minimal structural validation** after the array check, before returning `ok: true`:

- Reject the layout (new discriminant, e.g. `error: 'invalid_widgets'`) if **any** element fails:
  - `item != null` and `typeof item === 'object'` and not `Array.isArray(item)`
  - `typeof item.id === 'string'` and `item.id.length > 0` (matches builder’s use of `w.id` as RGL `i` and React `key`)
  - `item.position != null` and `typeof item.position === 'object'`
  - `['x','y','w','h'].every(k => typeof item.position[k] === 'number' && Number.isFinite(item.position[k]))`

- Do **not** strip or rewrite `config`, extra keys, or optional fields—only gate `ok`. Valid complete layouts (as in existing test and reproduction case 3) remain `ok: true` with widgets passed through unchanged (still `parsed as WidgetConfig[]` / shallow copy optional, not required).

**Wire consumers (small, compatible):**

- Add `'invalid_widgets'` to `LayoutResult` and to `layoutError` state in `DashboardBuilderPage`; reuse the existing corrupt-layout banner with a third message string (same “Start fresh” behavior as other layout errors).
- No change required to `BuilderCanvas` for the established defect if bad layouts never reach it.

This preserves **valid** stored layouts and **all** custom fields on valid elements; invalid persisted arrays get **non-crashing** error UI instead of a white screen.

**Focused regression tests** (in `parseLayout.test.ts`, matching existing style):

1. `[null]` → `ok: false`, `error: 'invalid_widgets'` (or chosen code).
2. `[{"id":"w1","type":"kpi_card"}]` → same.
3. Existing happy path unchanged (full widget with `position`).
4. `[]` → still `ok: true`.
5. Optional high-value cases: mixed `[valid, invalid]` → fail whole layout (consistent with strict corrupt handling); `position: null`; non-finite numbers.

**Do not** claim tests were run; user forbade execution.

---

### 5. Next useful action

Implement the `parseLayout` element guard + `invalid_widgets` discriminant, extend `DashboardBuilderPage` `layoutError` typing and banner copy, and add the regression cases above; optionally add a tiny pure helper test that mirrors the reproduction’s “canvas projection” `map` over `result.widgets` only for the three stdout inputs to lock the crash class without mounting React.

**Uncertainty note:** If product policy prefers **partial recovery** (load good widgets, drop bad ones), that is a different contract than the page’s current binary corrupt-layout UX; the packet supports **reject-with-banner** as the smallest match to existing behavior.

Primary judge's stated reason

A provides a clearer, evidence-faithful diagnosis for implementing and testing the correction: readers can distinguish confirmed dereference crashes from invalid values whose downstream effects remain unknown. This supports a clear preference on an explicit task obligation, rather than merely a forced stylistic preference; it does not establish that B's proposed guard would fail to prevent the reproduced crashes.

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

Battle wave: 1ac788c7-8a93-4502-8b1a-e4734c703741. Pair: brp1_e08d9c5335c71d5975a0253dbd100c90d979099f5d5d5ab9f3c7749c65ecef73. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.