← Model losses

Head-to-head comparison

openai / gpt-6-astra / medium / medium 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-astra / medium / medium effort answer

## Conclusion — established defect, high confidence

`parseLayout` accepts **every successfully parsed JSON array**, without inspecting its elements (`lib/parseLayout.ts:13–19`). The `as WidgetConfig[]` assertion performs no runtime validation.

Accepted shapes therefore include:
- `[null]`, primitive elements, nested arrays, and `{}` elements;
- widgets with missing or `null` `position`;
- widgets whose position is a primitive, array, incomplete object, or contains nonnumeric coordinates;
- missing/wrongly typed `id`, `type`, `title`, or `config`;
- mixtures of valid and malformed widgets.

Acceptance does **not** establish that each shape crashes.

### Established failures and consumer path

| Input | Supplied reproduction | Actual consumer consequence |
|---|---|---|
| `[null]` | Parser succeeds; projection throws reading `position` | `DashboardBuilderPage.tsx:49` first throws reading `w.id` during the next render. If passed directly to canvas, its mapping first reads `w.id` (`BuilderCanvas.tsx:43`). |
| `[{"id":"w1","type":"kpi_card"}]` | Parser succeeds; projection throws reading `x` | Page’s `find` is safe; canvas dereferences `w.position.x` and throws (`BuilderCanvas.tsx:44`). |
| Same widget with `{x:0,y:0,w:4,h:2}` | Parser succeeds; projection produces `[0]` | Establishes successful coordinate projection only, not successful full rendering. |

Both persisted-layout entry points put successful parser output directly into widget state and clear the error: URL loading (`DashboardBuilderPage.tsx:55–74`) and saved-dashboard selection (`130–146`). Nonempty arrays cause canvas rendering (`459–479`).

Thus malformed arrays bypass the existing invalid-layout banner and disabled-Save handling. The reproduction demonstrates a projection failure, rather than a mounted application test; source establishes the corresponding render-time dereferences. Missing-position failure matches the actual canvas path; the null-element error’s first property differs.

## Smallest compatible correction

Validate widget structure **at the parser boundary**, rejecting the entire layout with a new discriminant such as `invalid_widget`.

For a narrowly scoped layout-envelope check:
- Require each widget to be a non-null, non-array object.
- Require string `id` and `type`.
- Require non-null, non-array `position` with finite numeric `x`, `y`, `w`, and `h`.
- Return the original parsed objects unchanged after validation.

Update the page’s error-state union (`32`) to include that discriminant. Its existing failure branches already clear unsafe widget state, display the generic format message (`414–416`), and disable Save (`298`).

Preserve unknown widget types, custom configuration, query data, and extra properties. Avoid schema reconstruction, filtering malformed entries, invented defaults, or applying the drag/drop type allowlist to stored layouts. Those approaches can discard data or change accepted historical layouts unnecessarily. The supplied evidence does not justify additional grid bounds, integer constraints, or size limits.

This envelope check fixes the demonstrated defects. It is **not full validation of the declared `WidgetConfig` contract**, which additionally requires `title` and `config` (`api/dashboards.ts:40–55`). Whether omitted fields need rejection or compatibility defaults cannot be settled from these consumers alone; the reproduction’s third case does not settle that question.

## Focused regression tests

1. Parser rejects `[null]`, primitives/nested arrays, missing/null/non-object position, and incomplete or nonnumeric position fields.
2. Mixed valid/malformed arrays fail as a whole.
3. Valid widgets and `[]` still succeed; deep equality verifies preservation of custom types, nested config/query data, and extra fields.
4. Retain existing `invalid_json` and `not_array` expectations.
5. Exercise both saved-layout loading paths with the two reproduced failing inputs: no render exception, invalid-layout alert visible, Save disabled. Verify valid loading clears the error and Start fresh recovers.

## Limits and next action

`WidgetRenderer`, its exported widget type, and grid-library internals are outside the packet. Their validation requirements and failure modes are unestablished; backend persistence of malformed payloads and application error-boundary behavior are also unshown.

Next action: implement the boundary guard and focused regressions, resolving any broader widget-schema requirements separately. Assessment performed independently from the supplied evidence; no edits or tests run.

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 better-supported diagnosis of which inputs actually throw and where, helping implementers target regressions without treating undefined coordinates as an established exception. This is a clear task-relevant evidentiary advantage, not a preference based on presentation; both answers still provide useful correction plans.

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