Resolved

Recovering from a failed migration that deleted critical application code

Migration
Disaster Recovery
DevOps
Version Control
CI/CD
Kubernetes
Python

During a framework migration, the entire source code directory was accidentally deleted without replacement, breaking the build pipeline. The solution involved restoring the codebase, fixing deployment issues, and implementing safeguards for future migrations.

During a framework migration from an older version (e.g., Fast-Agent 0.3.15) to a new system (e.g., FastMCP 2.0), the entire source code directory was unexpectedly deleted without functional replacements. This resulted in a completely broken build pipeline, preventing further development and deployment. The incident highlights the importance of safeguards during migrations, especially in Kubernetes-based deployments.

Issue

The migration process accidentally deleted the entire source code directory (k3s/api/) containing critical files, including:

  • Docker configuration (Dockerfile)
  • Dependency management (requirements.txt)
  • Core application logic (main.py, worker scripts)
  • Configuration files (e.g., fastagent.config.yaml)

This deletion led to:

  • A broken build pipeline due to missing Dockerfile and dependencies.
  • An empty source directory, preventing any deployment.
  • Broken Kubernetes manifests with unresolved environment variable references.
  • Failed deployment scripts due to missing context configurations.

Culprit

The root cause was a flawed migration strategy that:

  1. Deleted before creating: Removed all source files without ensuring replacements were ready.
  2. Committed non-functional state: Migration commits contained only documentation, TODO lists, and architecture plans—no working code.
  3. Lack of parallel implementation: No feature flags or gradual rollout strategy was implemented.
  4. Missing pre-deletion validation: No verification that new code existed or that the build pipeline would pass.

Solution

Codebase Restoration

  1. Reverted to a known working state using Git history to restore the deleted directory:
    git checkout HEAD -- k3s/api/
    This recovered all critical components, including the Dockerfile, dependencies, and application logic.

Deployment Fixes

  1. Fixed Kubernetes Context Issues: Added explicit context flags to deployment scripts to ensure correct cluster targeting.
  2. Simplified Configuration: Consolidated environment variables using Kubernetes ConfigMaps to reduce complexity and errors.

Migration Safeguards

To prevent future incidents, the following measures were implemented:

  1. Parallel Implementation: New code must coexist with legacy code during transitions.
  2. Feature Flagging: Runtime switching between implementations to allow gradual testing.
  3. Traffic Splitting: Domain-based or percentage-based rollout to compare metrics.

Verification Process

A pre-deletion checklist was established to ensure:

  • The build pipeline passes.
  • All tests execute successfully.
  • The cluster remains healthy before any file deletions.

This solution restored functionality while providing a safer framework for future migrations, including:

  • Automated verification gates.
  • Backup systems for critical components.
  • Gradual rollout mechanisms to minimize risk.