From d93506db3344a586eb0e444a879585814bc5b3f2 Mon Sep 17 00:00:00 2001 From: Babissimo Date: Tue, 15 Sep 2026 19:21:23 +0100 Subject: [PATCH] Keep the leaked solver daemons off the known-lane pass under pytest test_interval_gate_holds_between_passes asserts that its first maybe_run_pass runs, and under xdist that assertion fails now and then with the attempt count still 0 (2026-09-06, 2026-09-15 on #389, and twice in a row on #403, all diffs that never touched the backend). conftest turns KNOWN_LANE_MODE off for the suite so the solver worker daemons every TestClient lifespan leaks do not poll the pass, but DARK_FOLLOW_MODE keeps its "shadow" default, lanes_armed() is true when either lane is on, and maybe_run_pass returns early only when both are off. So every leaked daemon takes the pass lock, stamps the pass clock and runs an empty dark-follow pass every two seconds, and one landing between the fixture's clock reset and the test's first call leaves that call gated. DARK_FOLLOW_MODE is now off for the suite the way KNOWN_LANE_MODE is, and the known-lane fixture turns it off again per test for a daemon armed while another file had a lane on, before the reset that drains any pass in flight. Tests that exercise dark following already set the mode themselves. The fixture's clock comment is trimmed to the reason the reset stands; the ordering story it told was the first guess at this. ClickUp: 123zgec3130 Co-Authored-By: Claude Fable 5.1 --- backend/tests/conftest.py | 6 ++++++ backend/tests/test_known_lane.py | 32 ++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index c827c7b1..51849d60 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -23,6 +23,12 @@ # known_lane counters. Tests that exercise the lane set the mode explicitly — # monkeypatch on core.state, or maybe_run_pass's mode argument. os.environ.setdefault("KNOWN_LANE_MODE", "off") +# Same for the dark-follow lane: lanes_armed() arms the hook when EITHER lane +# is on, and maybe_run_pass returns early only when both are off, so with this +# lane at its "shadow" default every leaked daemon still took the pass lock and +# stamped the pass clock every two seconds, gating the known-lane tests' first +# call. Tests that exercise dark following set the mode themselves. +os.environ.setdefault("DARK_FOLLOW_MODE", "off") # Needed so the /api/radar/detections auth guard is active in tests. os.environ.setdefault("RADAR_API_KEY", "test-key-abc123") # A fixed node-fuzz salt, so every published coordinate the suite sees is the diff --git a/backend/tests/test_known_lane.py b/backend/tests/test_known_lane.py index 0c7d7f98..b5d866f4 100644 --- a/backend/tests/test_known_lane.py +++ b/backend/tests/test_known_lane.py @@ -90,25 +90,33 @@ def _known_lane_state(): delattr so these tests keep passing unchanged once slice A declares the real attributes in core/state.py. - Deliberately does NOT arm state.KNOWN_LANE_MODE: TestClient lifespans - leak solver worker daemons into this process (see test_solver_worker's - private-queue rationale), and every one of them polls maybe_run_pass - against the live flag — arming it here would let a daemon race these - tests for the per-hex dedup window. Tests pass the mode explicitly - instead; only the live-flag-semantics tests set the attribute, and only - to values the lane reads as off. + Deliberately does NOT arm state.KNOWN_LANE_MODE, and turns + DARK_FOLLOW_MODE off: TestClient lifespans leak solver worker daemons + into this process (see test_solver_worker's private-queue rationale), + and one armed while another file had either lane on polls + maybe_run_pass against the live flags for the rest of the run. With + both off it returns before the pass lock, so it can neither race these + tests for the per-hex dedup window nor stamp the pass clock between + the reset below and a test's first call. Tests pass the mode + explicitly instead; only the live-flag-semantics tests set the + attribute, and only to values the lane reads as off. """ prev_claims = getattr(state, "known_claims", _SENTINEL) prev_mode = getattr(state, "KNOWN_LANE_MODE", _SENTINEL) + prev_dark = getattr(state, "DARK_FOLLOW_MODE", _SENTINEL) state.known_claims = {} - # The module keeps its pass-interval clock (_last_pass_ts) at module - # level; under xdist worksteal a test from another class can leave it - # inside the interval, so the first maybe_run_pass of the next test is - # gated and its attempt count reads 0 (seen once in CI, 2026-09-06). + state.DARK_FOLLOW_MODE = "off" + # The pass clock, dedup maps and counters live at module level; each test + # starts them from boot values. The reset takes the pass lock, so a daemon + # pass already in flight finishes before the test begins. known_lane._reset_for_tests() state._reset_for_tests() yield - for name, prev in (("known_claims", prev_claims), ("KNOWN_LANE_MODE", prev_mode)): + for name, prev in ( + ("known_claims", prev_claims), + ("KNOWN_LANE_MODE", prev_mode), + ("DARK_FOLLOW_MODE", prev_dark), + ): if prev is _SENTINEL: # A test may have deleted or never set it. if hasattr(state, name):