watchpr: detect merge/close in poll loop (was hanging after baseline) #3
Reference in New Issue
Block a user
Delete Branch "benvin/watchpr-poll-loop-fix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
In production,
watchpr --interval 60s unkin/artifactapi#118(single PR) printedbaseline establishedand then never exited even after the PR was merged -- the process stayed alive but never detected the merge.watchpr --oncereported the same PR correctly as merged, and an earlier two-PR watch had correctly detected a merge, so the single-shot fetch and change logic were fine; the watch loop was not.Root cause: the poll loop only reported a transition from the baseline snapshot.
MeaningfulChangedetects merge/close only across an edge (!prev.Merged && cur.Merged,prev.State=="open" && cur.State=="closed"). A PR already merged or closed when watchpr starts is captured as the baseline, so no transition ever occurs and the loop polls the dead PR forever.How
agent.Watchbehind aStateFetcherinterface, so the loop, its open->merged/close detection, and its poll-error resilience are unit-testable with a fake client.PR mergedwithout consuming a tick.