Reconciler not working after changeset errored
Created by: eseliger
Following setup:
I created a changeset before with Changeset spec 1:
...
diff: "+Hello world"
published: true
And that went through and is open. Then, I change my diff and apply a second time with changeset spec 2:
...
diff: "+Hello universe"
published: true
Apply this spec, and make it fail constantly (simulated github issue or something else). Then it's in an errored state and will eventually hit the max amount of retries. To retry, we tell people to then "just reapply the campaign spec", because it re-enqueues the changeset spec and then the reconciler will pick it up again. Under the hood, src-cli creates another new spec, changeset spec 3:
...
diff: "+Hello universe"
published: true
which is identical to the spec 2 besides the dbID. See it pass now (after removing the reason for failure). BUT: It will still have the "Hello world" patch on the code host.
Why? Because we compare the previous with the current spec. When we apply the first time, the changeset looks like this
previous_spec_id: 1
spec_id: 2
And the delta between those is: diffChanged: true
Now that we apply again, we get
previous_spec_id: 2
spec_id: 3
and between those the delta is diffChanged: false boom, the universe is destroyed now and we need to find a campaign spec to big bang up a new one pretty quickly.
Potential fix: The rewirer should, depending on the changeset reconciler state, do:
// Can't be processing because we await reconciler to finish.
if changeset.Errored() || changeset.Queued() {
changeset.ChangesetSpecID = newSpec.ID
} else {
changeset.PreviousSpecID = changeset.ChangesetSpecID
changeset.ChangesetSpecID = newSpec.ID
}