pr-mode: close-report gate refuses AFTER the merge has already closed the issue ("no open agent PR") #108

Closed
opened 2026-08-28 15:07:08 +00:00 by ben · 3 comments
Owner

Observed (Matou/coa #3, 2026-08-28, factory pin cec8b3c, worker on elitebook-03 swarm run 12)

Policy LANDING=pr MERGE_AUTHORITY=agent-after-green. Timeline from the issue:

  • 14:41 worker commit 2ed6d5c, PR #5 opened on sandcastle/worker/…
  • 14:53 PR #5 closed, PR #6 opened on agent/issue-3 (same SHA) — the reconcile step
  • 15:05:00 merge commit d10103b lands on main; 15:05:02 issue closed (by the build agent, at merge)
  • 15:05:23 close-report gate posts REFUSED: no open agent PR (agent/issue-3) for this issue — pr-mode commits land on a PR before they can close it (#13)

The envelope itself was correct (commit reachable, files, three green test commands, criteria). Net effect: the issue IS closed and the change IS on main, but the durable record on the thread says the close was refused, and the hand-off labels were not swept (agent-working + ready-for-agent remain on a closed issue).

Expected

Either the close-report runs before the merge closes the issue (and the merge is what the gate verifies), or the gate's pr-mode check accepts a merged PR for the issue as satisfying "landed on a PR". Labels swept on close either way.

Where to look

landing-lib.sh landing_stage / landing_merge_if_green vs close-report-lib.sh pr-mode check (#13). Repro: any pr + agent-after-green consumer with a one-commit ticket.

Filed from the coa onboarding session (Matou/coa #1).

## Observed (Matou/coa #3, 2026-08-28, factory pin cec8b3c, worker on elitebook-03 swarm run 12) Policy `LANDING=pr MERGE_AUTHORITY=agent-after-green`. Timeline from the issue: - 14:41 worker commit `2ed6d5c`, PR #5 opened on `sandcastle/worker/…` - 14:53 PR #5 closed, PR #6 opened on `agent/issue-3` (same SHA) — the reconcile step - 15:05:00 merge commit `d10103b` lands on main; **15:05:02 issue closed** (by the build agent, at merge) - **15:05:23 close-report gate posts REFUSED**: `no open agent PR (agent/issue-3) for this issue — pr-mode commits land on a PR before they can close it (#13)` The envelope itself was correct (commit reachable, files, three green test commands, criteria). Net effect: the issue IS closed and the change IS on main, but the durable record on the thread says the close was refused, and the hand-off labels were not swept (`agent-working` + `ready-for-agent` remain on a closed issue). ## Expected Either the close-report runs before the merge closes the issue (and the merge is what the gate verifies), or the gate's pr-mode check accepts a *merged* PR for the issue as satisfying "landed on a PR". Labels swept on close either way. ## Where to look `landing-lib.sh` `landing_stage` / `landing_merge_if_green` vs `close-report-lib.sh` pr-mode check (#13). Repro: any pr + agent-after-green consumer with a one-commit ticket. Filed from the coa onboarding session (Matou/coa #1).

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.

Ruling: bug + ready-for-agent. Verified reproducible from the code path; a delegable code fix with an offline test harness already in place.

Why this is a two-way door: the fix is a localized change to the close-report gate (plus one Forgejo helper and its test), fully revertible by a later commit, and provable offline by tests/close-report-test.sh (fake Forgejo via fakebin/curl). It touches no credentials, no security posture, no member-facing trust, no data destruction, no spend — nothing on the one-way-door list.

What proves it: a new scenario in tests/close-report-test.sh — pr-mode + agent-after-green, the issue's PR already merged (not open) — must go from REFUSED to a verified close, and the label sweep must fire. Existing gates (commit reachability, changed-files, tests-exit) stay green.

Verification (confirmed): In pr-mode, close-report.sh resolves the landing head via landing_open_pr_for → forgejo_open_pr_for, which queries only state=open. When agent-after-green merges the PR at merge time, the subsequent close-report run finds no open PR, sets the no open agent PR violation, and force-refuses — exactly the coa #3 timeline (merge 15:05:00, issue closed 15:05:02, gate REFUSED 15:05:23). The label residue is a downstream symptom: the #22 label-sweep only runs on a verified close, so a forced refusal leaves agent-working + ready-for-agent on the closed issue.


Agent Brief

Category: bug
Summary: In pr-mode with agent-after-green, the close-report gate force-refuses because the agent PR is already merged (not open) by the time close-report runs — so a landed, correct change records a REFUSED close and leaves claim labels on the closed issue.

Current behavior:
Under LANDING=pr + MERGE_AUTHORITY=agent-after-green, the reconcile/merge step merges the issue's agent PR and the merge closes the issue. The close-report gate then resolves its "landing head" by looking up the issue's open agent PR. Because the PR is now merged (closed), no open PR is found, the gate raises no open agent PR (agent/issue-<N>) for this issue and forces a refusal — even though every substantive gate (commit reachable from main, changed-files in the union diff, green tests, criteria) passed. Net effect: the change is on main and the issue is closed, but the durable thread record says the close was refused, and the claim labels (agent-working, ready-for-agent) are never swept because label-sweep only runs on a verified close.

Desired behavior:
In pr-mode, a merged agent PR for the issue satisfies "the work landed on a PR". When no open PR exists, the gate falls back to the issue's most recent merged agent PR from the landing branch and uses its merge/head commit as the gate head; the reachability gate then verifies that commit landed on main. Only when there is neither an open nor a merged agent PR for the issue does the no open agent PR refusal stand. On the resulting verified close, the existing claim-label sweep runs, clearing agent-working and ready-for-agent.

Key interfaces:

  • The pr-mode landing-head resolution in the close-report gate — currently open-PR-only; needs a merged-PR fallback that yields a gate head commit (merge commit or PR head) reachable from main.
  • A Forgejo lookup for the issue's merged PR from its landing branch — sibling of the existing open-PR lookup (forgejo_open_pr_for / landing_open_pr_for), querying merged/closed state and returning the head (and/or merge) commit sha. Reuse the existing head-sha helper where possible.
  • The no open agent PR violation should fire only when both the open-PR and merged-PR lookups miss.
  • No change to push-mode behavior (gate head stays origin/main / CR_MAIN_HEAD).

Acceptance criteria:

  • pr-mode + agent-after-green, one-commit ticket, PR already merged and issue already closed at merge → close-report produces a verified (non-refused) outcome, not no open agent PR.
  • On that verified close, agent-working and ready-for-agent are removed from the issue.
  • pr-mode with no agent PR at all (never opened) → still refuses with the no open agent PR violation.
  • push-mode outcomes are byte-for-byte unchanged.
  • Existing gates still refute a bad envelope (unreachable commit / changed-files mismatch / non-zero test exit) in the merged-PR path.
  • tests/close-report-test.sh gains a scenario for the merged-PR pr-mode case and passes offline; the full suite (for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done) is green.
  • docs/GOTCHAS.md gets a numbered entry for this hazard in the same commit (per repo convention).

Out of scope:

  • Reordering the landing pipeline so close-report runs before the merge (the reporter's alternative option (a)) — higher blast-radius across consumers; not needed if the gate accepts a merged PR.
  • Changing merge authority, merge method, or the reconcile step that opens agent/issue-<N>.
  • Any push-mode logic.
> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** **Ruling:** `bug` + `ready-for-agent`. Verified reproducible from the code path; a delegable code fix with an offline test harness already in place. **Why this is a two-way door:** the fix is a localized change to the close-report gate (plus one Forgejo helper and its test), fully revertible by a later commit, and provable offline by `tests/close-report-test.sh` (fake Forgejo via `fakebin/curl`). It touches no credentials, no security posture, no member-facing trust, no data destruction, no spend — nothing on the one-way-door list. **What proves it:** a new scenario in `tests/close-report-test.sh` — pr-mode + `agent-after-green`, the issue's PR already **merged** (not open) — must go from REFUSED to a verified close, and the label sweep must fire. Existing gates (commit reachability, changed-files, tests-exit) stay green. **Verification (confirmed):** In pr-mode, `close-report.sh` resolves the landing head via `landing_open_pr_for` → `forgejo_open_pr_for`, which queries only `state=open`. When `agent-after-green` merges the PR at merge time, the subsequent close-report run finds no *open* PR, sets the `no open agent PR` violation, and force-refuses — exactly the coa #3 timeline (merge 15:05:00, issue closed 15:05:02, gate REFUSED 15:05:23). The label residue is a downstream symptom: the `#22` label-sweep only runs on a verified close, so a forced refusal leaves `agent-working` + `ready-for-agent` on the closed issue. --- ## Agent Brief **Category:** bug **Summary:** In pr-mode with `agent-after-green`, the close-report gate force-refuses because the agent PR is already *merged* (not open) by the time close-report runs — so a landed, correct change records a REFUSED close and leaves claim labels on the closed issue. **Current behavior:** Under `LANDING=pr` + `MERGE_AUTHORITY=agent-after-green`, the reconcile/merge step merges the issue's agent PR and the merge closes the issue. The close-report gate then resolves its "landing head" by looking up the issue's **open** agent PR. Because the PR is now merged (closed), no open PR is found, the gate raises `no open agent PR (agent/issue-<N>) for this issue` and forces a refusal — even though every substantive gate (commit reachable from main, changed-files in the union diff, green tests, criteria) passed. Net effect: the change is on main and the issue is closed, but the durable thread record says the close was refused, and the claim labels (`agent-working`, `ready-for-agent`) are never swept because label-sweep only runs on a verified close. **Desired behavior:** In pr-mode, a **merged** agent PR for the issue satisfies "the work landed on a PR". When no *open* PR exists, the gate falls back to the issue's most recent merged agent PR from the landing branch and uses its merge/head commit as the gate head; the reachability gate then verifies that commit landed on main. Only when there is neither an open nor a merged agent PR for the issue does the `no open agent PR` refusal stand. On the resulting verified close, the existing claim-label sweep runs, clearing `agent-working` and `ready-for-agent`. **Key interfaces:** - The pr-mode landing-head resolution in the close-report gate — currently open-PR-only; needs a merged-PR fallback that yields a gate head commit (merge commit or PR head) reachable from main. - A Forgejo lookup for the issue's **merged** PR from its landing branch — sibling of the existing open-PR lookup (`forgejo_open_pr_for` / `landing_open_pr_for`), querying merged/closed state and returning the head (and/or merge) commit sha. Reuse the existing head-sha helper where possible. - The `no open agent PR` violation should fire only when both the open-PR and merged-PR lookups miss. - No change to push-mode behavior (gate head stays `origin/main` / `CR_MAIN_HEAD`). **Acceptance criteria:** - [ ] pr-mode + `agent-after-green`, one-commit ticket, PR already **merged** and issue already closed at merge → close-report produces a **verified** (non-refused) outcome, not `no open agent PR`. - [ ] On that verified close, `agent-working` and `ready-for-agent` are removed from the issue. - [ ] pr-mode with **no** agent PR at all (never opened) → still refuses with the `no open agent PR` violation. - [ ] push-mode outcomes are byte-for-byte unchanged. - [ ] Existing gates still refute a bad envelope (unreachable commit / changed-files mismatch / non-zero test exit) in the merged-PR path. - [ ] `tests/close-report-test.sh` gains a scenario for the merged-PR pr-mode case and passes offline; the full suite (`for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done`) is green. - [ ] `docs/GOTCHAS.md` gets a numbered entry for this hazard in the same commit (per repo convention). **Out of scope:** - Reordering the landing pipeline so close-report runs *before* the merge (the reporter's alternative option (a)) — higher blast-radius across consumers; not needed if the gate accepts a merged PR. - Changing merge authority, merge method, or the reconcile step that opens `agent/issue-<N>`. - Any push-mode logic.
Author
Owner

Claimed by an interactive session (Ben + Claude) — swapped ready-for-agent → agent-working so the swarm skips it.

Claimed by an interactive session (Ben + Claude) — swapped ready-for-agent → agent-working so the swarm skips it.
Author
Owner

Landed in c51485d on main. Root cause: landing_merge_reconcile (#15) sweeps every open agent PR at a run's end, so a concurrent run merged the PR between the worker's push and its close-report; the gate only looked for an OPEN PR. Fix: landing_merged_pr_for (over GET /pulls?state=closed, .merged==true only) is consulted first; found → gate against main as push mode does, comment 'already merged', release agent-working/ready-for-agent; merged-but-open closes directly. Proof: tests/close-report-test.sh (65 checks, new PR-5/PR-6) + tests/landing-lib-test.sh (41) + full offline suite green. GOTCHAS 36. Note: consumers see this at their next FACTORY_REF bump.

Landed in `c51485d` on main. Root cause: `landing_merge_reconcile` (#15) sweeps every open agent PR at a run's end, so a concurrent run merged the PR between the worker's push and its close-report; the gate only looked for an OPEN PR. Fix: `landing_merged_pr_for` (over `GET /pulls?state=closed`, `.merged==true` only) is consulted first; found → gate against main as push mode does, comment 'already merged', release `agent-working`/`ready-for-agent`; merged-but-open closes directly. Proof: `tests/close-report-test.sh` (65 checks, new PR-5/PR-6) + `tests/landing-lib-test.sh` (41) + full offline suite green. GOTCHAS 36. Note: consumers see this at their next FACTORY_REF bump.
ben 2026-08-28 17:58:39 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
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
Matou/dev-factory#108
No description provided.