Skip to content

ci(controller): label PRs on their lifecycle events - #1194

Merged
Birfy merged 2 commits into
mainfrom
agent/1187-controller-pr-trigger
Nov 20, 2026
Merged

Birfy merged 2 commits into
mainfrom
agent/1187-controller-pr-trigger

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1187.

What changed

.github/workflows/controller.yml:

  • adds pull_request: types: [opened, ready_for_review, reopened]; the cron moves from '7,37 * * * *' to '17 */6 * * *', and workflow_dispatch stays for hand dispatch. The half-hourly schedule declared 48 slots a day and in practice ran 3 times on 2026-11-19 and twice on 2026-11-20 (the schedule runs of this workflow, read from the Actions API), so immediacy comes from the PR events and the six-hourly cron is a backstop only.
    It has already fired on this PR: run 44773778580, event: pull_request, created_at 2026-11-20T16:28:42Z, head_sha cd5a608b…, conclusion success — plan and apply both succeeded, and the PR carried agent-pr + risk:T3 from 16:29:04Z, with no cron and no manual dispatch.
  • plan and apply carry the same-repo guard github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository. Under pull_request a fork head gets a read-only token, so it must not reach the write path — not even to fail there — and plan would otherwise hand it a live plan. apply keeps needs.plan.outputs.live + CONTROLLER_LIVE + AGENT_PAUSE with the guard parenthesised.
  • permissions unchanged: top-level permissions: {}, plan {contents: read, issues: read, pull-requests: read}, apply {contents: read, issues: write, pull-requests: write}; both jobs still pin ref: ${{ github.event.repository.default_branch }}; no secrets and no pull_request_target.

A fork head is not labelled by its own PR event; the schedule backstop and manual dispatch behave exactly as today, so a fork PR's visible behaviour is unchanged.

.github/scripts/controller.py is untouched: main() reads only GH_REPO, CONTROLLER_LIVE, AGENT_PAUSE, PLAN, GITHUB_STEP_SUMMARY and GITHUB_OUTPUT, and lists PRs through the API, so it does not depend on an event payload a pull_request event lacks.

Tests (tests/test_process_controller.py): test_workflow_shape now asserts the three trigger types exactly, the cron literal 17 */6 * * * (a silent return to the half-hourly cron turns it red), the unchanged permission maps and the default-branch pin on both jobs; test_a_fork_head_never_reaches_the_label_jobs asserts the guard text on plan and apply, so deleting it turns the test red; test_no_workflow_uses_pull_request_target parses every workflow's on: map rather than grepping the file, because risk-tier.yml and review-gate.yml mention the string only in comments.

Behaviour is still label-only: no comment, no approval, no merge, no close. CONTROLLER_LIVE/AGENT_PAUSE still gate apply, and concurrency: group: controller / cancel-in-progress: false are unchanged.

Red first at 050235a4

Clean worktree at 050235a4 with only this tip's test file copied in (git status --short → M tests/test_process_controller.py):

pytest tests/test_process_controller.py -o addopts="" -q
→ 2 failed, 31 passed
  • test_workflow_shape — AssertionError: set(on) is {"schedule", "workflow_dispatch"}; the pull_request key does not exist.
  • test_a_fork_head_never_reaches_the_label_jobs — KeyError: 'if' at tests/test_process_controller.py:298: the base plan job has no if, so the guard cannot be read.

The cron assertion is guarded on its own: at this tip, changing only the cron literal back to '7,37 * * * *' gives

pytest tests/test_process_controller.py::test_workflow_shape -o addopts="" -q
→ 1 failed
assert [{'cron': '7,37 * * * *'}] == [{'cron': '17 */6 * * *'}]

At this tip the same file gives 33 passed; the nine-file focused set gives 123 passed.

Tip SHA: b505832

Ran:

  • pytest tests/test_process_controller.py at this tip → 33 passed
  • focused set (test_process_controller, test_workflow_actions_pinned, test_docs_workflow_concurrency, test_publish_npm_workflow, test_changelog_fragments, test_process_labels, test_process_risk_gate, test_process_review_gate, test_process_merge_lane_base) → 123 passed
  • python -m tools.changelog_fragments check → 7 changelog fragment(s) OK
  • full offline suite at d1273f8, the same tree before the rebase onto 050235a4 (the cron literal, its comment and one test assertion are the only delta since) → 7937 passed, 32 failed, 29 skipped; all 32 ids are environment rows already red at the old base f5017f93 (15 test_era_* with no numpy in the sandbox runner, 12 test_sandbox_container with no Docker daemon, 2 test_integrations, test_genesis_example::test_a_shared_toolchain_directory_is_not_mounted, test_merge_golden, test_test_package_resolution)

Not run:

  • full offline suite at this exact tip — the only delta since the d1273f8 run is the cron literal, its comment and one test assertion; the focused set above was re-run at b5058326
  • Docker sandbox rows and the wheel smoke — host environment, unrelated to a workflow trigger
  • mkdocs build --strict — no docs/ or mkdocs.yml change

No UI surface: workflow trigger and its tests only.

@HugoXK HugoXK added enhancement New feature or request area:ci CI workflows, release, packaging and the repo process (.github/, AGENTS.md) labels Nov 20, 2026
@github-actions github-actions Bot added risk:T3 Risk tier T3 (core loop, release, process; needs Danyang's click), set by the controller agent-pr Pull request opened by an agent labels Nov 20, 2026
The schedule is throttled to 2-3 runs a day here, so a new PR can wait
hours for `agent-pr`. Run the controller on `pull_request` opened,
ready_for_review and reopened as well; the cron stays as the fallback.

A fork head's `pull_request` run gets a read-only token, so both jobs
skip it rather than fail on the first label write; fork PRs keep being
labelled by the cron.

Fixes #1187
@Birfy

Birfy commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Review (Birfy)

Tip SHA: b505832
Ran:

  • .github/scripts/risk_gate.py --repo ThinkFlowLab/agentdescent --pr 1194 → T3 (.github/workflows/controller.yml; 61 lines / 3 files)
  • pytest -o addopts="" -p no:cacheprovider -q tests/test_process_controller.py tests/test_controller.py tests/test_workflow_actions_pinned.py tests/test_process_labels.py tests/test_process_risk_gate.py tests/test_process_review_gate.py tests/test_changelog_fragments.py tests/test_safety_controller.py at this tip → 137 passed
  • python -m tools.changelog_fragments check → 7 changelog fragment(s) OK
  • Required CI at this tip → green (build, test (3.9)–test (3.13), otel-wire; deploy skipped; risk tier / reviewed tip report-only)
    Not run:
  • Full offline suite locally — the CI test matrix is the line
  • mkdocs build --strict — no docs/ or mkdocs.yml change in the diff
    Findings:
  • No actionable defects. The new pull_request triggers (opened, ready_for_review, reopened) label same-repo PRs immediately; both plan and apply skip a fork-head pull_request (read-only token), and the cron becomes a four-a-day backstop. The repo-wide assertion that no workflow uses pull_request_target is the right guard.
  • Non-blocking follow-up: AGENTS.md still says the controller "runs every 30 minutes". This PR is what makes that sentence stale; I'll fix it in a small follow-up after merge, rather than block this tip.
    Verdict: PASS

@Birfy
Birfy merged commit fa9d754 into main Nov 20, 2026
10 checks passed
@Birfy
Birfy deleted the agent/1187-controller-pr-trigger branch November 20, 2026 22:25
Birfy pushed a commit that referenced this pull request Nov 20, 2026
Fixes #1192.

## What changed

`.github/scripts/controller.py`:

- `read_prs` records `draft` from the pull list it already fetches — no
extra API request.
- `plan` skips a draft PR right after `hold`, with reason `draft` in the
existing `skipped` shape: `{"number": n, "label": "*", "reason":
"draft"}`. A skip is no add and no remove, so a draft keeps the labels
it already has; `hold` is still checked first, so an operator-held draft
reports `hold`.
- no new plan key: `plan()` still returns `{"ops", "skipped", "notes"}`,
`render` prints the entry as `- #20 `?`: draft`, `validate_plan` and
`apply` see exactly today's plan. `apply` is unchanged, so a PR
converted to draft between plan and apply can still take one round of
labels; that window is a recorded known gap, not fixed here.

`AGENTS.md`: the controller paragraph now says "open non-draft PRs"
instead of "open PRs" — the one clause this change makes stale.

`changelog.d/1192-draft-skip.md`: `Fixed`.

## Why this is live, not hypothetical

Run `44773778580` (`event: pull_request`, `created_at
2026-11-20T16:28:42Z`, `head_sha cd5a608…`) was `#1194`'s own `opened`
event executing that branch's new trigger with main's script. Its `plan`
job reported "4 operation(s), 0 skipped" (`16:28:54Z`) and `apply`
succeeded; the labels landed as `#1194` `agent-pr` + `risk:T3` from
`16:29:04Z` and the parked draft `#1191` `risk:T2` at `16:29:05Z`,
`agent-pr` at `16:29:06Z` — no cron, no dispatch. Once `#1187` merges,
every `opened`/`ready_for_review`/`reopened` fires that full pass, so
skipping drafts in `plan` is what keeps a parked draft out of the queue.

## Red first at `050235a4`

Clean worktree at `050235a4` with only the new test file copied in (`git
status --short` → `?? tests/test_process_controller_draft.py`):

```
pytest tests/test_process_controller_draft.py -o addopts="" -q
→ 4 failed, 1 passed
```

- `test_read_prs_records_the_draft_flag_it_already_fetches` — `KeyError:
'draft'`: the base record has no such field.
- `test_a_draft_pr_is_skipped_and_keeps_the_labels_it_has` — base
`plan()` for a `draft: true` PR returns `add risk:T2` + `add agent-pr`
with `skipped: []`.
- `test_a_ready_pr_next_to_it_is_labelled_normally` — the same ops
appear beside the `draft: false` control row, which must stay untouched.
- `test_the_draft_reason_needs_no_new_plan_key_and_renders` — the base
renders `| PR #30 | add | risk:T2 | risk-tier |` where the skip belongs.

The one pass is the `hold` control, which must hold before and after.

At this tip: 144 passed in the ten-file focused set; `python -m
tools.changelog_fragments check` → 7 fragments OK. Full offline suite on
the pre-rebase tree (`b64388b0`, identical diff): 7940 passed, 32
failed, 29 skipped — the same 32 environment rows red at the base (15
`test_era_*` without numpy in the sandbox runner, 12
`test_sandbox_container` without a Docker daemon, 2 `test_integrations`,
`test_genesis_example::test_a_shared_toolchain_directory_is_not_mounted`,
`test_merge_golden`, `test_test_package_resolution`).

Tip SHA: 83bae39

Ran:
- the ten-file focused set (`test_process_controller`,
`test_process_controller_draft`, `test_controller`,
`test_workflow_actions_pinned`, `test_process_labels`,
`test_process_risk_gate`, `test_process_review_gate`,
`test_process_merge_lane_base`, `test_changelog_fragments`,
`test_safety_controller`) at this tip → 144 passed
- `python -m tools.changelog_fragments check` → 7 changelog fragment(s)
OK
- full offline suite at `b64388b0`, the same diff before the rebase onto
`050235a4` → 7940 passed, 32 failed, 29 skipped, the same 32 ids red at
the base

Not run:
- full offline suite at this exact tip — the rebase replayed `b64388b0`
onto `050235a4`; the focused set was re-run at the tip
- Docker sandbox rows and the wheel smoke — host environment, unrelated
to a label filter
- `mkdocs build --strict` — no `docs/` or `mkdocs.yml` change

No UI surface: the controller script, its tests, and one clause in
AGENTS.md.
Birfy added a commit that referenced this pull request Nov 20, 2026
Closes #1197.

## What changed

After #1194 the label controller is event-driven, but two sentences in
`AGENTS.md` and the `tests/test_process_controller.py` module docstring
still said it ran every 30 minutes.

- Merge policy: the controller sets `risk:T*` on `opened` /
`ready_for_review` / `reopened` for a same-repo PR, or on the next
four-a-day cron tick for a fork PR.
- Controller section: it runs on those `pull_request` events (a
fork-head run is skipped) and on a four-a-day cron backstop.
- The test module docstring matches that schedule.

No change to `controller.yml` or `controller.py`.

`changelog.d/1197-controller-schedule-docs.md`: `Changed`.

## Stale text at `8d75685a`

On current main, the sentences this PR replaces are still the pre-#1194
wording:

- `AGENTS.md`: "the controller sets the `risk:T*` label within ~30
minutes."
- `AGENTS.md`: the Controller section "runs every 30 minutes".
- `tests/test_process_controller.py`: "It runs every 30 minutes with a
write token…"

Tip SHA: 9742081

Ran:
- `python -m tools.changelog_fragments check` → 9 changelog fragment(s)
OK
- `pytest -o addopts="" -p no:cacheprovider -q
tests/test_process_controller.py tests/test_process_controller_draft.py
tests/test_changelog_fragments.py` at this tip → 83 passed

Not run:
- Full offline suite / test matrix — docstring and process-doc wording
only
- `mkdocs build --strict` — no `docs/` or `mkdocs.yml` change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-pr Pull request opened by an agent area:ci CI workflows, release, packaging and the repo process (.github/, AGENTS.md) enhancement New feature or request risk:T3 Risk tier T3 (core loop, release, process; needs Danyang's click), set by the controller

Projects

None yet

Development

Successfully merging this pull request may close these issues.

controller.yml labels PRs only on a cron, so a new PR can wait hours for agent-pr

2 participants