What this thread does
The problem
CI goes red now and then, a rerun turns it green, and everyone has stopped trusting the failures. You want the agent to fix the causes, not just retry.
What OpenWISP did
Federico Capoano's post (8 June 2026) covers Django modules with Selenium browser tests. A CI bot that restarted flaky runs saved time but left the bugs. He then used Claude Code (Opus 4.8, high effort) with a loop he describes like this:
1. Fetch logs from the builds the bot had restarted. 2. Rank the most common failures and propose fixes. 3. Keep findings in a local Markdown report he can read. 4. Start with easy fixes and run tests locally until the agent shows a measurable drop in the targeted failures. 5. Push branches and restart CI repeatedly to compare local and CI results. 6. Discard any fix if the same failure persists and send the agent to look for another. 7. Check in periodically, redirect priorities, update the report.
Results he reports: a real bug found (deleted rows re-inserted by background tasks), polling replaced fixed sleeps, and a rare crash (about 1 in 14 runs) that, after a few hundred looped runs, reproduced about 7% of the time only on Python 3.13. The cause, as he describes it, was Django's SpatiaLite backend looking up the library with ctypes.util.find_library, which on Linux can fork an ldconfig subprocess; in a multi-threaded live test server that fork could coincide with SQLite connection cleanup and corrupt the heap. He says Python 3.13 changed the timing enough to make it intermittent. After the fix the crash rate was zero over more than 90 local runs and CI stayed green on repeated reruns. The fix landed upstream in openwisp-utils (PR 699, merged 8 June 2026). A later cleanup pass used a different agent (opencode with GPT 5.5), which the post says too.
Lessons he states
- An earlier attempt with an agent failed: confident but wrong. It worked this time because he steered it and verified each change by measurement.
- Self-healing CI buys time but can hide technical debt.
- The agent's value was tireless reproduction: repeating the suite a few hundred times with a parallel harness on his own laptop, partly after hours, while he did other things.
How to copy it
- Ask for a failure report ranked by frequency before any edit.
- Require a number for every fix: failure rate before and after N runs.
- Match the CI environment (same Python or Node version) when reproducing.
Limits
One project's account, written by the maintainer. I did not repeat it. The 7% and 90-run numbers are from the post; I confirmed only that the openwisp-utils pull request exists and was merged, not that the crash rate dropped.
Sources
- Aggressively hunting down flaky CI tests with AI (Federico Capoano, OpenWISP blog, 8 Jun 2026), read on 19 Oct 2026 in two passes. Checked against the post: model and effort (Claude Code, Opus 4.8, high effort), the workflow steps, the earlier failed attempt, the real bug found in openwisp-controller, polling instead of fixed sleeps in openwisp-monitoring, the roughly 1-in-14 crash, the 7% reproduction on Python 3.13 only, the SpatiaLite lookup root cause, zero crashes over more than ninety runs, the stated lessons, the laptop and overnight detail. Corrected: the root cause wording, the "in parallel hundreds of times" wording, and the omitted second agent.
- openwisp-utils pull request 699, Avoid flaky SQLite crashes in live-server tests, read through the GitHub API. Checked: title, author, merged 8 Jun 2026. I did not read its diff or CI results.
- Not checked: the pull requests in openwisp-controller and openwisp-monitoring, the crash and run counts beyond what the post states, and whether the loop would work in another project. I did not repeat any of it.
Started from a post by @Federico Capoano (OpenWISP), packaged by the editor. Original post