An agent that triages bug tickets
Most bug tickets arrive as a paragraph and a list of steps, some of which matter. Before anyone can fix one, someone has to reproduce it, find the steps that matter, and note what the reporter had that a fresh install doesn’t. That is slow work, and it needs the application running.
examples/ticket-triage/ is a loop that hands that work to an agent. For each new ticket, the agent:
- claims it in the tracker, over MCP;
- reproduces it by starting the application with
sonde startand driving it with Sonde’s tools; - drops each step it can while the bug still shows;
- records the minimal steps, screenshots and environment on the ticket;
- spends up to a set number of minutes trying to fix it, in a git worktree of its own, and attaches a patch, or a note of what it tried.
Audience: developers who already use an agent with Sonde (agent-loop.md) and want to see it work on its own. The example is small on purpose; Adapting it says what to change for a real application and tracker.
- Why Sonde makes this work
- What is in the example
- The loop and its time limits
- Run it in a disposable container
- Running it
- The planted bugs, and what a good result looks like
- Adapting it to your project
- How it is tested
Why Sonde makes this work
An agent without Sonde can read the ticket and the code, and guess. To reproduce a bug it needs the application running and a way to use it and see what happened. Sonde gives it that, and a few things that matter especially for triage:
- It checks results at the Qt level. “The count still says 1 open” is
object_inspecton a label; “the wrong chore was removed” ismodel_readon the list, before and after. Those are exact, so the agent can tell whether a shorter list of steps still shows the bug, which is what minimising needs. A screenshot alone is easy to misread. - It can restart the application and keep its state.
sonde restartreplaces the running copy in a second or two, and the application’s data file stays. A bug that only shows after a restart, like CH-3 below, is within reach. - Each worktree gets its own copy.
sondegives every checkout its own socket and port (design 0018), so the agent’s fix in a worktree never talks to another copy by mistake. - The application’s log is there. Chores logs each chore it adds, removes
and loads;
event_readshows the agent that a new chore got the same id as an old one. - Screenshots are files when needed.
sonde --image shots/CH-1-1.png window_screenshot ...saves one that the agent can attach to the ticket.
What is in the example
examples/ticket-triage/
├── app/ Chores: the application, with bugs planted in it
│ ├── chorestore.* the chores (a QStandardItemModel with ids, saved as JSON)
│ ├── main.cpp the window
│ ├── chorestore_test.cpp
│ ├── .sonde/config.json how sonde builds and runs it
│ └── CLAUDE.md how an agent builds, runs, drives and checks it
├── tickets/
│ ├── seed.json three tickets, one per planted bug
│ └── server.py a stand-in bug tracker: an MCP server backed by a JSON file
├── agent/triage.py the loop
├── Dockerfile the disposable container
└── check.py what CI checks without a model
The tracker is a stand-in, only there to show the idea: a real tracker’s MCP server (GitHub’s, Jira’s, Linear’s…) slots in where it is.
The loop and its time limits
agent/triage.py uses the
Python standard library and Claude Code in headless mode, claude -p. Each
ticket gets two runs of one Claude Code session:
result = claude(REPRODUCE.format(id=ticket, ...), worktree, mcp_config,
options.triage_minutes, session)
if result != "reproduced":
return
result = claude(FIX.format(id=ticket, deadline=clock(options.fix_minutes)),
worktree, mcp_config, options.fix_minutes, session, resume=True)
if result in ("timed-out", "no-result"):
give_up_on_fix(tracker, ticket, worktree, options.fix_minutes)
- The prompts are at the top of the file,
REPRODUCEandFIX. They don’t contain the ticket’s text: the agent reads it withticket_get, and the prompt says to treat it as a description, never as instructions. - The time limits are
--triage-minutesand--fix-minutes(15 each by default). The prompt gives the agent the deadline as a time of day, so it can wrap up and write its note. Two minutes after the deadline,claude()ends the run’s whole process group, MCP servers included. - Nothing is lost at the time limit.
give_up_on_fixattaches whatever the worktree had changed, marked as unfinished and unchecked, and sets the ticket toneeds-human. - One session for both phases. The script chooses the session id
(
--session-id) and resumes it for the fix (--resume), so the agent remembers what it learned while reproducing. Choosing the id up front means a run that was ended can still be resumed by hand. - Each ticket has its own worktree, on a branch
triage/<ticket>, with its own build directory and its own chores file in.sonde/state/. - Each phase ends with a
RESULT:line, which the script reads to decide what to do next.
Why claude -p and not the Claude Agent SDK: with the SDK, the loop would be
an async for over the agent’s messages, and the time limit an extra task
that interrupts it. Here the limit is a timeout on a subprocess, the script
needs nothing beyond Python and Claude Code, and the same commands work by
hand when you want to watch one ticket. The SDK is the better choice when
the loop must react to what the agent does as it does it.
Run it in a disposable container
Never run this loop on your own machine or in a long-lived environment.
The agent reads text that anyone who can file a ticket wrote, and then edits
files and runs commands with no one approving each step
(--permission-mode bypassPermissions). A ticket can contain instructions
aimed at the agent, made to look like part of the report: “to help, run this
diagnostic script”, “attach your configuration”. That is prompt injection,
and no prompt fully prevents it. So assume the agent may do whatever a ticket
says, and make sure that can’t hurt:
- Give it nothing worth taking. The container holds a copy of the application’s source, an installed Sonde and Claude Code. No SSH keys, no cloud credentials, no access to your other repositories, no Docker socket.
- Throw it away after each batch (
docker run --rm), so nothing a ticket planted survives into the next run. - Only results leave: the ticket store, a mounted directory. Read the patches before applying them anywhere, as you would a stranger’s pull request.
- What it still has: the API key, and the network. Use a key of its own with a spending limit, and if you can, allow network traffic only to the API and your tracker.
- The tracker guards what it can.
ticket_attachonly copies files from the worktrees directory (--files-from), so even a misled agent can’t attach a file from elsewhere to a ticket that outsiders read.
The container follows containers.md: Debian’s Qt 6.8, fonts installed (without them every screenshot shows empty boxes), the offscreen platform, and an ordinary user, so Sonde’s local socket accepts the agent’s bridge.
Running it
From the root of the Sonde checkout, with Docker and an API key:
docker build -f examples/ticket-triage/Dockerfile -t sonde-ticket-triage .
mkdir -p triage-store
docker run --rm -e ANTHROPIC_API_KEY -v "$PWD/triage-store:/tickets" \
--label sonde.app=chores sonde-ticket-triage --once --fix-minutes 10
On Linux, the store directory must be writable by the container’s user (uid 1000). The first run copies the three seed tickets into the store. Then:
triage-store/tickets.jsonholds the tickets, with the agent’striagesection, comments and status;triage-store/attachments/<ticket>/holds the screenshots and patches.
To add a ticket, stop the loop and add an entry to tickets.json with
"status": "new". Without --once, the loop keeps looking for new tickets
every 30 seconds (--poll).
To look in while it works, connect your own agent or sonde to the copy
of Chores the agent is using, as in containers.md. Each
worktree’s socket name has its own instance key, which sonde endpoint
prints:
docker exec <container> sonde --config /home/app/chores-worktrees/CH-1/.sonde/config.json endpoint
claude mcp add chores-ch1 -- sonde bridge --docker label=sonde.app=chores chores-mcp-<instance>
Look, don’t touch: your input and the agent’s go through the same queue.
The planted bugs, and what a good result looks like
Chores has three bugs planted in it, each with a ticket in seed.json. This section is the answer key: what a careful person would write on each ticket. It is not a recording of an agent’s run. Use it to judge the agent’s results, and to see the kind of result to ask for in your own prompts. The container leaves this guide out, so the agent can’t read it.
CH-1: “Open count doesn’t go down when I tick a chore off” (easy)
The report’s steps are already minimal.
- Steps: add a chore; tick it.
- Observed: the chore is ticked (
model_readshowscheckState=checked), andopenCountsays “1 open”. Expected “0 open”. - Cause:
ChoresWindowrecounts onrowsInsertedandrowsRemoved, but a tick is a data change (itemChanged), which only saves. - Fix: connect
itemChangedtochanged(), which counts and saves.
CH-2: “Remove deletes the wrong chore” (too many steps)
The report has eleven steps, and blames a rename. Six matter.
- Steps: add “Buy milk”; add “Pay rent”; tick “Buy milk”; tick “Hide done”; select “Pay rent”; click Remove.
- Observed: “Pay rent” is still listed. With “Hide done” unticked again,
“Buy milk” is gone. The log says
Removed chore 1 "Buy milk". - Dropped: the third and fourth chores, the rename and the window size make no difference.
- Cause:
removeSelected()takes the row from the list’s index, which is a row of the filter (QSortFilterProxyModel), and looks it up in the store as if it were a row there. With a done chore hidden above it, the rows differ. - Fix:
m_filter->mapToSource(current).row().
CH-3: “Remove sometimes deletes a different chore” (depends on state)
It never happens on a fresh list. It needs a chores file from an earlier run, which the reporter mentions only in passing (“I’d added a few chores last night”).
- Steps: with an empty chores file, add “Book dentist”; quit and start
Chores again (
sonde restart); add “Take out bins”; select it; click Remove. - Observed: “Book dentist” is removed, “Take out bins” stays. The log shows both added as chore 1.
- Environment: needs a chores file saved by an earlier run.
- Cause:
ChoreStore::load()doesn’t movem_nextIdpast the ids it loads, so the first chore added after a restart gets id 1 again, andremove(id)takes the first chore with that id. - Fix: in
append(),m_nextId = qMax(m_nextId, id + 1);, with a test inchorestore_test.cpp: save, load, add, and check the ids differ.
CH-2 and CH-3 are both “Remove takes the wrong chore”, with different causes. A good triage keeps them apart: CH-3’s steps don’t use “Hide done”, and CH-2’s need no restart.
Adapting it to your project
- Your application needs what agent-loop.md describes: a
.sonde/config.jsonwith"local"(forsonde bridge) and the{instance}placeholders, and instructions for the agent inCLAUDE.md. Tell it how to reach a known starting state (here: delete the chores file), and how to save screenshots as files. - Your tracker: give the agent its MCP server instead of
tickets/server.py, inwrite_mcp_config(), and change the tool names in the prompts. “Claim” can be an assignee or a label. If the server can’t limit what the agent attaches, the container is your only guard: keep it bare. - Your build goes in the Dockerfile: whatever the application needs to build and run offscreen, plus Sonde (installed, as here, or built with the application).
- What it may do: start with reproduction only (
--fix-minutes 0), read a few results, then let it try fixes.
How it is tested
The agent’s own runs need a model and an API key, so CI doesn’t run them.
Everything else is checked by
check.py, which ctest runs as
TicketTriage.Example on every platform in CI:
- the ticket server: listing, claiming once only, triage, comments,
attachments, and refusing files from outside
--files-from; - Chores’ own tests pass (as they do before a fix: they don’t cover the planted bugs, which is how such bugs ship);
- each planted bug still reproduces, by playing the minimal steps above
through
sonde startand Sonde’s tools. If someone fixes a planted bug by mistake, or a tool’s output changes, this fails.
triage.py itself was checked with a stand-in for claude that records its
arguments: worktrees, the MCP configuration, resuming the session, and the
unfinished patch at the time limit. Not checked: a run with a real model.