Skip to content

fix(push-hook): retry MR commits fetch to handle GitLab async race condition#173

Closed
sylvaincombes wants to merge 1 commit into
ManoManoTech:mainfrom
sylvaincombes:fix/push-hook-race-condition
Closed

fix(push-hook): retry MR commits fetch to handle GitLab async race condition#173
sylvaincombes wants to merge 1 commit into
ManoManoTech:mainfrom
sylvaincombes:fix/push-hook-race-condition

Conversation

@sylvaincombes
Copy link
Copy Markdown
Member

Problem

When Homer receives a push hook, it filters the pushed commits by cross-referencing the GitLab MR commits API (to remove rebase noise). Because GitLab updates MR content asynchronously, the just-pushed commit is sometimes absent from the API response at the time Homer fetches it.

Flow:

  1. A commit is pushed
  2. Homer receives the hook almost instantly and fetches the MR commits
  3. The commit isn't there yet → filtered out → no reviews left → Homer returns 204 and posts nothing (no error log, invisible)

Fix

Add a waitForMergeRequestCommits utility that polls the MR commits endpoint (up to 5 s, 1 s intervals) until at least one of the pushed commits appears, then falls back to a final fetch on timeout.

This follows the same pattern as the existing waitForReleasePipeline utility.

Changes

  • src/review/commands/share/utils/waitForMergeRequestCommits.ts — new polling utility
  • src/review/commands/share/hookHandlers/pushHookHandler.ts — use the new utility instead of a direct fetch
  • __tests__/review/pushHook.test.ts — update mock to return a matching commit (the "no related review" test was asserting on the wrong layer; the 204 comes from no review in DB, not from empty commits)

…ndition

When Homer receives a push hook, it filters commits by cross-referencing
the GitLab MR commits API. Because GitLab updates MR content
asynchronously, the just-pushed commit is sometimes absent from the API
response, causing Homer to silently return 204 and skip the Slack
notification.

Fix: poll the MR commits endpoint (up to 5s, 1s intervals) until the
pushed commit appears, then fall back to a final fetch on timeout.
@sylvaincombes
Copy link
Copy Markdown
Member Author

Closing — opened prematurely, still iterating.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

❌ Patch coverage is 77.27273% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.12%. Comparing base (9315d06) to head (47b117c).

Files with missing lines Patch % Lines
...commands/share/utils/waitForMergeRequestCommits.ts 72.22% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #173      +/-   ##
==========================================
- Coverage   89.29%   89.12%   -0.17%     
==========================================
  Files         104      105       +1     
  Lines        2269     2289      +20     
  Branches      440      441       +1     
==========================================
+ Hits         2026     2040      +14     
- Misses        230      236       +6     
  Partials       13       13              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant