After much investigation I'm not sure of the precise cause of this problem, except that it's caused by calling session_write_close() repeatedly during CLI execution of the install script by Behat. Running the install script normally, doesn't cause this problem. And doing the install through the web interface instead of CLI, also doesn't cause this problem.
Since the CLI interface doesn't actually generate and use sessions anyway, the easiest fix is just to make the functions in our Session class short-circuit if you're running in CLI.
After much investigation I'm not sure of the precise cause of this problem, except that it's caused by calling session_ write_close( ) repeatedly during CLI execution of the install script by Behat. Running the install script normally, doesn't cause this problem. And doing the install through the web interface instead of CLI, also doesn't cause this problem.
Since the CLI interface doesn't actually generate and use sessions anyway, the easiest fix is just to make the functions in our Session class short-circuit if you're running in CLI.