> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tracepress.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Why did my runs fail?

> Roll step notes up into failure modes per trial, per task and overall.

This recipe explains every failed run of a Harbor job from its steps and the verifier's failed
tests, then finds what the failures have in common per task and across the job. The full
script is
[examples/failure\_modes.py](https://github.com/Ziems/tracepress/blob/main/examples/failure_modes.py).

## 1. Small facts with plain Python

```python theme={null}
import tracepress as tp

tp.configure(lm="openrouter:openai/gpt-6-luna")
src = tp.read.harbor("jobs/my-job")

failed_tests = (
    src.tests.filter(lambda r: r.status != "passed")
    .group_by("trial")
    .reduce(lambda rs: {"failed_tests": ", ".join(r.name.split("::")[-1] for r in rs)},
            columns={"failed_tests": str}))
failed_runs = src.trials.group_by("task").reduce(
    lambda rs: {"failed_runs": sum((r.reward or 0) < 1 for r in rs)}, columns={"failed_runs": int})
```

## 2. A note per step

```python theme={null}
notes = src.steps.lm_map(
    "step -> what_happened, is_mistake: bool",
    instructions="Summarize this step of a coding agent's run in one sentence, "
                 "and say whether it was a mistake.")
```

## 3. Roll up per trial, per task and overall

```python theme={null}
per_trial = (notes.join(src.trials, on="trial").join(failed_tests, on="trial")
    .group_by("trial").lm_reduce(
        "instruction, reward, failed_tests, what_happened, is_mistake -> summary, failure_mode",
        instructions="Summarize the run and explain the failure using the failed tests. "
                     "For passes, use 'none' as failure_mode."))

per_task = (per_trial.join(failed_runs, on="task")
    .group_by("task").lm_reduce(
        "task, failed_runs, summary, failure_mode, reward -> common_failures: list[str], what_passing_runs_did_differently"))

overall = per_task.group_by().lm_reduce(
    "task, common_failures -> top_failure_modes: list[str]")

trial_rows, task_rows, overall_rows = tp.collect(per_trial, per_task, overall)
```

`reward` and `failed_tests` have one value per trial, so the per-trial reduce gets each once
rather than once per step. `tp.collect` runs all three tables in one pass and shares the work
they have in common.

## Run it

```bash theme={null}
uv run python examples/failure_modes.py example_harbor_jobs/trials --tasks wal-recovery-ordering gsea-proteomics
```

Add `--replay` to feed the same job in as a simulated stream; the final rows match.

## Next steps

> [card] [Terminal-Bench taxonomies](https://docs.tracepress.ai/pipelines.md)
>
> Label failures with a fixed taxonomy instead.

> [card] [Concepts](https://docs.tracepress.ai/concepts.md)
>
> Drill from a failure mode back to its steps with lineage.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.