> Agent-ready spec from Diff of the Day (2026-11-28, idea 3). Give this file to your coding agent (Claude Code, Codex, Cursor) and ask it to build the P0 requirements first.

# Spec: Small decision model for CI failure triage

## Problem Statement
Many teams call a large LLM for every CI failure just to decide a label such as flaky, infra or real bug. Michelle Chen of Cloudflare showed at the AI Engineer Code Summit (Nov 2026) that a small model trained on past decisions can make these calls with fewer requests and tokens. A small team can test this on its own CI history in a weekend.

## Goals
- A classifier that labels a CI failure as flaky, infrastructure or code from its log, trained on your past failures.
- At least 85% agreement with human labels on a held-out set.
- A side-by-side table of accuracy, latency and cost against an LLM prompt on the same set.

## Non-Goals
- Fixing failures: labelling only.
- A general model for every repo: one repo's history.
- Replacing the LLM everywhere: the LLM stays for cases the small model is unsure about.

## User Stories
- As a developer on a busy repo, I want each failed CI run labelled so that I skip flaky ones quickly.
- As a developer, I want low-confidence cases sent to the LLM so that hard cases still get a good answer.
- As a team lead, I want a cost and accuracy table so that I can decide whether to keep it.
- Edge case: as a developer, I want logs over the size limit cut to the failing step so that the model sees the relevant part.

## Requirements
### P0 (must have)
1. **Dataset**: export 200 or more past failed runs with their logs; label each by hand or from existing reruns and fixes.
   - [ ] Split 80/20 into training and held-out sets, stratified by label.
2. **Small model**: a classifier on log features (for example TF-IDF plus logistic regression, or a small fine-tuned encoder).
   - [ ] Reports accuracy and a confusion matrix on the held-out set.
3. **LLM baseline**: the same held-out set through one prompt to an LLM of your choice.
4. **Results table** `results.md`: accuracy, median latency, tokens and requests for both.

### P1 (nice to have)
- Confidence threshold: below it, fall back to the LLM; report the combined accuracy and cost.
- A CI step that posts the label on the failed run.

### P2 (future)
- Retrain monthly on new labelled failures.

## Success Metrics
- Leading: held-out accuracy of 85% or more.
- Lagging: after a month in CI, fewer LLM calls per failure and no rise in missed real bugs.

## Open Questions
- Where do the labels come from in your history? (you)
- Which LLM is the baseline? (you)

## Timeline
A weekend: day one for data and model, day two for baseline, table and P1.

## Agent Instructions
- **Suggested stack**: Python 3.12, scikit-learn first; a small transformer only if the simple model falls short.
- **Build order**: data export script → labelling helper → split → small model with tests → LLM baseline → results table.
- **Safety**: strip secrets and tokens from logs before training; keep API keys in environment variables.
- **Done when**: results.md compares both approaches on the same held-out set.

## Sources
- Michelle Chen (Cloudflare) at AI Engineer Code Summit, via AI.Engineer on X: https://x.com/aiDotEngineer/status/2126315113565097985
