How Far Must a Test Explore? Certifying Composable Read-Write Interfaces from Their Own Random Edits

Jiaxuan Guo, Xingyu Ren, Jingxin Yang, Youran Sun, Haizhao YangarXiv 2026 · arXiv

TL;DR

Testing stateful code by checking local algebraic laws (like "reading back what you just wrote") is standard practice, but local passes don't always guarantee global correctness. This paper establishes the theoretical bounds for how much random exploration is required to certify that a read-write interface truly behaves like a valid record, proving that while a single start state is easy to test, worst-case scenarios require exploration linear in the number of variables.

What Problem Does This Paper Address?

When we test stateful systems—like databases, file systems, or functional "lenses"—we often rely on random testing. We start from some state, perform a sequence of random operations, and check if certain "laws" hold at the resulting state. For a simple record with $m$ variables, these laws include:

  • Success: If you write a value, you read it back.
  • Commutation: Writing to variable A then variable B is the same as B then A.
  • Overwrite: Writing to the same variable twice means the second write wins.

The challenge is that these laws are local—they only check a few operations at a time. However, behaving like a proper record is a global property of how all possible states fit together. An implementation could pass every local law check at every state reached by a test, yet still be "far" from any valid record.

The authors ask: How far must a test explore? Specifically, how long must the random sequences of writes be, and how deep must the tester's own probes go, to bridge the gap between local law-abiding behavior and global correctness?

Methods

The authors model an interface with $m$ binary variables. They define a "composable interface" as a perfect record that might contain "hidden data" (data that doesn't affect the visible variables but might affect internal state).

To measure exploration, they use two parameters:

  1. Run length ($\ell$): The mean length of a random sequence of writes performed before taking a sample.
  2. Tester depth ($d$): The length of the chain of writes the tester itself performs starting from a sample.

They introduce a novel Audit Algorithm. Instead of just checking laws, the audit walks from a sample toward a "target label" and checks if specific "flip" operations (writing the opposite of a current bit) eventually rejoin that walk. This allows the tester to probe the global structure of the state space more effectively than simple law checks.

Datasets

Not discussed in the paper. This is a theoretical study providing mathematical proofs and complexity bounds rather than an empirical evaluation on specific software datasets.

Key Insights and Ideas

  • The "One Start State" Surprise: If a test always begins from a single, fixed start state, the problem is much easier. The authors prove that checking laws at $O(m^2 \log m / \epsilon)$ samples is enough to certify correctness for any positive run length.
  • The "Twist" Counterexample: To prove lower bounds, the authors construct a "twisted" interface. This implementation passes local law checks but contains a global "twist"—a hidden bit that toggles only when a specific sequence of writes occurs. This "twist" is invisible to shallow exploration but makes the interface fundamentally different from a record.
  • Writes Generate the Distribution: Unlike standard property testing where a tester might have a uniform distribution over inputs, here the distribution of states is generated by the writes themselves. If the writes are "bad," they might trap the tester in a small, law-abiding corner of a globally broken state space.
  • Separation of Budgets: The paper distinguishes between a "sample budget" (how many states you look at) and a "write budget" (how many operations you perform). They show that if you only care about the number of samples, you can get away with less exploration, but at the cost of an exponential number of writes per sample.
An interface where local laws hold but global distance is large. The "split corner" (c) shows how a composable interface would need to merge states that the implementation keeps separate.

Key Results

The paper maps out the "certification landscape" based on exploration depth and run length:

  • Worst-Case Distribution: For the most difficult starting distributions, a polynomial budget of samples and writes can only certify correctness if the mean run length is linear in the number of variables ($\ell = \Omega(m)$).
  • Critical Depth: If there are no random runs ($\ell=0$), the tester must explore to a depth of roughly $m/2$ to certify the interface. This corresponds to the typical Hamming distance between two random bitstrings.
  • Thresholds: At a specific error threshold $\epsilon = 1/(32m)$, the critical mean run length for a polynomial sample budget is $\Theta(m \log(m/d) / \log m)$.
Schematic of certification regions. In the "one start state" case (left), law checks always work. In the "worst start distribution" case (right), there is a clear boundary where polynomial budgets fail.

Limitations and Future Work

  • Binary Variables: The current theory is built for binary variables. Extending this to variables with larger domains (e.g., integers or strings) is an open challenge.
  • Uniform Writes: The results assume writes are chosen uniformly at random. Real-world testing might use biased distributions, which could change the exploration requirements.
  • Local Exactness: A key theoretical quantity, $a_d$ (the maximum distance of a "locally exact" interface), is not yet fully characterized. Determining if $a_d \to 0$ as depth $d$ increases is a major open problem.
  • Intermediate Distributions: The gap between the "one start state" and the "worst-case distribution" is large. Future work could explore how exploration needs scale for start distributions with limited (e.g., polynomial) support.

Summary updated

Abstract

Random tests of stateful code check laws, like reading back a written value, at states that random writes reach. The laws hold at every state exactly when the code behaves like a record with hidden data, so a pass is taken as evidence. This can fail: the laws can hold at every sample while the code is far from any record. The laws are local, but behaving like a record is global. Self-testing and stability theorems bridge this gap when the query distribution is controlled by the tester or preserved by the tested maps, but here it is generated by the tested writes, which need not be invertible. We ask how far a test must explore. An interface has $m$ binary variables, each with a read and two writes; in a record, reads return their bits and writes set only their bits. Samples are the ends of geometric runs of mean $\ell$ of uniformly random writes from a start distribution; a tester adds its own write chains of depth $d$. The distance is the least, over records with hidden data, of the largest probability that a read or write differs from it at a sample. From one start state, law checks at $O(m^2\log m/ε)$ samples certify, at fixed confidence, any threshold $ε$ after geometric runs of every positive mean, while runs of fixed positive length can pass at distance $1/2$. For the worst start distribution, take $ε=m^{-β}$ with fixed $0<β\le1$. For $d\le cm$ with fixed $c<1/2$, a polynomial budget of samples and writes exists exactly when $\ell=Ω(m)$, where law checks suffice. With no runs, the least depth for this budget is $(1/2+o(1))m$. Counting samples alone, in the worst case at $ε=1/(32m)$ and $d\le m/16$, the critical mean for a polynomial budget is $Θ(m\log(m/d)/\log m)$, by exhaustive search. So one start state needs only law checks, and the worst case at these thresholds needs exploration linear in $m$ if writes are counted.
BibTeX
@misc{guo2026how,
  author = {Jiaxuan Guo and Xingyu Ren and Jingxin Yang and Youran Sun and Haizhao Yang},
  title = {{How Far Must a Test Explore? Certifying Composable Read-Write Interfaces from Their Own Random Edits}},
  year = {2026},
  eprint = {2611.11899},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.11899},
}
Figure