# Failure clusters

Failing runs grouped by what went wrong, largest first, each with its share of failures, how it moved since last period, and a few real examples. The bar is length only; the count is always printed beside it.

- Registry name: `failure-clusters` (`@candor/failure-clusters`)
- Tier: Pro. Installing it needs a Pro, Premium or Team licence key: the person runs `npx candor-ui key <key>` themselves; never ask for the key in chat or write it to a file.
- Docs: https://candor.themethodic.com/docs/failure-clusters

## Install

```bash
npx candor-ui add failure-clusters
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/failure-clusters`.
It brings in: agent-avatar, collapsible, locale, ops, utils.
npm packages: lucide-react@^1.67.0.

## Example

```tsx
"use client"

import { FailureClusters } from "@/components/failure-clusters"
import type { FailureCluster } from "@/lib/ops"

const clusters: FailureCluster[] = [
  { id: "x1", label: "Row lock during data backfill", count: 14, delta: 9, agent: { id: "dev", name: "Dev agent", role: "coder" }, examples: ["Add region to customers: batch 12, lock timeout ×4", "Backfill tier on subscriptions: batch 3 locked by a nightly job"] },
  { id: "x2", label: "Code search timed out", count: 9, delta: -2, agent: { id: "qa", name: "QA agent", role: "tester" }, examples: ["Find code reading legacy_score: timed out after 30s"] },
  { id: "x3", label: "Asked to act without a clear target environment", count: 6, delta: 0, examples: ["“Clean up the old flags” with Production and Staging both connected"] },
]

export default function Example() {
  return <FailureClusters className="max-w-xl" clusters={clusters} />
}
```

## <FailureClusters>

Props:

- `clusters: FailureClusterInput[]`: Failure groups, each with its count, change since the comparison and example runs. Shown largest first. A `delta` of null (nothing to compare with) is shown as unknown.
- `title?: string | undefined`: The heading. Defaults to "Why runs failed".
- `unit?: string | undefined`: What the total counts, plural, as in "12 failures". Defaults to "failures".
- `since?: string | undefined`: What the change is measured against, read after "more than" and "fewer than", as in "production's run". Defaults to "last period".
- `className?: string | undefined`

## Strings (`failureClusters`)

The fixed words, English by default. Override any of them under `failureClusters` in `<LocaleProvider strings={{ failureClusters: { … } }}>`; the table is exported as `failureClustersStrings`.

- `title`: Why runs failed
- `unit`: failures
- `total`: {total} {unit}
- `since`: last period
- `more`: more than {since}
- `fewer`: fewer than {since}
- `noChange`: no change since {since}
- `unknown`: change unknown

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
