← Model losses

Head-to-head comparison

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

## Conclusion: the defect is established

Independent, read-only analysis; no source edits or tests run.

`[REDACTED: private project name]/frontend/src/lib/parseLayout.ts:15–17` accepts **every successfully parsed top-level JSON array**, without validating its elements. The `as WidgetConfig[]` assertion adds no runtime protection.

Consequently, accepted shapes include nulls, primitives, nested arrays, empty objects, missing/null `position`, incomplete or incorrectly typed coordinates, and malformed IDs/types. Mixed valid/malformed arrays also succeed unchanged.

### Reproduction and actual consumer failures

| Input | Supplied reproduction | Source-established consumer behavior |
|---|---|---|
| `[null]` | `parserOk:true`; projection throws reading `position` | `DashboardBuilderPage.tsx:49` first evaluates `w.id` in `.find()`, so this page throws reading **`id` before reaching the canvas**. Independently, the actual canvas projection also reads `w.id` first at `BuilderCanvas.tsx:43`. |
| `[{"id":"w1","type":"kpi_card"}]` | `parserOk:true`; projection throws reading `x` | Page lookup succeeds without throwing; `BuilderCanvas.tsx:44` dereferences the missing `position`, producing the demonstrated `undefined.x` failure. |
| Same object with numeric `position` | `parserOk:true`; projection returns `[0]` | The supplied geometry satisfies the canvas’s coordinate reads. This does **not** prove complete rendering succeeds: the object lacks the API interface’s required `title` and `config`, and `WidgetRenderer` is outside the packet. |

Both persisted-layout entry points trust parser success: URL loading at `[REDACTED: private project name]/frontend/src/pages/DashboardBuilderPage.tsx:59–65` and saved-dashboard selection at `:132–138`. They install malformed entries and clear `layoutError`. Thus the error banner and Save blocking (`:53`, `:298`, `:394`) do not protect these inputs.

Other direct consequences are source-established: missing/null `position` throws when `.x` is accessed; primitive and nested-array widgets ordinarily have no `position` and fail similarly. Conversely, `position:{}` or a non-null scalar position can merely produce undefined coordinates during projection—**a later grid-library crash is not established by this packet**.

## Smallest compatible correction

Validate the widget envelope in `[REDACTED: private project name]/frontend/src/lib/parseLayout.ts` **before returning success**:

- Each element is a non-null, non-array object.
- `id` and `type` are strings.
- `position` is a non-null, non-array object containing finite numeric `x`, `y`, `w`, and `h`.
- Reject the entire layout if any entry fails, using a distinct error such as `invalid_widget`.

Return accepted objects unchanged. Preserve custom type strings, arbitrary widget/config/query data, and extra properties; do not impose the drag/drop type allowlist, reconstruct widgets, discard invalid entries, or silently substitute an empty successful layout.

Extend `LayoutResult` and the page’s `layoutError` type at `DashboardBuilderPage.tsx:32`. Its existing failure branches already clear widgets and block Save; the banner’s non-JSON message already covers an unexpected shape.

This is a narrow correction for the demonstrated envelope/geometry defect—not certification of every renderer input. Additional requirements for `title`, `config`, coordinate ranges, uniqueness, or grid bounds should not be introduced incidentally. They either exceed the demonstrated failure or require compatibility evidence not supplied here.

## Focused regression tests

Extend `[REDACTED: private project name]/frontend/src/lib/parseLayout.test.ts`, whose current tests check JSON syntax/top-level arrays but no malformed elements:

1. Reject `[null]`, primitive/nested-array elements, `{}`, and the missing-position reproduction.
2. Reject null/scalar/array positions, missing coordinates, and nonnumeric/nonfinite coordinates.
3. Cover missing/nonstring IDs and types under the proposed envelope contract.
4. Reject a mixed valid/invalid array entirely.
5. Preserve `[]`, existing valid fixtures, custom type strings, nested custom configuration, query data, and extra fields by deep equality.
6. Keep the coordinate-complete reproduction as a positive envelope case; do not describe it as proven renderer-valid.
7. For both page loading paths, verify malformed layouts show the alert, do not pass invalid widgets to the canvas, disable Save without issuing a mutation, and permit explicit “Start fresh” recovery.

## Limits and next action

The packet does not establish backend acceptance of malformed stored values, actual database contents, renderer/editor behavior, grid-library validation, or surrounding error-boundary handling. The confirmed claim is a reachable render exception **when these stored values are loaded**, not necessarily an application-wide uncaught crash.

Next action: implement the narrow parser validation and error-type update, then add the focused regressions above. A canvas-only fallback would leave the page’s earlier null dereference and incorrectly successful parsing unresolved.

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 is preferable with a clear task-grounded advantage: it avoids treating undefined coordinate values as proven projection exceptions and accurately distinguishes the reproduction helper from the actual page/canvas evaluation order. This improves diagnosis and the scope of regression assertions. The advantage is not based on length or optional refinements; both recommendations remain practically useful.

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