DEV Community

Cover image for Our CI agent fixed the bug. Then it put the bug back.
Tushar Tandon
Tushar Tandon

Posted on

Our CI agent fixed the bug. Then it put the bug back.

wo hours before the end of a 72-hour hackathon, our CI agent fixed a bug taken from the history of a real Python library. Then it took its own fix back out.

The library was boltons, and the bug was in SpooledStringIO.readline(0), which should return an empty string and returned a whole line. prOwl, our agent, traced it to Python's codecs reader, which sizes a read as size or 72. Zero is falsy, so a request for zero characters read up to 72. prOwl added an early return '' for length zero and ran the suite. Our guard stopped the run (trace):

policy: 621 tests ran but 623 ran earlier in this run; a fix may not remove or deselect tests
Enter fullscreen mode Exit fullscreen mode

The agent's next note:

The policy says only 621 tests ran this time versus 623 earlier, so I'll undo my change and rerun to see whether the drop comes from my edit.

It removed its fix, read the file back, and ran the suite again. The bug came back, and so did the count of 623. It worked out that the two "missing" tests had never been tests. It decided it couldn't prove that under the policy, and handed the fix to a person with the arithmetic written out (undo · rerun · handoff):

I reverted the change (confirmed at ioutils.py:462-466) and did not try to work around the policy.

The agent was right, and the guard was ours. It was also the third time in 30 hours that our own bookkeeping had counted the wrong thing.

TL;DR. Three times in 30 hours, a guardrail in our agent counted a description of something instead of the thing itself. One broken commit became two pull requests. A Stop would have left a broken commit unfixed forever. A correct fix "lost" two tests that were never tests. The model was right every time. Count the thing itself, never a description of it. Each section ends with a test you can run on your own agent.

This is our Near Miss write-up for Agentware 2026.

Three counts, three wrong units

An unattended agent's safety isn't only the model's judgment. Much of it is plain code that answers bookkeeping questions. Have we already handled this? Is that work finished? Did that test run prove anything? Each of our three near misses was one of those answers counting the wrong unit.

Hour The count What it counted What it should have counted What nearly happened
40 open cases descriptions of a failure broken commits two identical PRs on GitHub, 51 s apart
69 fixes in flight records saying "fix proposed" fixes that reached GitHub after a Stop, prOwl would skip a broken commit forever
70 tests run lines in pytest's summary tests a correct fix blocked and undone

"The model wasn't the problem" is a common conclusion after an agent nearly misbehaves, and it's too broad to act on. Ours is narrower, and you can test for it: each of these guards was a count, and each one counted a description instead of the thing.

Count the thing itself, never a description of it. Not who noticed it, not how a log worded it, not what a status field claims.

What prOwl is

prOwl is our Developer Workflow entry: a night shift for a repository with nobody on call. When main breaks, prOwl reproduces the failure in a Docker sandbox with no network. It fixes the code (never the tests) under a guard enforced in code, re-tests the branch in a clean checkout, and opens a draft PR. It never merges or approves. Stop bumps a "kill epoch" that every loop and every GitHub write checks first. Every run writes a signed, hash-chained trace, and the agent's quotes in this post come from those traces.

Our 2:35 demo. A failed Actions run becomes draft PR #8 in 38 seconds, and Stop cancels a second run 37 ms after the click.

Near miss 1: two pull requests for one broken commit (hour 40)

On November 29 we pushed a commit called "Speed up percent_of with plain float math" to a fresh playground repository. It swapped a Decimal calculation for round(cents * float(rate) / 100). Python's round() rounds half to even, so 2.5 cents became 2, and two money tests failed.

prOwl notices a broken main in two ways, on purpose. Repo watch runs the tests on every new commit, so it covers repositories without CI. Actions log ingestion reads failed GitHub Actions runs. Both noticed commit 322591d, 47 seconds apart. Both runs found the cause, changed the same line, and passed the clean-checkout re-test.

Opened (UTC) Title
PR #2 09:56:11 Restore half-up rounding in percent_of (fixes CI on 322591d)
PR #4 09:57:02 Restore half-up rounding in percent_of (fixes CI at 322591d)

We had two layers of duplicate protection. Both counted descriptions.

  1. The case key included the detector. Each event's ID was hashed from its type, repo, ref and source. sentinel:322591d and github:actions/… are different sources, so one commit became two cases.
  2. The failure signature depended on the log's formatting. prOwl skips a failure whose signature (the sorted names of the failing tests) already has a fix open. Our pattern for test names was anchored at the start of a line. But gh run view --log-failed puts the job, the step and a timestamp in front of every line.
pytest  Run python -m pytest -q 2026-11-29T09:55:30.3447682Z FAILED tests/test_pricing.py::test_bulk_discount_applies_at_threshold - assert 10000 == 9000
Enter fullscreen mode Exit fullscreen mode

The line shape our regression test replays: three tab-separated fields come before FAILED.

So the Actions copy fell back to a hash of the log, and a hash never equals a list of test names. As far as prOwl could tell, no fix was open.

The fix, commit ae51093, landed 43 minutes after PR #4. It strips the prefix and keys a CI failure on the commit, whoever noticed it:

# a failing commit is one case, whether repo watch or GitHub Actions noticed it first
source = None if event["type"] == "ci_failure" else event["source"]
Enter fullscreen mode Exit fullscreen mode

A regression test sends the same commit from both detectors and asserts that one case is queued. A person marked PR #2 ready and merged it. We closed PR #4 with a comment linking the fix.

Try it on your agent: send one event through every detector you have, and count the cases. A new detector adds a new description of the same thing.

Near miss 2: zero fixes after a Stop (hour 69)

By hour 69 the kill switch was the part we trusted most, so we tried to break it properly. One complete fix-and-publish run writes 19 trace events. prowl stopsweep runs the case 19 times from scratch, pressing Stop right after event N on run N. Then it presses Resume and lets the watcher look at the same commit again. A stop point passes only if nothing is written after Stop, no orphan branch is left, the trace is intact, and the remote ends with exactly one draft PR. Never zero, never two. (The model's decisions are scripted in the sweep; everything else is real except GitHub, as the limits below explain.)

The first sweep failed at 3 of 19 points, all between the agent finishing and the draft PR landing. Two of them were the near miss: Stop right after the clean-checkout re-test (#15), and Stop after the push but before the draft PR (#17). In both, the run had already been recorded as "fix proposed". Nothing was published and nothing looked wrong. But the rule that decides whether to work on a commit is skip it if a fix was already proposed, the same duplicate rule we had tightened at hour 40. It would have believed the record and skipped that broken commit forever. The third failure (#16) was the reverse: a push that never started was marked "delivery uncertain".

A dedupe rule is a promise that an earlier attempt finished. Find the record it trusts, and check everything that can write that record: Stop, crashes, retries.

Now a run stopped before its draft PR reaches GitHub is recorded as stopped, and the watcher retries it after Resume. Any unpushed branch is removed. If Stop lands after the PR was delivered (#19), the record stands, and Resume opens no second PR. Sweep: 19 of 19 · regression tests

A crash gives the code no chance to clean up. An hour later, prowl crashtest killed the real watcher process with SIGKILL at five points. One was just after GitHub accepted the draft PR, before prOwl had recorded it. Because prOwl journals every GitHub write before making it, and reconciles on restart with read-only lookups, GitHub never received a second draft PR at any of the five points. A delivery it can't confirm waits for a person. Crash test: 5 of 5

Try it on your agent: press Stop after every event of one full run, not just once, and count the side effects after Resume. Then kill -9 it the moment the remote says yes. When you don't know whether a write landed, look; don't retry.

Near miss 3: two tests that were never missing (hour 70)

Back to boltons. To test prOwl on code we had never seen, we rebuilt ten historical bug fixes from it. Each case is the commit before the upstream fix, plus only the tests that fix introduced. A case passes only if prOwl proposes a fix on its own branch, touches no test file, and the entire upstream suite (600+ tests) passes in a clean checkout. Everything ran locally in Docker with no network, and nothing was posted upstream. Benchmark

The guard came from a teammate's review at hour 17. The cheapest way for an agent to turn CI green is to make tests stop running. So prOwl remembers the largest test count it has seen in a run, and it won't verify a passing run below that count. The comment in our code says why: a "pass" that ran fewer tests than before proves nothing. Guard

But boltons uses pytest subtests.

State of the library What pytest reported What our guard counted
Broken 2 failed, 621 passed, 20 subtests passed 623
Fixed 621 passed, 22 subtests passed 621

Both failures were subtests of one test, test_readline_zero_length: one ran in memory (rolled=False) and one after rollover to disk (rolled=True). The parent test was already among the 621, and pytest reports each failing subtest as an extra failure on top of it. When the subtests passed, they moved to the separate "subtests passed" column, which our parser ignored. Our guard was counting entries in pytest's summary, not tests.

What the agent did next is the behaviour we most want to keep. It didn't retry, reword its fix, or touch the tests. It treated the guard's message as a claim it could check: undo, rerun, compare. Even when that check suggested the guard was miscounting, it didn't overrule the guard:

I can't verify this under policy, so escalate with the fix.

That choice cost us in our own numbers, and that's how we found the bug. We scored the benchmark on verified repairs, not on obedience, so the first pass went down as 9 of 10. The final status, escalated, looks like an ordinary miss, but the trace shows the fault was in our code. So make "stop and ask, with evidence" a real outcome, and count it as a miss: then a broken guard shows up in your numbers. Both attempts

We fixed the count where prOwl reads pytest output. It now subtracts the SUBFAILED and SUBERROR records from the summary total, and the rule against a shrinking suite stays. Three regression tests pin it down (tests · parser):

  • The real broken and fixed reports must both count as 621.
  • 620 passed, 22 subtests passed must still count as fewer tests.
  • An ordinary 1 failed, 8 passed must still count as 9.

Eight minutes after the handoff, the case ran again from scratch. prOwl proposed the same early return '' on its own branch, and a clean checkout passed the full boltons suite. That made 10 of 10, and both attempts stay in the results. Verified re-run

One limit remains. Our guard compares two numbers. If one test disappears and a different one appears, the count stays level. If your promise is "the same tests ran", compare test IDs, not totals.

Try it on your agent's guard:

  • Give it a real failing report and its fixed twin. It must accept the fix.
  • Take one test out of the fixed report. It must block.
  • Swap one test for a different one. If it still accepts, your guard counts tests but can't tell which tests ran.

What we haven't proved

  • Stop can't recall a write GitHub already accepted. It prevents every later write, but a PR that landed before the click stays up.
  • The Stop sweep and the crash test script the model's decisions, and in them GitHub is a local remote with a counting transport. Our live GitHub evidence is PR #2 and PR #4, the demo's PR #8, and the 37 ms Stop followed by PR #9 after Resume.
  • An unconfirmed delivery after a crash waits for a person. We chose blocking over guessing.
  • The corpus is small: one playground repository, and ten bugs from one library. boltons is public, so its fixes may be in a model's training data.

Check it yourself

You need Git and Python 3.12 or newer. It costs $0, with no API key and no GitHub account. The README has the same quickstart.

git clone https://github.com/TushxrTxndon/prOwl.git && cd prOwl
git checkout --detach 4e3c12aff25c8057449614628fdf5b12e9072f53
python -m venv .venv && . .venv/bin/activate      # Windows: .venv\Scripts\activate
python -m pip install --require-hashes -r requirements.lock
python -m prowl judge
python -m pytest -q tests/test_subtests_count.py tests/test_stop_publish.py "tests/test_github.py::test_one_ci_case_per_commit_whoever_notices_it"
Enter fullscreen mode Exit fullscreen mode

judge replays our evaluation scenarios against the real tools, verifies every committed trace and prints a scorecard. The last command runs the regression tests for all three near misses. python -m prowl audit <path to trace.jsonl> checks that a trace hasn't been edited. Every code and trace link in this post points at our submitted commit, 4e3c12a.


Built in 72 hours for Agentware 2026, run by Hackathon Raptors (@raptorsdev). We wrote prOwl with Claude Code as our pair programmer, and the boltons benchmark ran Claude Opus through Claude Code. The bugs in this post were ours. Thanks to FileClerk for sponsoring the Near Miss write-up awards.

Top comments (1)

Collapse
 
remycalder profile image
Remy Calder •

on the limit you mention at the end, one way to get test ids instead of totals without parsing the summary line at all: run with --junitxml (or a small conftest hook that writes item.nodeid for every collected item to a file) on main and on the fix branch, then diff the two sets. the guard passes if nothing in main's set is missing from the branch's set, and the handoff can list the exact ids that went missing instead of 621 vs 623. it also catches the one-out-one-in swap.

two things to watch with ids. parametrized tests put the param values in the id (test_x[2.5-2]), so a fix that touches a param list looks like a remove plus an add, probably worth showing to a person rather than blocking. and subtests don't get their own node ids at collection time, so compare on the parent and treat subtest results as part of it, which is roughly what your SUBFAILED fix does now.

same idea for near miss 1: if the Actions job uploads the junit file as an artifact, prOwl can read the failing test ids from it instead of from gh run view --log-failed, so the log prefix stops mattering.

(disclosure: I'm building something in the testing-coding-agents space, and this comment was drafted with AI)