---
title: "Debugging and Testing with Codex"
description: "A practical Codex debugging workflow: reproduce a bug, trace the cause, make a focused fix and test the behavior that originally failed."
author: Power of AI
date: 2026-09-06
url: https://powerofai.ca/codex/debugging-and-testing
---

# Debug with Codex: turn “it is broken” into a verified repair

A practical Codex debugging workflow: reproduce a bug, trace the cause, make a focused fix and test the behavior that originally failed.

The most valuable sentence is often “here is how to reproduce it.”

An agent can edit code quickly. A useful repair requires a connection between an observed failure, its cause and a check that would catch it again. Your contribution is often the clearest description of the failure.

## Write a bug report with a before and after

Start with the exact sequence. “On the reading list, choose History, search for a title in that topic, then clear search. The list becomes empty. It should return all History entries.” Include the URL or screen, any visible error and the input that caused it. Tell the agent whether the failure happens every time.

If you only have a screenshot, describe the expected behavior too. An image can show an empty panel; it usually cannot explain whether that panel is correct. If the bug is intermittent, ask the agent to gather evidence around the transition rather than immediately changing several unrelated components.

### A request you can adapt

Reproduce this bug before editing: [steps]. Expected: [behavior]. Actual: [behavior]. Inspect the relevant state and code path, identify the likely cause with evidence, make a focused repair and repeat the original sequence. Preserve unrelated changes. Report checks that could not run.

## Ask for a causal explanation

A useful explanation points to the condition that fails. “The reset action clears the selected topic but leaves a stale query in the derived results” is something you can assess. “I improved state management” is too vague. Ask which input or state transition demonstrates the defect.

Be wary of a repair that disables the feature that failed. Removing validation can make an error message disappear while allowing invalid data through. A test that merely repeats the new implementation can also pass for the wrong reason. The check should describe what a user needs, independently of how the code achieves it.

## Use the right check at the right layer

For a calculation, test known inputs and expected values. For a parser, test representative valid and invalid files. For a UI flow, open the page and perform the interaction. For a build problem, run the actual build. These checks answer different questions and can complement one another.

After the original failure is fixed, inspect one adjacent behavior that could have been affected. If search reset changed, try a filter reset too. Broaden the work when there is a reason; endlessly rerunning unrelated checks makes the report longer without necessarily increasing confidence.

## Finish with a repair you can review

Ask for the changed files, the cause, the behavior after the fix and the evidence from testing. If the agent could not launch the browser or lacked a required service, that limitation belongs in the finish. A passing build should not be presented as proof of a flow nobody exercised.

Then do the original action yourself. For a change that matters, review what was edited or ask for a plain-language walk-through of the diff. Save the working state. The next bug becomes easier to investigate when the baseline is clear.

### A request you can adapt

Summarize the repair in four parts: trigger, cause, changed behavior, and verification. Distinguish checks you ran from checks you recommend. Show me how to reproduce the corrected behavior myself.

## Take this into your next task

Make the failure observable, connect it to a cause, and verify the same behavior after the change.

[Build a project brief](/showcase#brief-builder).

## Sources and editorial notes

Reviewed September 6, 2026. Product capabilities depend on the app, plan, region and workspace settings. Workflows and prompts are authored teaching material, not recorded model results or measured time-saving claims.

- [OpenAI: prompting and context](https://learn.chatgpt.com/docs/prompting)

## Keep going

- [Build Your First Tool with Codex: A CSV Checker](/codex/build-your-first-tool)
- [Test a Website with an AI Browser Agent](/computer-use/browser-testing)
- [AGENTS.md: Give Codex Useful Project Instructions](/codex/project-instructions)
