If we actually need this flag, I think it should be set before calling MFPutWorkItem(), and then it's more natural to check for it first in purge_pending_commands() before filtering by command types.
We must check for `SESSION_CMD_SET_TOPOLOGY` in `session_purge_pending_commands()` even after the op is submitted, because it ends the purge if it has not been executed. The `submitted` check could be moved above the check for other commands, but the flag is only for cleanup and is not meant to affect purging, so I think it should stay where it is for clarity. The mutex is locked in all cases where it is set or checked.
Would it make sense to remove it from commands list right before it's submitted and use a second list for submitted commands?
The op stays in the list until execution because its presence flags that any new command must not be submitted immediately in `session_submit_command()`. Only one command at a time may be pending in the work queue, so we would need only a single pending op variable instead of a second list. But then in `session_purge_pending_commands()` we would need to check for `SESSION_CMD_SET_TOPOLOGY` in the pending op in addition to the list.
I think it best to limit changes to command submission due to the risk of regression. This commit effectively only changes cleanup responsibility in `session_purge_pending_commands()`.