What if you:

1) changed this function to be called "removeJob" or "removeJobAndGetIndependentStages" (or whatever better name you can think of), and remove p here
2) As mentioned above, call removeStage for the independent stages here -- since it doesn't seem like there's a time when you'd ever want to remove a job but *not* the stages that depend only on it
3) the function will return a set of independent stages, which can be used on line 930 to deal with the cancellation

Seems like that might improve readability without sacrificing flexibility.  Feel free to ignore this though, or wait until the-powers-that-be review it, since they may have different thoughts.