βΎ Anti-Pattern: Infinite Loop Without an Exit Condition
The costliest mistake in loop engineering: starting a loop without defining when it should stop. The agent keeps running, spending tokens, without converging on any result. It is the equivalent of a while(true) without break.
π¨ Symptoms
- βToken costs spiking with no visible output
- βAgent repeats the same actions in successive cycles
- βplan.md has no tasks marked as complete
- βNo /goal or max iterations defined
β Fix
# SEMPRE combine /goal + max iterations
/goal All tasks in plan.md are checked off
/loop --max-iterations 15 work through plan.md one task at a time
# Para multi-agent: max rounds no orchestrator
"Maximum 5 rounds. If spec is not satisfied after 5 rounds, stop and report what's missing."
π₯ Anti-Pattern: Context Window Overflow
Looping in the same agent session accumulates context with each cycle. After several iterations, the LLM becomes overloaded: responses degrade, instructions are ignored, and the agent starts hallucinating.
"If you leave it looping for a while, your LLMβs context gets huge, and it gets overloaded. Thatβs why we need a system that distributes the work across different coding agent sessions."
π¨ Symptoms
- βResponse quality degrades after 5-10 iterations
- βAgent "forgets" instructions from the start of the session
- βAnswers become repetitive or contradictory
- βHallucination errors in file and function names
β Fix
- βExternal state: record progress in a database (Postgres), not in the context window
- βSeparate sessions: each worker in its own agent session
- βContext trimming: keep only the current state in the prompt, not the complete history
- βCompact/resume: use resumable sessions with context compaction
π¨ Anti-Pattern: Port Conflicts in Parallel Sessions
When multiple workers run dev servers or tests that use network ports, they all try to use port 3000 (or 5173, 8080, etc.). The first one works; the others fail silently.
"A lot of different things, like port conflicts, which we also want to resolve."
β Fix
# Alocar porta dinamica por worker
export PORT=$((3000 + WORKER_ID))
# Ou usar porta 0 (sistema aloca automaticamente)
node server.js --port 0
# No prompt do worker: instrua a usar porta unica
"Use port {{3000 + worker_index}} for any dev server. Do NOT use port 3000."
π£ Anti-Pattern: Workers Stepping on Each Otherβs Toes
Without proper isolation, workers edit the same files, create merge conflicts, and overwrite one another's work. This problem has two dimensions: code and data.
β No Isolation
- βAll workers in the same checkout
- βSame database for everyone
- βConstant merge conflicts
- βMigrations breaking other workers
β With Isolation
- βGit worktree per worker
- βNeon branch per worker
- βMerge only after validation
- βEach worker operates within a defined scope
π Debugging with Dashboard Logs
Observability is key to diagnosing problems in loops. Without it, you're in the dark. Cole Medin built an open source dashboard exactly for this: to see orchestrator decisions, worker progress, and accumulated cost in real time.
"I have a lot of observability built into this dashboard. Being able to see exactly what decisions are being made here makes it easy to analyze everything, even ask my coding agent to analyze the runs in the database, and then figure out how to improve the loop."
π What to Monitor
Orchestrator decisions
Which workers were dispatched, with which prompts, in which round
Tokens per round
Accumulated cost to identify inefficient rounds
Worker statuses
Which ones completed, which ones failed, execution time
Validation results
Did the tests pass? Were the spec criteria met?
β Checklist: Ready to Loop
Before starting any loop, go through this checklist. Each item is a prerequisite that helps avoid the anti-patterns discussed in this module. Click the items to check them off as you verify them.
π Pre-Flight Checklist
Exit Conditions
State and Durability
Isolation
Budget and Cost
Observability
Human-in-the-Loop
Mark all applicable items before starting the loop.
π― Reflection Point
Cole Medin sums it up: "I really do want to incorporate loop engineering. I like the concept of it, and I want to drive how autonomous my coding agents can be, but you got to have the right system. Otherwise, things are going to completely fall apart." The checklist exists to make sure the system is correct before letting the agent run.
π Module Summary
Track 4 Conclusion
You've gone from the simple loop (plan.md) to the multi-agent orchestrator, and now you know what can go wrong and how to prevent it. The next step is yours: build your first loop, start simple, and evolve as needed.