|

Agentic Orchestration Part 4: SemVer Nuances and Self-Correction

In Part 3, we watched our major-upgrader agent read documentation and rewrite application code. But AI models are not infallible. What happens when the migration guide is incomplete, or the codebase is too complex for the agent to resolve a test failure?

We must program failure handling and self-correction directly into the Orchestrator.

The “Three Strikes” Rule

When the major-upgrader runs the validation gate (test -> format -> lint -> build), a failure doesn’t crash the pipeline. Instead, it triggers a self-correction loop.

The agent reads the compiler or test output, searches the migration guide again, and attempts to fix the code. However, left unchecked, an LLM might try to fix a complex TypeScript error 50 times in a row, hallucinating increasingly absurd solutions and burning through API tokens.

To prevent this, our agent instructions enforce a strict three strikes rule:

If any fails:
1. Read the full error output.
2. Cross-reference migration guide for missed breaking changes.
3. Fix and re-run all four commands.
4. Up to **three fix attempts**.
5. After three failures: run `git reset --hard HEAD && pnpm install`, document the blocker, mark group BLOCKED, and move to next group.

If the agent fails to resolve the issue after three attempts, it acknowledges defeat. It triggers the Rollback Protocol. By resetting the branch and reinstalling the old dependencies, the repository returns to a clean state. The agent then logs the blocker in its summary report and gracefully moves on to the next upgrade group.

Dependency Overrides

Another common failure mode is transitive dependency issues. Suppose pnpm install fails because a sub-dependency enforces a strict peer requirement that conflicts with the new major version.

Instead of giving up, our major-upgrader is authorized to surgically edit the package.json to inject pnpm.overrides:

{
  "pnpm": {
    "overrides": {
      "obscure-utils": "1.2.3"
    }
  }
}

By forcefully pinning problematic transitive dependencies, the agent bypasses ecosystem conflicts. When the agent hands off the branch to the pr-creator, the PR description explicitly highlights that a manual override was applied, ensuring a human engineer reviews the decision.

The Final Report

At the end of the major-upgrade pipeline, the orchestrator outputs a Final Report that clearly outlines what succeeded and what was blocked:

## Completed
| Group | Packages | Before | After | PR |
|-------|----------|--------|-------|----|
| @nestjs/* | 8 | v10 | v11 | #44 |

## Blocked / Needs Manual Intervention
| Group | Blocker |
|-------|---------|
| eslint | 200+ rule violations; requires ESLint config rewrite. Agent failed after 3 attempts. |

This ensures zero silent failures. In the final part of our series, Part 5, we will explore how we execute these workflows safely inside Docker Sandbox MicroVMs to achieve true “YOLO Mode” autonomy.

Keep pushing forward and savor every step of your coding journey.