PTENES
MODULE 4.4

⚠ Anti-Patterns and Troubleshooting

The most common mistakes in loop engineering, how to diagnose them, and an interactive "ready to loop" checklist to review before launching any system.

6
Topics
25
Minutes
Ref.
Level
Guide
Type
1

β™Ύ 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."
2

πŸ’₯ 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."
-- Cole Medin

🚨 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
3

🚨 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."
-- Cole Medin

βœ… 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."
4

πŸ‘£ 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
5

πŸ” 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."
-- Cole Medin

πŸ“Š What to Monitor

1

Orchestrator decisions

Which workers were dispatched, with which prompts, in which round

2

Tokens per round

Accumulated cost to identify inefficient rounds

3

Worker statuses

Which ones completed, which ones failed, execution time

4

Validation results

Did the tests pass? Were the spec criteria met?

6

βœ… 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

βœ—
Infinite loop -- always define exit conditions + max iterations
βœ—
Context overflow -- use external state and separate sessions
βœ—
Port conflicts -- assign unique ports to each worker
βœ—
Workers without isolation -- worktrees + database branches
βœ“
Ready to Loop checklist -- 15 checks before launching

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.