Repository navigation
Description
Summary
tests/unit/test_1081_physical_meter.py::TestPerAgentMeter::test_available_floors_at_zero_over_ceiling[sqlite]
fails when the full unit suite runs, and passes 14/14 when its file runs alone.
pytest-randomly is installed, so file order is randomized per run — which makes
this a coin flip on ordering rather than a deterministic failure.
Found while verifying an unrelated branch (#2044 / ent#243). Pre-existing on
dev — confirmed by running the identical command against a clean, unmodified
origin/dev worktree.
Evidence
Clean worktree at origin/dev @ 47f8843b, no changes of any kind:
$ git worktree add ~/wt-base --detach origin/dev
$ cd ~/wt-base/src/backend
$ python -m pytest ../../tests/unit -q -p no:warnings -x --timeout=120
FAILED ../../tests/unit/test_1081_physical_meter.py::TestPerAgentMeter::test_available_floors_at_zero_over_ceiling[sqlite]
1 failed, 2657 passed, 12 skipped in 92.58s
In isolation, same worktree:
$ python -m pytest ../../tests/unit/test_1081_physical_meter.py -q -p no:randomly
14 passed in 3.51s
Two independent full-suite runs both stopped at this same test after different
pass counts (2657 and 3821) — consistent with pytest-randomly drawing a
different seed each run and -x halting at the same landmine from different
positions.
Likely mechanism (structurally verified; not yet reduced to a minimal pair)
src/backend/services/settings_service.py:18isfrom database import db— it
binds thedbobject at module-import time.tests/unit/test_1081_physical_meter.pydeliberately evictsdatabase(and
db.connection,db.schedules, …) fromsys.modulesso production code
re-resolves against thedb_harnessengine, and snapshots/restores those names
around every test (Issue fix(tests): test_audit_log_unit.py — 50 collection ImportErrors when run in full suite #762 hygiene,_STUBBED_MODULE_NAMES).services.settings_serviceis not in that snapshot list. If any earlier
file in the session has already imported it, it keeps a reference to the
pre-evictiondb.- The failing test then does
set_ceiling(2)— writingmax_parallel_tasks_ceiling
through the re-resolved harnessdatabase— while the clamp is read through
settings_service's staledb. The ceiling lookup misses,clamp_to_ceiling
falls back to the default, and the assertionst.max_parallel_tasks == 2sees
the unclamped value.
This fits the failing assertion exactly (it is the only test in the class that
depends on a ceiling written by the fixture and read back through
settings_service), and it fits settings_service being deliberately
cache-free at the read layer (#506, --workers 2 consistency) — the value is
re-read from the DB every call, so a wrong db binding surfaces immediately.
Not yet proven: which file does the priming import. Pairwise runs of
test_1081_pull_mode, test_1069_voip_call_path_param, and
test_1615_ssh_password_removed ahead of it all pass, so the chain is longer
than two files.
Why it matters
CI pins three seeds (12345, 67890, 99999 in backend-unit-test.yml), so
whether this is caught depends on whether a pinned seed happens to order the
polluter ahead of this file. That is a latent source of unexplained red on
unrelated PRs, and of false green — the failure mode #1958 and #1895 are also
about.
Suggested fix
Smallest correct change: add services.settings_service (and audit for sibling
from database import db importers reachable from these tests) to
_STUBBED_MODULE_NAMES in tests/unit/test_1081_physical_meter.py, so the
snapshot/restore fixture covers it.
Worth considering more broadly, since this is the third instance of the class:
the from database import db object-binding idiom is what makes module eviction
load-bearing at all. A test-visible accessor (database.get_db()) would make
these files immune rather than each having to enumerate its own eviction set.
Repro
git worktree add ~/wt-base --detach origin/dev
cd ~/wt-base/src/backend
python -m pytest ../../tests/unit -q -p no:warnings -x --timeout=120Re-run until an unlucky seed lands, or bisect with --randomly-seed=<n> to pin one.
Activity
obasilakis commentedon Aug 6, 2026
Data point: seed 12345 does not reproduce
Full unit suite on clean
origin/dev@47f8843bwith the ordering pinned to one of CI's three seeds:Fully green —
test_available_floors_at_zero_over_ceilingpasses at this seed.That is consistent with the analysis above rather than a contradiction: the failure needs the polluting file ordered ahead of
test_1081_physical_meter.py, and seed 12345 happens not to do that. It also means a greenpytest (…, seed 12345)job is not evidence this bug is absent — worth knowing before anyone closes it on a clean CI run.Unseeded runs (fresh random seed each time) reproduced it twice on clean
dev, halting at the same test after different pass counts (2657 and 3821).A second ordering-dependent cluster showed up in the same sweep and is very likely the same root class —
test_subscription_auto_switch_pingpong.py::TestHotReloadSwitcherrored 7/7 under one random ordering, and passes 26/26 in isolation and at seed 12345. Not filed separately; noting it here since a fix to thefrom database import dbbinding idiom would likely cover both.