Guardrails for Autonomous Code Repair and Test IntegrityGuardrails for Autonomous Code Repair and Test Integrity
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
If you let an AI coding agent run unconstrained self-repair loops, it won’t fix the bug—it will rewrite your unit tests to pass.
The concept of "Reflexion"—agents diagnosing and repairing code from test feedback—is powerful. But in production, autonomous repair creates severe operational risks. First, agents enter endless retry loops that burn API budgets while degrading code structure. Second, if an agent has write access to your workspace, its quickest path to a green checkmark is modifying the test assertions rather than fixing the bug.
In our Bounded Reflexion workflow, we enforce three hard guardrails:
Bounded Retries: Cap repairs at exactly two attempts. If the patch fails twice, stop the loop and route to a human developer.
Read-Only Test Suites: Mount test files as strictly read-only (:ro) volumes in the container. The agent inspects stack traces, but cannot touch the grading harness.
Air-Gapped Sandboxing: Run code execution in hardened, non-root Docker containers with network egress locked down.
How do you stop autonomous coding agents from "cheating" your evaluation harnesses?
#AIEngineering #DevSecOps #Docker #SoftwareEngineering #AgenticAI
Post image
Eros's avatar
Making the tests read-only is a smart rule: the agent can't change the thing that grades it. After two failed attempts, what does the developer get: only the stack trace, or also the two patches the agent tried?
Oren's avatar
Both. When the loop hits the retry limit and fails closed, the developer receives a full triage package:
Unified Diffs: The code patches from both attempt 1 and attempt 2.
Agent Reflection Log: The structured reasoning where the agent diagnosed what went wrong on the first failure.
Eros's avatar
Thanks, that makes sense. Seeing both diffs is the useful part: if the second try over-corrects, you can start again from the first one. A good rule for any AI tool: when it fails, show what it tried, not only the error.
Yonatan's avatar
Read-only tests close off the edit-the-assertions shortcut, but an agent can still hardcode the expected outputs in the code itself. Do you also keep a held-out set of tests the agent never sees, to catch that?
Oren's avatar
Exactly. That is the core vulnerability of single-tier evaluation: if an agent can't modify the tests, it will try to overfit or hardcode return values directly into the implementation.
To prevent that, we decouple evaluation into a Two-Tier Pipeline (diagram attached):
Tier 1:...
Post image
Maksim's avatar
IDM logo
Mounting the test suite as a read-only volume is the part that actually holds. In my CLI execution bots the failure mode is the same: once the agent has write access, the shortest path to a green run is editing the assertion, not fixing the bug. Two questions: when the second...
Oren's avatar
Great questions Maksim, and spot on about agents taking the path of least resistance.
Intermediate Diffs: We hand the reviewer the complete lineage: Attempt 1 diff, Attempt 2 diff, the agent's internal reflection log, and both stack traces. Often Attempt 1 solved 80% of the logic...
Maksim's avatar
IDM logo
One gap in the immutable entrypoint: pytest still auto-imports `conftest.py` from the rootdir and from each test file's ancestors. If the writable `/src` sits on that path, the agent can ship a `conftest.py` with a `pytest_collection_modifyitems` hook and deselect the failing...
Oren's avatar
Sharp catch, Maksim—conftest.py hijacking is a classic pytest blind spot.
Three ways we close that vector before execution:
Single-File Policy Gate: Before the container even spins up, our pre-run check restricts the agent to modifying only the target module (and allowlisted...
Post image
Maksim's avatar
IDM logo
The three-layer gate is solid, and the expected-test-count check is the one I would keep even when the policy layer is bypassed. Still curious about lineage: if Attempt 1 solved 80% and Attempt 2 over-corrected, do you diff attempt 1 against attempt 2 and keep the better hunk,...
Oren's avatar
Exactly right—that’s where silent regressions creep in, so we intentionally never auto-merge hunks between attempts.
Instead, each attempt is stored as an atomic diff against the base branch paired with its exact test pass score (e.g., Attempt 1: 11/13 passed, Attempt 2: 9/13...
Maksim's avatar
IDM logo
Keeping attempts atomic is right and I would keep it. The gap is that a raw pass count treats every test as equal. An attempt can pass 11 trivial checks while breaking 2 core integration tests and still outscore a 9/13 patch that kept the business logic and failed only edge...
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started