Loop Until Dry
Codebase ReviewThe 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
- Open-ended discovery where you don't know how many items exist
- Bug hunting, issue scanning, dead code detection
- Any task where "done" means "nothing new found for K rounds"
When NOT to Use
- Tasks with a well-defined, finite scope (use a simple loop with a count)
- When running cost could spiral — always pair with a budget cap
- Real-time tasks where convergence time is unpredictable
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.