scm_pr_merged never fires for a pull request merged while a sync is running

Aperta
#534 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
64/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
github, go
Ambito
backend

Direzione di ricerca

Start in internal/scm/sync.go: read shouldEmitPRMergeEvent, shouldRunSmartCommits, syncRepository (where last_synced_at is written) and upsertPullRequestSCMLink. Trace the order of listing pull requests versus writing the checkpoint, then reproduce with a sync that starts before a merge and finishes after it. Done means a newly observed open-to-merged transition emits scm_pr_merged exactly once and smart commits run, while a newly connected repository does not replay history. Check the existing internal/scm tests before changing the check.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

fixed-0.9.5

A pull request that merges while a repository sync is in progress never fires the scm_pr_merged action trigger. The link is updated to merged, but no action event is recorded, so automations on "SCM: pull request merged" do not run for that pull request and never will.

Seen on v0.9.4 (2ebdd711) with a GitHub connection. The relevant code is the same on main.

What happened

Times are UTC, from the server log and the database:

  1. ~10:15:56 — a sync of the repository starts and lists the pull request while it is still open.
  2. 10:16:13 — the pull request is merged on GitHub.
  3. ~10:19 — that sync finishes and writes last_synced_at.
  4. 10:20:54 — the next sync sees the pull request as merged and sets item_scm_links.state to merged.

Afterwards the link row is merged, action_event_batches has no scm_pr_merged row for it, and the action has no entry in action_execution_logs. An scm_pr_linked action on the same item and pull request had run normally earlier.

Steps 1 and 3 are inferred from log timestamps; the sync was slow because the connection was being rate limited on the tag-listing step, which widened the window from seconds to minutes.

Cause

shouldEmitPRMergeEvent (via shouldRunSmartCommits) in internal/scm/sync.go only allows the event when the merge is newer than the checkpoint:

if !lastSyncedAt.IsZero() {
	return pr.MergedAt.After(lastSyncedAt)
}

syncRepository writes the checkpoint at the end of a sync, after pull requests, commits, branches, tags and releases have all been processed:

UPDATE workspace_repositories SET last_synced_at = CURRENT_TIMESTAMP, ...

So the checkpoint is later than the moment the pull requests were listed. A merge that lands between the listing and the end of the sync has MergedAt < last_synced_at when the next sync observes it, emitMerged is false, and upsertPullRequestSCMLink moves the row to merged without emitting. Because the stored state is now merged, becameMerged is false on every later sync and the event is lost for good.

Smart commits for the pull request are skipped by the same check.

Possible fixes
  • Record the time the sync started (before listing pull requests) and store that as last_synced_at, so the checkpoint never passes a change the sync did not see.
  • Or, when a link already exists and its state changes from open to merged, emit regardless of MergedAt. The stored previous state already shows the merge is new; the time check is only needed when the link is first created, to avoid replaying history on a newly connected repository.
Workaround

Move the affected item by hand. There is no way to re-fire the trigger once the link is merged.

Lingua principale
Go
Stelle
421
Fork
50
Merge medio
17h 34m
PR unite (30g)
80

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Windshiftapp/core

Tutte le issue di Windshiftapp/core

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.