@Mutate ModelMap task dependencies weirdness

Example

build.gradle

group 'com.mkobit.test'
version '1.0-SNAPSHOT'

class MyPlugin implements Plugin<Project> {

  @Override
  void apply(final Project project) {
    project.tasks.create('firstTask') {
      doFirst {
        println 'Me first!'
      }
    }

    project.tasks.create('lastTask') {
      doFirst {
        println 'Last task here!'
      }
    }
  }

  static class Rules extends RuleSource {
    @Mutate
    void taskDeps(ModelMap<Task> tasks) {
      final lastTask = tasks.get('lastTask')
      tasks.create('newTask') { task ->
        final firstTask = tasks.get('firstTask')
        task.dependsOn(firstTask)
        task.doFirst {
          println 'New task execution'
        }
        // <1>
        lastTask.dependsOn(task)
      }
      // <2>
      // lastTask.dependsOn('newTask')
    }
  }
}

apply plugin: MyPlugin

model {
  tasks {
    wrapper {
      gradleVersion = '3.1-rc-1'
    }
  }
}

Output with <1>

With <1> compiled and <2> commented out:

./gradlew lastTask
:lastTask
Last task here!

Output with <2>

With <2> compiled and <1> commented out

./gradlew lastTask
:firstTask
Me first!
:newTask
New task execution
:lastTask
Last task here!

System Details

Gradle Version: 3.1-rc-1 (saw this on 2.14.1 and 3.0, too)
Operating System:
Is this a regression? If yes, which version of Gradle do you know it last worked for?

Details

I ran into a situation like above when trying to write tasks using the PublishingExtension.

The weirdness seems to be in how the configurations are executed, but it took a while to get it working.
I was very confused when <1> did not work, and it was hard to change it to a working solution.