Letting an AI Agent Open PRs Without Letting It Break Things
November 5, 2026
The demo version of "AI fixes your bugs" is easy. Point a model at a repo, hand it a shell, ask it to fix the issue, and watch it open a pull request. It works often enough to be impressive and fails often enough to be dangerous.
When I built Dequeuee — a tool where a bug report goes in and a draft PR comes out — most of the engineering wasn't the agent. It was deciding what the agent is not allowed to do, and making those limits structural rather than polite requests in a prompt.
Split "understand" from "change"
The single most useful decision was splitting every issue into two separate runs with two different toolboxes.
The investigate run gets read-only tools: list a directory, read a file, search the code, read
the git history, and run commands in a sandbox. It cannot write a single byte to the repo. It ends
by calling submit_proposal with a root cause, the affected files, a step-by-step plan, the risks,
a test plan, and a confidence level.
Then it stops. A person reads the proposal, discusses it in a thread, and approves it — or doesn't.
Only after approval does an implement run start, and only that run gets write_file,
edit_file, and delete_file. This isn't enforced by telling the model "please don't edit files
yet." The write tools simply don't exist in the first run. You can't prompt-inject your way into a
tool that isn't there.
The side effect I didn't expect: the proposal is more valuable than the PR. Reviewers can reject a wrong diagnosis in thirty seconds, before anyone spends time reviewing a wrong diff.
Let the agent say "this is a business decision"
A surprising number of bugs aren't really code problems. Should a waiver that starts on the incident day cover it? Do refunds round up or down? Should we fix past records or only new ones? An agent will happily pick an answer and write very confident code around it.
So the investigate run has a second exit: ask_product_owner. Instead of proposing a fix, it
states what it found and asks short, one-decision questions. The run ends there, and the fix is
proposed only after someone who owns the business rule has answered. Having spent years on a fleet
platform where "who gets charged" is the whole bug, this felt more important than any model
upgrade.
Treat every command as hostile
The agent needs to run tests and reproduce bugs, which means running arbitrary shell commands from someone else's repository. Each one runs in a throwaway Docker container:
--network none— no network, except for the repo's one-time setup step that installs dependencies- 2 GB of memory, 2 CPUs, and a 512-process limit, so a fork bomb or runaway test can't take the worker down
no-new-privileges, so nothing inside can escalate- none of the worker's environment variables — no API keys, no GitHub tokens
- a hard timeout that kills the container, and output capped so a chatty test suite can't flood the model's context
File tools get the same treatment: every path is resolved and rejected if it lands outside the checked-out repositories.
Put a ceiling on cost, not just on behavior
Agent loops are expensive in a sneaky way: every turn re-sends the whole conversation, so the next turn always costs at least as much as the last. A run that's slightly lost doesn't fail — it just keeps spending.
Each run has a hard token cap. When it's mostly used up, the agent gets one nudge to wrap up and submit its best current understanding; past the cap, the loop stops cleanly and reports the usage instead of crashing. On top of that, each workspace has a monthly budget checked before a run even starts. Teams bring their own model keys (Claude, Gemini, or any OpenAI-compatible API), which keeps the incentives honest: the person paying can see exactly what each run cost.
Make the last step boring
When the implement run finishes, the worker commits to a dedicated dequeuee/issue-… branch and
opens a draft pull request. Never a merge, never a push to the default branch. The PR goes
through the same review and CI as a human's would. Bug reports from outside the team — the
embeddable widget, or a monday.com ticket from someone who isn't linked to a workspace — land in a
triage queue first, so a stranger can't use a "bug report" to steer an agent at your codebase.
What I'd tell anyone building one
The model matters less than the shape of the system around it. Separate reading from writing, make dangerous tools physically absent rather than discouraged, give the agent a legitimate way to say "a human needs to decide this," and cap the cost of being wrong. With those in place, a mediocre run wastes a few cents and a minute of review. Without them, a great model is still one bad assumption away from a mess.