Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/scripts/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ def closing_refs(body: Optional[str], repo: str) -> List[int]:
return sorted(out)


# A body can point at its issue without promising to close it: ``Refs #12``,
# ``Part of #12``. Those keep a claim alive (issue #1161), but they never make a
# PR an agent PR — for that only ``closing_refs`` counts.
_LINKING = re.compile(r"\b(?:refs?|part\s+of)\b:?[ \t]+((?:[\w.-]+/[\w.-]+)?#\d{1,7}"
r"(?:[ \t]*(?:,|and)[ \t]*(?:[\w.-]+/[\w.-]+)?#\d{1,7})*)", re.I)
_REF = re.compile(r"(?:([\w.-]+/[\w.-]+))?#(\d{1,7})\b")


def ttl_refs(body: Optional[str], repo: str) -> List[int]:
"""Every issue this body points at: the closing refs plus ``Refs``/``Part of``."""
out = set(closing_refs(body, repo))
for m in _LINKING.finditer(str(body or "")[:20000]):
for ref in _REF.finditer(m.group(1)):
if not ref.group(1) or _same(ref.group(1), repo):
out.add(int(ref.group(2)))
return sorted(out)


def is_agent_pr(pr: Dict[str, Any], config: Dict[str, Any], repo: str, agent_issues: Iterable[int]) -> bool:
"""By author, or a branch of this repository with an agent prefix, or a
branch of this repository that closes an agent-ready/agent-working issue.
Expand Down Expand Up @@ -353,7 +371,7 @@ def read_prs(api: Any, repo: str, config: Dict[str, Any], gate: "risk_gate.Gate"
def linked_prs(prs: List[Dict[str, Any]], repo: str) -> Dict[int, List[Dict[str, Any]]]:
linked: Dict[int, List[Dict[str, Any]]] = {}
for pr in prs:
for n in closing_refs(pr["body"], repo):
for n in ttl_refs(pr["body"], repo):
linked.setdefault(n, []).append({"lastPushAt": pr["lastPushAt"]})
return linked

Expand Down
5 changes: 5 additions & 0 deletions changelog.d/1161-claim-expiry-refs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fixed
A claim no longer expires under a pull request that links its issue with
`Refs #N` or `Part of #N`: the controller now reads those references when it
decides whether the claim's TTL is still fed by a push, while only closing
keywords still make a PR an agent PR (#1161).
26 changes: 26 additions & 0 deletions tests/test_process_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,32 @@ def test_claim_expiry():
assert not c.claim_expired(fresh, [], CONFIG, NOW)


def test_a_refs_pull_request_keeps_the_claim_alive():
claimed = issue(2, ["agent-working"], [ev("labeled", "2026-10-19T01:00:00Z", "Birfy", "agent-working")])
for body in ("Refs #2", "refs #2", "Part of #2", "Part of ThinkFlowLab/agentdescent#2",
"Refs #2, #3"):
prs = [pr(30, body=body)]
linked = c.linked_prs(prs, REPO).get(2, [])
assert not c.claim_expired(claimed, linked, CONFIG, NOW), f"{body!r} must keep the claim alive"
foreign = c.linked_prs([pr(30, body="Refs other/repo#2")], REPO)
assert 2 not in foreign, "a foreign repository reference names another issue"


def test_no_reference_still_expires_the_claim():
claimed = issue(2, ["agent-working"], [ev("labeled", "2026-10-19T01:00:00Z", "Birfy", "agent-working")])
for body in ("", "see #2", "Refs #29", "mentions #2 in prose"):
assert c.claim_expired(claimed, c.linked_prs([pr(30, body=body)], REPO).get(2, []), CONFIG, NOW), body
stale = [pr(30, body="Refs #2", push="2026-10-19T05:00:00Z")]
assert c.claim_expired(claimed, c.linked_prs(stale, REPO).get(2, []), CONFIG, NOW), "a stale push expires"


def test_a_refs_pull_request_is_still_not_an_agent_pr():
cfg = dict(CONFIG, agentAuthors=["bot-x"])
assert not c.is_agent_pr(pr(1, body="Refs #7"), cfg, REPO, {7})
assert not c.is_agent_pr(pr(1, body="Part of #7"), cfg, REPO, {7})
assert c.is_agent_pr(pr(1, body="Fixes #7"), cfg, REPO, {7}), "closing refs still decide agent-PR-ness"


def test_plan_issues():
ready_by_other = issue(3, ["agent-ready", "agent-working"],
[ev("labeled", "2026-10-19T01:00:00Z", "HugoXK", "agent-ready")])
Expand Down
Loading