← Work

Long-Running Coding Agents: A 6,000-Line Migration

Completed a 6,000-line Python-to-TypeScript migration with an AI coding agent by treating the model as a stateless executor and myself as the planner - using an external progress file to hold state across sessions.

Role
Planner & architect (human-in-the-loop); AI agent as executor
Date
June 19, 2025
Stack
Python · TypeScript · Claude Code CLI · Claude Sonnet 4

Summary

A large Python-to-TypeScript migration (~6,000 lines) completed with an AI coding agent without losing coherence or introducing regressions across multiple sessions. The core pattern: treat the model as a stateless executor and the human as the high-level planner, and keep the plan in an external progress file the agent re-reads each session.

The problem

Capable coding models still degrade on long-running, multi-session work. Three failure modes recur:

  • Lost-in-the-middle: details buried in a long context stop influencing the model’s output.
  • Plan/execution drift: each step is locally optimal but slowly diverges from the goal.
  • Session volatility: an in-memory plan evaporates when the CLI crashes or the terminal closes.

Why it mattered

A migration of this size spans many sessions. Without external scaffolding, resuming becomes “archaeological reconstruction” (inferring intent from half-finished code), which is exactly where regressions and wasted effort come from.

Constraints

  • No behavior changes; a straight port.
  • Work had to survive crashes and span days/sessions.
  • Quality had to be verifiable.

Role

I acted as the planner and architect: decomposed the work, owned the target design, and reviewed output. The agent executed steps against the plan. This human-as-planner / agent-as-executor split is the central idea.

Architecture

An external progress file is persistent memory: the current plan, what’s done, what’s next, and constraints that must not be forgotten. Each session begins by re-injecting that file, so the agent re-anchors to the global goal instead of drifting toward local coherence. State lives outside the model, the way a web server keeps sessions in external storage.

Key decisions

  • Externalize state so the plan doesn’t depend on the context window retaining it.
  • Re-inject the plan every session to counter drift and the lost-in-the-middle effect.
  • Keep the human as planner: the model executes decomposed steps and doesn’t own the design.

Tradeoffs

  • Maintaining the progress file is manual overhead, deliberately accepted as the price of coherence across sessions.
  • Smaller step sizes mean more iterations but far less rework from drift.

Testing / evaluation

Quality was verified with tests: the test suite guarded against regressions, and each step was reviewed against the progress file.

Outcome

The migration completed without losing clarity or introducing regressions (as described in the companion post). More durably, it produced a repeatable pattern for long-running agent work.

What I learned

The reliability of a long-running agent comes from the surrounding workflow (external state, re-anchoring, and human planning) more than from raw model capability.

What I’d change next

Automate progress-file upkeep (generate/update it from diffs and test results) so the pattern needs less manual bookkeeping.