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

Ouverte
#534 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
64/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
github, go
Domaine
backend

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Go
Étoiles
421
Forks
50
Merge moyen
17 h 34 min
PR mergées (30 j)
80

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de Windshiftapp/core

Toutes les issues de Windshiftapp/core

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.