Skip to content

test_label_communities_batches_when_over_batch_size is flaky on v8 HEAD (order-dependent, full-suite only) #2877

Closed

Description

@AromalBiju1

Summary

tests/test_labeling.py::test_label_communities_batches_when_over_batch_size
fails intermittently when run as part of the full suite, but passes
consistently when run in isolation. Confirmed on a clean v8 checkout with
no other changes applied.

Version

v8 @ b14b52e (v0.9.47), Python 3.14.

Reproduction

Isolated — passes every time:

uv run pytest tests/test_labeling.py::test_label_communities_batches_when_over_batch_size -q

1 passed (repeated 6/6 runs)

Full suite — fails intermittently:

uv run pytest tests/ -q

FAILED tests/test_labeling.py::test_label_communities_batches_when_over_batch_size
assert [100, 50, 100] == [100, 100, 50]

Reproduced this way twice on a clean tree (no local changes, verified via
git stash before each run).

What the test asserts

The test dispatches 250 communities in batches of 100 and asserts the fake
LLM call receives them in submission order: [100, 100, 50]. Under the
full suite it sometimes observes [100, 50, 100] instead — same set of
batch sizes, different order.

Suspected cause

Looks like label_communities's batch dispatch doesn't guarantee
submission order is preserved on return — consistent with something like
ThreadPoolExecutor + as_completed() (completion order, not submission
order) rather than executor.map() (which preserves order). This would
only surface under contention, which lines up with it passing standalone
and failing under full-suite load.

Two possible fixes, not sure which is intended:

  • label_communities switches to an order-preserving collection method, or
  • the test sorts/normalizes calls before comparing, since exact dispatch
    order may not actually be a real invariant worth asserting

Haven't dug into graphify/llm.py's batching implementation, so filing as
an observation rather than a proposed fix.

Why filing this

CONTRIBUTING.md asks contributors to run the full suite and confirm it
passes before opening a PR. Flagging this since it currently blocks that
on a totally clean v8 checkout, independent of any particular PR's
changes.

Activity

  1. GREYGROUPJP commented on Sep 10, 2026

    @GREYGROUPJP

    This looks fixed. 98d62e23 ("test(labeling): pin max_concurrency=1 so batch-order assertion is deterministic", cherry-picked from #3374) shipped in 0.9.56 and makes the batch-order assertion deterministic. The commit does not reference this issue, so it stayed open.

    I ran a controlled before/after on one clean clone — same virtualenv, same machine (macOS 26.3.1 arm64, Python 3.13.14), 30 isolated runs of the test at each tag:

    tag fix isolated failures
    v0.9.55 absent 20/30
    v0.9.57 present 0/30

    On v0.9.57, tests/test_labeling.py is 35 passed across five consecutive runs, and test_label_communities_parallel_matches_sequential — the sibling test the fix defers concurrency coverage to — passes.

    One correction to the original report for the record: the flake was not full-suite-only. It reproduces standalone on v0.9.55 at roughly a 45-67% rate (20/30 and, in a further sample, 11/25). Every observed failure was the same order, assert [100, 50, 100] == [100, 100, 50] — the trailing 50-community batch consistently completes ahead of the second 100-batch. The cause was label_communities() submitting batches to a ThreadPoolExecutor and merging via as_completed(), so the fake's shared calls list recorded arrival order rather than dispatch order, which is what 98d62e23 addresses.

    Safe to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions