Skip to content

test(labeling): don't assert batch completion order - #3269

Open
mallyskies wants to merge 1 commit into
Graphify-Labs:v8from
masquepublishing:fix/labeling-batch-test-order
Open

test(labeling): don't assert batch completion order#3269
mallyskies wants to merge 1 commit into
Graphify-Labs:v8from
masquepublishing:fix/labeling-batch-test-order

Conversation

@mallyskies

Copy link
Copy Markdown
Contributor

test_label_communities_batches_when_over_batch_size fails about 75% of the time — 9 of 12 runs on a clean v8 checkout here, in isolation, with no other test involved.

assert [100, 50, 100] == [100, 100, 50]
E   At index 1 diff: 50 != 100

label_communities fans its batches out across a ThreadPoolExecutor and collects them with as_completed, so the mocked _call_llm runs on several threads and completion order is not dispatch order. The 50-community batch is the smallest and usually finishes before the second 100.

The batching itself is correct on every run: 250 communities at batch_size=100 always produces 100/100/50. Only the recorded order varies — which the test never intended to pin, going by its own comment, "250 communities / 100 per batch -> 3 batches (100, 100, 50)".

Change

Assert on the sorted sizes rather than the sequence:

assert sorted(calls) == [50, 100, 100]

and guard the shared list with a threading.Lock instead of relying on list.append being atomic under the GIL. That second part isn't fixing an observed failure — CPython makes it safe today — but the test appends from a thread pool and shouldn't depend on that.

Verification

  • Before: 9/12 runs fail, isolated
  • After: 0/20 runs fail, isolated; 0/20 for the whole of tests/test_labeling.py
  • Full suite goes from 14 failures to 13 on this machine, and the one that disappears is this test. The other 13 are environmental here (terraform grammar, ollama, wheel payload, markdown frontmatter) and unrelated.

🤖 Generated with Claude Code

`test_label_communities_batches_when_over_batch_size` fails about 75% of
the time (9 of 12 runs here, in isolation — not an interaction with any
other test).

`label_communities` fans its batches out across a ThreadPoolExecutor and
collects them with `as_completed`, so the mocked `_call_llm` is invoked
from several threads and finishing order is not dispatch order. The
50-community batch is the smallest and usually completes before the
second 100, so the recorded list is `[100, 50, 100]`:

    assert [100, 50, 100] == [100, 100, 50]

The batching itself is always correct — 250 communities at batch_size=100
gives 100/100/50 every run. Only the order varies, which the test never
meant to pin: its own comment says "3 batches (100, 100, 50)".

Asserts on the sorted sizes instead, and guards the shared list with a
lock rather than relying on `list.append` being atomic under the GIL.

20/20 runs pass with the change; the rest of the suite is unaffected.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).


Graphify review — findings

Guards the shared calls list in test_label_communities_batches_when_over_batch_size with a lock and asserts on the sorted contents, reflecting that label_communities now dispatches batches across a ThreadPoolExecutor where completion order is nondeterministic.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 76 functions depend on the 76 functions this change touches.

Health — grade A; no new coupling hotspots.

Verification — 76 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 76 function(s) in the blast radius were not formally verified this run

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant