Repository navigation
ci(controller): label PRs on their lifecycle events - #1194
Merged
Merged
Conversation
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
Collaborator
|
Review (Birfy) Tip SHA: b505832
|
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.
This was referenced Nov 20, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1187.
What changed
.github/workflows/controller.yml:pull_request: types: [opened, ready_for_review, reopened]; the cron moves from'7,37 * * * *'to'17 */6 * * *', andworkflow_dispatchstays 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 (thescheduleruns 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…, conclusionsuccess—planandapplyboth succeeded, and the PR carriedagent-pr+risk:T3from16:29:04Z, with no cron and no manual dispatch.planandapplycarry the same-repo guardgithub.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository. Underpull_requesta fork head gets a read-only token, so it must not reach the write path — not even to fail there — andplanwould otherwise hand it a live plan.applykeepsneeds.plan.outputs.live+CONTROLLER_LIVE+AGENT_PAUSEwith the guard parenthesised.permissions: {},plan{contents: read, issues: read, pull-requests: read},apply{contents: read, issues: write, pull-requests: write}; both jobs still pinref: ${{ github.event.repository.default_branch }}; no secrets and nopull_request_target.A fork head is not labelled by its own PR event; the
schedulebackstop and manual dispatch behave exactly as today, so a fork PR's visible behaviour is unchanged..github/scripts/controller.pyis untouched:main()reads onlyGH_REPO,CONTROLLER_LIVE,AGENT_PAUSE,PLAN,GITHUB_STEP_SUMMARYandGITHUB_OUTPUT, and lists PRs through the API, so it does not depend on an event payload apull_requestevent lacks.Tests (
tests/test_process_controller.py):test_workflow_shapenow asserts the three trigger types exactly, the cron literal17 */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_jobsasserts the guard text onplanandapply, so deleting it turns the test red;test_no_workflow_uses_pull_request_targetparses every workflow'son:map rather than grepping the file, becauserisk-tier.ymlandreview-gate.ymlmention the string only in comments.Behaviour is still label-only: no comment, no approval, no merge, no close.
CONTROLLER_LIVE/AGENT_PAUSEstill gateapply, andconcurrency: group: controller/cancel-in-progress: falseare unchanged.Red first at
050235a4Clean worktree at
050235a4with only this tip's test file copied in (git status --short→M tests/test_process_controller.py):test_workflow_shape—AssertionError:set(on)is{"schedule", "workflow_dispatch"}; thepull_requestkey does not exist.test_a_fork_head_never_reaches_the_label_jobs—KeyError: 'if'attests/test_process_controller.py:298: the baseplanjob has noif, 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 * * * *'givesAt this tip the same file gives
33 passed; the nine-file focused set gives123 passed.Tip SHA: b505832
Ran:
pytest tests/test_process_controller.pyat this tip → 33 passedtest_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 passedpython -m tools.changelog_fragments check→ 7 changelog fragment(s) OKd1273f8, the same tree before the rebase onto050235a4(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 basef5017f93(15test_era_*with no numpy in the sandbox runner, 12test_sandbox_containerwith no Docker daemon, 2test_integrations,test_genesis_example::test_a_shared_toolchain_directory_is_not_mounted,test_merge_golden,test_test_package_resolution)Not run:
d1273f8run is the cron literal, its comment and one test assertion; the focused set above was re-run atb5058326mkdocs build --strict— nodocs/ormkdocs.ymlchangeNo UI surface: workflow trigger and its tests only.