When an AI coding agent changes one feature but breaks code elsewhere, the cause is often a hidden dependency, an overly broad edit, or a missing regression test. This guide shows how to isolate the change, find the first failure, and repair it without piling on unrelated edits. You’ll need the project’s usual test and version-control tools, plus a clean way to compare the agent’s changes with the last known-good state.
What You’ll Need
- A Git working tree, or another version-control system that can show and restore changes.
- The project’s documented setup instructions and test commands.
- A reproducible failure: the command, input, page, or workflow that now behaves incorrectly.
- Access to the agent’s diff or change summary, including any generated files it modified.
Step-by-Step
- Stop adding changes and preserve the current state. Don’t ask the agent to “fix everything” yet. Check
git statusand save or commit work you need to keep. If the changes are uncommitted, create a patch or temporary branch before experimenting. This gives you a way back and avoids losing unrelated local work. - Reproduce the break with a specific check. Record what you expected, what happened instead, and the smallest reliable steps to trigger it. Run the same test or workflow twice if the failure may be intermittent. Note the exact command, relevant input, and error output. A vague report such as “the app is broken” is hard to diagnose; a failing test name or repeatable interaction is much more useful.
- Establish a baseline. Run the failing check on the current branch, then determine whether it also fails on the parent commit or known-good revision. Use a separate worktree or temporary branch if you need to test the older revision without disturbing current work. If the baseline already fails, the agent’s change may not be the cause; check environment, dependencies, test data, and recent changes before editing.
- Inspect the whole diff, not just the intended feature. Use
git diff --statto see the scope, thengit diffto review each change. Look for edits outside the requested area, renamed or deleted files, altered shared functions, dependency or configuration changes, formatting rewrites, and generated output. Ask what each changed line is for. A short request can produce a broad diff, so do not assume every modification is necessary. - Find the first failing layer. Run the narrowest relevant test first, then expand to the affected module’s tests and the project’s normal suite. If available, run formatting, linting, type checks, and build checks separately. Read the first meaningful error and its stack trace; later failures can be knock-on effects. Compare against the baseline so you can distinguish a new regression from an existing warning or failure.
- Trace the regression to a changed assumption. Follow the failing call path and compare the old and new behavior. Check shared APIs, data shapes, default values, null or empty handling, error behavior, and side effects. For example, a changed return type may break another caller that the agent did not inspect. Search for all callers or uses of a modified symbol, not only the feature named in the request.
- Reduce the change to the smallest safe fix. Revert unrelated edits, or use a temporary copy of the branch to test them independently. Keep necessary feature changes and repair the compatibility issue directly. Avoid broad rewrites or speculative cleanup while diagnosing: each extra edit makes it harder to identify what fixed or worsened the problem. If an agent makes the repair, ask it to explain the failing test and limit its edit to the relevant files.
- Add a regression test and verify the full result. Write or update a test that fails with the broken behavior and passes with the fix. Run that test, the relevant neighboring tests, and the project’s documented checks. Review the final diff again, including files changed by test runs or code generation. Confirm the original feature still works and that no unrelated work was discarded before committing.
Common Mistakes
- Accepting the agent’s summary instead of inspecting the diff. Summaries can omit incidental changes. Review the actual files and lines.
- Running only the new feature’s test. Shared code can affect other callers. Add tests for the broken behavior and run relevant existing suites.
- Changing several things at once. A large follow-up prompt may hide the original cause. Make one controlled change, then rerun the same check.
- Deleting failing tests or weakening assertions. That can hide a regression rather than fix it. Change a test only when its expected behavior is genuinely outdated, and explain why.
- Blaming the agent before checking the baseline. Environment changes, stale fixtures, and pre-existing failures can produce the same symptoms.
Tips
- Ask the agent to state its assumptions, list files it plans to change, and stop before editing when the scope is unclear.
- Prefer small commits or checkpoints so you can bisect the change and restore a known-good state.
- Use the project’s established test commands; inventing a substitute can miss setup steps or required services.
- When a regression is hard to isolate, use
git bisecton commits, if the failure can be tested reliably. Mark a known-good and known-bad revision and follow its prompts. - Keep secrets, credentials, and private data out of prompts, logs, and test fixtures.
Troubleshooting
The failure is intermittent: Repeat the same check and record timing, environment, and inputs. Look for shared mutable state, concurrency, ordering assumptions, and tests that depend on external services. Don’t treat a single passing run as proof that the issue is fixed.
The test suite fails in many places: Start with the earliest independent error. Confirm dependencies and setup match the project documentation, then separate compile or configuration failures from behavioral test failures. A missing service or stale generated file can cause many misleading errors.
The diff appears clean, but behavior changed: Check dependency lockfiles, environment settings, generated code, build scripts, and files ignored by ordinary diff views. Compare runtime inputs and configuration between the working and failing cases.
You cannot reproduce the original bug: Preserve the failing logs and environment details, then check whether the fix depends on different data, a fresh build, or a restart. Avoid merging a change solely because the error disappeared once.
You are unsure what can be reverted: Don’t reset the whole working tree. Save local work, inspect individual files, and restore only changes you have identified as unrelated. Ask a teammate to review if ownership or shared behavior is unclear.
Frequently Asked Questions
Should I revert all of the agent’s changes?
Only if that is the safest way to restore service and you have preserved work. Otherwise, isolate the offending edits and keep the parts that are needed and verified.
What if the agent changed files outside the requested feature?
Check whether each change is required. Revert unrelated modifications, then rerun the failing check and relevant tests to confirm the reduced diff behaves correctly.
How do I tell whether a failure is new?
Run the same reproducible check on a known-good revision with the same setup and inputs. If it fails there too, investigate the baseline or environment before attributing it to the new change.
Should I let the agent run the entire test suite?
It can help, but first run the narrow test that demonstrates the regression. Then use the project’s full checks when practical, and verify the commands and results yourself.
What if there is no test for the broken behavior?
Create a focused regression test if the project supports it. Otherwise, document a repeatable manual check and consider adding automated coverage for future changes.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Skype Messaging Updates: What Changed
- Filter Values Within Tolerance: How It Works
- Why Chromecast Still Good Purchase
- Programming Skills for Job: What You Need120 hours
- Asus ProArt P16 Laptops: Specs, Pros, Cons & Buying Tips
- Analytical Database Engine: What It Does & When to Use