Other

Run a Cross-File Bug Fix in an AI-Powered Code Editor

2026-11-27·6 min read·Updated 2026-11-27

The short answer

Use the AI-powered code editor for tracing and drafting, not for finishing. Paste a failing test, the exact error, and the call path into the editor's chat; ask for a ranked hypothesis list with tiny verification steps. Run the smallest step, then ask for a minimal patch to one file. Repeat until tests pass. You own the merge.

This workflow assumes an editor with chat that can read selected files or the workspace and propose diffs you review. If your editor only autocompletes, use it for the patch step and do the tracing in a normal editor.

A figure at a fork chooses a narrow three-gate path over a tangled many-file path toward a single green check.

Starting material you need before opening the editor

A useful AI request starts with evidence. Gather these five items first:

  1. A failing test that reproduces the bug, or a recorded request/response pair if no test exists. Write the test before prompting if you can; it gives the model a pass/fail signal you control.
  2. The exact error text, copied, not retyped—including stack frames and the first failing assertion.
  3. The call path from entry point to the suspected module. Even a rough list (handler → service → repository → serializer) narrows the search.
  4. A one-line bug statement in user terms: "Order totals are double-counted when a coupon is applied after a line-item edit."
  5. Your constraints: which files are off-limits, which dependencies must not change, and the runtime and test command.

If a test is flaky, stabilize it first. An AI that debugs a flaky test will produce confident, wrong patches.

Settings and prompt structure that produce usable answers

Most AI editor chats have three settings that change outcomes. Set them deliberately:

  • Context scope: select specific files rather than attaching the whole repo. Whole-repo context invites the model to touch unrelated code. Start with the failing test, the entry-point handler, and the one module the stack trace names.
  • Read-only vs. edit mode: start in read-only chat. Ask for analysis and a patch as text; only switch to diff-apply mode once a hypothesis is supported by a run.
  • Test command: tell the model the exact command (npm test -- orders.coupon.test.ts, for example) and ask it to include it in its plan. Models often propose verification steps but omit the command you actually use.

A prompt structure that reliably works:

Prompt
Bug: <one-line user-facing statement>
Failing test: <paste test output>
Error: <paste exact error>
Call path: <entry → module → suspect>
Constraints: no dependency changes; do not edit billing/*; runtime Node 22
Task: list up to 3 ranked hypotheses. For each, state the evidence for it
and one command or assertion that would confirm or kill it. Do not write a
patch yet.

The "do not write a patch yet" line matters. When you ask for hypotheses and a patch together, the model rationalizes the first patch it drafts. Separating the steps forces evidence before editing.

Worked example: a double-counted coupon

The bug: an order total doubles the coupon discount when a line item is edited after the coupon is applied. The failing test asserts a total of 42.00 and gets 34.00—an extra 8.00 discount.

Step 1—trace. With the test, the handler, and the totals module attached, the first prompt returns three hypotheses:

  • H1: the edit handler recalculates totals and reapplies the coupon already stored on the order.
  • H2: the totals module applies the coupon twice when called from the recalc path.
  • H3: a cache returns a stale discount value after the edit.

Step 2—verify cheaply. You ask for one confirming check per hypothesis. For H1, the model proposes logging the call count of applyCoupon during the test. You run it: the log shows two calls. H2 and H3 would not produce two calls, so you drop them.

Step 3—minimal patch. Now you ask for a fix restricted to the edit handler, with an instruction to prove the fix with the same test. The proposed diff removes the redundant applyCoupon call from the edit path and leaves the totals module untouched. You review the diff: one deleted call, one comment, no new helper functions.

Step 4—verify. Run the single test. Then run the full order suite, because the edit handler also feeds refunds. When the full suite passes, run your type check and linter. If the diff touches a serializer or API shape, run the contract test too.

Step 5—record. Commit the test and fix together. Ask the editor to write the commit message from the diff and the bug statement, then edit it yourself—generated messages often overstate what changed.

For a deeper treatment of cross-file fixes and small edits, the OTTERMIND workflow guide walks through a similar trace-first approach, and the GPT-6 coding review covers how model choice affects small-edit accuracy. If you are still choosing an editor, the developer assistant comparison is a useful starting point.

When it fails: five symptoms and what to change

Failures in this workflow are usually about context, not model quality. Match the symptom to the fix:

  • The AI immediately writes a patch that breaks other tests. You skipped the hypothesis step. Return to read-only chat, paste the newly failing tests back in, and ask which hypothesis the new failure supports.
  • It keeps proposing a change in the wrong file. The stack trace likely points at a wrapper, not the bug. Paste the call path and ask it to name every function that could produce the wrong value, with line references, before proposing anything.
  • It edits files you marked off-limits. Scope is too broad. Attach only the test, the handler, and one suspect file; restate the constraint in the prompt as a hard stop: "If the fix requires editing billing/*, stop and explain why."
  • The patch passes the single test but the suite is slower or flakier. Ask the model to list side effects of its change and to check whether any shared state is now written twice. Review the diff for removed waits, retries, or error handling.
  • It confidently cites code that does not exist. Treat every cited line as unverified. Ask it to quote the surrounding 10 lines from the attached file. If it cannot, the claim is inferred—discard it and trace manually.

The general rule: when two attempts fail, stop prompting and shrink the problem. Cut the failing test to the smallest reproduction, delete unrelated context, and ask one question: "Which line produces the wrong value?"

What to check before you merge

Run this checklist on every AI-assisted fix:

  • The failing test passes, and it failed before the patch for the right reason.
  • The full related suite passes, not just the one test.
  • The diff is smaller than you expected; if it is large, ask the model to justify each hunk or revert and re-prompt.
  • No dependency, lockfile, or config change appears unless you asked for one.
  • Error handling and logging behavior are unchanged or improved, not silently removed.
  • You can explain the root cause in one sentence without reading the patch again.

Limits. This workflow does not prove correctness; it proves the bug you can describe is fixed and nothing adjacent broke. It cannot substitute for domain knowledge about money, permissions, or data migrations—review those diffs line by line yourself. And when the codebase lacks tests, an AI editor has no reliable pass/fail signal, so write the test first; the fix gets easier after that.

Draft your own trace-first bug prompt

You are helping me prepare a bug-tracing prompt for an AI-powered code editor. Inputs: my bug statement, the failing test output, the exact error, the call path, and my constraints (off-limits files, dependencies that must not change, runtime, test command). Use only what I provide; do not invent code, line numbers, or test results. Constraints: ask for up to three ranked hypotheses with evidence and one cheap confirming check each; no patch yet; keep the prompt under 200 words. Output format: (1) the ready-to-paste prompt in a code block, (2) a five-item checklist of evidence I still need to gather, (3) one sentence naming the most likely missing input.

Continue in Studio

Further reading

Download desktop & mobile app

Access Ottermind anytime, anywhere.

Computer