Skip to content

Flaky test_main_loop_thread_can_align_ecm: drain order depends on inter-channel timing #4524

Closed

Description

@Yicong-Huang

What happened?

core/runnables/test_main_loop.py::TestMainLoop::test_main_loop_thread_can_align_ecm is intermittently red on CI for unrelated PRs (observed on #4512 and #4520). Locally it always passes.

The test puts a data tuple and an alignment-completing ECM into input_queue back-to-back, then assumes output_queue.get() yields the DataElement (to the downstream worker) before the NoOperation ReturnInvocation (back to "sender" / coordinator):

input_queue.put(ECMElement(tag=mock_control_input_channel, payload=test_ecm))   # 1
input_queue.put(mock_binary_data_element)                                        # 2
input_queue.put(ECMElement(tag=mock_data_input_channel, payload=test_ecm))      # 3 -> aligns ECM, runs NoOperation
output_data_element: DataElement = output_queue.get()    # ASSUMES data first

output_queue is a LinkedBlockingMultiQueue whose sub-queues are keyed by channel, with priority 1 for control sub-queues and priority 2 for data sub-queues (internal_queue.py:80). MainLoop produces in this order: data → NoOperation reply. Whichever items are present when the test calls .get() decides what it sees:

  • Fast (local): the test pops between the two production puts → only data is queued → data first → ✅ (test happens to pass)
  • Slow (CI): both items queued before pop → priority returns the control reply first → ❌
AssertionError: ChannelIdentity(..., to='sender', is_control=True)  # actual (control reply)
            != ChannelIdentity(..., to='dummy_worker_id', is_control=False)  # expected (data)

The production behavior is correct — control to coordinator outranking data on egress is the intended priority, and within any one data channel sub-queue FIFO is preserved (so an ECM forwarded on a data channel stays behind data tuples on the same channel). The bug is that the test never synchronized on the precondition (both channels populated) before asserting an order, so on a fast pop it accidentally validated the wrong thing.

How to reproduce?

  1. Push a Python change to a PR; wait for the python matrix.
  2. The flake hits sometimes; rerunning sometimes turns it green.
  3. Locally on macOS the test passes 100/100 in isolation and 30/30 of the full file.

Version

1.1.0-incubating (Pre-release/Master)

Commit Hash (Optional)

Pre-existing on main; the test and the priority logic were added in the same commit (#3245, 2025-02-19). Failures observed on 19cb2d1c92 (#4512) and 42aa3eaeae (#4520).

What browsers are you seeing the problem on?

No response — backend test.

Relevant log output

core/runnables/test_main_loop.py::TestMainLoop::test_main_loop_thread_can_align_ecm FAILED
>       assert output_data_element.tag == mock_data_output_channel
E       AssertionError: assert ChannelIdentity(from_worker_id=ActorVirtualIdentity(name='dummy_worker_id'), to_worker_id=ActorVirtualIdentity(name='sender'), is_control=True) == ChannelIdentity(from_worker_id=ActorVirtualIdentity(name='dummy_worker_id'), to_worker_id=ActorVirtualIdentity(name='dummy_worker_id'), is_control=False)
core/runnables/test_main_loop.py:1176: AssertionError

Possible directions

The cleanest fix is to make the test's per-channel intent explicit and assert the actual priority guarantee:

  1. Wait until both expected channel sub-queues have their item in output_queue. Sub-queues are added lazily on first put, so the wait should safely treat a missing key as size zero.
  2. With both items present, assert priority pop order: get() first returns the control reply (priority 1), then the data element (priority 2).
  3. Bound with a timeout so a regression that drops one of the channels fails fast with a descriptive message instead of hanging.

PR #4526 implements this.

Activity

  1. added theissue type on Apr 26, 2026
  2. changed the title [-]Flaky test_main_loop_thread_can_align_ecm: assumes FIFO output_queue, but it is priority-based[/-] [+]output_queue priority breaks ECM ordering: NoOperation reply jumps ahead of data[/+] on Apr 26, 2026
  3. added a commit that references this issue on Apr 26, 2026
    b8b51ca
  4. changed the title [-]output_queue priority breaks ECM ordering: NoOperation reply jumps ahead of data[/-] [+]Flaky test_main_loop_thread_can_align_ecm: drain order depends on inter-channel timing[/+] on Apr 26, 2026
  5. added a commit that references this issue on Apr 26, 2026
    a6ae296
  6. added a commit that references this issue on Jun 22, 2026
    808c94e
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions