Retrace
Turn failed Python tests and CI runs into AI-debuggable replay sessions.
Retrace records a Python execution as a .retrace artifact. When pytest or CI
fails, Retrace can replay the same failed run through the AI debugger and write
a report, or you can open the artifact locally in VS Code and inspect the
runtime state yourself.
The same recording model works for Python apps and production crashes. Start with tests today; move to production when the trust is there.
Start here: use the pytest AI-debugger quick start below, or follow the manual VS Code replay quickstart.
Why Retrace
Most failed test and CI artifacts are logs, tracebacks, screenshots, or partial traces. They show symptoms. They do not preserve the execution.
Retrace preserves the failed run itself.
| Today | With Retrace |
|---|---|
| CI artifacts are logs and tracebacks | CI artifact is replayable |
| AI agents infer from partial context | AI agents get runtime evidence |
| Stack trace shows where it crashed | Replay shows what happened before |
| Logs show what you predicted would matter | Retrace preserves the failed execution |
The failed execution becomes something you can inspect, replay, and share.
Quick Start: AI-Debug a Failed pytest Run
Install Retrace in your virtual environment:
python -m pip install --upgrade pip
python -m pip install --upgrade retracesoftware pytest
Check that both the Python package and the split DAP/replay package installed:
python -m pip show retracesoftware
python -m pip show retracesoftware-dap
Print the same pytest AI-debugger setup in your terminal at any time:
retrace quickstart
Set auto-debug once for the current terminal, create a recordings directory, and
run your normal pytest command through retracepython:
export RETRACE_AUTO_DEBUG=1
mkdir -p recordings
retracepython --recording recordings/pytest.retrace -m pytest tests
You can keep your usual pytest arguments:
retracepython --recording recordings/pytest.retrace -m pytest tests -vs
retracepython --recording recordings/pytest.retrace -m pytest tests/test_example.py
retracepython --recording recordings/pytest.retrace -m pytest tests/test_example.py -k "some_test"
This runs the real pytest command, records the execution to
recordings/pytest.retrace, and, if pytest fails, replays the recording through
the DAP AI debugger. Retrace preserves pytest's original exit code and writes an
AI report next to the trace:
recordings/pytest.ai-report.md
Open that report in your editor. On macOS:
open recordings/pytest.ai-report.md
The default hosted auto-debug flow can request a free client token
automatically. You normally do not need RETRACE_API_KEY for a first run; set
it only when you want to use an authenticated Retrace AI service account.
There is also a shorter form:
RETRACE_AUTO_DEBUG=1 retracepython -m pytest tests
The short form writes default artifacts in the current directory, usually
pytest.retrace and pytest.ai-report.md. The explicit --recording recordings/pytest.retrace form is recommended because it keeps artifacts in a
predictable location across environments.
Quick Start: Replay a Failed pytest Run In VS Code
If you want a manual replay/debugging session instead of an AI report, run pytest through Retrace's explicit runner:
mkdir -p recordings
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python -m retracesoftware --recording recordings/pytest.retrace -- -m pytest tests -q --tb=short
If pytest fails, Retrace leaves behind a .retrace artifact for that exact failed run.
This preview command keeps pytest plugin loading explicit so the first-run demo stays focused, repeatable, and easy to inspect.
Open the same project in VS Code:
code .
Then:
- Install the
Retrace Debug Extensionfrom the Marketplace. - Open the Retrace sidebar.
- Choose
Open Recording.... - Select
recordings/pytest.retrace. - Open the failing test or the code under test.
- Set a breakpoint near the failing assertion or exception.
- Start replay from the Retrace view.
You can now debug the failed execution locally, inspect runtime state, and step backwards from the failure without re-running the test.
CI Artifacts
Retrace works with ordinary CI artifact upload.
For example, in GitHub Actions:
- name: Run pytest with Retrace
run: |
mkdir -p recordings
set +e
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 \
python -m retracesoftware --recording recordings/pytest.retrace -- -m pytest tests -q --tb=short
PYTEST_STATUS=$?
exit "$PYTEST_STATUS"
- name: Upload Retrace recording
if: failure()
uses: actions/upload-artifact@v4
with:
name: retrace-failed-run
path: recordings/pytest.retrace
A failed CI run becomes a replayable artifact. Download it, open it locally in VS Code, and debug the same execution that failed in CI.
No hosted trace service or GitHub App is required.
A 30-Second Example
A test fails:
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python -m retracesoftware --recording recordings/failure.retrace -- -m pytest tests/test_checkout.py -q --tb=short
Instead of rerunning and guessing, open recordings/failure.retrace in VS Code. Replay the exact failed execution, inspect locals and call stack, and step backwards from the failing assertion to the state that caused it.
The recording is the failed run. No reproduction steps, no retry loop, no guessing from logs.
How It Works
-
Run
Run pytest, CI, or your Python app with Retrace enabled.
-
Record
Retrace records the execution into a
.retraceartifact. -
Replay
Replay the artifact through the AI debugger or open it locally in VS Code.
-
Inspect
Inspect the runtime state that caused the failure instead of rerunning live.
Under the hood, Retrace records the boundary between your Python code and the nondeterministic outside world: network responses, filesystem state, clocks, randomness, subprocess behavior, thread scheduling, API calls, database calls, and other external effects.
During replay, your Python code runs for real, but those recorded boundary calls return their captured values instead of touching the live world. That makes replay deterministic and lets the debugger move through the original execution.
Built For Humans And AI Agents
Retrace gives a developer, debugger, or AI coding agent the runtime ground truth of a failed execution, not just source code, logs, and a stack trace.
That matters because AI agents often infer what happened from partial context. A .retrace artifact gives them runtime evidence from the actual failed run.
CLI access and AI-agent workflows are arriving alongside the VS Code path.
Full Quickstart
The full quickstart includes a small failing pytest demo, a replay bundle helper, terminal replay, and VS Code replay debugging.
Clone the repo and enter the quickstart directory:
git clone https://github.com/retracesoftware/retracesoftware.git
cd retracesoftware/quickstart
Create and activate a virtual environment:
python3.12 -m venv .venv
source .venv/bin/activate
Install Retrace and the demo dependencies:
python -m pip install --upgrade pip
python -m pip install retracesoftware
python -m pip install -r requirements.txt
Record the pytest demo:
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python -m retracesoftware --recording recordings/pytest.retrace -- -m pytest pytest_demo -q --tb=short
Open the project in VS Code:
code .
In VS Code:
- Install the
Retrace Debug Extensionfrom the Marketplace. - Open the Retrace sidebar.
- Choose
Open Recording.... - Select
recordings/pytest.retrace. - Open
pytest_demo/checkout.py. - Set a breakpoint inside
build_receipt. - Start replay from the Retrace view.
The replay should stop at your breakpoint inside the recorded execution. You can inspect variables, continue, step forward, and step backward without running pytest live again.
For the full walkthrough, see quickstart/README.md.
Production Is The Destination
The .retrace artifact from a failed test uses the same architecture as a production crash replay.
Start with tests today. Run the same tool against production when the trust is there.
Retrace records the boundary between your Python code and the outside world — databases, APIs, files, time, randomness, and other nondeterministic calls — then replays those results locally.
Recording overhead is designed to be low enough for production processes to stay recorded.
What Retrace Is Not
Retrace is not a logging library. You do not decide in advance which variables, branches, or errors might matter.
Retrace is not a metrics or tracing dashboard. It does not sample requests or aggregate performance data across your application.
Retrace is not rr for Python. It does not record an entire machine process at the syscall level. Instead, it records the boundary between your Python code and the outside world, then replays those interactions so the original execution can be debugged deterministically.
Requirements
- CPython 3.11 or 3.12
- macOS or Linux, 64-bit
pip- VS Code is optional for manual replay/debugging
Supported PyPI wheels include Retrace's replay binary, so normal pip install retracesoftware users do not need Go installed. Go is only required when building Retrace from source or on unsupported platforms where pip has to build from source.
Recording Python Commands
Install the package:
python -m pip install retracesoftware
Installing Retrace does not automatically record Python processes. Choose the launcher mode that matches the workflow.
One-Shot Recording
Use retracepython when you want to record one command:
retracepython --recording recordings/run.retrace my_script.py
Record a pytest run:
mkdir -p recordings
retracepython --recording recordings/tests.retrace -m pytest tests/ -q --tb=short
Record a module-based CLI:
retracepython --recording recordings/cli.retrace -m your_package.cli --input examples/input.json
Record a one-off command:
retracepython --recording recordings/debug.retrace -c "import random; print(random.random())"
retracepython is intentionally one-shot. If the recorded program explicitly
runs ordinary python, that child process is not automatically recorded.
To automatically run the AI debugger when the recorded command fails, set
RETRACE_AUTO_DEBUG=1. You can set it once for the current terminal:
export RETRACE_AUTO_DEBUG=1
mkdir -p recordings
retracepython --recording recordings/run.retrace my_script.py
Or prefix one command:
RETRACE_AUTO_DEBUG=1 retracepython my_script.py
On failure, Retrace runs retrace-ai-driver with the DAP tool executor against
the recording and writes a report next to the trace, for example
recordings/run.ai-report.md. The driver starts the Retrace DAP server and
drives it through the retrace-ai-service/provider configuration supplied to
the driver. The default hosted service can request a free client token when
RETRACE_API_KEY is unset. Configure the driver with environment variables
such as RETRACE_AI_SERVER, RETRACE_API_KEY, and RETRACE_REPLAY_BIN when
you need a custom service, authenticated account, or local replay binary.
RETRACE_AI_SERVER defaults to
https://retrace-ai-service.retracesoftware.workers.dev.
RETRACE_AI_DRIVER_COMMAND can override the packaged driver command for
development.
When auto-debug uses the default recording path, successful runs delete the
temporary trace. If you pass --recording or set RETRACE_RECORDING, Retrace
keeps that explicit trace even when the command succeeds.
Retrace-Aware Virtual Environment
Use a Retrace venv when ordinary python commands in that environment should
record, including sys.executable child processes:
python -m retracesoftware venv .retrace-venv
.retrace-venv/bin/python my_script.py
pip, ensurepip, venv, and Retrace's own commands bypass recording inside
the generated venv.
Active-Environment Hook
If you already have a configured Python environment, install an env-gated hook into that environment:
python -m retracesoftware enable-hook
RETRACE=1 python my_script.py
The hook is inert unless RETRACE=1, RETRACE_AUTO_DEBUG=1,
RETRACE_RECORDING, or RETRACE_CONFIG is set. Remove it with:
python -m retracesoftware disable-hook
Retrace creates the parent directory if needed and writes an executable .retrace file. The recording stores the command, working directory, environment, Python version, Retrace checksums, and recorded boundary calls.
You can also record through the underlying CLI:
python -m retracesoftware --recording recordings/run.retrace -- my_script.py
For more examples, see docs/getting-started/recording-python-commands.md.
Replay And Debug In VS Code
Open the same folder that contains your source and .retrace file:
code .
Then open the recording from the Retrace sidebar or right-click the .retrace file and choose Open as Retrace Recording.
The extension reads the replay binary path embedded in the .retrace shebang, indexes the recorded process tree, and launches replay debugging through the Go replay tool.
Set breakpoints in the recorded Python code and start replay. The debugger runs the recorded execution, not a live process.
See docs/getting-started/vscode-extension.md.
Terminal Replay
Extract the recording:
./recordings/run.retrace --extract
That creates:
recordings/run.d/index.json
recordings/run.d/<PID>.bin
Find the root process:
ROOT_PID=$(python -m retracesoftware --recording recordings/run.retrace --list_pids | head -1)
Replay it:
./recordings/run.d/${ROOT_PID}.bin
Other Editors And CLI
Retrace speaks the Debug Adapter Protocol, so any DAP-compatible debugger should be able to drive a Retrace replay session.
VS Code is the first supported editor. PyCharm, Zed, and other DAP clients are on the path.
A standalone CLI workflow is also coming, so you will not need an editor at all to drive a replay. Watch the Discussions for updates.
Documentation
- Documentation index
- Getting started
- Installation
- Quickstart
- Recording Python commands
- VS Code extension
- Reference
- CLI reference
- Environment variables
- Recording files
- Compatibility
- Troubleshooting
- Internals
- Architecture
Development From Source
Install from this checkout:
python -m pip install --upgrade pip wheel
python -m pip install "meson>=1.3" "meson-python>=0.18.0" "setuptools_scm>=8.0.4" ninja
python -m pip install --no-build-isolation -e .
The package includes Python code, native extensions built by Meson, module interception config, and the Go replay tooling used for extraction, terminal replay, and VS Code replay/debugging.
Supported wheels include the replay binary. Source/development installs build the replay binary locally, so Go 1.25 or newer must be available on PATH.
On macOS with Homebrew:
brew install go
On Linux, install Go 1.25 or newer from your distro packages or from go.dev/dl.
Run Python tests:
python -m pytest tests/ -v --tb=short
Run Go tests:
cd go
go test ./...
Repository Layout
quickstart/first-run demo and public quickstart flowsrc/retracesoftware/__main__.pyCLI record/replay entrypointsrc/retracesoftware/retracepython.pyandretrace_venv.pylauncher implementationssrc/retracesoftware/tape.pyrecording file setup, checksums, and tape I/Osrc/retracesoftware/install/runtime patching and import hookssrc/retracesoftware/proxy/record/replay boundary semanticssrc/retracesoftware/modules/stdlib and third-party interception configsrc/retracesoftware/stream/andcpp/stream/trace serializationsrc/retracesoftware/dap/Python debugger protocol piecesretrace-dap/replay extraction, indexing, and debug adapter toolingvscode/VS Code extensiontests/anddockertests/unit, replay, and scenario testsdocs/user and maintainer documentation
License
Apache-2.0
Metadata
Release files for retracesoftware 0.2.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| retracesoftware-0.2.18-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.17+ x86-64 | Details |
| retracesoftware-0.2.18-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.17+ ARM64 | Details |
| retracesoftware-0.2.18-cp312-cp312-macosx_12_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 12.0+ ARM64 | Details |
| retracesoftware-0.2.18-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.17+ x86-64 | Details |
| retracesoftware-0.2.18-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.17+ ARM64 | Details |
| retracesoftware-0.2.18-cp311-cp311-macosx_12_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 12.0+ ARM64 | Details |
Total release size: 17.6 MB
Release files / retracesoftware-0.2.18-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | retracesoftware-0.2.18-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 3.2 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
22a08aa11df5cfda2de6aa8b22c0e1abc59bff781ce0c9b46d9e0591ea14b718
|
|
BLAKE2b-256 checksum How to use checksums |
6d9d494dde64b7afbfec6f8b4c6e35b9430290f875a2283123b877ec65ef5a79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.
Transparency logRelease files / retracesoftware-0.2.18-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | retracesoftware-0.2.18-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 3.2 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
d222f897c477ec7ee75536d23f2d4854a724a4b376a3911588ac79e558dc8674
|
|
BLAKE2b-256 checksum How to use checksums |
1947df39369e505405b10d692b17af25bdd91d5dc3d0401872d06540652706ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.
Transparency logRelease files / retracesoftware-0.2.18-cp312-cp312-macosx_12_0_arm64.whl
| Download URL | retracesoftware-0.2.18-cp312-cp312-macosx_12_0_arm64.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.12 macOS 12.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d8a6f20a91b0b602d0d3b9f2abd2178a4ebac10ee6e4a6242dd810ab0bec21c8
|
|
BLAKE2b-256 checksum How to use checksums |
6f3a706215863673eb8b0bd1413e71bf3b5868622f50f4fe057f84b0d8f60649
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.
Transparency logRelease files / retracesoftware-0.2.18-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | retracesoftware-0.2.18-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 3.1 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
cb5448c9b123286c7b4e8de7bde24f39a35ba9ca66d7905480b9c030138d40b1
|
|
BLAKE2b-256 checksum How to use checksums |
fd434ac69c8d016f132dc95fd1c1c22fca84ded201bb0c4322efe560db987461
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.
Transparency logRelease files / retracesoftware-0.2.18-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | retracesoftware-0.2.18-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 3.1 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
4613662bf053c5dba181e5625640d03e5f0d3735acd568a0debe7f6b730b85de
|
|
BLAKE2b-256 checksum How to use checksums |
d2822df80c10d9fc402522885fd11ef8f1e126b9afc2a139b0b6929851373d54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.
Transparency logRelease files / retracesoftware-0.2.18-cp311-cp311-macosx_12_0_arm64.whl
| Download URL | retracesoftware-0.2.18-cp311-cp311-macosx_12_0_arm64.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.11 macOS 12.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d67f955c01c59866363ffd1d860c2a80f044a73e34dc194adbbb8d3313898029
|
|
BLAKE2b-256 checksum How to use checksums |
b3f64bfe4324dfc33103e53e57fb35bc5b1d09805cb0b20b405ff10730ac4dee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.
Transparency log