batches: changeset spec expiration is too aggressive when the batch spec hasn't been applied or superseded
Created by: LawnGnome
This is split from #20146.
As background: we have BatchSpecTTL and ChangesetSpecTTL, which are currently hard coded to 7 and 2 days, respectively. The intention here is that batch specs that are unapplied after 7 days are removed, and changeset specs that aren't attached to a batch spec after 2 days are removed.
The logic as implemented appears to break down in this specific scenario:
- A batch spec is uploaded with
src batch preview. - No action occurs on the batch spec or any associated batch change for more than two days.
- The changeset specs get erroneously pruned.
- Viewing the batch spec preview results in a confusing message indicating the lack of changeset specs, or (worse) sets up a scenario where the existing changesets will be closed, since they don't have changeset specs.
I'm pretty sure the underlying issue is this clause in the query to prune expired changeset specs. This was added in #12780 to work around an ordering violation when pruning batch specs and changeset specs at the same time, but I think this is matching in scenarios it shouldn't right now: if the batch spec hasn't been applied and the changeset spec isn't attached to a changeset, this should use the batch spec TTL and not the changeset spec TTL.