← All patterns

Loop Until Dry

Codebase Review

The Problem

Discovery tasks — finding bugs, security issues, missing tests — have an unknown search space. A fixed number of passes will either under-cover (miss things) or over-cover (waste compute). You need a stopping condition based on results, not on an arbitrary count.

The Pattern

┌─────────────────────────────┐
│  seen = {}                  │
│  dry_rounds = 0             │
└─────────────┬───────────────┘
              │
              ▼
        ┌──────────┐
        │  Finder  │  (discovery agent)
        └────┬─────┘
             │
      ┌──────┴──────┐
      ▼             ▼
  New items?    Nothing new
      │             │
      ▼             ▼
  Add to seen   dry_rounds++
  dry_rounds=0      │
      │         dry_rounds == N?
      │             │
      └──────┬──────┘
             │ No: loop back
             │ Yes: stop
             ▼
           Done

When to Use

When NOT to Use

Code Example

import { QueueAI } from "@queueai/sdk"

const queue = new QueueAI({ apiKey: process.env.QUEUEAI_API_KEY })

const task = await queue.submit({
  name: "codebase-review",
  input: {
    repoUrl: "https://github.com/your-org/your-repo",
    strategy: "loop-until-dry",
    dryRoundsToStop: 2,
  },
  model: { primary: "anthropic/claude-sonnet-4-6" },
  budget: { maxCostUsd: 3.00 },
  retries: 2,
})
from queueai import QueueAI

queue = QueueAI(api_key=os.environ["QUEUEAI_API_KEY"])

task = queue.submit(
    name="codebase-review",
    input={
        "repo_url": "https://github.com/your-org/your-repo",
        "strategy": "loop-until-dry",
        "dry_rounds_to_stop": 2,
    },
    model={"primary": "anthropic/claude-sonnet-4-6"},
    budget={"max_cost_usd": 3.00},
    retries=2,
)

See it in action: This pattern powers the Codebase Review template in QueueAI.