Skip to content

Commit eb5e6fd

Browse files
kai-linuxclaude
andcommitted
Open PRs for partial/blocked tasks so merged PRs close their issues
sync_result only created PRs for status=complete, so blocked/partial tasks with real commits had no PR. The orphan branch handler later created one with a generic body missing the issue reference, which meant _cleanup_merged_pr_issues couldn't find the issue to close. - Create PRs in sync_result for any status with a commit, not just complete — the PR body always includes #issue_number - Orphan branch handler now searches for the linked issue via _find_issue_for_task and includes it in the PR body as fallback Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fe1d57c commit eb5e6fd

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

orchestrator/github_sync.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,8 @@ def sync_result(meta: dict, result: dict, commit_hash: str | None):
399399
comment += f"\n### Follow-up issue\n{followup_issue_url}\n"
400400

401401
pr_url = None
402-
if status == "complete":
402+
has_commits = bool(commit_hash)
403+
if has_commits:
403404
pr_url = create_pr_for_branch(
404405
repo,
405406
branch,

orchestrator/pr_monitor.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,25 @@ def _branch_has_commits_ahead_of_main(repo: str, branch: str, base: str = "main"
197197
return False
198198

199199

200+
def _find_issue_for_task(repo: str, task_id: str) -> int | None:
201+
"""Search for an open or recently closed issue that was dispatched for this task."""
202+
if not task_id:
203+
return None
204+
try:
205+
issues = gh_json([
206+
"issue", "list", "-R", repo, "--state", "all",
207+
"--search", task_id, "--json", "number,body",
208+
"--limit", "10",
209+
]) or []
210+
except Exception:
211+
return None
212+
for issue in issues:
213+
body = issue.get("body", "")
214+
if task_id in body or f"agent/{task_id}" in body:
215+
return int(issue["number"])
216+
return None
217+
218+
200219
def _find_merged_pr_for_task(repo: str, task_id: str) -> dict | None:
201220
if not task_id:
202221
return None
@@ -254,7 +273,12 @@ def _create_prs_for_orphan_branches(repos: set[str]):
254273
pass
255274
continue
256275
title = f"Agent: {task_id}"
257-
body = f"Automated changes from agent branch `{branch}`."
276+
# Try to find the linked issue number for proper cleanup on merge
277+
issue_number = _find_issue_for_task(repo, task_id)
278+
if issue_number:
279+
body = f"Automated changes for issue #{issue_number}"
280+
else:
281+
body = f"Automated changes from agent branch `{branch}`."
258282
pr_url = create_pr_for_branch(repo, branch, title, body)
259283
if pr_url:
260284
print(f" Opened PR for orphan branch {branch}: {pr_url}")

0 commit comments

Comments
 (0)