feat: recover stalled MRs via emoji-triggered API refresh#45
Merged
Conversation
Missed merge/close webhooks (delivery failures, or partial rollbacks where state="merged" commits but msg_to_delete/refs cleanup doesn't) leave Teams cards frozen on the open-state view. Emoji events on the MR now trigger a recovery probe: cleanup tick fetches current state from the GitLab API; on confirmed terminal state, the leftover refs are PATCHed to the merged card and queued for deletion. Idempotent -- no-op if refs already cleaned. - Synthesize action from state on terminal/reopen transitions (cards/render.py keys icon off action, not state). - Normalize API ISO 8601 updated_at to webhook format so the existing fromisoformat parser keeps a single canonical shape. - Assume UTC for naive datetimes (host-TZ skew protection); tolerate unparseable timestamps without sticking the pending refresh. - Distinguish API-unavailable (warning) from API-confirmed-open in logs for triage. Rate-limit relies on the existing pending_mr_refresh debounce.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Missed merge/close webhooks (delivery failures, or partial rollbacks where
state=\"merged\"commits butmsg_to_delete/refs cleanup doesn't) leave Teams cards frozen on the open-state view. Emoji events on the MR now trigger a recovery probe: cleanup tick fetches current state from the GitLab API; on confirmed terminal state, the leftover refs are PATCHed to the merged card and queued for deletion. Idempotent — no-op if refs already cleaned.Key changes
DBHelper.refresh_mr_payload_from_api: rewrites stored payload from API response. Synthesizesaction="merge"/"close"/"reopen"only on terminal/reopen transitions becausecards/render.pykeys icon selection offaction, notstate.updated_atto webhook format (YYYY-MM-DD HH:MM:SS UTC) so the existingfromisoformatparser keeps a single canonical column shape.pending_mr_refreshrow.api-refresh-closecleanup branch fires only when the API was actually called and confirmed terminal state (api_refreshed AND is_closing_state); idempotent viaupdate_all_messages_transactional's no-op on emptylocked_messages.Rate-limit relies on the existing
pending_mr_refreshdebounce (PRIMARY KEY onmerge_request_ref_id, ON CONFLICT extendingprocess_after) — multiple emoji on the same MR collapse to one API call per debounce window.Test plan
tests/test_refresh_mr_payload.pycovering state→action mappings, head_pipeline absent/present/null, ISO normalization (Z, offset, naive), unparseable timestamps, draft sync, no-token short-circuit, and HTTP-error handling.pytest230/230 (full suite incl. e2e against testcontainer).pre-commit run --all-filesclean.