← All 96 breakdowns

The step gate: stop your agent's long tasks falling apart

A free one-pager from Adam Rosler. The thing you commented STEPS for: the hook, the settings, and a test template.

The problem in 30 seconds

Every step an agent takes is a bet, and the bets multiply. If each step is right 95% of the time, twenty steps in a row all come out right about 36% of the time (0.95^20 = 0.358). At 98% a step it's still only 67%: a smarter model alone barely moves it.

The best public measurement agrees. METR times AI agents on real software tasks, measured by how long the same task takes a human professional. The length of task frontier models finish half the time has doubled about every seven months since 2019, but the tasks they finish four times out of five are 4-6x shorter (Kwa et al., Measuring AI Ability to Complete Long Software Tasks, arXiv 2503.14499; METR's post). In their words, even models that sometimes succeed on hard tasks "cannot reliably perform tasks of moderate length".

The fix isn't hoping each step gets better. It's catching each miss before the next step builds on it.

What I tested (23 Nov 2026)

A 20-step data task (turn a bank's CSV export into a quarterly report, step01 ... step20, each step feeding the next), run 16 times in Claude Code with the same model (Haiku 5.5), the same ticket and the same data:

Runs All 20 steps matched the bank's figures Final report matched
No checks 8 0 of 8 (every run missed 1-3 steps) 7 of 8
A test after every step (the gate below) 8 8 of 8 8 of 8

With the gate, every run hit at least one failure (step 12 in all eight), saw it straight away, and fixed it before moving on: 13 misses caught and fixed. The misses weren't exotic. One run decided "a tip isn't a person" and skipped a split payment; others kept corrected rows in the wrong order or left the weekend fee off a money-in transport row. A ticket leaves those details open; a test pins them down. Without one, the guess just rides along into every later step.

The three rules

  1. Test every step. One small check per step, with the real expected output. If you can't write the check, the step is too big: split it.
  2. Send a failure straight back. The agent sees the failing check the moment it edits, and fixes that step before it writes the next one. It can't stop while anything fails.
  3. Every N steps, it stops for you. A checkpoint where it summarises what it built and waits for your OK. Short loops: your attention goes where the risk is, not on every keystroke.

The hook (Claude Code, about 5 minutes)

Save gate.py in your project as .claude/gate.py (about 120 lines, standard library plus pytest). Then add this to .claude/settings.json:

{
  "env": { "GATE_CHECKPOINT_EVERY": "10" },
  "hooks": {
    "PostToolUse": [
      { "matcher": "Edit|Write|MultiEdit",
        "hooks": [{ "type": "command", "command": "python3 \"$CLAUDE_PROJECT_DIR/.claude/gate.py\"" }] }
    ],
    "Stop": [
      { "hooks": [{ "type": "command", "command": "python3 \"$CLAUDE_PROJECT_DIR/.claude/gate.py\" --stop" }] }
    ]
  }
}

What it does:

  • After every edit to your steps file, it finds the steps that are written (not still raise NotImplementedError) and runs their checks. A failure exits with code 2, which Claude Code feeds back to the agent with the failing output: "gate: step12 failing its check. Fix it before you write the next step."
  • When the agent tries to finish, it refuses (exit 2) while any step is missing or failing, up to GATE_MAX_REFUSALS times (default 6), then hands over to you instead of looping forever.
  • Every GATE_CHECKPOINT_EVERY passing steps it tells the agent to stop, summarise and wait for your OK, and runs GATE_NOTIFY if you set one (notify-send gate, or a curl to an ntfy topic for your phone).
  • Everything it decides goes to tests/gate.log, so you can see what it caught.

Settings: GATE_TESTS (default tests), GATE_STEPS (20), GATE_CODE (pipeline.py), GATE_CHECKPOINT_EVERY (0 = off), GATE_NOTIFY, GATE_MAX_REFUSALS.

Tested on 23 Nov 2026 in Claude Code 2.1.323: it caught two failures, paused at step 10 ("I've stopped at the project's checkpoint with steps 01-10 written and passing"), resumed on "carry on", and finished 20 of 20.

The test template

One file per step, tests/test_step07.py, with a small input that covers the rule's edge, and the exact expected output:

from pipeline import step07


def test_currency_half_even():
    rows = [{"cents": -150, "currency": " gbp"}, {"cents": 2500, "currency": "CHF"},
            {"cents": 100, "currency": "JPY"}]
    out = step07(rows)
    assert [(r["cents"], r["currency"]) for r in out] == [(-176, "EUR"), (2650, "EUR")]   # JPY dropped

How to write them fast:

  • Use real outputs. Take expected values from the system you're matching (the bank's figures, last month's report, the API's response), not from what the agent produced.
  • One edge per check: the rounding tie, the empty field, the duplicate, the odd format. The edge is where the agent guesses.
  • Keep checks out of the agent's way if you can. In my runs the checks lived outside the project, so the agent saw only what failed, like CI. It's fine if it reads a failing test to learn the rule: that's the point.
  • No step without a check. If a step has no check, it isn't done.

Where it won't help

  • Steps with no checkable output (a vague "make it better"). Split them until each has one.
  • Wrong checks. The gate makes the agent match your tests exactly, so a wrong test gets you a confidently wrong result. Write expected values from the real source.
  • Very long loops without a checkpoint: the gate catches failures, not drift in what you actually wanted. That's what the checkpoint is for.

Sources: Kwa et al., arXiv 2503.14499 v4 (abstract; §3.2.1: "models' 80% time horizons are 4-6x shorter, suggesting that even models that sometimes succeed on difficult and diverse tasks cannot reliably perform tasks of moderate length"); METR, 19 Mar 2025. The test runs, their logs and the scoring are in this reel's demo/ folder.

FREE ONE-TIME UNLOCK

Unlock the full STEPS breakdown

Drop your email once to read the complete step-by-step guide, grab the files, and unlock all 96 Reel breakdowns on this device forever.

✓ Instant reveal right here✓ No spam, unsubscribe any time