Method · Doc

The Ralph Loop

Ralph Loop — in depth

"I'm in danger 😄" — Ralph Wiggum

The Ralph Loop is the self-correction cycle that operates inside DARE's Execute phase. It ensures tasks are only considered complete once they pass all the defined Validation Gates.

🎬 The metaphor

Ralph Wiggum, from The Simpsons, has that iconic scene: the house on fire, him holding a flower, smiling, saying "I'm in danger 😄". Persistent, innocent, and curiously effective — in the end, the story always works itself out.

An AI running code for the first time has exactly that vibe:

The joke (and the name) acknowledges this pattern. The Ralph Loop is about embracing persistent iteration as a feature, not a bug.

🔁 The algorithm

┌──────────────────────────────────────────────────────┐
│                                                      │
│  1. AI reads task-NNN.md                             │
│             ↓                                        │
│  2. AI implements the code                           │
│             ↓                                        │
│  3. AI runs Validation Gates                         │
│       ├─ Unit tests                                  │
│       ├─ Integration tests                           │
│       ├─ Linter / formatter                          │
│       ├─ Type checker                                │
│       └─ Others (defined in the task)                │
│             ↓                                        │
│  4. Result?                                          │
│       ├─ ✓ ALL PASSED → Task complete               │
│       └─ ✗ SOMETHING FAILED → Continue              │
│             ↓                                        │
│  5. AI reads the error message                       │
│             ↓                                        │
│  6. AI identifies what to fix                        │
│             ↓                                        │
│  7. AI applies the fix                               │
│             ↓                                        │
│  8. Back to step 3                                   │
│                                                      │
└──────────────────────────────────────────────────────┘
                       ⟲ Ralph Loop

⏱️ How many iterations are "normal"?

From practice observed at Dewtech:

Iterations Frequency Signal
1 (passed first try) ~30% simple or well-specified task
2-3 ~50% normal — AI caught a typing error, import, edge case
4-6 ~15% task was ambiguous or Validation Gates incomplete
7+ ~5% ESCALATE — probably an architectural problem, go back to the Blueprint

Canonical rule (v3.2+): the ceiling and the saturation of repeated failures are decided
deterministically by packages/cli/src/verification/decay/policy.ts (decideNextAction), not by
a fixed cap contradicting this doc. The agent consumes the LoopVerdict (CONTINUE, FRESH_START,
REPLAN, ESCALATE, DONE) emitted by the CLI after each attempt.

🎯 Validation Gates — what makes it all possible

The Ralph Loop only works because the task carries objective gates. The AI doesn't need to "guess" whether things are good — it has commands to run. Examples by stack:

Node.js / TypeScript

npm test                # vitest / jest
npm run lint            # eslint
npm run typecheck       # tsc --noEmit
npm run format:check    # prettier

Python

pytest -xvs             # tests
ruff check .            # lint
ruff format --check .   # format check
mypy .                  # type checker

PHP / Laravel

php artisan test        # phpunit
./vendor/bin/pint --test  # format check
./vendor/bin/phpstan analyse  # static analysis

Go

go test ./...           # tests
go vet ./...            # static analysis
golangci-lint run       # full lint

Rust

cargo test              # tests
cargo clippy -- -D warnings  # strict lint
cargo fmt --check       # format check

The task-NNN.md always lists the exact command + expected result ("exit 0", "0 errors").

🚦 When the Ralph Loop should stop

Auto-stop situations

Criterion Reason
All gates passed ✓ task complete
Same error repeats 3+ times in a row semantic deadlock — a human needs to step in
Attempt #7 without passing probably a problem in the BLUEPRINT
AI detects ambiguity in the spec better to pause than to guess

What to do when stopping without success

  1. Read the logs of the attempts (some implementations record them in DARE/EXECUTION/<task>/attempts/)
  2. Cross-check against the BLUEPRINT.md
  3. Decide: fix the task spec, refine a Validation Gate, or go back to Architect

🧠 Why it works

Research and practice show that AI agents are much better at tactical iteration than at strategic planning. The Ralph Loop acknowledges this:

It's design aligned with the current nature of the models.

📚 Origin of the concept

The term "Ralph Loop" isn't a Dewtech invention — it's an emerging community usage in 2025-2026 to describe this pattern. Dewtech adopts and formalizes it within DARE.

External references

🔗 Related topics