Skip to content

Backend unit suite red on main: ModuleNotFoundError models.client_processing in merge suites (import-isolation ordering) #12779

Closed

Description

@aryanorastar

Backend unit suite is red on main and takes every open PR with it. The failure is an ordering effect, not a missing file.

Symptom

Setup ERROR, not a test failure, in the merge-related suites:

tests/unit/test_merge_validation.py         ERROR
tests/unit/test_batch_upload_storage.py     ERROR
tests/unit/test_merge_deleted_source_race.py ERROR

E   ModuleNotFoundError: No module named 'models.client_processing'
utils/conversations/projection_payload.py:19: ModuleNotFoundError

Evidence it is main, not a branch

It is not a missing file

backend/models/client_processing.py exists on main:

$ git cat-file -e origin/main:backend/models/client_processing.py && echo EXISTS
EXISTS

And the three suites pass on clean main when run through the repo runner in isolation:

$ BACKEND_UNIT_TEST_FILE_LIST=/tmp/mergetests.txt bash test.sh -q
40 passed
27 passed
3 passed

So the import resolves fine on its own. It only fails in the full-suite ordering, which points at import isolation: something earlier in the run replaces or partially stubs models in sys.modules, and utils/conversations/projection_payload.py imports models.client_processing at module import time, so the stub is what it sees.

Why it is worth fixing rather than re-running

The failure is ordering-dependent, so a re-run can look green and hide it. In the meantime it is a required check, so it blocks unrelated PRs and trains people to treat a red Backend unit suite as noise — which is the expensive part.

Two directions, whichever the owner of that area prefers: have the stubbing test restore sys.modules (or scope its stub), or make projection_payload import models.client_processing lazily so a stubbed models package cannot break collection for unrelated suites.

I have not touched it — this sits in the conversations/merge area rather than anything I have open, and the fix should come from whoever owns that isolation harness.

Activity

  1. aryanorastar commented on Sep 5, 2026

    @aryanorastar
    CollaboratorAuthor

    Still red, and now on two consecutive main commits — so this is not a one-off flake in the ordering.

    main commit Backend unit suite
    cfa5c1cb success
    7c0e4361 success
    23156505 failure
    09ff17e4 failure

    Both failures are the same ModuleNotFoundError: No module named 'models.client_processing' raised from utils/conversations/projection_payload.py:19 during collection of tests/unit/test_batch_upload_storage.py and tests/unit/test_merge_validation.py.

    It is now blocking unrelated PRs that cannot do anything about it. Two of mine, whose diffs do not touch any path in the failure:

    Neither can turn the check green by merging main, because main is where it is red.

    The suspect window is between 7c0e4361 and 23156505. Since the tests pass in isolation and fail only in the full-suite ordering, the likely culprit is a test that stubs or partially replaces models in sys.modules without restoring it, combined with projection_payload.py importing models.client_processing at module import time — so collection of a later suite sees the stub rather than the real package.

    Happy to bisect that window and send a fix if nobody who owns the conversations/merge isolation harness is already on it — say the word rather than both of us doing it.

  2. aryanorastar commented on Sep 5, 2026

    @aryanorastar
    CollaboratorAuthor

    Some triage for whoever picks this up. I tried to find the polluter and did not, but I eliminated the obvious suspects, so the next person need not repeat this.

    Still failing. main is red across multiple commits now (23156505, 09ff17e4, 2cdb89f5), and it has failed the same required check on approved PRs repeatedly — #12748 has been flagged three times.

    Ordering constraint. The CI runner walks tests/unit/ alphabetically, so the polluter sorts before test_batch_upload_storage.py. That bounds the search to roughly the first 104 files.

    The obvious suspects are not it. Five suites reach into sys.modules['models']:

    tests/unit/test_sync_silent_failure.py:751       sys.modules['models'].__path__ = []
    tests/unit/test_action_item_date_validation.py   __path__ = [BACKEND_DIR/"models"]
    tests/unit/test_conversation_structure_timezone.py  same
    tests/unit/test_prompt_cache_integration.py      same
    tests/unit/test_desktop_transcribe.py:121        _models_pkg = sys.modules['models']
    

    test_sync_silent_failure.py looks damning — an empty __path__ makes every models.* submodule unimportable, which is exactly this error. It is not the cause: it stubs models after saving the original, mutates only the stub, and teardown_class restores. Pairing each of these ten files with test_merge_validation.py reproduces nothing:

    $ for f in $(grep -rln "sys.modules\[.models" tests/); do
        pytest "$f" tests/unit/test_merge_validation.py -q -p no:randomly ...
      done
    # no ModuleNotFoundError from any pair
    

    So it is either an interaction needing more than two files, or something that stubs utils.conversations / models.client_processing rather than the models package.

    What I could not do. Running the alphabetical prefix (104 files) in one local process crashes the interpreter for unrelated reasons, so I could not reproduce the CI ordering locally to bisect it properly.

    Worth considering regardless of the root cause: utils/conversations/projection_payload.py imports models.client_processing at module import time. Making that import lazy would stop any models stubbing anywhere from breaking collection of unrelated suites — a narrower blast radius than chasing each polluter as it appears. That is a call for whoever owns the module, not something I want to change from outside it.

    Not taking this further — it sits in the conversations/merge isolation harness and I would rather leave it to someone who owns that code than keep guessing at it from the outside. Flagging the impact honestly though: it is currently blocking approved PRs that cannot do anything about it.

  3. aryanorastar commented on Sep 5, 2026

    @aryanorastar
    CollaboratorAuthor

    Correcting my triage above — it was wrong, and wrong for an embarrassing reason.

    I ran that entire investigation in a worktree that was 372 commits behind main, sitting on an unrelated commit. utils/conversations/projection_payload.py did not even exist in it. That is why the polluter sweep "found nothing" and why the 104-file prefix crashed the interpreter — neither result was about this bug.

    On a correct checkout of main, the same sweep finds the polluters immediately:

    $ for f in $(grep -rln "sys.modules\[.models" tests/); do
        pytest "$f" tests/unit/test_merge_validation.py -q -p no:randomly ...
      done
    POLLUTER: tests/unit/test_sync_silent_failure.py
    POLLUTER: tests/unit/test_payment_promotion_codes.py
    POLLUTER: tests/unit/test_sync_cloud_tasks.py
    POLLUTER: tests/unit/test_sync_v2.py
    POLLUTER: tests/unit/test_conversation_jit_processing.py
    POLLUTER: tests/unit/test_sync_opus_decode.py
    POLLUTER: tests/unit/test_sync_pcm_decode.py
    

    Seven, not zero. So please disregard "the obvious suspects are not it" — that conclusion was an artifact of the stale tree, as was my claim that the erroring suites "pass in isolation on clean main".

    Fix: #12785

    Given seven polluters and nothing preventing an eighth, auditing each one's teardown is the whack-a-mole option. #12785 takes the other route and defers the models.client_processing import into strip_client_processing, its only consumer, so no models stub anywhere can break collection of that module.

    That also restores what the module already claimed to be — its docstring says it lives outside process_conversation specifically so importing it "must not drag in the coordinator's module graph". A module-scope import of a models submodule was the same mistake one level down.

    Every polluter, paired with the two erroring suites, now collects and runs; the same pairings produce 40 collection errors before the change. The regression test installs the same bare stub those suites use and is mutation-checked — restoring the module-scope import fails it with the exact production error at the exact line.

    Two things this does not settle

    I still cannot reproduce CI's full-suite ordering locally, so I am not claiming #12785 turns the check green — only that the failure mode is removed at its source. CI is the authority.

    A second, unrelated pollution is now visible. With collection fixed, test_sync_opus_decode / test_sync_pcm_decode running before test_batch_upload_storage leak MagicMocks for utils.other.storage, giving assert 0 == 1 on upload_audio_chunks_batch. Those tests never executed before — they died at collection — so this is pre-existing breakage becoming visible rather than a regression. In alphabetical order test_batch_upload_storage sorts before both, so the triggering direction should not arise in CI; flagging it rather than asserting it cannot.

  4. aryanorastar commented on Sep 5, 2026

    @aryanorastar
    CollaboratorAuthor

    CI has now confirmed the fix, so the blocker on this PR has a verified remedy rather than a candidate.

    #12785's Backend unit suite is green — run 33961213829, 3m29s, with 1072 backend unit test files selected and zero occurrences of No module named 'models.client_processing'. The same required check is red with that exact error on every other open PR, including this one.

    Root cause, for the record: utils/conversations/projection_payload.py imported models.client_processing at module scope, and seven suites under tests/unit replace sys.modules['models'] with a bare stub. While one of those stubs is installed, merely collecting a later module that reaches it dies — which is why the error surfaces on test_batch_upload_storage / test_merge_validation rather than on whatever caused it. #12785 defers that import to its only consumer, so no models stub anywhere can break collection.

    Nothing changes on this PR. Once #12785 lands, a merge of main here should turn the check green.

  5. aryanorastar commented on Sep 6, 2026

    @aryanorastar
    CollaboratorAuthor

    Fixed and verified on main — closing.

    #12785 deferred the module-scope from models.client_processing import PROJECTION_FAMILY_FIELDS into strip_client_processing, and merged to main on 2026-09-05 at 11:38Z.

    Confirmed at main today rather than assumed:

    • backend/utils/conversations/projection_payload.py no longer contains a module-scope from models.client_processing import (grep count 0).
    • The last six repo-checks runs on main are all success — most recently 492a563f at 11:17Z today.

    The root cause, for the record: seven suites in tests/unit replace sys.modules['models'] with a stub. A module-scope import in projection_payload.py then made merely collecting later alphabetically-sorted suites fail — test_batch_upload_storage.py and test_merge_validation.py — even though neither imports that module. Deferring the import to call time resolves it after the stub is torn down. The regression test in test_client_processing_acceptance.py evicts both models and models.client_processing from sys.modules; evicting only the first made the test vacuous.

    One related finding, filed separately rather than reopening this: the same class of leak exists between testing/contracts/test_desktop_backend_parity.py and tests/unit/test_batch_upload_storage.py (AttributeError: <module 'utils.other.storage'> has no attribute 'storage_client'). It reproduces with main's own copy of the contract file, and CI never sees it because contracts and unit run as separate jobs.

  6. moved this from Someday to In review in omi TODO / bountieson Sep 6, 2026
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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions