hypothesis icon indicating copy to clipboard operation
hypothesis copied to clipboard

`large_base_example` health check fails for unique collections of non-empty collections since 6.170.1

Open eric-weaver opened this issue 1 month ago • 1 comments

Since 6.170.1, a unique collection whose elements are non-empty collections fails the large_base_example health check, even when the strategy is tiny:

from hypothesis import given, strategies as st


@given(st.sets(st.frozensets(st.integers(), min_size=1), min_size=1))
def test(x):
    pass
hypothesis.errors.FailedHealthCheck: The smallest natural input for this test is very large. ...

This passes on 6.170.0 and fails on 6.170.1 and 6.170.2. The same happens with st.lists(st.lists(st.booleans(), min_size=1), unique_by=tuple, min_size=1) and with st.sets(st.from_regex(r"[a-z]+", fullmatch=True), min_size=1).

It needs both min_size=1 arguments. The outer one makes the probe draw an element at all. The inner one triggers the bug: st.sets(st.lists(st.integers()).map(tuple), min_size=1) still passes, and the same strategy with st.lists(st.integers(), min_size=1) fails.

Environment: Hypothesis 6.170.1 and 6.170.2, Python 3.12.8, macOS.

Cause

This looks like a side effect of #4834. Inside an element of a unique collection, the ChoiceTemplate("simplest") probe now draws simplest_index % compute_max_children(...), and simplest_index increments on every unforced draw in the element.

When the element's first item is forced, the element then alternates a "draw another?" boolean with an item draw. Every boolean lands on an odd index, so it is always True and the probe never terminates. On 6.170.2, as (choice type, simplest_index, value):

('integer', 0, 0)
('boolean', 1, True)
('integer', 2, -1)
('boolean', 3, True)
... continues until the probe overruns BUFFER_SIZE

On 6.170.0 the same probe produces {frozenset({0})}.


This issue was drafted with AI assistance. I have reviewed it and verified the reproduction and trace myself.

eric-weaver avatar Oct 19 '26 21:10 eric-weaver

I'd like to take this one. I reproduced the failure on 6.170.2 and have a fix in progress: use a counter per (choice type, constraints) instead of the global simplest_index, so the "draw another?" booleans don't inherit the parity of the element draws.

I'll open a PR with regression tests for the nested-list case and the reported health check.

This comment was prepared with AI assistance under my review.

agustin18 avatar Oct 20 '26 19:10 agustin18