Skip to content

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

Merged
pfongkye merged 1 commit into
ManoManoTech:mainfrom
sylvaincombes:fix/push-hook-race-condition
Jun 5, 2026
Merged

fix(push-hook): retry MR commits fetch to handle GitLab async race condition#174
pfongkye merged 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 — this removes rebase noise by keeping only commits that actually belong to the MR.

The issue: GitLab updates MR content asynchronously. Right after a push, the just-pushed commit is sometimes absent from the MR commits API response at the time Homer fetches it. The intersection is empty, the handler silently returns 204, and no Slack notification is sent. No error is logged, making it invisible.

Fix

Introduce waitForMergeRequestCommits, a utility that polls the MR commits endpoint until at least one pushed commit appears, then returns. It follows the same pattern as the existing waitForReleasePipeline.

  • Retries every 1s up to a 5s timeout
  • Transient fetch errors (e.g. GitLab 5xx) are caught and retried rather than aborting
  • Falls back to the last known result on timeout, preserving the existing silent-204 behaviour as a last resort
  • Logs a warning on timeout so the failure becomes visible

Trade-offs

  • The webhook response is now delayed by up to ~5s on the stuck path. GitLab's default webhook timeout is 10s so this should be safe, but worth monitoring.
  • A cleaner long-term design would be to ack the webhook immediately (200) and process asynchronously, which would remove the timeout concern entirely and allow a more generous retry window. Left as a future improvement.

Changes

  • src/review/commands/share/utils/waitForMergeRequestCommits.ts — new polling utility
  • src/review/commands/share/hookHandlers/pushHookHandler.ts — use the new utility
  • __tests__/review/waitForMergeRequestCommits.test.ts — unit tests covering: immediate hit, retry-until-found, error retry, timeout
  • __tests__/review/pushHook.test.ts — one-line update: the "no related review" test now correctly gets its 204 from no review in DB (the retry logic is owned by the unit tests above)

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.36%. Comparing base (9315d06) to head (0b784dc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #174      +/-   ##
==========================================
+ Coverage   89.29%   89.36%   +0.07%     
==========================================
  Files         104      105       +1     
  Lines        2269     2295      +26     
  Branches      440      444       +4     
==========================================
+ Hits         2026     2051      +25     
- Misses        230      231       +1     
  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.

Comment thread src/review/commands/share/utils/waitForMergeRequestCommits.ts
Comment thread __tests__/review/waitForMergeRequestCommits.test.ts Outdated
@sylvaincombes sylvaincombes force-pushed the fix/push-hook-race-condition branch 2 times, most recently from 6c92c80 to 84da116 Compare June 5, 2026 08:57
…ndition

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,
causing a silent 204 with no Slack notification.

Fix: poll the MR commits endpoint (up to 5s, 1s intervals) until at least
one pushed commit appears. Network errors and non-2xx responses (which
callAPI resolves as non-arrays) are both retried. Falls back to the last
known valid result on timeout, ensuring a graceful 204 rather than a 500.

Note: an ack-first design (respond 200 immediately, then process) would
remove the webhook timeout concern entirely and allow a more generous retry
window — left as a future improvement.
@sylvaincombes sylvaincombes force-pushed the fix/push-hook-race-condition branch from 84da116 to 0b784dc Compare June 5, 2026 09:30
@pfongkye pfongkye merged commit 3f57606 into ManoManoTech:main Jun 5, 2026
3 checks passed
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.

2 participants