{"slug": "the-physical-laws-of-ai-migrations-architecting-an-llm-orchestrator-that-reality", "title": "The Physical Laws of AI Migrations: Architecting an LLM Orchestrator that Survives Reality", "summary": "A developer architecting an LLM orchestrator for large codebase migrations discovered that naive implementations fail under real-world load due to race conditions, Git lock collisions, and resource exhaustion. By applying distributed systems principles—such as using an append-only ledger for state, isolated Git worktrees for parallelism, and bounded retry loops—the orchestrator can survive reality and complete migrations without blocking concurrent development.", "body_md": "Large codebase migrations are not typing problems; they are distributed state machine problems.\n\nWhen you attempt to execute a multi-step, multi-PR refactor using an LLM—such as the workflows I proposed in this [migration-orchestration-skill](https://github.com/mhosseinab/skills/blob/master/migration-orchestration/SKILL.md)—you are not just writing code. You are instantiating a distributed system. Your orchestrator is the control plane, your LLM subagents are asynchronous worker nodes, and the local repository is your shared database.\n\nMost AI workflow documentation assumes a \"happy path\" where agents neatly read instructions, edit files, and check off a Markdown list. This is whiteboard architecture at its most naive. In reality, agents hallucinate, Git locks up, test suites hang, and state files corrupt. To build an orchestrator that actually finishes a migration, we must align our architecture with the mechanical realities of the environment.\n\nThe core business requirement is to safely sequence, verify, and commit a massive architectural change (e.g., migrating a monolith to partitioned micro-databases or rewriting React classes to hooks) without blocking concurrent human feature development.\n\nThe fundamental distributed systems headache? You are coordinating asynchronous, non-deterministic compute nodes (LLM agents) attempting concurrent mutations against a rigidly sequential, locally-locked state store (the local filesystem and Git). If you don't engineer strict boundaries, the result is corrupted code, blown context windows, and thousands of dollars in wasted API tokens.\n\nThe standard MVP implementation breaks the migration into discrete steps (`S1..Sn`\n\n), defines a dependency graph, and instructs an orchestrator to spawn concurrent subagents for any steps that touch \"disjoint files.\" The state of the migration is tracked by having agents read and update a human-readable `<slug>-progress.md`\n\nfile. When an agent fails a test suite, it enters a `worker → reviewer → fix`\n\nloop until the tests pass.\n\nUnder real-world load, this implodes almost immediately:\n\n`progress.md`\n\nfile, wiping out each other's status updates.`npm install`\n\nor `cargo build`\n\nin parallel. They exhaust I/O, thrash memory, and crash the local machine.`.git/index.lock`\n\ncollisions, causing unhandled fatal errors that halt the orchestrator entirely.To fix this, we must deconstruct the pipeline and apply mechanical sympathy to every failure domain.\n\n`<slug>-progress.md`\n\n) as a concurrent data store. It guarantees race conditions, phantom reads, and lost updates when multiple agents edit the file.`Ctrl+C`\n\n), the lock is never released. The migration is permanently deadlocked.`{\"step\": \"S2\", \"status\": \"passed\", \"sha\": \"abc1234\", \"timestamp\": 1719154980}`\n\n.\nThe Markdown file is strictly a materialized, read-only projection generated by the orchestrator for human consumption. If an agent's expected prior state doesn't match the latest ledger sequence, the append is rejected, and the agent must reconcile.`auth.ts`\n\n, Agent B edits `db.ts`\n\n) prevents conflicts.`git add`\n\nand `git commit`\n\n.`git worktree add ../S2-branch`\n\n) for every concurrent step. This gives each agent a completely isolated index, working directory, and execution environment. Parallelism is no longer an illusion; it is mechanically enforced by OS-level filesystem boundaries.`worker → reviewer → fix`\n\nloop assumes that every code problem is solvable if the LLM just tries hard enough. It acts as an unbound `while(true)`\n\nloop.`max_attempts=3`\n\n). If the agent fails, it marks the step as `blocked`\n\n.`in_progress`\n\n. Because downstream steps in the DAG depend on this node, the system indefinitely buffers out-of-order sequences waiting for the missing tail. This is a classic zombie state.`expires_at: 1719155980`\n\n). If the orchestrator detects an expired lease, the step is violently revoked, marked as a Poison Pill, and sent to the DLQ. The orchestrator halts execution of dependent nodes and pages the human operator. A strict dependency chain cannot skip broken links; it must halt safely and predictably.Drawing dependency boxes on a whiteboard is easy. Executing them reliably against physical constraints is Staff-level engineering.\n\nAn LLM orchestration framework is not exempt from the physical laws of distributed systems. File lock contention, out-of-order execution, unparseable ASTs, and process crashes are guaranteed. If you rely on \"happy path\" prompts to sequence a codebase migration, your system will fail. But if you design your AI pipeline with immutable ledgers, isolated execution environments, and strict TTL bounds, you graduate from writing fragile prompt chains to operating a resilient, production-grade migration machine. Real engineering is found in how your system handles failure, not how it behaves when everything goes right.", "url": "https://wpnews.pro/news/the-physical-laws-of-ai-migrations-architecting-an-llm-orchestrator-that-reality", "canonical_source": "https://dev.to/_mh/the-physical-laws-of-ai-migrations-architecting-an-llm-orchestrator-that-survives-reality-5co8", "published_at": "2026-06-24 05:11:00+00:00", "updated_at": "2026-06-24 05:13:14.114895+00:00", "lang": "en", "topics": ["large-language-models", "developer-tools", "ai-agents"], "entities": ["LLM", "Git", "DLQ"], "alternates": {"html": "https://wpnews.pro/news/the-physical-laws-of-ai-migrations-architecting-an-llm-orchestrator-that-reality", "markdown": "https://wpnews.pro/news/the-physical-laws-of-ai-migrations-architecting-an-llm-orchestrator-that-reality.md", "text": "https://wpnews.pro/news/the-physical-laws-of-ai-migrations-architecting-an-llm-orchestrator-that-reality.txt", "jsonld": "https://wpnews.pro/news/the-physical-laws-of-ai-migrations-architecting-an-llm-orchestrator-that-reality.jsonld"}}