<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Oscar Barrios</title>
    <description>The latest articles on DEV Community by Oscar Barrios (@srbarrios).</description>
    <link>https://dev.to/srbarrios</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F379610%2F2973f987-4615-4a23-a8e0-b9cb7da10949.png</url>
      <title>DEV Community: Oscar Barrios</title>
      <link>https://dev.to/srbarrios</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/srbarrios"/>
    <language>en</language>
    <item>
      <title>My AI Testers Aren't Allowed to Touch the Browser. That's Why Their Bugs Are Reproducible</title>
      <dc:creator>Oscar Barrios</dc:creator>
      <pubDate>Tue, 24 Nov 2026 17:43:29 +0000</pubDate>
      <link>https://dev.to/srbarrios/my-ai-testers-arent-allowed-to-touch-the-browser-thats-why-their-bugs-are-reproducible-j7m</link>
      <guid>https://dev.to/srbarrios/my-ai-testers-arent-allowed-to-touch-the-browser-thats-why-their-bugs-are-reproducible-j7m</guid>
      <description>&lt;p&gt;Ask an LLM agent to explore a web application and it will happily come back with a list of bugs. Then try to reproduce them.&lt;/p&gt;

&lt;p&gt;Which page was it on? Which button did it click, and with which selector? Was that error real, or a misread of the DOM? Without answers, a bug report written by an AI is just an opinion, and developers are right to ignore opinions.&lt;/p&gt;

&lt;p&gt;That is the real problem with AI-driven testing. Finding "bugs" is easy. &lt;strong&gt;Finding bugs a developer will believe&lt;/strong&gt; is hard.&lt;/p&gt;

&lt;p&gt;So I built &lt;a href="https://github.com/srbarrios/agentic-test-explorer" rel="noopener noreferrer"&gt;Agentic Test Explorer&lt;/a&gt; around one rule: &lt;strong&gt;the agents think, but they never touch the browser.&lt;/strong&gt; Everything they do goes through a deterministic engine that records it, and every bug ends up as a Playwright test you can run on your machine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Eight LangGraph agents, each playing a different kind of user, explore any web app configured with a small &lt;code&gt;config.yaml&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Agents emit &lt;strong&gt;JSON intents&lt;/strong&gt;. A Playwright engine validates them, executes them and appends them to an immutable &lt;strong&gt;Action Tape&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;When an agent finds a bug, the tape is translated into a runnable &lt;code&gt;reproduction_*.spec.ts&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The engine &lt;strong&gt;rejects brittle selectors&lt;/strong&gt; (XPath, &lt;code&gt;nth-child&lt;/code&gt;, positional chains) before they reach the browser.&lt;/li&gt;
&lt;li&gt;A SQLite-backed memory remembers pages, flaky selectors and known bugs between runs, and can generate regression missions from them.&lt;/li&gt;
&lt;li&gt;Point it at a GitHub pull request and it writes test missions for the UI areas the diff touches.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The architecture in one picture
&lt;/h2&gt;



&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    M[Mission YAML or PR URL] --&amp;gt; S{Supervisor&amp;lt;br/&amp;gt;routing LLM}
    S --&amp;gt;|next agent| A1[Persona agents&amp;lt;br/&amp;gt;ReAct loop]
    A1 --&amp;gt;|JSON intent| E[Browser engine&amp;lt;br/&amp;gt;validate + execute]
    E --&amp;gt;|DOM snapshot| A1
    E --&amp;gt; T[(Action Tape&amp;lt;br/&amp;gt;JSONL)]
    A1 --&amp;gt; SUM[Summarizer&amp;lt;br/&amp;gt;compacts history]
    SUM --&amp;gt; S
    S --&amp;gt;|FINISH| R[Report + .spec.ts + screenshots]
    T --&amp;gt; R&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;It is a &lt;strong&gt;supervisor-worker swarm&lt;/strong&gt; built with LangGraph. A supervisor decides which persona acts next; the persona runs a ReAct loop with its tools; a summarizer keeps the conversation bounded; control goes back to the supervisor until it decides the mission is done.&lt;/p&gt;

&lt;p&gt;This is the actual graph for the standard swarm. I didn't draw it by hand: it is the Mermaid diagram that the tool's own Visual Mode generates, with the active agent highlighted.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;stateDiagram-v2
    new_user_agent : New User
    power_user_agent : Power User
    adversarial_user_agent : Adversarial

    [*] --&amp;gt; Supervisor
    Supervisor --&amp;gt; new_user_agent
    Supervisor --&amp;gt; power_user_agent
    Supervisor --&amp;gt; adversarial_user_agent
    Supervisor --&amp;gt; FINISH

    new_user_agent --&amp;gt; Summarizer
    power_user_agent --&amp;gt; Summarizer
    adversarial_user_agent --&amp;gt; Summarizer
    Summarizer --&amp;gt; Supervisor
    FINISH --&amp;gt; [*]

    classDef active fill:#10b981,stroke:#047857,stroke-width:4px,color:#000
    class power_user_agent active&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;
  
  
  Rule #1: the brain is not the hands
&lt;/h2&gt;

&lt;p&gt;Agents get exactly one way to act on the page: the &lt;code&gt;execute_browser_command&lt;/code&gt; tool, which takes a &lt;strong&gt;strict JSON object&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"fill"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"selector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"input[aria-label='Search']"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"value"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eleven actions are allowed: &lt;code&gt;navigate&lt;/code&gt;, &lt;code&gt;click&lt;/code&gt;, &lt;code&gt;fill&lt;/code&gt;, &lt;code&gt;press&lt;/code&gt;, &lt;code&gt;select_option&lt;/code&gt;, &lt;code&gt;hover&lt;/code&gt;, &lt;code&gt;wait_for&lt;/code&gt;, &lt;code&gt;scroll&lt;/code&gt;, &lt;code&gt;extract_text&lt;/code&gt;, &lt;code&gt;snapshot&lt;/code&gt; and &lt;code&gt;check_page_health&lt;/code&gt;. Anything else is rejected with an error the agent can read. The raw Playwright toolkit tools are explicitly filtered out of every agent's tool list, so there is no back door.&lt;/p&gt;

&lt;p&gt;For every command, the engine:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Parses and validates the JSON.&lt;/li&gt;
&lt;li&gt;Checks the selector against the resilience policy (more on that below).&lt;/li&gt;
&lt;li&gt;Executes it with Playwright.&lt;/li&gt;
&lt;li&gt;Takes a fresh DOM snapshot.&lt;/li&gt;
&lt;li&gt;Appends an entry to the per-mission Action Tape, in memory and in &lt;code&gt;action_tape.jsonl&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Returns a plain-text block to the agent:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;STATUS: ERROR
ACTION: click {"selector": "[data-test-subj='checkout']"}
DURATION_MS: 5012
ERROR: TimeoutError: ...  (Recoverable — try a different selector or action.)
DOM_SNAPSHOT:
URL: https://app.example.com/cart
TITLE: Cart
SOURCE: accessibility_tree
* [0] role=button name='Update'
- [1] role=heading name='Your cart'
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Errors are returned as text, not raised. That is what makes the agents &lt;strong&gt;self-healing&lt;/strong&gt;: a failed click is just another observation, and the agent can try a different selector on its next step.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;check_page_health&lt;/code&gt; action deserves a mention: it scans the live DOM for visible error banners, &lt;code&gt;role="alert"&lt;/code&gt; elements and spinners that never stop (&lt;code&gt;aria-busy="true"&lt;/code&gt;), so "the page is quietly broken" becomes something an agent can detect.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the agent actually "sees"
&lt;/h2&gt;

&lt;p&gt;Feeding raw HTML to an LLM is slow, expensive and noisy. The engine builds a compact digest instead:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Primary: Playwright's accessibility tree.&lt;/strong&gt; It already excludes scripts, styles and hidden nodes, so it is the smallest faithful picture of what a user can perceive. It is flattened to at most 150 elements, and the agent receives up to 80 of them, with interactive roles marked with &lt;code&gt;*&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fallback: a pruned JavaScript DOM walk&lt;/strong&gt; that skips &lt;code&gt;script&lt;/code&gt;, &lt;code&gt;style&lt;/code&gt;, &lt;code&gt;svg&lt;/code&gt; internals and invisible elements, and keeps buttons, links, inputs, &lt;code&gt;data-test-subj&lt;/code&gt; attributes and short visible text.
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    P[Page] --&amp;gt; AX{Accessibility tree&amp;lt;br/&amp;gt;available?}
    AX --&amp;gt;|yes| F1[Flatten tree&amp;lt;br/&amp;gt;max 150 nodes]
    AX --&amp;gt;|no| JS[Pruned JS DOM walk]
    F1 --&amp;gt; D[Digest for the LLM&amp;lt;br/&amp;gt;max 80 elements]
    JS --&amp;gt; D&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;
  
  
  Rule #2: no brittle selectors, ever
&lt;/h2&gt;

&lt;p&gt;LLMs love selectors like &lt;code&gt;div &amp;gt; div:nth-child(3) &amp;gt; button&lt;/code&gt;. They work once and break with the next CSS change, and a reproduction script full of them is useless a week later.&lt;/p&gt;

&lt;p&gt;So the engine refuses them &lt;strong&gt;before touching the browser&lt;/strong&gt;. A regular expression catches XPath, &lt;code&gt;:nth-child&lt;/code&gt;, &lt;code&gt;:nth-of-type&lt;/code&gt; and bare positional &lt;code&gt;div&lt;/code&gt;/&lt;code&gt;span&lt;/code&gt;/&lt;code&gt;li&lt;/code&gt; chains. These are real results from the validator:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Selector&lt;/th&gt;
&lt;th&gt;Verdict&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;//div[@id='x']/button&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;div &amp;gt; div:nth-child(3) &amp;gt; button&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ul &amp;gt; li:nth-of-type(2)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;main &amp;gt; div &amp;gt; span&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;[data-test-subj='saveButton']&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;accepted&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;button:has-text('Save')&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;accepted&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;role=button[name='Submit']&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;accepted&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The rejection message tells the agent what to use instead, in order of preference: &lt;code&gt;data-test-subj&lt;/code&gt;, then &lt;code&gt;aria-label&lt;/code&gt;, then visible text, then semantic role, and suggests taking a DOM snapshot to find a stable attribute.&lt;/p&gt;

&lt;h2&gt;
  
  
  From Action Tape to a runnable test
&lt;/h2&gt;

&lt;p&gt;When an agent decides something is wrong, its instructions are to call two tools immediately: &lt;code&gt;capture_bug_screenshot&lt;/code&gt; and &lt;code&gt;generate_reproduction_spec&lt;/code&gt;. The second one translates the tape into Playwright code. For a tape like this one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;navigate  https://app.example.com/cart
fill      input[aria-label='Quantity'] = "-1"
click     button:has-text('Update')
click     [data-test-subj='checkout']   -&amp;gt; TimeoutError
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the generator writes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@playwright/test'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;storageState&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'auth.json'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'reproduce: Checkout button disappears after negative quantity'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;120_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://app.example.com/cart'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'input[aria-label=\'Quantity\']'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'-1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'button:has-text(\'Update\')'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// FAILED AT RECORD TIME (kept to reproduce error): click {"selector": "[data-test-subj='checkout']"}&lt;/span&gt;
  &lt;span class="c1"&gt;//   Error: TimeoutError: locator not visible&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'[data-test-subj=\'checkout\']'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;(The URL and steps are an example; the generated lines are the real output of the translator for that tape.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;My favourite detail is the comment: &lt;strong&gt;failed steps are kept&lt;/strong&gt;, annotated with the error seen at record time. The failure &lt;em&gt;is&lt;/em&gt; the reproduction, so dropping it would defeat the purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Eight ways to use (and abuse) your app
&lt;/h2&gt;

&lt;p&gt;Each agent is the same ReAct loop with a different system prompt. The mission's &lt;code&gt;thread_id&lt;/code&gt; decides which swarm runs:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Swarm&lt;/th&gt;
&lt;th&gt;Persona&lt;/th&gt;
&lt;th&gt;What it tries&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Standard&lt;/td&gt;
&lt;td&gt;New User&lt;/td&gt;
&lt;td&gt;Onboarding, discoverability, default and empty states&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Standard&lt;/td&gt;
&lt;td&gt;Power User&lt;/td&gt;
&lt;td&gt;Keyboard shortcuts, bulk operations, advanced filters, chained workflows&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Standard&lt;/td&gt;
&lt;td&gt;Adversarial User&lt;/td&gt;
&lt;td&gt;Invalid input, injection-like strings, rapid clicks, back-button abuse&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Advanced&lt;/td&gt;
&lt;td&gt;Accessibility&lt;/td&gt;
&lt;td&gt;Keyboard-only navigation, labels, WCAG issues&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Advanced&lt;/td&gt;
&lt;td&gt;Data Heavy&lt;/td&gt;
&lt;td&gt;Large inputs, long strings, many records&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Advanced&lt;/td&gt;
&lt;td&gt;Impatient&lt;/td&gt;
&lt;td&gt;Cancelling mid-flight, refreshing during submissions, double clicks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Advanced&lt;/td&gt;
&lt;td&gt;Returning User&lt;/td&gt;
&lt;td&gt;Stale sessions, cached pages, old bookmarks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Advanced&lt;/td&gt;
&lt;td&gt;Explorer&lt;/td&gt;
&lt;td&gt;Open-ended exploration and cross-feature regressions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A mission is just YAML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;missions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;thread_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;test_adversarial_user_01&lt;/span&gt;
  &lt;span class="na"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Persona: adversarial_user_agent
&lt;/span&gt;
    &lt;span class="s"&gt;Test &amp;lt;APP_URL&amp;gt; adversarially. Enter malformed strings, manipulate the URL parameters&lt;/span&gt;
    &lt;span class="s"&gt;manually, abuse the browser back/forward buttons constantly, and check if the&lt;/span&gt;
    &lt;span class="s"&gt;app degrades securely without exposing sensitive info.'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Keeping a swarm on a leash
&lt;/h2&gt;

&lt;p&gt;Multi-agent systems fail in boring ways: they loop, they forget the goal, or they blow up the context window. Most of the code in the orchestration layer is about preventing that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Routing is structured.&lt;/strong&gt; The supervisor doesn't free-text its decision. It uses structured output with a JSON schema whose &lt;code&gt;next&lt;/code&gt; field is an enum of the agent names plus &lt;code&gt;FINISH&lt;/code&gt;, so it cannot route to an agent that doesn't exist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The supervisor reads a brief, not the whole transcript.&lt;/strong&gt; Before each decision it gets a bounded summary: the mission, the last 12 progress lines, the last 10 browser actions, up to 8 bugs found and up to 8 explored URLs. That is enough to pick the next worker, and it doesn't grow with the length of the mission.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A step limit forces diversity.&lt;/strong&gt; After &lt;code&gt;--max-steps&lt;/code&gt; cycles (30 by default), the supervisor injects a reset directive: &lt;em&gt;"Navigate back to {app URL}, reset state, and pick a COMPLETELY DIFFERENT area of the application. Do not repeat any interaction already tried."&lt;/em&gt; It includes the list of areas already explored.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;History is compacted without an LLM call.&lt;/strong&gt; After every agent turn, a &lt;code&gt;Summarizer&lt;/code&gt; node keeps the original mission and the 20 most recent messages, and replaces everything in between with a one-message textual digest. The state also keeps only the last 50 tape entries; the full tape lives in the JSONL file.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    A[Agent turn ends] --&amp;gt; B{More than 21 messages?}
    B --&amp;gt;|no| S[Supervisor]
    B --&amp;gt;|yes| C[Keep mission + last 20 messages]
    C --&amp;gt; D[Replace the middle with&amp;lt;br/&amp;gt;a compact text summary]
    D --&amp;gt; S
    S --&amp;gt; E{Step limit reached?}
    E --&amp;gt;|yes| F[Inject reset directive:&amp;lt;br/&amp;gt;go home, explore a new area]
    E --&amp;gt;|no| G[Route to next agent or FINISH]
    F --&amp;gt; G&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;
  
  
  Counting bugs is harder than finding them
&lt;/h2&gt;

&lt;p&gt;An unexpected amount of work went into a question that sounds trivial: &lt;em&gt;how many bugs did we find?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Agents describe the same finding in three different shapes: a snake_case slug in the screenshot tool, a structured entry in their closing message, and prose like &lt;em&gt;"BUG FOUND: Empty cart lacks messaging."&lt;/em&gt; Counting all three triples the number.&lt;/p&gt;

&lt;p&gt;The fix has two parts. First, a contract in the system prompt: every agent must finish its turn with a &lt;code&gt;&amp;lt;bugs_found&amp;gt;&lt;/code&gt; block containing one JSON object per issue (&lt;code&gt;title&lt;/code&gt;, &lt;code&gt;summary&lt;/code&gt;, &lt;code&gt;location&lt;/code&gt;, &lt;code&gt;severity&lt;/code&gt;), or an explicit empty list. Second, a deduplication step that normalises each entry to a lowercase title key and treats two entries as the same bug when one key is a prefix of the other and the shorter one has at least 12 characters. "Login error" and "Login redirect" stay separate; three phrasings of the empty cart issue collapse into one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Memory: the second run is smarter than the first
&lt;/h2&gt;

&lt;p&gt;Exploration without memory is groundhog day: every run rediscovers the same pages and trips over the same flaky selectors. The framework keeps a LangGraph store in SQLite, namespaced by a hash of the app URL:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    R[Mission run] --&amp;gt; SEM[Semantic memory&amp;lt;br/&amp;gt;pages, selector reliability, quirks]
    R --&amp;gt; EPI[Episodic memory&amp;lt;br/&amp;gt;session summaries, bug catalog]
    EPI --&amp;gt; PRO[Procedural memory&amp;lt;br/&amp;gt;LangMem prompt optimizer]
    SEM --&amp;gt; RISK[Risk-ranked pages&amp;lt;br/&amp;gt;for the supervisor]
    EPI --&amp;gt; RISK
    EPI --&amp;gt; REG[--regression&amp;lt;br/&amp;gt;missions from known bugs]
    PRO --&amp;gt; NEXT[Prompt supplements&amp;lt;br/&amp;gt;for the next run]&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Semantic memory&lt;/strong&gt; tracks every page visited, the success and failure count of every selector, and application quirks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Episodic memory&lt;/strong&gt; stores a summary of each session and a &lt;strong&gt;bug catalog&lt;/strong&gt;, deduplicated with a fingerprint of page plus summary, that counts how many sessions have seen each bug.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Procedural memory&lt;/strong&gt; runs after a batch of missions: LangMem's prompt optimizer reviews the session trajectories and writes prompt supplements for the agents and routing rules for the supervisor, which are injected on the next run.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The supervisor also receives a list of high-risk pages, scored with a simple formula: twice the number of times a bug was seen there, plus confirmed quirks, plus 1.5 times the selector failures. And &lt;code&gt;--regression&lt;/code&gt; turns the bug catalog into missions, one per page with open or recurring bugs: &lt;em&gt;"Verify whether these bugs still exist and look for related regressions."&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Test what the pull request changed
&lt;/h2&gt;

&lt;p&gt;Exploring a whole application on every PR is wasteful. With &lt;code&gt;--pr-url&lt;/code&gt;, the framework fetches the PR (through the GitHub MCP server if configured, otherwise the &lt;code&gt;gh&lt;/code&gt; CLI) and asks the LLM to act as a test architect and write 3 to 8 missions for the UI areas the diff is likely to affect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;agent-explorer --pr-url https://github.com/org/repo/pull/123 --execute --headed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details keep this from turning into a prompt-size problem or a hallucination problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Diff budgeting.&lt;/strong&gt; The prompt gets at most 40,000 characters of diff. For large PRs, each file gets its own slice with its headers and changed lines, so one huge generated file can't eat the whole budget. If the memory store has historical bugs for the app, they are added to the prompt.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Output validation.&lt;/strong&gt; The generated YAML is rejected unless every mission has a &lt;code&gt;thread_id&lt;/code&gt; namespaced to the PR (&lt;code&gt;pr_123_...&lt;/code&gt;), targets an existing persona, and keeps its prompt under 1,200 characters.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Watching it work
&lt;/h2&gt;

&lt;p&gt;Running with &lt;code&gt;--visual&lt;/code&gt; launches a Streamlit dashboard that polls the agent state every second. It shows the live browser screenshot, the stream of agent thoughts, the bugs found so far and the swarm diagram above with the active node highlighted, which makes it easy to see where a mission is spending its time.&lt;/p&gt;

&lt;p&gt;Every mission also leaves a report folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;report_&amp;lt;thread_id&amp;gt;/
├── traces.log                  # every thought, plan and tool call
├── test_report.md              # executive summary: objective, actions, bugs, PASS/FAIL
├── action_tape.jsonl           # every browser command, in order
├── reproduction_*.spec.ts      # one Playwright test per bug
└── screenshots/                # evidence for each bug
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Bring your own app, model and knowledge
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Any web app.&lt;/strong&gt; A &lt;code&gt;config.yaml&lt;/code&gt; with the app name, URL, description and auth settings, plus &lt;code&gt;agent-auth&lt;/code&gt; to save a logged-in session.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Claude or Gemini.&lt;/strong&gt; The provider is detected from the credentials available, or forced with &lt;code&gt;--provider&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MCP servers&lt;/strong&gt; listed in &lt;code&gt;mcp_servers.json&lt;/code&gt; become tools the agents can query for domain knowledge, such as API specs or documentation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Agent Skills&lt;/strong&gt; under &lt;code&gt;AGENT_SKILLS_ROOT&lt;/code&gt; are exposed automatically, including running their scripts with a timeout.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The agents are told to use all of this with &lt;strong&gt;progressive disclosure&lt;/strong&gt;: start with the mission and the current page, and only fetch extra context for the specific feature under test.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lessons from building it
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Separate deciding from doing.&lt;/strong&gt; The LLM chooses; deterministic code executes and records. Every trustworthy property of the system (reproducible specs, selector policy, audit trail) comes from that split.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make errors observations.&lt;/strong&gt; Returning failures as text lets agents recover on their own, and keeps the failure on the tape for the reproduction.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bound everything.&lt;/strong&gt; Snapshots, history, routing context, diffs, the tape kept in state. Long missions fail because context grows, not only because models make mistakes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Specify the output of agents like an API.&lt;/strong&gt; The &lt;code&gt;&amp;lt;bugs_found&amp;gt;&lt;/code&gt; contract and the PR mission validator turn free text into data the rest of the system can trust.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test the framework itself.&lt;/strong&gt; The repository has 115 unit tests covering the engine, bug extraction, PR analysis, config and the dashboard state.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/srbarrios/agentic-test-explorer.git
&lt;span class="nb"&gt;cd&lt;/span&gt; agentic-test-explorer
pip install -e .
playwright install chromium

cp config.yaml.example config.yaml   &lt;span class="c"&gt;# point it at your app&lt;/span&gt;
agent-auth                            &lt;span class="c"&gt;# save an authenticated session&lt;/span&gt;
agent-explorer --missions missions/new_user_agent.yaml --headed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a &lt;a href="https://github.com/srbarrios/agentic-test-explorer#-demo" rel="noopener noreferrer"&gt;demo video in the README&lt;/a&gt;, and the &lt;a href="https://github.com/srbarrios/agentic-test-explorer/blob/main/ARCHITECTURE_GUIDE.md" rel="noopener noreferrer"&gt;architecture guide&lt;/a&gt; walks through the LangGraph concepts behind every part of the code.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Code (MIT):&lt;/strong&gt; &lt;a href="https://github.com/srbarrios/agentic-test-explorer" rel="noopener noreferrer"&gt;github.com/srbarrios/agentic-test-explorer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are an SDET or a QE engineer experimenting with agents: what would make you trust a bug report written by an AI? I'd love to hear it in the comments, and issues and pull requests are welcome.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://oscarbarrios.tech/agentic-test-explorer/" rel="noopener noreferrer"&gt;oscarbarrios.tech&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>testing</category>
      <category>ai</category>
      <category>playwright</category>
      <category>opensource</category>
    </item>
    <item>
      <title>I Asked an LLM to Find Our Flaky Tests. The Final Version Runs on 80 Lines of Rules</title>
      <dc:creator>Oscar Barrios</dc:creator>
      <pubDate>Tue, 24 Nov 2026 17:43:11 +0000</pubDate>
      <link>https://dev.to/srbarrios/i-asked-an-llm-to-find-our-flaky-tests-the-final-version-runs-on-80-lines-of-rules-eno</link>
      <guid>https://dev.to/srbarrios/i-asked-an-llm-to-find-our-flaky-tests-the-final-version-runs-on-80-lines-of-rules-eno</guid>
      <description>&lt;p&gt;The build is red. Again.&lt;/p&gt;

&lt;p&gt;Is it the change you merged an hour ago, or is it &lt;em&gt;that&lt;/em&gt; test, the one that "sometimes fails"? Somebody re-runs the job. It goes green. Everybody moves on, a little less confident in the pipeline than yesterday.&lt;/p&gt;

&lt;p&gt;Multiply that by hundreds of end-to-end tests running against real Linux machines and you get the most expensive kind of noise in CI: &lt;strong&gt;people stop trusting red&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I wanted a dashboard that answers one question with data: &lt;em&gt;which failures are real, and which are flaky?&lt;/em&gt; My first version handed the whole problem to an LLM. The version that is in the repository today doesn't call the model at all.&lt;/p&gt;

&lt;p&gt;This post is the story of that tool, &lt;a href="https://github.com/srbarrios/jenkins-flaky-tests-detector" rel="noopener noreferrer"&gt;jenkins-flaky-tests-detector&lt;/a&gt;, and of why rules beat the model for this job.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prometheus already knows your test history if you scrape Jenkins with an exporter. You only need to read it the right way.&lt;/li&gt;
&lt;li&gt;A flaky test and a regression look identical in a failure counter. They look completely different as a &lt;strong&gt;time series&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;I went from "LLM classifies everything" to "rules first, LLM for the doubtful cases" to "rules only, and flag the rest". About 80 lines of Python do the classification.&lt;/li&gt;
&lt;li&gt;The output is a JSON file that Grafana reads through the Infinity data source. No database, no extra service.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The signal is already in Prometheus
&lt;/h2&gt;

&lt;p&gt;We scraped Jenkins with a &lt;code&gt;jenkins-exporter&lt;/code&gt;, which publishes a metric per test case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight prometheus"&gt;&lt;code&gt;&lt;span class="na"&gt;jenkins_build_test_case_failure_age{jobname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;suite&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"FAILED"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value is the &lt;strong&gt;failure age&lt;/strong&gt;: how many consecutive builds that test has been failing. &lt;code&gt;0&lt;/code&gt; (or no sample) means it passed. &lt;code&gt;1, 2, 3...&lt;/code&gt; means it has been red for that many builds in a row.&lt;/p&gt;

&lt;p&gt;That single number carries the whole story once you look at it over time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;regression:  0 0 0 0 1 2 3 4 5 6 7 8 9 ...     (breaks once, stays broken)
flaky:       0 1 0 0 1 0 1 0 0 0 1 0 ...       (yo-yo without code changes)
infra/dead:  1 2 3 4 5 6 7 8 9 10 11 ...       (never passes in the window)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A dashboard that counts failures sees "8 failures" in both of the first two rows. The &lt;em&gt;shape&lt;/em&gt; is what tells them apart.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;



&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    J[Jenkins] --&amp;gt;|test results| E[jenkins-exporter]
    E --&amp;gt;|scrape| P[(Prometheus)]
    P --&amp;gt;|PromQL range queries| D[flaky-detector]
    D --&amp;gt;|rules| C{Classify}
    C --&amp;gt; F[flaky_tests.json]
    F --&amp;gt;|HTTP :8080| G[Grafana&amp;lt;br/&amp;gt;Infinity data source]&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The detector is a small Python process that runs in a loop inside a container:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Harvest&lt;/strong&gt; the history of every failing test from Prometheus.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reconstruct&lt;/strong&gt; a dense time series from sparse samples.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Classify&lt;/strong&gt; each test with deterministic rules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Expose&lt;/strong&gt; the result as a static JSON file for Grafana.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 1: harvest, and let Prometheus tell you which jobs exist
&lt;/h2&gt;

&lt;p&gt;I didn't want to maintain a list of Jenkins jobs, so the detector discovers them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'count by (jobname) (max_over_time(jenkins_build_test_case_failure_age[30d]))'&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;custom_query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;jobs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'metric'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'jobname'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="s1"&gt;'jobname'&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'metric'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, for each job, one range query brings back only the series that ever failed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;'jenkins_build_test_case_failure_age{{jobname="{job_name}", status=~"FAILED|REGRESSION"}}'&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;custom_query_range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;start_time&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end_time&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The default window is 15 days with a one-hour step. Tests that never failed never come back from the query, so the analysis only touches the tests that matter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: rebuild the timeline (the part everyone gets wrong)
&lt;/h2&gt;

&lt;p&gt;Here is the catch: because the query filters on failing statuses, &lt;strong&gt;a passing test produces no samples&lt;/strong&gt;. Prometheus gives you islands of failures with nothing in between, and "nothing" does not mean "no data", it means "it passed".&lt;/p&gt;

&lt;p&gt;So the detector rebuilds a continuous timeline with pandas, and imputes &lt;code&gt;0&lt;/code&gt; (pass) wherever there is no sample:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;full_time_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;date_range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;pd_start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;pd_end&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;freq&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;'{step}s'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DataFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'values'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ds'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'y'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ds'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_datetime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ds'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'s'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'y'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_numeric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'y'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ds'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;df_resampled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resample&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;'{step}s'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                     &lt;span class="c1"&gt;# worst status in the bucket&lt;/span&gt;
&lt;span class="n"&gt;df_reindexed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df_resampled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reindex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;full_time_index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillna&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# missing = pass&lt;/span&gt;
&lt;span class="n"&gt;history&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df_reindexed&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'y'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;astype&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tolist&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details matter here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;max()&lt;/code&gt; per bucket&lt;/strong&gt;: if a job ran twice in the same hour, the worst result wins. A failure is never hidden by a later pass in the same bucket.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;fillna(0)&lt;/code&gt;&lt;/strong&gt;: the whole classifier depends on this assumption. It is right for "the test ran and passed", and wrong for "the job didn't run at all". More on that at the end.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result is, for every test, a list of about 360 integers (15 days of hourly buckets) that the rules can reason about.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: classify the shape
&lt;/h2&gt;

&lt;p&gt;From each series the detector computes four numbers:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;transitions&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;How many times the test flipped between pass and fail&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;failure_rate&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Share of buckets where it was failing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;max_streak&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Longest run of consecutive failures (the max failure age)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;steps_since_fail&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;How long it has been green since the last failure&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;And then applies the rules in order. This is the actual decision tree:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    A[Test history] --&amp;gt; B{Failing in 100% of the window?}
    B --&amp;gt;|yes| ENV[ENVIRONMENTAL&amp;lt;br/&amp;gt;infra or dead test]
    B --&amp;gt;|no| C{3 or more pass/fail flips?}
    C --&amp;gt;|yes| FL1[FLAKY&amp;lt;br/&amp;gt;oscillation, score 1.0]
    C --&amp;gt;|no| D{Green now and failure rate under 30%?}
    D --&amp;gt;|yes| D2{Green for more than 48 buckets?}
    D2 --&amp;gt;|yes| FX1[FIXED&amp;lt;br/&amp;gt;healed]
    D2 --&amp;gt;|no| FL2[FLAKY&amp;lt;br/&amp;gt;sporadic, score 0.95]
    D --&amp;gt;|no| E{Green now and longest streak 6 or less?}
    E --&amp;gt;|yes| FL3[FLAKY or FIXED&amp;lt;br/&amp;gt;cluster]
    E --&amp;gt;|no| F{Green now?}
    F --&amp;gt;|yes| FX2[FIXED&amp;lt;br/&amp;gt;was a long regression]
    F --&amp;gt;|no| G{Failing for 3 or more builds now?}
    G --&amp;gt;|yes| REG[REGRESSION&amp;lt;br/&amp;gt;active, score 0.05]
    G --&amp;gt;|no| UNK[UNKNOWN&amp;lt;br/&amp;gt;too early to tell]&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The oscillation rule is the heart of it. Counting flips is almost embarrassingly simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;_count_transitions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lst&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;flips&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lst&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lst&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lst&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;flips&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;flips&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check the behaviour, I fed some synthetic histories (about 360 hourly buckets each) to the real classification code. These are its actual outputs:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;History&lt;/th&gt;
&lt;th&gt;Pattern (score)&lt;/th&gt;
&lt;th&gt;Reason&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;... 1 0 1 0 1 0 ...&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;FLAKY (1.0)&lt;/td&gt;
&lt;td&gt;OSCILLATION: Flipped state 6 times.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;one failure, 20 hours ago&lt;/td&gt;
&lt;td&gt;FLAKY (0.95)&lt;/td&gt;
&lt;td&gt;SPORADIC: Low failure rate (0.3%) but unstable.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;one failure, 80 hours ago&lt;/td&gt;
&lt;td&gt;FIXED (0.0)&lt;/td&gt;
&lt;td&gt;HEALED: Sporadic failures (rate 0.3%) but passed last 80 runs.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;failing for the last 5 builds&lt;/td&gt;
&lt;td&gt;REGRESSION (0.05)&lt;/td&gt;
&lt;td&gt;ACTIVE: Broken for 5 consecutive builds.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;failing for the last 2 builds&lt;/td&gt;
&lt;td&gt;UNKNOWN (0.5)&lt;/td&gt;
&lt;td&gt;Complex pattern: [0, 0, 0, 1, 2]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;failing for the whole window&lt;/td&gt;
&lt;td&gt;ENVIRONMENTAL (0.0)&lt;/td&gt;
&lt;td&gt;INFRA: Test has 100% failure rate.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Notice the score: it is not "probability of a bug". It is a &lt;strong&gt;flakiness score&lt;/strong&gt;. Grafana sorts by it, so the yo-yo tests float to the top and the real regressions sink to the bottom, where the team should already be looking at them anyway.&lt;/p&gt;

&lt;h2&gt;
  
  
  The LLM journey: from "do everything" to "out of the loop"
&lt;/h2&gt;

&lt;p&gt;This is the part I find most interesting, and it is all in the git history.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Version 1: the LLM classifies everything.&lt;/strong&gt; The first draft sent batches of 30 time series to Gemini with a structured output schema (&lt;code&gt;FLAKY&lt;/code&gt;, &lt;code&gt;REGRESSION&lt;/code&gt;, &lt;code&gt;ENVIRONMENTAL&lt;/code&gt;, &lt;code&gt;UNKNOWN&lt;/code&gt;), temperature 0.2, and a long prompt explaining what each pattern looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- Chaotic oscillation: `1, 0, 1, 0, 2, 0` (Randomly fails).
- CLUSTER FLAKES: A test fails for a short burst and then passes WITHOUT a long-term pattern.
- REGRESSION: Long, sustained failure blocks that require a fix. `0, 0, 1, 2, 3, 4, 5, 6, 7... 15`
- ENVIRONMENTAL: `25, 25, 25` (Metric is stuck/stale).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read that prompt again. I was describing &lt;strong&gt;rules&lt;/strong&gt; to the model in English, and paying tokens for it to apply them to every test.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Version 2: AI in the loop.&lt;/strong&gt; Deterministic rules first; only the cases they couldn't decide went to Gemini, in batches of 20. The model went from classifying every failing test to looking only at the leftovers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Version 3: rules only.&lt;/strong&gt; When I made the detector auto-discover and scan every Jenkins job, the model call came out of the loop. The leftovers are labelled &lt;code&gt;UNKNOWN&lt;/code&gt; with their last five data points, so a human can glance at them.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    V1["v1&amp;lt;br/&amp;gt;LLM classifies&amp;lt;br/&amp;gt;every failing test"] --&amp;gt; V2["v2&amp;lt;br/&amp;gt;rules first,&amp;lt;br/&amp;gt;LLM for leftovers"] --&amp;gt; V3["v3&amp;lt;br/&amp;gt;rules only,&amp;lt;br/&amp;gt;leftovers flagged UNKNOWN"]&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Looking at what ends up in that bucket explains why. The ambiguous case is a test that started failing one or two builds ago. That is not a pattern problem, it is a &lt;strong&gt;missing-data&lt;/strong&gt; problem: nobody, human or model, can tell yet whether it will recover on the next build or stay red. The next run of the detector, a few hours later, will usually classify it with no help at all.&lt;/p&gt;

&lt;p&gt;The general lesson I took from it: &lt;strong&gt;keep the deterministic part deterministic, and spend a model only where it adds information you don't already have.&lt;/strong&gt; When your prompt is a list of rules, write the rules.&lt;/p&gt;

&lt;p&gt;The Gemini settings are still in the config template, so bringing the model back for the &lt;code&gt;UNKNOWN&lt;/code&gt; bucket is a small change if it ever proves useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: expose it the boring way
&lt;/h2&gt;

&lt;p&gt;The output is a flat JSON array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"job_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"my-acceptance-job"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"test_suite"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"features/core"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"test_case"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Register a client"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"flakiness_score"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"failure_pattern"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"FLAKY"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"reasoning"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OSCILLATION: Flipped state 4 times."&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;(Field values here are illustrative.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Serving it takes a 30-line &lt;code&gt;http.server&lt;/code&gt; sidecar on port 8080. In Grafana, the &lt;strong&gt;Infinity&lt;/strong&gt; data source reads the URL and a UQL query does the rest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;parse-json
| filter "job_name" == "${jobname}"
| project "test_suite", "test_case", "failure_pattern", "flakiness_score", "reasoning"
| order by "flakiness_score" desc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A &lt;code&gt;jobname&lt;/code&gt; dashboard variable (built with &lt;code&gt;parse-json | project "job_name" | distinct "job_name"&lt;/code&gt;) gives a drop-down per test suite, and value mappings colour the pattern column: yellow for FLAKY, red for REGRESSION, blue for INFRA, purple for FIXED.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running it
&lt;/h2&gt;

&lt;p&gt;The container runs both processes from a tiny entrypoint: the web server in the background and the detector in a loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 serve_results.py --dir /data &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    python3 flaky_detector.py --config /app/config.yaml &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Detector failed, retrying next interval."&lt;/span&gt;
    sleep &lt;span class="nv"&gt;${CHECK_INTERVAL:-14400}&lt;/span&gt;   &lt;span class="c"&gt;# every 4 hours by default&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A GitHub Actions workflow builds and pushes the image to GHCR on every push to &lt;code&gt;main&lt;/code&gt; (tagged &lt;code&gt;latest&lt;/code&gt;, by version tag and by commit SHA). In the monitoring infrastructure where I ran it, a Salt state rendered the config from a Jinja template with the secrets taken from the pillar, and kept the container running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;jenkins-flaky-tests-detector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;docker_container.running&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ghcr.io/srbarrios/jenkins-flaky-tests-detector:latest&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;binds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;/data/jenkins-flaky-tests-detector/config.yaml:/app/config.yaml:ro&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;/data/jenkins-flaky-tests-detector/output:/data&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;CHECK_INTERVAL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;14400&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;restart_policy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/data/jenkins-flaky-tests-detector/config.yaml&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;watch&lt;/code&gt; means that changing the config in the pillar restarts the container with the new settings on the next highstate.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would change next
&lt;/h2&gt;

&lt;p&gt;Writing this post made me run the rules against synthetic data, and that is a good way to find your own blind spots:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Rule order matters more than thresholds.&lt;/strong&gt; With about 360 buckets, almost any test has a failure rate under 30%, so the &lt;em&gt;sporadic&lt;/em&gt; rule fires before the &lt;em&gt;cluster&lt;/em&gt; rule ever gets a chance. A burst of four failures followed by green is reported as "sporadic" rather than "cluster". The verdict is still right, but the reason is less precise.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Buckets are not builds.&lt;/strong&gt; The "healed" threshold is 48 &lt;em&gt;hourly buckets&lt;/em&gt;, not 48 runs. For a nightly job that is two runs; for a job that runs every 15 minutes it is close to 200. The threshold should be expressed in builds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"No sample" is not always "pass".&lt;/strong&gt; If a job didn't run for a weekend, the timeline shows two green days. Joining with a "build ran" metric would remove that bias.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Close the loop.&lt;/strong&gt; The natural next step is to feed &lt;code&gt;FLAKY&lt;/code&gt; tests back into the pipeline: quarantine them, re-run them automatically, or open an issue.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The repository is archived now and I'm not adding features, but the code is open source (GPL-3.0) and small enough to read in one sitting.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Code:&lt;/strong&gt; &lt;a href="https://github.com/srbarrios/jenkins-flaky-tests-detector" rel="noopener noreferrer"&gt;github.com/srbarrios/jenkins-flaky-tests-detector&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How do you deal with flaky tests in your pipelines? Quarantine, automatic retries, or a dashboard like this one? I'd love to hear what has worked for you.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://oscarbarrios.tech/jenkins-flaky-tests-detector/" rel="noopener noreferrer"&gt;oscarbarrios.tech&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>testing</category>
      <category>devops</category>
      <category>observability</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
