Foundry

Blog

How to Keep Your AI Coding Agent on Track (and Stop It Undoing Fixes)

How to stop your AI agent forgetting decisions, breaking things it already fixed and drifting off task, and how to check its fixes work.

Josh Bradford

3 min read


AI coding agents bring back bugs you already fixed, drift away from what you agreed on, and sometimes say a bug is fixed when nothing changed.

Most of that comes from memory. The agent starts every session blank, so the rules and the checking have to come from you.

Write decisions down where the agent will read them#

Anything decided in chat is gone next session. Keep a decisions file in your project and point your agent's context file at it.

Markdown
## Decisions
- Enemies respawn only when the player leaves the room. Do not change.
- Retry logic: 3 attempts, 2s apart. Tested, do not refactor.
- Save format is v2. Never change field names.
## Not doing
- No multiplayer.
- No inventory weight system.

The "Not doing" list matters as much as the decisions. It's how you stop the agent from steering the project somewhere you didn't want.

Protect what already works with tests#

The most reliable way to stop an agent from undoing a fix is a test that fails when the fix breaks.

Even a few tests on the stuff that keeps breaking helps a lot.

Make it prove the fix#

Don't take "fixed" at face value. Ask for evidence:

If it can't explain the cause, it probably guessed. And an agent reading back its own code doesn't count as verifying the fix.

Keep tasks small and specific#

Big vague tasks are where drift happens. "Clean up the code" gives the agent permission to change anything, including the parts you just got working. Compare:

Saying what not to change is as important as saying what to change.

Use git like a save point#

Commit every time something works. Then:

Start fresh when it gets confused#

Long sessions get worse over time. The agent is juggling too much and starts mixing things up. When it starts contradicting itself or repeating mistakes, stop, write down where things stand, and start a new session with that summary.

A simple routine that works#

  1. Start a session with one specific task.
  2. Agent reads the context and decisions files.
  3. Agent writes a short plan. You approve or fix it.
  4. Agent makes the change, writes or updates a test, runs everything.
  5. You read the diff and check it yourself.
  6. Commit.
  7. Update the decisions file if anything new was decided.

It adds a couple of minutes per task. That's still faster than fixing the same regressions over and over.

Comments

Loading comments