Repository navigation
Description
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 firstoutput_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?
- Push a Python change to a PR; wait for the
pythonmatrix. - The flake hits sometimes; rerunning sometimes turns it green.
- 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: AssertionErrorPossible directions
The cleanest fix is to make the test's per-channel intent explicit and assert the actual priority guarantee:
- 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. - With both items present, assert priority pop order:
get()first returns the control reply (priority 1), then the data element (priority 2). - 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
[-]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[/+]test(amber-python): per-channel sync in test_main_loop_thread_can_ali…
[-]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[/+]test(amber-python): assert control-before-data priority on aligned ECM
test(amber-python): per-channel sync in test_main_loop_thread_can_ali…
test(amber-python): per-channel sync in test_main_loop_thread_can_ali…