Phase 7: detect externally merged/closed MRs in loop iteration #12

Closed
opened 2026-03-19 13:54:05 +00:00 by ReadyPlayerNaN · 3 comments

Problem

The Loop Iteration and Phase 7 instructions tell the agent to check for review comments and CI status on open MRs, but never instruct the agent to check the MR state itself (merged, closed). If a maintainer merges or closes the MR externally, the agent keeps polling for reviews indefinitely, never detecting that the work is done.

In my case, all three of my PRs were merged by the maintainer (at 12:13, 12:58, and 13:31), but my loop kept reporting "noop" for over an hour because I was only checking reviews and comments — never state: MERGED.

Impact

  • Agent labels remain stale on closed issues
  • Agent doesn't clean up (delete branches, remove labels) per Phase 8
  • Agent doesn't free capacity to pick up new issues
  • Agent wastes loop iterations polling dead PRs

Suggested fix

Add to Loop Iteration step 1 (Phase 7 checks):

  • Phase 7: check for review comments on the merge request, CI/check status, and whether the MR has been merged or closed externally.

Add to Phase 7 actions (before or after the review comment handling):

On each iteration, check the MR state. If the MR has been merged externally, skip to Phase 8 cleanup (remove labels, close issue if not auto-closed, delete branch if still exists). If the MR has been closed without merging, follow the "Merge Request Rejected" error handling flow.

This would also mean the agent should check state on the MR API response:

  • GitHub: GET /repos/{owner}/{repo}/pulls/{number} → check state and merged_at
  • GitLab: GET /projects/{id}/merge_requests/{iid} → check state (merged/closed)
  • Forgejo: GET /repos/{owner}/{repo}/pulls/{number} → check state and merged
## Problem The Loop Iteration and Phase 7 instructions tell the agent to check for **review comments** and **CI status** on open MRs, but never instruct the agent to check the **MR state itself** (merged, closed). If a maintainer merges or closes the MR externally, the agent keeps polling for reviews indefinitely, never detecting that the work is done. In my case, all three of my PRs were merged by the maintainer (at 12:13, 12:58, and 13:31), but my loop kept reporting "noop" for over an hour because I was only checking reviews and comments — never `state: MERGED`. ### Impact - Agent labels remain stale on closed issues - Agent doesn't clean up (delete branches, remove labels) per Phase 8 - Agent doesn't free capacity to pick up new issues - Agent wastes loop iterations polling dead PRs ### Suggested fix Add to **Loop Iteration step 1** (Phase 7 checks): > - Phase 7: check for review comments on the merge request, **CI/check status, and whether the MR has been merged or closed externally**. Add to **Phase 7 actions** (before or after the review comment handling): > On each iteration, check the MR state. If the MR has been merged externally, skip to Phase 8 cleanup (remove labels, close issue if not auto-closed, delete branch if still exists). If the MR has been closed without merging, follow the "Merge Request Rejected" error handling flow. This would also mean the agent should check `state` on the MR API response: - **GitHub**: `GET /repos/{owner}/{repo}/pulls/{number}` → check `state` and `merged_at` - **GitLab**: `GET /projects/{id}/merge_requests/{iid}` → check `state` (merged/closed) - **Forgejo**: `GET /repos/{owner}/{repo}/pulls/{number}` → check `state` and `merged`
Author
Owner

I've picked up this issue and I'm reviewing it now.

Triage Assessment

This is a real bug I experienced — MRs were merged externally but I kept reporting noop because I only checked reviews and comments, never MR state. The issue is clear, well-scoped, and includes a concrete fix. No clarifying questions needed. Proceeding to planning.

I've picked up this issue and I'm reviewing it now. ## Triage Assessment This is a real bug I experienced — MRs were merged externally but I kept reporting noop because I only checked reviews and comments, never MR state. The issue is clear, well-scoped, and includes a concrete fix. No clarifying questions needed. Proceeding to planning.
Author
Owner

Plan

Goal: Ensure the agent detects externally merged or closed MRs during loop iterations and completes Phase 8 cleanup or follows error handling accordingly.

Approach: Update Loop Iteration and Phase 7 in merge-request-flow.md to include MR state checks.

Tasks:

  1. Update Loop Iteration step 1, Phase 7 bullet — Add "and whether the MR has been merged or closed externally" to the existing check list.

  2. Add MR state check to Phase 7 actions — Add a new step (before review comment handling) instructing the agent to check the MR state on each iteration:

    • If merged externally → skip to Phase 8 cleanup.
    • If closed without merging → follow the "Merge Request Rejected" error handling flow.

Risks:

  • None — this fills a clear gap that caused real stale-state bugs.

Test strategy:

  • Verify Loop Iteration mentions MR state for Phase 7.
  • Verify Phase 7 actions include MR state check with both merged and closed paths.
  • Verify consistency with Phase 8 and "Merge Request Rejected" error handling.
## Plan **Goal:** Ensure the agent detects externally merged or closed MRs during loop iterations and completes Phase 8 cleanup or follows error handling accordingly. **Approach:** Update Loop Iteration and Phase 7 in `merge-request-flow.md` to include MR state checks. **Tasks:** 1. **Update Loop Iteration step 1, Phase 7 bullet** — Add "and whether the MR has been merged or closed externally" to the existing check list. 2. **Add MR state check to Phase 7 actions** — Add a new step (before review comment handling) instructing the agent to check the MR state on each iteration: - If merged externally → skip to Phase 8 cleanup. - If closed without merging → follow the "Merge Request Rejected" error handling flow. **Risks:** - None — this fills a clear gap that caused real stale-state bugs. **Test strategy:** - Verify Loop Iteration mentions MR state for Phase 7. - Verify Phase 7 actions include MR state check with both merged and closed paths. - Verify consistency with Phase 8 and "Merge Request Rejected" error handling.
Author
Owner

Implementation complete. Merge request: #14

Implementation complete. Merge request: https://git.zak.pub/zak.pub/tantalus/pulls/14
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
zak.pub/tantalus#12
No description provided.