Running cells one by one does not work seamlessly

I’m using jupyterlab 3.3.2 with a Python 3.9.5 kernel. In the first cell of my notebook I have some library imports, and the second cell defines some variables. The third cell invokes a library method using the previously defined variable.

When I click on the button that says “Restart Kernel and Run All Cells…”, I get an error in the third cells complaining about undefined modules and variables. Seems like the results of first and second cells are not properly propagated to the third cells by the time it starts executing.

This happens even if I run the cells one by one manually. Only works the second or third time of asking. What could be the problem?