Level 4: You Write the Specs
PLLevel 4 of the autonomy ladder is the stage where a developer authors the specification, a protected test oracle, and a machine-checkable stop condition, allowing an agent to run unattended for hours while the human judges the result on evidence rather than reading every diff. Level 4 holds only while the run cannot edit the checks defining done.
You launch a large migration at six in the evening. At eight the next morning, the agent reports “all tests pass”—and one of those green tests is the assertion it loosened at three in the morning. This guide gives developers moving past Level 3 the four pre-run artifacts and hook invariants that prevent that failure, and gives tech leads and CTOs the exact four metrics that prove Level 4 is real.
Are you at Level 4? The four-point test
Section titled “Are you at Level 4? The four-point test”Dan Shapiro (The Five Levels, 23 January 2026) sums up Level 4 plainly: write a spec, “leave for 12 hours, and check to see if the tests pass.” A loop operates at Level 4 when all four conditions hold:
- You author specs and finish lines rather than implementation code. Your primary output is clear intent and acceptance criteria.
- Runs outlast live supervision. The agent iterates across turns without interactive babysitting.
- Deterministic checks decide completion. Tests, type checks, linters, and domain validators—never the agent’s prose summary—prove done.
- The oracle is outside the agent’s write reach. Test suites, CI workflows, and hook scripts cannot be weakened silently by the same run.
If item 4 fails, the agent grades its own homework—leaving you at Level 3 with the reviewer removed.
Four artifacts required before starting a Level 4 run
Section titled “Four artifacts required before starting a Level 4 run”Write these four artifacts in strict sequence before letting an agent run unattended:
- Authoritative spec (
spec.md). States target behavior, constraints, non-goals, and edge cases in one file the run reads (spec-driven development, acceptance criteria). - Reviewed plan. Drafted by the agent in read-only plan mode and verified by you upfront. Catching a flawed design on a one-page plan saves hours of compute and review.
- Independent oracle. Failing acceptance tests, contract checks, and static rules written or reviewed before implementation. At Level 4, test-driven development is about provenance: a test written before the run cannot be engineered after the fact to fit buggy code (oracle strength).
- Bounded stop condition. Explicit shell commands that must exit 0, forbidden paths, a structured checkpoint log, and a hard retry or turn cap. Stripe’s production Minions enforce a strict ceiling of at most two rounds of CI before escalating back to a human (Stripe engineering blog, 9 February 2026).
Deterministic Stop hooks and tool-level loop controls
Section titled “Deterministic Stop hooks and tool-level loop controls”A model evaluating its own finish line can mistake a plausible narrative for a passing suite. Deterministic lifecycle hooks close that gap by executing real shell checks whenever the agent attempts to stop:
| Tool | Goal & loop control | Deterministic guardrail | Official docs |
|---|---|---|---|
| Claude Code | Goal-directed runs & headless mode | Lifecycle hooks (PreToolUse, PostToolUse, Stop, plus org-enforced managed hooks). Check stop_hook_active inside Stop hooks to prevent infinite continuation loops, and block test-path edits with PreToolUse | Claude Code docs |
| Codex | Goal-directed runs, worktrees, and cloud environments | Separate sandbox_mode (workspace-write / read-only) from approval_policy (on-request, never, granular; note legacy untrusted was retired) alongside Stop hooks and admin requirements.toml | OpenAI Codex docs |
| Cursor | Plan Mode, Cloud/Background Agents, and automations | Hooks observing or blocking agent stages, .cursor/rules/*.mdc, plus Bugbot with .cursor/BUGBOT.md on the pull request | Cursor docs |
Keep the core Stop-hook invariant identical across tools:
- Record the starting commit SHA before launching the long run.
- When the agent tries to finish, check the recursion guard (e.g.,
stop_hook_activein Claude Code) and a retry counter so the loop always terminates cleanly on hard blockers. - Fail closed if
git diffagainst the starting commit touched any protected test, snapshot, hook, or CI path. - Execute the repository’s unified test, typecheck, and lint command directly and return failing stderr to the agent only when exit status is non-zero.
Because repository-local hook configs can still be modified by a compromised or misconfigured session, always duplicate oracle-integrity and test checks in CI outside the agent’s write scope (agent hooks, protecting the oracle).
The morning verification protocol
Section titled “The morning verification protocol”Never review a twelve-hour run by scrolling through 2,000 lines of diff. Verify six artifacts in order:
- Re-run the oracle independently in CI or locally—never trust the agent’s transcript alone.
- Confirm oracle integrity: verify zero unapproved changes to tests, snapshots, fixtures, hooks, or CI workflows since the run’s base commit.
- Compare the spec delta against
spec.mdto confirm every acceptance criterion maps to an executed test and no unrequested behavior crept in. - Inspect turning points in the run log. Long autonomous trajectories decay structurally: SlopCodeBench (Orlanski et al., arXiv, 25 March 2026) evaluated 15 agents across 196 checkpoints and found no agent solved any problem end to end, with the best passing 14.8% amid compounding structural erosion. Repeated failed retries signal a broken design that needs splitting.
- Read source code strictly for escalation classes (auth, billing, schemas, data migrations, and uncovered paths) as defined in reading evidence instead of code.
- Sign off on the evidence bundle or return with a tighter spec.
Four metrics leaders track at Level 4
Section titled “Four metrics leaders track at Level 4”Run npx @wondelai/harness-audit (Harness Audit) to verify repository station readiness, and track four operational metrics per change class:
| Metric | Definition | Warning signal |
|---|---|---|
| Run acceptance rate | Unattended runs merging without rework divided by total runs started | Drops as run duration grows |
| Oracle-edit rate | Runs whose diff modified tests, CI, or hooks without explicit spec approval | Any non-zero trend—demote immediately |
| Escaped defects per class | Production bugs traced to evidence-approved merges | Sends that class back to Level 3 |
| Budget overrun rate | Runs hitting turn or retry limits before satisfying the stop condition | Vague specs or unreachable stop conditions |
Six ways an unattended Level 4 run fails while reporting green
Section titled “Six ways an unattended Level 4 run fails while reporting green”- Silent oracle edits. Tests pass because assertions were weakened. Recovery: revert test edits, enforce
CODEOWNERSandPreToolUse/CI path blocks on test and CI directories. - Unexecuted claims. The agent summarizes passing checks without running the final command. Recovery: require deterministic
Stophooks and mandatory CI runs before review. - Thrashing and architectural drift. The run log repeats the same failed patch three ways. Recovery: reset to the last clean checkpoint, narrow the spec, and provide one concrete existing module as a reference pattern.
- Unbounded loops burning budget. A vague stop condition exhausts turns. Recovery: prove the check passes on a minimal manual baseline first and enforce strict turn/CI round bounds.
- Hooks silently bypassed. Unverified folders or disabled hook configs skip local gates. Recovery: treat local hooks as fast feedback and CI workflows pinned to the default branch as the authoritative gate.
- Green checks with broken user behavior. The oracle is too weak for that risk class. Recovery: add a failing regression test, strengthen mutation/behavior coverage, and return the class to code review until the upgraded checks catch real faults.
When a change class is ready for Level 5
Section titled “When a change class is ready for Level 5”A class earns promotion toward Level 5 only when unattended runs sustain high acceptance rates, oracle-edit rate sits at zero, escaped defects stay flat, and every finished run feeds lessons back into rules, skills, or fitness functions. Intent, taste, and escalation paths always remain the human’s job.
Next steps
Section titled “Next steps”Did this guide help you?
One tap, no sign-in.
What will you do with it?
How did it read?
What got in the way? Pick any that apply
Your role?
Thanks. I read every answer. Michał Jaskólski
Did this guide help?
One tap each. Close whenever you like.
no sign-in
Frequently asked questions
What is Level 4 on the autonomy ladder?
Level 4 is the stage where a developer writes the specification, a protected test oracle, and a machine-checkable stop condition, letting the agent iterate unattended for hours before verifying the result through evidence instead of reading every diff. Dan Shapiro describes it as writing a spec, leaving for 12 hours, and checking whether the tests pass.
Why is a model-judged goal condition not enough on its own?
An LLM evaluator judges what appears in the conversation transcript rather than independently verifying disk state or oracle integrity. Pairing goal-directed runs with deterministic Stop hooks and CI checks outside the agent's write reach ensures the actual test suite ran and passed unmodified.
What fails most often in multi-hour autonomous runs?
Oracle tampering and gradual structural drift. An agent left unconstrained can weaken assertions, skip suites, or erode architecture across long retries (as measured in SlopCodeBench, March 2026). Lock test paths with hooks and CODEOWNERS, bound retries, and verify independently in CI.
Primary sources & references
- Dan Shapiro — The Five Levels of AI Coding (January 2026) https://www.danshapiro.com/blog/2026/01/the-five-levels-from-spicy-autocomplete-to-the-software-factory/
- Stripe — Minions: One-Shot End-to-End Coding Agents (February 2026) https://stripe.dev/blog/minions-stripes-one-shot-end-to-end-coding-agents-part-2
- Orlanski et al. — SlopCodeBench (March 2026) https://arxiv.org/abs/2603.24755