Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .claude/skills/fix-issue/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ never write the key anywhere.

- Push the branch (never `main`, never `--force`), open the PR with the
template: imperative title, `Fixes #N`, short body, `Tip SHA:` / `Ran:` /
`Not run:`. Assign `Birfy`; labels `agent-pr` + type + area.
`Not run:`. Assign `Birfy`; labels type + area (never `agent-pr`: retired, #1161).
- Tier: `python3 .github/scripts/risk_gate.py --pr <n>`.

## 5. Review at the tip
Expand Down
6 changes: 3 additions & 3 deletions .github/agent/controller.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"note": "Read by .github/scripts/controller.py from the default branch. Editing this file is T3. Maintainers listed here are the only people whose agent-ready label (and whose later edits) keep an issue agent-ready.",
"maintainers": ["Birfy"],
"agentBranchPrefixes": ["agent/"],
"agentAuthors": [],
"maintainers": [
"Birfy"
],
"claimTtlHours": 6,
"maxPrsPerRun": 50,
"maxIssuesPerRun": 50
Expand Down
29 changes: 6 additions & 23 deletions .github/scripts/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
(``Fixes #N``); changed files are read only through the API and judged by the
risk gate's rules.

- sets ``agent-pr`` on pull requests an agent opened, and ``risk:T0..T3``
(the risk gate's tier) on every open PR not on ``hold``
- sets ``risk:T0..T3`` (the risk gate's tier) on every open PR not on
``hold``. It never adds the retired agent PR label: the owner banned it
(#1161)
- removes ``agent-ready`` (and ``agent-working``) when someone who is not a
maintainer labeled the issue, or edited its text after it was labeled
- removes ``agent-working`` from a claim older than the TTL with no recent
Expand Down Expand Up @@ -43,11 +44,11 @@
RISK = ["risk:T0", "risk:T1", "risk:T2", "risk:T3"]
MANAGED = {
# label -> what the controller may do with it. It can never ADD agent-ready.
"add": set(["agent-pr"] + RISK),
"add": set(RISK),
"remove": set(["agent-ready", "agent-working"] + RISK),
}
MAX_OPS = 200
REASONS = {"labeled-by-non-maintainer", "edited-by-non-maintainer", "claim-expired", "risk-tier", "agent-pr"}
REASONS = {"labeled-by-non-maintainer", "edited-by-non-maintainer", "claim-expired", "risk-tier"}


# ---- mode -------------------------------------------------------------------
Expand Down Expand Up @@ -83,8 +84,7 @@ def closing_refs(body: Optional[str], repo: str) -> List[int]:


# 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.
# ``Part of #12``. Those keep a claim alive (issue #1161).
_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")
Expand All @@ -100,20 +100,6 @@ def ttl_refs(body: Optional[str], repo: str) -> List[int]:
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.
A fork PR counts only by author."""
if any(_same(a, pr["author"]) for a in config["agentAuthors"]):
return True
if not pr["sameRepo"]:
return False
if any(p and pr["headRef"].startswith(p) for p in config["agentBranchPrefixes"]):
return True
agent_issues = set(agent_issues)
return any(n in agent_issues for n in closing_refs(pr["body"], repo))


def _last(events: List[Dict[str, Any]], pred: Callable[[Dict[str, Any]], bool]) -> Optional[Dict[str, Any]]:
hits = sorted((e for e in events if pred(e)), key=lambda e: e["at"])
return hits[-1] if hits else None
Expand Down Expand Up @@ -172,7 +158,6 @@ def push(kind: str, number: int, found: List[Dict[str, str]], reason: str) -> No
else:
ops.append({"kind": kind, "number": number, "op": f["op"], "label": f["label"], "reason": reason})

agent_issues = {i["number"] for i in state["issues"]}
for issue in state["issues"]:
labels = issue["labels"]
if any(_same(l, "hold") for l in labels):
Expand Down Expand Up @@ -201,8 +186,6 @@ def push(kind: str, number: int, found: List[Dict[str, str]], reason: str) -> No
want = f"risk:{pr['tier']}"
push("pr", pr["number"], _diff_labels(pr["labels"], add=[want], remove=[l for l in RISK if l != want]),
"risk-tier")
if is_agent_pr(pr, config, state["repo"], agent_issues):
push("pr", pr["number"], _diff_labels(pr["labels"], add=["agent-pr"]), "agent-pr")
if len(ops) > MAX_OPS:
notes.append(f"{len(ops)} operations; keeping the first {MAX_OPS}")
del ops[MAX_OPS:]
Expand Down
16 changes: 9 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ Source of truth: [`.github/labels.json`](.github/labels.json), synced by the
- **Source:** `self-test` (filed by the self-test routine; issues only).
- **State:** `needs-info` (spec unclear), `needs-human` (needs Danyang's
decision; the last comment says what), `agent-ready`, `agent-working`,
`agent-pr`, `awaiting-approval` (green T2/T3 PR waiting for a PASS and
Danyang's click), `hold` (automation leaves the item alone).
`awaiting-approval` (green T2/T3 PR waiting for a PASS and Danyang's click),
`hold` (automation leaves the item alone). `agent-pr` is retired: the owner
banned it and the controller no longer sets it (#1161).
- **Risk:** `risk:T0` … `risk:T3`, set by the controller only, never by hand.

### Triage: when an issue is `agent-ready`
Expand All @@ -98,16 +99,17 @@ question in a comment. Agents develop **only** `agent-ready` issues.
- Before work: skip an issue someone else is assigned to. Otherwise assign
`Birfy`, add `agent-working`, and comment naming the branch.
- Stopping without a PR: unassign, remove `agent-working`, say why.
- The PR says `Fixes #N`, is assigned to `Birfy`, labeled `agent-pr` plus its
type and area. Agent branches start with `agent/`.
- The PR says `Fixes #N`, is assigned to `Birfy`, labeled with its type and
area — never `agent-pr`, which is banned. Agent branches start with `agent/`.

## Controller

[`.github/workflows/controller.yml`](.github/workflows/controller.yml) runs every
30 minutes with the built-in `GITHUB_TOKEN` only (no GitHub App, no secrets) and
changes labels and nothing else: it sets `risk:T*` and `agent-pr` on open PRs,
removes `agent-ready`/`agent-working` when a non-maintainer set or edited an
issue after it was approved, and expires a claim after 6 h with no linked push.
changes labels and nothing else: it sets `risk:T*` on open PRs, removes
`agent-ready`/`agent-working` when a non-maintainer set or edited an issue after
it was approved, and expires a claim after 6 h with no linked push. It never
adds `agent-pr`; that label is retired (#1161).
It never adds `agent-ready`, never merges, comments or closes.

| Repository variable | Effect |
Expand Down
5 changes: 5 additions & 0 deletions changelog.d/1161-controller-drop-agent-pr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fixed
The label controller no longer adds the retired `agent-pr` label, so a
scheduled run cannot undo the repository-wide strip the owner made: the add
block, its reason string and the agent-author/branch heuristics behind it are
gone, and `controller.json` drops the two keys only that rule read (#1161).
56 changes: 34 additions & 22 deletions tests/test_process_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,6 @@ def test_closing_refs_reads_this_repository_only():
assert c.closing_refs(body, REPO) == [12, 13, 14]


def test_is_agent_pr():
cfg = dict(CONFIG, agentAuthors=["bot-x"])
assert c.is_agent_pr(pr(1, author="bot-x", same=False), cfg, REPO, set())
assert c.is_agent_pr(pr(1, head="agent/fix-3"), cfg, REPO, set())
assert not c.is_agent_pr(pr(1, head="agent/fix-3", same=False), cfg, REPO, set()), "fork: by author only"
assert c.is_agent_pr(pr(1, body="Fixes #7"), cfg, REPO, {7})
assert not c.is_agent_pr(pr(1, body="Fixes #8"), cfg, REPO, {7})


def test_judge_ready():
ok = issue(1, ["agent-ready"], [ev("labeled", "2026-10-19T01:00:00Z", "Birfy", "agent-ready")])
assert c.judge_ready(ok, CONFIG)["demote"] is None
Expand Down Expand Up @@ -126,11 +117,17 @@ def test_no_reference_still_expires_the_claim():
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_a_refs_pull_request_never_gets_the_agent_pr_label():
"""The agent-PR rule is retired, so no body shape can bring the label back:
a reference-only PR (``Refs``/``Part of``) and one that closes the issue
alike get the risk label only (#1163)."""
closed = issue(7, ["agent-ready"], [ev("labeled", "2026-10-19T01:00:00Z", "Birfy", "agent-ready")])
out = run(issues=[closed],
prs=[pr(11, tier="T1", head="agent/x", body="Refs #7"),
pr(12, tier="T2", head="agent/fix-7", body="Part of #7"),
pr(13, tier="T3", head="feat/plain", body="Fixes #7", author="bot-x")])
assert [o for o in out["ops"] if o["label"] == "agent-pr"] == []
assert not hasattr(c, "is_agent_pr"), "the agent-PR rule is gone, not just unused"


def test_plan_issues():
Expand All @@ -143,11 +140,24 @@ def test_plan_issues():
assert {"number": 4, "label": "*", "reason": "hold"} in out["skipped"]


def test_plan_prs_get_one_risk_label_and_agent_pr_by_rule():
def test_plan_prs_get_one_risk_label_and_nothing_else():
out = run(prs=[pr(10, ["risk:T1", "risk:T3"], tier="T3"), pr(11, tier="T0", head="agent/x"),
pr(12, ["hold"], tier="T3"), pr(13, tier=None)])
ops = {(o["number"], o["op"], o["label"]) for o in out["ops"]}
assert ops == {(10, "remove", "risk:T1"), (11, "add", "risk:T0"), (11, "add", "agent-pr")}
assert ops == {(10, "remove", "risk:T1"), (11, "add", "risk:T0")}


def test_a_plan_never_adds_agent_pr_not_even_on_an_agent_branch():
"""The owner banned ``agent-pr`` repo-wide and the sweep strips it, so the
controller must not put it back — whatever the author, the branch prefix or
the issue the PR closes (#1161)."""
closed = issue(7, ["agent-ready"], [ev("labeled", "2026-10-19T01:00:00Z", "Birfy", "agent-ready")])
out = run(issues=[closed],
prs=[pr(11, tier="T0", head="agent/x"),
pr(12, tier="T2", head="agent/fix-7", body="Fixes #7"),
pr(13, tier="T1", head="feat/plain", author="bot-x")])
assert [o for o in out["ops"] if o["label"] == "agent-pr"] == []
assert "agent-pr" not in c.MANAGED["add"]


def test_a_missing_label_is_skipped_never_created():
Expand All @@ -167,10 +177,12 @@ def test_plan_only_proposes_managed_labels_and_never_adds_agent_ready():

@pytest.mark.parametrize("bad", [
None, {}, {"version": 2, "ops": []},
{"version": 1, "ops": [{"number": 0, "op": "add", "label": "agent-pr", "reason": "agent-pr"}]},
{"version": 1, "ops": [{"number": True, "op": "add", "label": "agent-pr", "reason": "agent-pr"}]},
{"version": 1, "ops": [{"number": 1, "op": "close", "label": "agent-pr", "reason": "agent-pr"}]},
{"version": 1, "ops": [{"number": 1, "op": "add", "label": "agent-ready", "reason": "agent-pr"}]},
{"version": 1, "ops": [{"number": 0, "op": "add", "label": "risk:T1", "reason": "risk-tier"}]},
{"version": 1, "ops": [{"number": True, "op": "add", "label": "risk:T1", "reason": "risk-tier"}]},
{"version": 1, "ops": [{"number": 1, "op": "close", "label": "risk:T1", "reason": "risk-tier"}]},
{"version": 1, "ops": [{"number": 1, "op": "add", "label": "agent-ready", "reason": "risk-tier"}]},
# the banned label is refused even in a hand-written plan (#1161)
{"version": 1, "ops": [{"number": 1, "op": "add", "label": "agent-pr", "reason": "risk-tier"}]},
{"version": 1, "ops": [{"number": 1, "op": "remove", "label": "hold", "reason": "risk-tier"}]},
{"version": 1, "ops": [{"number": 1, "op": "add", "label": "risk:T0", "reason": "because"}]},
{"version": 1, "ops": [{"number": 1, "op": "add", "label": "risk:T0", "reason": "risk-tier"}] * 201},
Expand Down Expand Up @@ -205,12 +217,12 @@ def test_apply_writes_only_label_endpoints_and_rechecks_the_state():
{"number": 2, "op": "add", "label": "risk:T1", "reason": "risk-tier"},
{"number": 3, "op": "remove", "label": "risk:T3", "reason": "risk-tier"},
{"number": 4, "op": "remove", "label": "agent-working", "reason": "claim-expired"},
{"number": 5, "op": "add", "label": "agent-pr", "reason": "agent-pr"},
{"number": 5, "op": "add", "label": "risk:T1", "reason": "risk-tier"},
]
api = FakeApi({1: {"state": "open", "labels": []}, 2: {"state": "closed", "labels": []},
3: {"state": "open", "labels": [{"name": "risk:T3"}, {"name": "hold"}]},
4: {"state": "open", "labels": [{"name": "agent-working"}]},
5: {"state": "open", "labels": [{"name": "agent-pr"}]}})
5: {"state": "open", "labels": [{"name": "risk:T1"}]}})
out = c.apply({"version": 1, "ops": ops}, api, REPO)
assert [o["number"] for o in out["done"]] == [1, 4]
assert {s["number"]: s["why"] for s in out["skipped"]} == {2: "closed", 3: "hold", 5: "already"}
Expand Down
Loading