Chapter 15 | The 3-Strike Fallback Protocol

4 MIN READ | UPDATED: 2026-05-15

In the last lesson, the Agent demonstrated impressive self-healing capabilities in the traffic light test. However, real-world code is often plagued by dependency errors that are far more agonizing than mathematical range calculations, such as a package that refuses to install or a native C++ binding error at the operating system level.

Without constraints, a headstrong AI can get stuck in a mindless infinite loop of "Fix -> Error -> Repeat the same fix -> Error again". Not only does this deadlock the task, but it also burns through extremely expensive API tokens at an alarming rate!

1. Defensive Layer: Implementing a Circuit Breaker in planning-with-files

Open the workflow in .agents/skills/planning-with-files/SKILL.md that we created in the previous phase. We need to inject the most critical manual fallback rule at the bottom of the file—the 3-Strike limit.

Append the following rule:

## Fallback Protocol: The 3-Strike Error Protocol

**Absolute Rule: Never attempt the exact same fix for the third time when encountering the same error!**

Follow this troubleshooting sequence:

**ATTEMPT 1: Diagnose & Fix**
  → Read the error message, take a deep breath, identify the source of the error, then modify the code and try to run it again.
  
**ATTEMPT 2: Alternative Approach**
  → If you encounter a very similar error again? At this point, you are strictly forbidden from going in circles with the same logic!
  → You must switch to a completely different library, bypass the current framework, or find a workaround. Clearly document the change in your thought process in `progress.md`.

**ATTEMPT 3: Broader Rethink**
  → Failed a second time? This usually indicates it's not a syntax bug, but a system dependency issue or a deep-seated problem.
  → Question the requirements or high-level architectural assumptions. Try again after only patching the outermost configuration.

**AFTER 3 FAILURES: Red Alert, Escalate to User**
  → Once failures accumulate to 3, you must forcibly stop all your self-correction attempts!
  → Summarize your three failed attempts, and write down the error origins and your thought process in `docs/bugs.md` (or a dedicated section in findings).
  → Hand over the terminal response to the human: "Sir, I have attempted 3 different approaches and all have failed. I cannot break through on my own. Please take over, review the logs, and provide new instructions."

2. The Effect and Philosophy

There's a famous saying in big tech development: "Fail fast, fail early."

We aren't afraid of the AI writing incorrect code; we're afraid of it hallucinating and pretending that its code is correct.

With the 3-Strike protocol, you can ensure that if the agent starts drowning in the deep waters of complex business logic (failing 3 times in a row), it will leave behind a highly valuable "troubleshooting post-mortem report." When you (the officer) take over, you can read this report and, in just 30 seconds, point out, "Oh, it failed to compile because there's no Python environment on this machine." Then, the agent can get back to work.

This creates an incredibly resilient team structure!

Now that we've established this cognitive failsafe, in the next episode, we will start teaching the Agent the core principle of large-scale backend development: how to mock third-party APIs without making real requests.