The Deska blog

Hunting a Regression With git bisect and an Agent

Learn how to accelerate hunting a regression using git bisect combined with AI coding agents to find the exact commit that broke your build.

· 10 min read

Debugging a software failure that appeared suddenly in a codebase can be one of the most time consuming tasks in development. When a feature that worked yesterday is broken today, you are effectively hunting a regression to identify exactly when the logic diverged from its intended behavior. Git provides a powerful built-in tool for this called git bisect, which uses a binary search algorithm to find the specific commit that introduced a bug. While manual bisection is effective, combining this process with an autonomous agent can significantly reduce the cognitive load and time required to isolate the fault.

Understanding the Binary Search Logic of Git Bisect

At its core, git bisect is a search optimization utility. If you know that the current version of your code is "bad" (broken) and a version from two weeks ago was "good" (working), you have a range of commits to inspect. Instead of checking every single commit one by one, which would be a linear search, the tool picks the midpoint of the range.

You test that midpoint. If it works, the bug was introduced in the second half of the range. If it fails, the bug is in the first half. By repeating this process, you can narrow down thousands of commits to the single culprit in about twelve steps for every 4,000 commits. This efficiency is why the tool remains a staple in professional software engineering.

The Manual Bisection Process

To start the process manually, you use a sequence of commands in your terminal. First, you initiate the session:

git bisect start

Next, you define the boundaries. You mark the current state as bad:

git bisect bad

Then, you provide a known working commit hash or tag:

git bisect good v2.0.4

Git will then checkout a commit in the middle. At this point, you must build the project, run your tests, or manually verify the bug. Once you have a result, you tell Git git bisect good or git bisect bad. The process repeats until the first bad commit is identified.

Integrating AI Agents into the Bisect Loop

While the binary search is mathematically optimal, the human effort lies in the verification step. You have to wait for builds to finish, remember the specific reproduction steps, and keep track of state. This is where AI agents like Claude Code or Codex CLI become invaluable.

When you run these agents within a flexible environment, they can handle the heavy lifting. The agent can examine the current commit, determine the necessary build commands, execute the test suite, and report the outcome back to the bisect process. This turns a manual chore into an automated pipeline.

In a workspace like Deska, you can arrange your environment to support this. You might have one terminal dedicated to the git bisect state, another running a continuous build, and a third where an agent is analyzing the diffs between the good and bad states. Seeing these panels side by side helps you maintain context without constantly switching tabs.

Automated Bisection with git bisect run

Git allows for even deeper automation through the run command. If you have a script that returns a zero exit code for success and a non-zero code for failure, Git can perform the entire bisection without human intervention.

  1. Write a small script (e.g., test.sh) that triggers the specific failure.
  2. Ensure the script compiles the code if necessary.
  3. Command Git to automate: git bisect run ./test.sh.

An agent can help you write this script. If the bug is intermittent or hard to reproduce, the agent can analyze logs to find the exact conditions needed for a consistent failure. Being able to run coding agents directly in your terminal allows you to generate these test cases on the fly.

Why a Desktop Workspace Matters for Debugging

Hunting a regression is often a multi-dimensional task. You are not just looking at code; you are looking at logs, documentation, and perhaps a browser window showing the frontend failure.

Conventional editors often hide this complexity behind tabs. Using a local-first workspace that emphasizes visibility can change your approach. In Deska, the infinite canvas allows you to keep the git bisect output visible in one corner while the agent works in another. You can use Ask Deska via voice to open new terminals or check on the status of a long-running build while your hands remain on the keyboard or mouse, adjusting the logic in the Monaco editor.

FactorManual BisectionAutomated ScriptAgent-Assisted
SpeedSlowFastMedium-Fast
ComplexityLowHighMedium
FlexibilityHighLowVery High
Context RetentionDifficultAutomaticAssisted

Refinement and Verification

Once the bisection is complete and Git identifies the "first bad commit", the job is only half done. You now have the "what" and "when", but you still need the "why".

This is the perfect moment to leverage your agent again. You can point the agent to the specific diff of that commit. Ask it to explain why these specific lines caused a regression. Often, the bug is a side effect in a different module that was not directly touched but relied on a behavior that changed. By using agent threads, you can keep a history of this investigation, which is useful for the eventual pull request that fixes the bug.

Mobile Monitoring of Long Bisections

Some bisections take a long time, especially in large monorepos where each step requires a full clean build and a long integration test suite. You do not need to sit at your desk for an hour watching a progress bar.

Using a mobile app to track your progress allows you to step away. You can monitor the terminal output through a secure relay that connects your phone directly to your workstation. If the agent hits a snag or requires a manual decision, you can provide input remotely without being tethered to your desk.

FAQ: Frequently Asked Questions

how to git bisect when test is slow

When tests are slow, the best approach is to optimize the build range. Use git bisect skip if you know certain commits are broken for unrelated reasons. Additionally, using an agent to create a "smoke test" (a faster, minimal version of the full test) can help you descart large chunks of the history before running the full suite on final candidates.

git bisect find commit that deleted file

You can use the same logic to find when a file was deleted. The "good" state is when the file exists, and the "bad" state is when it is missing. A simple script like ls path/to/file can serve as your test command for git bisect run.

automating git bisect with ai agents

Integrating AI involves giving the agent access to your terminal. The agent can observe the failure, suggest a reproduction script, and then monitor the git bisect run process. This ensures that if the build fails for an unrelated reason, the agent can fix the environment and keep the search moving.

Getting Started with Automated Debugging

Hunting a regression does not have to be a frustrating experience of trial and error. By combining the mathematical precision of git bisect with the intelligence of modern coding agents, you can isolate bugs in minutes instead of hours.

If you are looking for a place to coordinate these tools, you can download the Deska app for Mac, Windows, or Linux. It provides the terminals, editors, and agent integrations needed to build a professional debugging environment that stays entirely on your local machine.

💡 Ideas+🐛 BugsSuggest a feature or report a bug