Get Started with Datadog

AI

Ephyra: A new agentic property-based testing library to find the bugs you missed

Published

Read time

9m

Ephyra: A new agentic property-based testing library to find the bugs you missed
Alp Keles

Alp Keles

Research Scientist

A 24-year-old memory-safety bug in OCaml, a 21-year-old exponential parsing bug in PostgreSQL, and a 13-year-old database corruption in SQLite had all survived years of extensive testing. Coding agents helped us find them by writing and improving test case generators with Ephyra, our open source testing library. Across 26 well-tested popular open source systems, our experiments uncovered 535 unique and previously unknown bugs, including 313 that maintainers have already fixed.

Coding agents are increasingly better at writing software. Verifying that the software behaves correctly is still difficult: Code review can miss subtle interactions, and traditional testing methods are overwhelmed with the volume of AI-written code. We have been studying how agents can help write property-based tests, an established software testing technique. Engineers define rules the code must conform to, such as sorting a list without changing any elements, and a testing framework generates random inputs that try to break those rules. Traditionally, building effective input generators takes significant time and expertise. Ephyra, the open source framework for agentic property-based testing we built, uses coding agents for this task. Agents write and improve generators using feedback from test executions.

The bugs we found span databases such as DataFusion and FoundationDB; language implementations such as OCaml and Lean; developer tools and infrastructure; AI tooling; and formally verified systems. We validated each bug with a minimal reproducer and reported 535 bugs upstream. Maintainers have confirmed 373 so far, including 313 that are already fixed. Our accompanying research paper, which will appear in the Future of Property-Based Testing workshop at POPL 27 in January, describes Ephyra’s design in detail. In this post, we show how the approach works in practice and how readers can try it on their own systems.

Ephyra workflow from an engineer-defined property to agent-optimized testing and reported bugs.
Engineers define properties, agents optimize generators, and Ephyra runs tests and triages bugs.
Ephyra workflow from an engineer-defined property to agent-optimized testing and reported bugs.
Engineers define properties, agents optimize generators, and Ephyra runs tests and triages bugs.

Property-based testing

Programs have rules. For instance, sorting a list should put its elements in order and preserve every element, including duplicates. Such a rule is called a property, a general statement about the system that must hold for any state or input. To test this property, we use a generator that produces random lists, and Ephyra checks the rule against each one. If the sorting code returns an unsorted list, or drops a duplicate, Ephyra simplifies the failing list until a small example still exposes the bug, such as two equal values reduced to one. This is property-based testing.

Animated testing loop that generates lists, detects a failure, and shrinks it to [7, 7].
The generator produces inputs, the property checks them, and the shrinker minimizes a failing input.
Animated testing loop that generates lists, detects a failure, and shrinks it to [7, 7].
The generator produces inputs, the property checks them, and the shrinker minimizes a failing input.

Property-based testing with Ephyra

In Ephyra, software engineers define the properties, and coding agents gradually improve the generators. Properties range from simple rules, such as requiring that the system never produces a memory violation, to highly specialized, domain-specific properties such as Ternary Logic Partitioning (TLP). TLP is a property of SQL’s three-valued logic, in which each predicate evaluates to TRUE, FALSE, or NULL. Researchers have previously used TLP to find hundreds of bugs in production database systems. We used it with Ephyra to test SQLite, Turso, PostgreSQL, DataFusion, and DuckDB.

Below, we present an example of a bug we found in SQLite using TLP. In this example, SQLite silently returns an incorrect result for a query that uses sum(b ORDER BY a):

Animated TLP test in which three partitioned queries total 2 while sum(b ORDER BY a) returns 1.
The partitioned queries total 2, but SQLite returns 1 for the original query.
Animated TLP test in which three partitioned queries total 2 while sum(b ORDER BY a) returns 1.
The partitioned queries total 2, but SQLite returns 1 for the original query.

Once a property such as TLP is written, it is an abstract rule that applies to every possible database and query. To test it, we use random test-case generators and mutators. With Ephyra, we envision software engineers constraining and shaping these generators while coding agents write and optimize them in a continuous optimization loop such as BitsEvolve. 

For SQLite, we started by asking the agent to generate valid database files, then guided changes to the testing harness such as adding new properties to test for or new parts of SQLite to explore. Each new feature added to the generator could expose bugs in that feature or in its interactions with features already being tested. The following animation shows how improving the generator during each round enabled testing to reach more of the SQLite codebase and find bugs in previously unreachable regions.

SQLite source-code treemap filling in over 37 rounds, from 35.9% to 74.1% coverage, with bugs marked as they are found.
Over 37 rounds, the generator’s coverage of SQLite’s instrumented counters grew from 35.9% to 74.1%, and testing found 26 bugs.
SQLite source-code treemap filling in over 37 rounds, from 35.9% to 74.1% coverage, with bugs marked as they are found.
Over 37 rounds, the generator’s coverage of SQLite’s instrumented counters grew from 35.9% to 74.1%, and testing found 26 bugs.

The code regions represent a range of SQLite features. Once a feature is added to the generated input space, it becomes part of the generator’s vocabulary. This can reveal bugs both in the feature’s implementation and in its interactions with the features already under test.

As Ephyra evolves its generator to hill-climb code coverage, the software engineer can choose to remain entirely outside the loop. The agent can then autonomously select new regions and features to cover, as well as triage, deduplicate, locate, and perhaps even fix the bugs it finds.

Animated summary of 37 rounds: SQL features grow from 79 to 261, SQLite coverage from 35.9% to 74.1%, and 26 bugs are found, including the sum(b ORDER BY a) bug at round 8.
Over 37 rounds, the generator grew from 79 to 261 SQL features and from 35.9% to 74.1% coverage, finding 26 bugs.
Animated summary of 37 rounds: SQL features grow from 79 to 261, SQLite coverage from 35.9% to 74.1%, and 26 bugs are found, including the sum(b ORDER BY a) bug at round 8.
Over 37 rounds, the generator grew from 79 to 261 SQL features and from 35.9% to 74.1% coverage, finding 26 bugs.

Start testing your software using Ephyra

Ephyra is an open source research project at datadog-labs/ephyra. It includes the testing library, a variety of case studies, a CLI for running tests and inspecting results, and a Datadog integration. Ephyra is experimental and is not a supported Datadog product offering.

Ephyra is written in Rust, but it can be used to test software in many languages, including C++ and Python. The startup guide explains how to use it with a coding agent.

To try Ephyra, give the following starter prompt to your coding agent:

Let's test <my library> with ephyra
(https://github.com/datadog-labs/ephyra). Read its README and
STARTUP.md first, then autonomously start writing and optimizing
Ephyra tests until we find any bugs; validate, triage, and notify me.

If you encounter problems using Ephyra or would like to collaborate on future research, contact alp.keles@datadoghq.com or open an issue or pull request in the repository.

Some of the bugs we found using Ephyra

We have used Ephyra across a wide range of projects and found many kinds of bugs. The complete list is available in the repository and the paper’s appendix. Next, we highlight a subset of bugs that illustrate the range of features we tested, followed by a graph showing the bugs’ lifetimes across these projects, ranging from one day to 24 years.

SQLite

Three DELETE statements caused SQLite to report its own database as malformed. This database-corruption bug had been in SQLite’s code for nearly 13 years when we found it, and it was the first bug we reported using Ephyra.

PRAGMA page_size=512;
CREATE TABLE t(c PRIMARY KEY) WITHOUT ROWID;
INSERT INTO t VALUES
(hex(zeroblob(35))), (hex(zeroblob(36))), (hex(zeroblob(37))),
(hex(zeroblob(38))), (hex(zeroblob(44))), (hex(zeroblob(45))),
(hex(zeroblob(46))), (hex(zeroblob(47))), (x''),
(zeroblob(94)), (zeroblob(95)), (zeroblob(96));
PRAGMA integrity_check; -- ok
DELETE FROM t WHERE c = zeroblob(94);
DELETE FROM t WHERE c = hex(zeroblob(44));
DELETE FROM t WHERE c = x''; -- database disk image is malformed

Upstream report: SQLite forum 9d039d4ca7

OCaml

A non-exhaustive match caused OCaml to jump through a wild pointer. Instead of raising Match_failure, the program crashed, revealing a memory-safety issue in plain, safe OCaml code. The bug had been in OCaml for 24 years when we found it.

let f x y = match x, y with
| _, true -> 0
| (0 | 2), _ -> 1
| 3, true -> 2
| -1, _ -> 3
let () = print_int (f (Sys.opaque_identity 4) false)
(* crashes; expected Match_failure *)

Upstream report: ocaml/ocaml#15185

Lean 4

Lean 4 treated 5 and 5.0 as different patterns in a match on floating-point values, even though they represented the same value. The bug had been in the code for four months when we found it. In the example below, the input 5.0, 1 fails the first branch because n is not 0 and should take the second branch, but Lean skips it and returns 0. Both the compiled program and Lean’s proof checker produce the same incorrect result, so decide proves that f 5.0 1 = 2 is false. Lean fixed the bug the day after we reported it.

def f (x : Float) (n : Nat) : Nat :=
match x, n with
| 5, 0 => 1
| 5.0, _ => 2
| _, _ => 0
#eval f 5.0 1 -- 0; expected 2
example : f 5.0 1 = 2 := by decide
-- error: `decide` proved that the proposition f 5.0 1 = 2 is false

Upstream report: leanprover/lean4#16198

PostgreSQL

A 670-byte PostgreSQL query required nearly 100 GB of memory to parse. PostgreSQL rewrites a BETWEEN b AND c as a >= b AND a <= c by copying a, causing the work to double with every level of nesting. At 26 levels, the query required nearly 100 GB and could not be canceled. The underlying bug had been in PostgreSQL for at least 21 years when we found it.

SET statement_timeout = '100ms';
SELECT 1 WHERE (((true BETWEEN true AND false)
BETWEEN true AND false)
BETWEEN true AND false); -- ... nested 20 levels deep
-- 20 levels: 1.5 s and 1.5 GB in parsing before the 100 ms timeout fires;
-- every extra level doubles both

Upstream report: PostgreSQL BUG #19758

QED

QED incorrectly proved that 0.1 and 0.100000001 were equal. QED is a SQL prover for query equivalence, but it reads every decimal constant as a 32-bit float. Constants that round to the same float therefore become indistinguishable, causing QED to consider the two queries below equivalent. The bug had been in the code for 4 years when we found it.

CREATE TABLE t (c0 DOUBLE, c1 DECIMAL(20,10), c2 INTEGER);
SELECT c2 FROM t WHERE c0 = 0.1;
SELECT c2 FROM t WHERE c0 = 0.100000001;
-- qed-prover: "provable": true

Upstream report: qed-solver/prover#13

LiteLLM

Turning on streaming caused a LiteLLM agent to skip a tool call. LiteLLM provides a single OpenAI-style API for many LLM providers. We ran the same agent twice against the same server response, changing only the value of stream. With stream=True, the server ended the tool call with finish_reason: "stop", so the agent neither answered nor ran the tool. The bug had been in the code for at least 11 months when we found it.

Stream=false and stream=true animation
Stream=false and stream=true animation

Upstream report: BerriAI/litellm#48716

DuckDB

A query with LIMIT 1 returned three rows in DuckDB. LIMIT X should return no more than X rows, but Ephyra found a case in which DuckDB did not respect that limit. The bug had been in the code for 15 days when we found it.

CREATE TABLE t(a INT);
SELECT * FROM range(3) r(i), (SELECT count(*) AS n FROM t) WHERE i >= n LIMIT 1;
-- 1.5.6: (0, 0)
-- 2.0.0: (0, 0), (1, 0), (2, 0)

Upstream report: duckdb/duckdb#27714

Dot plot with the ages of bugs Ephyra found across 26 systems, grouped by system category.
Bugs Ephyra found across 26 open source systems ranged in age from less than a day to 24 years.
Dot plot with the ages of bugs Ephyra found across 26 systems, grouped by system category.
Bugs Ephyra found across 26 open source systems ranged in age from less than a day to 24 years.

The road ahead for Ephyra

Our work so far provides evidence that autonomous generator optimization is an effective testing strategy. It does not yet validate Ephyra’s design choices or establish Ephyra’s place in the broader agentic testing landscape. We plan to investigate three areas:

  • Controlled, isolated, clean-room experiments for agentic testing: Finding novel bugs in well-tested systems such as SQLite and PostgreSQL is a traditional way to evaluate testing tools, but it leaves many questions unanswered. Controlled experiments will help us measure reliability, or how consistently an approach finds a given bug; cost, or how much time, compute, and tokens it requires; and generality, or what types and proportions of bugs it finds in a given system.

  • Packaging Ephyra Agent as a standalone tool: Our closed-loop experiments begin with a short description of each system and a fixed budget. They have produced promising results and detailed triage reports, but we still personally validated and submitted every bug report. We want to determine what information autonomous reports should contain so that more teams and projects can use Ephyra without taking on an additional maintenance burden.

  • Optimizing Ephyra itself: Although Ephyra is a programmable property-based testing library, our experiments so far have used a classical property-based testing loop. Within this setup, the experiments should be reproducible in any PBT library that supports handwritten generators and shrinkers. The differentiating elements of Ephyra’s design will matter more in future experiments, where we envision agents optimizing the entire testing loop. For example, agents could implement swarm testing or tune the power scheduler, rather than optimizing only the generator.

Interested in working on AI research and agentic systems like Ephyra? Explore open roles at Datadog.

Start monitoring your metrics in minutes