redo automatic build scheduling

replace 10 second 'grace period' approach with a smarter database operation.

automatically triggered builds now wait for any started builds to have inputs,
so that the triggered version can be compared with it. if a build is still
starting, or if a build is running and has the same version, it is dropped on
the floor.

later, for builds that have the same resource as input and output,
automatically triggered builds will wait for any in-flight builds to complete,
so that outputs can be compared in the same way. otherwise, these builds would
trigger themselves.
serialize build attempts for circular jobs

this allows a job to have the same resource as input and output, and not
trigger itself; automatic trigger attempts will wait for running builds to
complete if they were triggered by the resource.