Ask
91
@muslin_mira ·

one big agent-driven refactor or twenty small ones on a 60k-line codebase refactor

60k lines of TypeScript, five years old, and we want to move from a hand-rolled DI container to plain constructor injection. Touches roughly 180 files. Nothing about it is hard, it's just enormous and boring — exactly the sort of thing an agent should be good at.

Option A: one branch, let it grind through all 180 files over a couple of days, review at the end.
Option B: 20 PRs of nine files each, merged as they go.

A is obviously less merge pain. B is obviously more reviewable. Team of three, we ship to production twice a week and can't freeze the codebase.

Has anyone done the big one and been glad?

10 answers Share
Report

Answering anonymously — a moderator will review it first.

  • @heirloom_hank · 5mo ago · 2 replies

    B, and not for the reviewability reason — for the rebase reason.

    You ship twice a week with three people. A branch touching 180 files that lives for two days will conflict with everything, and resolving conflicts in a diff you didn't write is genuinely miserable. Doing it once is annoying; doing it across 180 files after two days of drift is a lost afternoon and a real chance of silently reverting somebody's fix.

    The version that works: write the transformation spec first, with two examples done by hand. Then batch by directory, 8-12 files at a time, merged same day. The agent does the same work either way — you're choosing how much unmerged state exists at once.

    Twenty PRs sounds like twenty times the ceremony. In practice each is a four-minute review because they're all the same shape and you get fast at spotting the one that isn't.

    118
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @muslin_mira · 5mo ago

      The 'you get fast at spotting the deviation' point is what tipped it. Twenty of the same shape is much easier than twenty different shapes at once.

      27
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @coworking_cass · 5mo ago · 3 replies

    Also: if the transformation is genuinely mechanical, consider not using an agent for the bulk of it. A ts-morph or jscodeshift transform does 170 of the 180 files deterministically and identically, and you use the model for the ten weird ones and for writing the codemod itself.

    Deterministic where you can, judgement where you can't. An agent that produces subtly different-looking output in file 140 than in file 3 is something you'll be reading diffs about for a week.

    64
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @muslin_mira · 5mo ago

      We wrote the codemod in the end. It got about 150 files perfectly, the model handled the 30 with circular-ish wiring, and the whole thing took three days instead of the two weeks we'd budgeted.

      31
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
    • @wonder_why_wren · 5mo ago

      Matches my experience. The best use of a model on a big mechanical refactor is writing the tool that does the refactor.

      16
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @negativesplitz · 5mo ago

    Whichever you pick, put the invariant in CI first. A lint rule that fails on any new use of the old container, added on day one. Then the migration is monotonic — nobody adds to the pile while you're draining it.

    Big refactors fail when the codebase keeps generating new instances of the thing you're removing.

    38
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @iris_tanaka · 5mo ago

    Watch review fatigue on option B specifically. PR 17 of 20 gets a much worse review than PR 2 and everyone knows it. Mitigate by making the boring ones genuinely boring — same shape every time, no drive-by improvements, agent instructed to change nothing except the wiring.

    15
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @rubberduck_rae · 6mo ago

    Do one directory by hand yourself first. Not for the code — for the spec. You will discover three exceptions you didn't know existed, and those exceptions are exactly what an agent will silently get wrong across 180 files if you haven't named them up front.

    An hour of manual work is the highest-leverage part of this whole project.

    22
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @overlap_owen · 5mo ago · 2 replies

    we did the big bang on 200 files, took a weekend, merged monday morning before anyone was in. worked fine

    14
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @heirloom_hank · 5mo ago

      Freezing the repo over a weekend is a legitimate strategy and it does work. The OP said they can't freeze, which is what rules it out here — not the size.

      12
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report