Ask
246
@heirloom_hank ·

agent rewrote 340 lines to fix a two-line bug, third time this week it-failed

Asked it to fix an off-by-one in a pagination helper. It fixed the off-by-one. It also renamed four variables, extracted two functions, turned a for loop into a reduce, added JSDoc to everything, and changed the error type thrown on invalid input, which broke a test in a different file.

Diff was 340 lines. The actual fix was two.

This isn't the model being stupid — most of the refactor was reasonable in isolation. But I now can't review the fix without reviewing a refactor I didn't ask for, and I do this fifteen times a day. What are people actually doing about scope creep in diffs?

12 answers Share
Report

Answering anonymously — a moderator will review it first.

  • @coworking_cass · 2w ago · 3 replies

    Constrain the blast radius mechanically instead of asking nicely.

    What works for me, in order of effect:

    • give it a failing test and say the only success condition is that test passing with no other test changing. Now there's a definition of done that isn't "improve the code"
    • state the line budget out loud. "Fix this with the smallest possible diff. If the fix is more than 10 lines, stop and explain why before writing anything." The explain-first clause is the important half — it turns an unwanted refactor into a sentence you can say no to
    • keep a rule in the repo config: no unrequested refactors, no renames, no new abstractions unless asked

    The stop-and-explain pattern changed my day-to-day more than anything else. Most of the time it comes back with "it's three lines" and just does it.

    201
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @heirloom_hank · 2w ago

      The explain-first clause is doing a lot of work. It's caught two cases this morning where I actually did want the bigger change, and one where I very much didn't.

      46
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
    • @iris_tanaka · 3w ago

      Same. It also surfaces when it has misunderstood the bug — the explanation is wrong before the code is, and that's much cheaper to catch.

      31
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @wonder_why_wren · 2w ago · 2 replies

    Split the two things into two turns and two commits. Turn one: fix. Commit. Turn two: "now, if you think this file needs refactoring, propose it." Half the time the proposal is good and I take it, as its own commit with its own review.

    The problem isn't that it refactors, it's that the fix and the refactor arrive in one diff and you can't approve one without the other. Git solves that, not prompting.

    88
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @heirloom_hank · 3w ago

      Two commits is obvious in retrospect and I wasn't doing it. It also makes the revert clean when the refactor turns out to be wrong a week later.

      22
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @drainfield_dez · 2w ago

    Smaller context helps more than people expect. Give it the whole file and it treats the whole file as in scope. Give it the function plus its test and the diff tends to stay inside the function.

    I've started selecting the specific range rather than opening the file for small fixes. It sounds fussy and it measurably shrinks diffs.

    61
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @mature_student_j · 3w ago · 2 replies

    Cheap trick in the meantime: git add -p and stage only the hunks you asked for, discard the rest. Takes 30 seconds, gets you the fix without the refactor, and doesn't depend on the model cooperating at all.

    19
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @heirloom_hank · 3w ago

      Doing this today while I sort out the rest.

      12
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @muslin_mira · 2w ago

    Worth saying plainly: 340-line diffs from a two-line ask are a review problem, and the review problem is now the actual bottleneck. If you're doing this fifteen times a day your throughput is bounded by how fast you can read, not by how fast it can write. Anything that makes diffs smaller is worth more than anything that makes generation faster.

    34
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @aquariumdad · 3w ago · 2 replies

    this is why i don't let it write code. i ask it to explain the bug and i type the fix. way faster than reading 340 lines

    18
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @wonder_why_wren · 2w ago

      That's a legitimate mode and I use it for anything subtle. It isn't faster for boilerplate though — a 200-line CRUD handler I'd have typed in 25 minutes takes four to review. The skill is knowing which category you're in before you start.

      15
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @negativesplitz · 2w ago

    Check whether a formatter or lint autofix is in the loop before you blame the model for all 340. Some of those lines might be Biome or Prettier reformatting on save with settings that differ from what's committed. I chased "it keeps rewriting my file" for a week and it was my editor.

    11
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report