Skip to content

(fix): prevent duplicate wfIDs in syncer#21524

Open
justinkaseman wants to merge 1 commit intodevelopfrom
fix/syncer-duplicate-wid
Open

(fix): prevent duplicate wfIDs in syncer#21524
justinkaseman wants to merge 1 commit intodevelopfrom
fix/syncer-duplicate-wid

Conversation

@justinkaseman
Copy link
Contributor

@justinkaseman justinkaseman commented Mar 14, 2026

Changes

Since the Workflow Syncer invokes the event handler via goroutines, duplicate events can cause races.

Three scenarios can lead to unintended workflow loading behavior:

  • When there is a contract source that has multiple families with the same workflow on them, this can lead to duplicate workflows being loaded.
  • When there is both a contract source and an extra source there could be duplicates across them.
  • If one of the sources contains duplicates of a workflow.

These happen because of a lack of checks for workflowsSeen[id]. Adds guards for these cases.

Additionally this PR:

  • Cleans up "hooks". There is only one left OnStartFailure, and it is not used. The place where it is invoked is in an initial w.workflowDonNotifier.WaitForDon(ctx) call. This is redundant, because syncUsingReconciliationStrategy calls this on every tick.

@justinkaseman justinkaseman requested a review from a team as a code owner March 14, 2026 03:11
Copilot AI review requested due to automatic review settings March 14, 2026 03:11
@github-actions
Copy link
Contributor

👋 justinkaseman, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@github-actions
Copy link
Contributor

✅ No conflicts with other open PRs targeting develop

@github-actions
Copy link
Contributor

I see you updated files related to core. Please run make gocs in the root directory to add a changeset as well as in the text include at least one of the following tags:

  • #added For any new functionality added.
  • #breaking_change For any functionality that requires manual action for the node to boot.
  • #bugfix For bug fixes.
  • #changed For any change to the existing functionality.
  • #db_update For any feature that introduces updates to database schema.
  • #deprecation_notice For any upcoming deprecation functionality.
  • #internal For changesets that need to be excluded from the final changelog.
  • #nops For any feature that is NOP facing and needs to be in the official Release Notes for the release.
  • #removed For any functionality/config that is removed.
  • #updated For any functionality that is updated.
  • #wip For any change that is not ready yet and external communication about it should be held off till it is feature complete.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes race conditions caused by duplicate workflow IDs appearing in reconciliation metadata when workflows are associated with multiple DON families or multiple sources. It adds deduplication guards in generateReconciliationEvents and clears stale pending events that could cause permanent invariant violations. Additionally, it removes the unused Hooks struct and redundant WaitForDon call at startup.

Changes:

  • Added workflowsSeen checks to skip duplicate workflow IDs for both active (no engine) and paused status paths in generateReconciliationEvents.
  • Added stale pending event cleanup when an active engine is already registered (the case true path), preventing invariant violations across sources.
  • Removed unused Hooks struct, its initialization, and a redundant WaitForDon call that is already performed on every tick in syncUsingReconciliationStrategy.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
core/services/workflows/syncer/v2/workflow_registry.go Adds duplicate-ID guards, stale pending event cleanup, and removes unused Hooks type and redundant startup logic
core/services/workflows/syncer/v2/workflow_registry_test.go Adds three test cases covering duplicate IDs with pending events, stale pending events with active engines, and duplicate paused workflows

@justinkaseman justinkaseman changed the title (fix): prevent duplicate wfIDs in synced from multiple sources/families (fix): prevent duplicate wfIDs in syncer Mar 14, 2026
@cl-sonarqube-production
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
5.83% Technical Debt Ratio on New Code (required ≤ 4%)
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube

Catch issues before they fail your Quality Gate with our IDE extension SonarQube IDE SonarQube IDE

@trunk-io
Copy link

trunk-io bot commented Mar 14, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@justinkaseman justinkaseman requested a review from a team March 14, 2026 05:07
for _, wfMeta := range workflowMetadata {
workflowMetadataMap[wfMeta.WorkflowID.Hex()] = wfMeta
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider deduping here by just dumping it into a map and logging a warn if there's a duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants